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.

106 lines
3.4 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(?:kid)?\.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': r're:^https?://.*',
  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. 'url': 'https://videakid.hu/videok/origo/jarmuvek/supercars-elozes-jAHDWfWSJH5XuFhH',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'https://videakid.hu/player?v=8YfIAjxwWGwT8HVQ',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'https://videakid.hu/player/v/8YfIAjxwWGwT8HVQ?autoplay=1',
  50. 'only_matching': True,
  51. }]
  52. @staticmethod
  53. def _extract_urls(webpage):
  54. return [url for _, url in re.findall(
  55. r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//videa\.hu/player\?.*?\bv=.+?)\1',
  56. webpage)]
  57. def _real_extract(self, url):
  58. video_id = self._match_id(url)
  59. info = self._download_xml(
  60. 'http://videa.hu/videaplayer_get_xml.php', video_id,
  61. query={'v': video_id})
  62. video = xpath_element(info, './/video', 'video', fatal=True)
  63. sources = xpath_element(info, './/video_sources', 'sources', fatal=True)
  64. title = xpath_text(video, './title', fatal=True)
  65. formats = []
  66. for source in sources.findall('./video_source'):
  67. source_url = source.text
  68. if not source_url:
  69. continue
  70. f = parse_codecs(source.get('codecs'))
  71. f.update({
  72. 'url': source_url,
  73. 'ext': mimetype2ext(source.get('mimetype')) or 'mp4',
  74. 'format_id': source.get('name'),
  75. 'width': int_or_none(source.get('width')),
  76. 'height': int_or_none(source.get('height')),
  77. })
  78. formats.append(f)
  79. self._sort_formats(formats)
  80. thumbnail = xpath_text(video, './poster_src')
  81. duration = int_or_none(xpath_text(video, './duration'))
  82. age_limit = None
  83. is_adult = xpath_text(video, './is_adult_content', default=None)
  84. if is_adult:
  85. age_limit = 18 if is_adult == '1' else 0
  86. return {
  87. 'id': video_id,
  88. 'title': title,
  89. 'thumbnail': thumbnail,
  90. 'duration': duration,
  91. 'age_limit': age_limit,
  92. 'formats': formats,
  93. }