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.

97 lines
3.1 KiB

  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. mimetype2ext,
  8. parse_codecs,
  9. xpath_element,
  10. xpath_text,
  11. )
  12. class VideaIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. https?://
  15. videa\.hu/
  16. (?:
  17. videok/(?:[^/]+/)*[^?#&]+-|
  18. player\?.*?\bv=|
  19. player/v/
  20. )
  21. (?P<id>[^?#&]+)
  22. '''
  23. _TESTS = [{
  24. 'url': 'http://videa.hu/videok/allatok/az-orult-kigyasz-285-kigyot-kigyo-8YfIAjxwWGwT8HVQ',
  25. 'md5': '97a7af41faeaffd9f1fc864a7c7e7603',
  26. 'info_dict': {
  27. 'id': '8YfIAjxwWGwT8HVQ',
  28. 'ext': 'mp4',
  29. 'title': 'Az őrült kígyász 285 kígyót enged szabadon',
  30. 'thumbnail': 'http://videa.hu/static/still/1.4.1.1007274.1204470.3',
  31. 'duration': 21,
  32. },
  33. }, {
  34. 'url': 'http://videa.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://videa.hu/player?v=8YfIAjxwWGwT8HVQ',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://videa.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1',
  41. 'only_matching': True,
  42. }]
  43. @staticmethod
  44. def _extract_urls(webpage):
  45. return [url for _, url in re.findall(
  46. r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//videa\.hu/player\?.*?\bv=.+?)\1',
  47. webpage)]
  48. def _real_extract(self, url):
  49. video_id = self._match_id(url)
  50. info = self._download_xml(
  51. 'http://videa.hu/videaplayer_get_xml.php', video_id,
  52. query={'v': video_id})
  53. video = xpath_element(info, './/video', 'video', fatal=True)
  54. sources = xpath_element(info, './/video_sources', 'sources', fatal=True)
  55. title = xpath_text(video, './title', fatal=True)
  56. formats = []
  57. for source in sources.findall('./video_source'):
  58. source_url = source.text
  59. if not source_url:
  60. continue
  61. f = parse_codecs(source.get('codecs'))
  62. f.update({
  63. 'url': source_url,
  64. 'ext': mimetype2ext(source.get('mimetype')) or 'mp4',
  65. 'format_id': source.get('name'),
  66. 'width': int_or_none(source.get('width')),
  67. 'height': int_or_none(source.get('height')),
  68. })
  69. formats.append(f)
  70. self._sort_formats(formats)
  71. thumbnail = xpath_text(video, './poster_src')
  72. duration = int_or_none(xpath_text(video, './duration'))
  73. age_limit = None
  74. is_adult = xpath_text(video, './is_adult_content', default=None)
  75. if is_adult:
  76. age_limit = 18 if is_adult == '1' else 0
  77. return {
  78. 'id': video_id,
  79. 'title': title,
  80. 'thumbnail': thumbnail,
  81. 'duration': duration,
  82. 'age_limit': age_limit,
  83. 'formats': formats,
  84. }