You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.8 KiB

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