indavideo.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. parse_age_limit,
  5. parse_iso8601,
  6. time_seconds,
  7. update_url_query,
  8. )
  9. class IndavideoEmbedIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:(?:embed\.)?indavideo\.hu/player/video/|assets\.indavideo\.hu/swf/player\.swf\?.*\b(?:v(?:ID|id))=)(?P<id>[\da-f]+)'
  11. # Some example URLs covered by generic extractor:
  12. # https://indavideo.hu/video/Vicces_cica_1
  13. # https://index.indavideo.hu/video/Hod_Nemetorszagban
  14. # https://auto.indavideo.hu/video/Sajat_utanfutoban_a_kis_tacsko
  15. # https://film.indavideo.hu/video/f_farkaslesen
  16. # https://palyazat.indavideo.hu/video/Embertelen_dal_Dodgem_egyuttes
  17. _EMBED_REGEX = [r'<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)//embed\.indavideo\.hu/player/video/[\da-f]+)']
  18. _TESTS = [{
  19. 'url': 'https://indavideo.hu/player/video/1bdc3c6d80/',
  20. 'md5': 'c8a507a1c7410685f83a06eaeeaafeab',
  21. 'info_dict': {
  22. 'id': '1837039',
  23. 'ext': 'mp4',
  24. 'title': 'Cicatánc',
  25. 'description': '',
  26. 'thumbnail': r're:^https?://.*\.jpg$',
  27. 'uploader': 'cukiajanlo',
  28. 'uploader_id': '83729',
  29. 'timestamp': 1439193826,
  30. 'upload_date': '20150810',
  31. 'duration': 72,
  32. 'age_limit': 0,
  33. 'tags': ['tánc', 'cica', 'cuki', 'cukiajanlo', 'newsroom'],
  34. },
  35. }, {
  36. 'url': 'https://embed.indavideo.hu/player/video/1bdc3c6d80?autostart=1&hide=1',
  37. 'only_matching': True,
  38. }]
  39. _WEBPAGE_TESTS = [{
  40. 'url': 'https://indavideo.hu/video/Vicces_cica_1',
  41. 'info_dict': {
  42. 'id': '1335611',
  43. 'ext': 'mp4',
  44. 'title': 'Vicces cica',
  45. 'description': 'Játszik a tablettel. :D',
  46. 'thumbnail': r're:^https?://.*\.jpg$',
  47. 'uploader': 'Jet_Pack',
  48. 'uploader_id': '491217',
  49. 'timestamp': 1390821212,
  50. 'upload_date': '20140127',
  51. 'duration': 7,
  52. 'age_limit': 0,
  53. 'tags': ['cica', 'Jet_Pack'],
  54. },
  55. }]
  56. def _real_extract(self, url):
  57. video_id = self._match_id(url)
  58. video = self._download_json(
  59. f'https://amfphp.indavideo.hu/SYm0json.php/player.playerHandler.getVideoData/{video_id}/',
  60. video_id, query={'_': time_seconds()})['data']
  61. video_urls = []
  62. video_files = video.get('video_files')
  63. if isinstance(video_files, list):
  64. video_urls.extend(video_files)
  65. elif isinstance(video_files, dict):
  66. video_urls.extend(video_files.values())
  67. video_urls = list(set(video_urls))
  68. filesh = video.get('filesh') or {}
  69. formats = []
  70. for video_url in video_urls:
  71. height = int_or_none(self._search_regex(
  72. r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None))
  73. if not height and len(filesh) == 1:
  74. height = int_or_none(next(iter(filesh.keys())))
  75. token = filesh.get(str(height))
  76. if token is None:
  77. continue
  78. formats.append({
  79. 'url': update_url_query(video_url, {'token': token}),
  80. 'height': height,
  81. })
  82. timestamp = video.get('date')
  83. if timestamp:
  84. # upload date is in CEST
  85. timestamp = parse_iso8601(timestamp + ' +0200', ' ')
  86. thumbnails = [{
  87. 'url': self._proto_relative_url(thumbnail),
  88. } for thumbnail in video.get('thumbnails', [])]
  89. tags = [tag['title'] for tag in video.get('tags') or []]
  90. return {
  91. 'id': video.get('id') or video_id,
  92. 'title': video.get('title'),
  93. 'description': video.get('description'),
  94. 'thumbnails': thumbnails,
  95. 'uploader': video.get('user_name'),
  96. 'uploader_id': video.get('user_id'),
  97. 'timestamp': timestamp,
  98. 'duration': int_or_none(video.get('length')),
  99. 'age_limit': parse_age_limit(video.get('age_limit')),
  100. 'tags': tags,
  101. 'formats': formats,
  102. }