videa.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_duration,
  8. xpath_element,
  9. xpath_text,
  10. xpath_attr,
  11. urlencode_postdata,
  12. unescapeHTML,
  13. )
  14. class VideaIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:.+?\.)?videa\.hu/videok/(?P<id>[^#?]+)'
  16. _TESTS = [{
  17. 'url': 'http://videa.hu/videok/allatok/az-orult-kigyasz-285-kigyot-kigyo-8YfIAjxwWGwT8HVQ',
  18. 'md5': '97a7af41faeaffd9f1fc864a7c7e7603',
  19. 'info_dict': {
  20. 'id': '8YfIAjxwWGwT8HVQ',
  21. 'display_id': '8YfIAjxwWGwT8HVQ',
  22. 'ext': 'mp4',
  23. 'title': 'Az őrült kígyász 285 kígyót enged szabadon',
  24. 'thumbnail': 'http://videa.hu/static/still/1.4.1.1007274.1204470.3',
  25. 'duration': 21,
  26. },
  27. }, {
  28. 'url': 'http://videa.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH',
  29. 'only_matching': True,
  30. }]
  31. def _real_extract(self, url):
  32. video_id = self._match_id(url)
  33. video_data = self._download_json("http://videa.hu/oembed/?" + urlencode_postdata({"url": url.split('?')[0], "format": "json"}), video_id)
  34. video_url = self._search_regex(
  35. r'src="(.+?)"', video_data.get('html'), 'embed url')
  36. return {
  37. '_type': 'url_transparent',
  38. 'url': video_url,
  39. 'ie_key': 'VideaEmbed'
  40. }
  41. class VideaEmbedIE(InfoExtractor):
  42. _VALID_URL = r'(?P<protocol>https?:)(?P<baseurl>//(?:.+?\.)?videa\.hu)/player(?:\?v=|/v/)(?P<id>[^/#?]+)';
  43. _TESTS = [{
  44. 'url': 'http://videa.hu/player?v=8YfIAjxwWGwT8HVQ',
  45. 'md5': '97a7af41faeaffd9f1fc864a7c7e7603',
  46. 'info_dict': {
  47. 'id': '8YfIAjxwWGwT8HVQ',
  48. 'ext': 'mp4',
  49. 'title': 'Az őrült kígyász 285 kígyót enged szabadon',
  50. 'thumbnail': 'http://videa.hu/static/still/1.4.1.1007274.1204470.3',
  51. 'duration': 21
  52. },
  53. }, {
  54. 'url': 'http://videa.hu/player?v=jAHDWfWSJH5XuFhH',
  55. 'only_matching': True,
  56. }];
  57. @staticmethod
  58. def _extract_url(webpage):
  59. mobj = re.search(
  60. r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:.+?\.)?videa\.hu/player(?:\?v=|/v/)[^/#?]+)\1',
  61. webpage)
  62. if mobj:
  63. return mobj.group('url')
  64. def _real_extract(self, url):
  65. protocol, base_url, display_id = re.search(self._VALID_URL, url).groups()
  66. xml = self._download_xml(protocol + base_url + "/flvplayer_get_video_xml.php?v=" + display_id, display_id)
  67. medias = []
  68. for xml_media in xml.findall('video') + xml.findall('audio'):
  69. media_url = protocol + xpath_attr(xml_media, 'versions/version', 'video_url')
  70. media = {
  71. 'id': display_id,
  72. 'ext': 'mp4',
  73. 'title': xpath_text(xml_media, 'title', 'title', True),
  74. 'duration': parse_duration(xpath_text(xml_media, 'duration')),
  75. 'thumbnail': protocol + xpath_text(xml_media, 'still', 'still', True),
  76. 'url': media_url,
  77. }
  78. medias.append(media)
  79. if len(medias) > 1:
  80. self._downloader.report_warning(
  81. 'found multiple medias; please '
  82. 'report this with the video URL to http://yt-dl.org/bug')
  83. if not medias:
  84. raise ExtractorError('No media entries found')
  85. return medias[0]