pornovoisines.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import datetime
  5. import random
  6. from ..compat import compat_urllib_parse
  7. from .common import InfoExtractor
  8. class PornoVoisinesIE(InfoExtractor):
  9. _VALID_URL = r'^((?:http://)?(?:www\.)?pornovoisines.com)/showvideo/(\d+)/([^/]+)'
  10. VIDEO_URL_TEMPLATE = 'http://stream%d.pornovoisines.com' \
  11. '/static/media/video/transcoded/%s-640x360-1000-trscded.mp4'
  12. SERVER_NUMBERS = (1, 2)
  13. _TEST = {
  14. 'url': 'http://www.pornovoisines.com/showvideo/1285/recherche-appartement/',
  15. 'md5': '5ac670803bc12e9e7f9f662ce64cf1d1',
  16. 'info_dict': {
  17. 'id': '1285',
  18. 'display_id': 'recherche-appartement',
  19. 'ext': 'mp4',
  20. 'title': "Recherche appartement",
  21. 'upload_date': '20140925',
  22. 'view_count': int,
  23. 'duration': 120,
  24. 'categories': ["Débutante", "Scénario", "Sodomie"],
  25. 'description': 're:^Pour la .+ original...$',
  26. 'thumbnail': 're:^http://',
  27. 'uploader': "JMTV",
  28. 'average_rating': float,
  29. 'comment_count': int,
  30. 'age_limit': 18,
  31. }
  32. }
  33. @classmethod
  34. def build_video_url(cls, id):
  35. server_nr = random.choice(cls.SERVER_NUMBERS)
  36. return cls.VIDEO_URL_TEMPLATE % (server_nr, id)
  37. @staticmethod
  38. def parse_upload_date(str):
  39. return datetime.datetime.strptime(str, "%d-%m-%Y").strftime("%Y%m%d")
  40. @staticmethod
  41. def parse_categories(str):
  42. return map(lambda s: s.strip(), str.split(','))
  43. def _real_extract(self, url):
  44. mobj = re.match(self._VALID_URL, url)
  45. url_prefix = mobj.group(1)
  46. id = mobj.group(2)
  47. display_id = mobj.group(3)
  48. webpage = self._download_webpage(url, id)
  49. title = self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title',
  50. flags=re.DOTALL)
  51. url = self.build_video_url(id)
  52. upload_date = self.parse_upload_date(
  53. self._search_regex(r'Publié le (\d\d-\d\d-\d{4})', webpage,
  54. 'upload date'))
  55. view_count = int(self._search_regex(r'(\d+) vues', webpage, 'view count'))
  56. duration = int(self._search_regex('Durée (\d+)', webpage, 'duration'))
  57. categories = self.parse_categories(self._html_search_regex(
  58. r'<li class="categorie">(.+?)</li>', webpage, "categories",
  59. flags=re.DOTALL))
  60. description = self._html_search_regex(
  61. r'<article id="descriptif">(.+?)</article>', webpage, "description",
  62. flags=re.DOTALL)
  63. thumbnail = url_prefix + self._html_search_regex(re.compile(
  64. '<div id="mediaspace' + id + '">.*?<img src="(.+?)"', re.DOTALL),
  65. webpage, "thumbnail")
  66. uploader = re.sub(r' *\| *$', '',
  67. self._html_search_regex(r'<li class="auteur">(.+?)</li>', webpage,
  68. "uploader", flags=re.DOTALL))
  69. average_rating = float(self._search_regex(r'Note : (\d+,\d+)',
  70. webpage, "average rating").replace(',', '.'))
  71. comment_count = int(self._search_regex(r'\((\d+)\)', webpage,
  72. "comment count"))
  73. return {
  74. 'id': id,
  75. 'display_id': display_id,
  76. 'url': url,
  77. 'title': title,
  78. 'upload_date': upload_date,
  79. 'view_count': view_count,
  80. 'duration': duration,
  81. 'categories': categories,
  82. 'description': description,
  83. 'thumbnail': thumbnail,
  84. 'uploader': uploader,
  85. 'average_rating': average_rating,
  86. 'comment_count': comment_count,
  87. 'age_limit': 18,
  88. }