pornovoisines.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. float_or_none,
  5. unified_strdate,
  6. )
  7. class PornoVoisinesIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?pornovoisines\.com/videos/show/(?P<id>\d+)/(?P<display_id>[^/.]+)'
  9. _TEST = {
  10. 'url': 'http://www.pornovoisines.com/videos/show/919/recherche-appartement.html',
  11. 'md5': '6f8aca6a058592ab49fe701c8ba8317b',
  12. 'info_dict': {
  13. 'id': '919',
  14. 'display_id': 'recherche-appartement',
  15. 'ext': 'mp4',
  16. 'title': 'Recherche appartement',
  17. 'description': 'md5:fe10cb92ae2dd3ed94bb4080d11ff493',
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. 'upload_date': '20140925',
  20. 'duration': 120,
  21. 'view_count': int,
  22. 'average_rating': float,
  23. 'categories': ['Débutante', 'Débutantes', 'Scénario', 'Sodomie'],
  24. 'age_limit': 18,
  25. 'subtitles': {
  26. 'fr': [{
  27. 'ext': 'vtt',
  28. }]
  29. },
  30. }
  31. }
  32. def _real_extract(self, url):
  33. mobj = self._match_valid_url(url)
  34. video_id = mobj.group('id')
  35. display_id = mobj.group('display_id')
  36. settings_url = self._download_json(
  37. 'http://www.pornovoisines.com/api/video/%s/getsettingsurl/' % video_id,
  38. video_id, note='Getting settings URL')['video_settings_url']
  39. settings = self._download_json(settings_url, video_id)['data']
  40. formats = []
  41. for kind, data in settings['variants'].items():
  42. if kind == 'HLS':
  43. formats.extend(self._extract_m3u8_formats(
  44. data, video_id, ext='mp4', entry_protocol='m3u8_native', m3u8_id='hls'))
  45. elif kind == 'MP4':
  46. for item in data:
  47. formats.append({
  48. 'url': item['url'],
  49. 'height': item.get('height'),
  50. 'bitrate': item.get('bitrate'),
  51. })
  52. webpage = self._download_webpage(url, video_id)
  53. title = self._og_search_title(webpage)
  54. description = self._og_search_description(webpage)
  55. # The webpage has a bug - there's no space between "thumb" and src=
  56. thumbnail = self._html_search_regex(
  57. r'<img[^>]+class=([\'"])thumb\1[^>]*src=([\'"])(?P<url>[^"]+)\2',
  58. webpage, 'thumbnail', fatal=False, group='url')
  59. upload_date = unified_strdate(self._search_regex(
  60. r'Le\s*<b>([\d/]+)', webpage, 'upload date', fatal=False))
  61. duration = settings.get('main', {}).get('duration')
  62. view_count = int_or_none(self._search_regex(
  63. r'(\d+) vues', webpage, 'view count', fatal=False))
  64. average_rating = self._search_regex(
  65. r'Note\s*:\s*(\d+(?:,\d+)?)', webpage, 'average rating', fatal=False)
  66. if average_rating:
  67. average_rating = float_or_none(average_rating.replace(',', '.'))
  68. categories = self._html_search_regex(
  69. r'(?s)Catégories\s*:\s*<b>(.+?)</b>', webpage, 'categories', fatal=False)
  70. if categories:
  71. categories = [category.strip() for category in categories.split(',')]
  72. subtitles = {'fr': [{
  73. 'url': subtitle,
  74. } for subtitle in settings.get('main', {}).get('vtt_tracks', {}).values()]}
  75. return {
  76. 'id': video_id,
  77. 'display_id': display_id,
  78. 'formats': formats,
  79. 'title': title,
  80. 'description': description,
  81. 'thumbnail': thumbnail,
  82. 'upload_date': upload_date,
  83. 'duration': duration,
  84. 'view_count': view_count,
  85. 'average_rating': average_rating,
  86. 'categories': categories,
  87. 'age_limit': 18,
  88. 'subtitles': subtitles,
  89. }