zapiks.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. parse_duration,
  6. parse_iso8601,
  7. xpath_text,
  8. xpath_with_ns,
  9. )
  10. class ZapiksIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?zapiks\.(?:fr|com)/(?:(?:[a-z]{2}/)?(?P<display_id>.+?)\.html|index\.php\?.*\bmedia_id=(?P<id>\d+))'
  12. _EMBED_REGEX = [r'<iframe[^>]+src="(?P<url>https?://(?:www\.)?zapiks\.fr/index\.php\?.+?)"']
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.zapiks.fr/ep2s3-bon-appetit-eh-be-viva.html',
  16. 'md5': 'aeb3c473b2d564b2d46d664d28d5f050',
  17. 'info_dict': {
  18. 'id': '80798',
  19. 'ext': 'mp4',
  20. 'title': 'EP2S3 - Bon Appétit - Eh bé viva les pyrénées con!',
  21. 'description': 'md5:7054d6f6f620c6519be1fe710d4da847',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'duration': 528,
  24. 'timestamp': 1359044972,
  25. 'upload_date': '20130124',
  26. 'view_count': int,
  27. },
  28. },
  29. {
  30. 'url': 'http://www.zapiks.com/ep3s5-bon-appetit-baqueira-m-1.html',
  31. 'only_matching': True,
  32. },
  33. {
  34. 'url': 'http://www.zapiks.com/nl/ep3s5-bon-appetit-baqueira-m-1.html',
  35. 'only_matching': True,
  36. },
  37. {
  38. 'url': 'http://www.zapiks.fr/index.php?action=playerIframe&amp;media_id=118046&amp;width=640&amp;height=360&amp;autoStart=false&amp;language=fr',
  39. 'only_matching': True,
  40. },
  41. ]
  42. def _real_extract(self, url):
  43. mobj = self._match_valid_url(url)
  44. video_id = mobj.group('id')
  45. display_id = mobj.group('display_id') or video_id
  46. webpage = self._download_webpage(url, display_id)
  47. if not video_id:
  48. video_id = self._search_regex(
  49. r'data-media-id="(\d+)"', webpage, 'video id')
  50. playlist = self._download_xml(
  51. f'http://www.zapiks.fr/view/index.php?action=playlist&media_id={video_id}&lang=en',
  52. display_id)
  53. NS_MAP = {
  54. 'jwplayer': 'http://rss.jwpcdn.com/',
  55. }
  56. def ns(path):
  57. return xpath_with_ns(path, NS_MAP)
  58. item = playlist.find('./channel/item')
  59. title = xpath_text(item, 'title', 'title') or self._og_search_title(webpage)
  60. description = self._og_search_description(webpage, default=None)
  61. thumbnail = xpath_text(
  62. item, ns('./jwplayer:image'), 'thumbnail') or self._og_search_thumbnail(webpage, default=None)
  63. duration = parse_duration(self._html_search_meta(
  64. 'duration', webpage, 'duration', default=None))
  65. timestamp = parse_iso8601(self._html_search_meta(
  66. 'uploadDate', webpage, 'upload date', default=None), ' ')
  67. view_count = int_or_none(self._search_regex(
  68. r'UserPlays:(\d+)', webpage, 'view count', default=None))
  69. comment_count = int_or_none(self._search_regex(
  70. r'UserComments:(\d+)', webpage, 'comment count', default=None))
  71. formats = []
  72. for source in item.findall(ns('./jwplayer:source')):
  73. format_id = source.attrib['label']
  74. f = {
  75. 'url': source.attrib['file'],
  76. 'format_id': format_id,
  77. }
  78. m = re.search(r'^(?P<height>\d+)[pP]', format_id)
  79. if m:
  80. f['height'] = int(m.group('height'))
  81. formats.append(f)
  82. return {
  83. 'id': video_id,
  84. 'title': title,
  85. 'description': description,
  86. 'thumbnail': thumbnail,
  87. 'duration': duration,
  88. 'timestamp': timestamp,
  89. 'view_count': view_count,
  90. 'comment_count': comment_count,
  91. 'formats': formats,
  92. }