logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

indavideo.py (4415B)


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