videa.py 2.8 KB

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