indavideo.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. int_or_none,
  7. parse_age_limit,
  8. parse_iso8601,
  9. update_url_query,
  10. )
  11. class IndavideoEmbedIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:(?:embed\.)?indavideo\.hu/player/video/|assets\.indavideo\.hu/swf/player\.swf\?.*\b(?:v(?:ID|id))=)(?P<id>[\da-f]+)'
  13. _TESTS = [{
  14. 'url': 'http://indavideo.hu/player/video/1bdc3c6d80/',
  15. 'md5': 'c8a507a1c7410685f83a06eaeeaafeab',
  16. 'info_dict': {
  17. 'id': '1837039',
  18. 'ext': 'mp4',
  19. 'title': 'Cicatánc',
  20. 'description': '',
  21. 'thumbnail': r're:^https?://.*\.jpg$',
  22. 'uploader': 'cukiajanlo',
  23. 'uploader_id': '83729',
  24. 'timestamp': 1439193826,
  25. 'upload_date': '20150810',
  26. 'duration': 72,
  27. 'age_limit': 0,
  28. 'tags': ['tánc', 'cica', 'cuki', 'cukiajanlo', 'newsroom'],
  29. },
  30. }, {
  31. 'url': 'http://embed.indavideo.hu/player/video/1bdc3c6d80?autostart=1&hide=1',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://assets.indavideo.hu/swf/player.swf?v=fe25e500&vID=1bdc3c6d80&autostart=1&hide=1&i=1',
  35. 'only_matching': True,
  36. }]
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. video = self._download_json(
  40. 'http://amfphp.indavideo.hu/SYm0json.php/player.playerHandler.getVideoData/%s' % video_id,
  41. video_id)['data']
  42. title = video['title']
  43. video_urls = []
  44. video_files = video.get('video_files')
  45. if isinstance(video_files, list):
  46. video_urls.extend(video_files)
  47. elif isinstance(video_files, dict):
  48. video_urls.extend(video_files.values())
  49. video_file = video.get('video_file')
  50. if video:
  51. video_urls.append(video_file)
  52. video_urls = list(set(video_urls))
  53. video_prefix = video_urls[0].rsplit('/', 1)[0]
  54. for flv_file in video.get('flv_files', []):
  55. flv_url = '%s/%s' % (video_prefix, flv_file)
  56. if flv_url not in video_urls:
  57. video_urls.append(flv_url)
  58. filesh = video.get('filesh')
  59. formats = []
  60. for video_url in video_urls:
  61. height = int_or_none(self._search_regex(
  62. r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None))
  63. if filesh:
  64. if not height:
  65. continue
  66. token = filesh.get(compat_str(height))
  67. if token is None:
  68. continue
  69. video_url = update_url_query(video_url, {'token': token})
  70. formats.append({
  71. 'url': video_url,
  72. 'height': height,
  73. })
  74. self._sort_formats(formats)
  75. timestamp = video.get('date')
  76. if timestamp:
  77. # upload date is in CEST
  78. timestamp = parse_iso8601(timestamp + ' +0200', ' ')
  79. thumbnails = [{
  80. 'url': self._proto_relative_url(thumbnail)
  81. } for thumbnail in video.get('thumbnails', [])]
  82. tags = [tag['title'] for tag in video.get('tags') or []]
  83. return {
  84. 'id': video.get('id') or video_id,
  85. 'title': title,
  86. 'description': video.get('description'),
  87. 'thumbnails': thumbnails,
  88. 'uploader': video.get('user_name'),
  89. 'uploader_id': video.get('user_id'),
  90. 'timestamp': timestamp,
  91. 'duration': int_or_none(video.get('length')),
  92. 'age_limit': parse_age_limit(video.get('age_limit')),
  93. 'tags': tags,
  94. 'formats': formats,
  95. }
  96. class IndavideoIE(InfoExtractor):
  97. _VALID_URL = r'https?://(?:.+?\.)?indavideo\.hu/video/(?P<id>[^/#?]+)'
  98. _TESTS = [{
  99. 'url': 'http://indavideo.hu/video/Vicces_cica_1',
  100. 'md5': '8c82244ba85d2a2310275b318eb51eac',
  101. 'info_dict': {
  102. 'id': '1335611',
  103. 'display_id': 'Vicces_cica_1',
  104. 'ext': 'mp4',
  105. 'title': 'Vicces cica',
  106. 'description': 'Játszik a tablettel. :D',
  107. 'thumbnail': r're:^https?://.*\.jpg$',
  108. 'uploader': 'Jet_Pack',
  109. 'uploader_id': '491217',
  110. 'timestamp': 1390821212,
  111. 'upload_date': '20140127',
  112. 'duration': 7,
  113. 'age_limit': 0,
  114. 'tags': list,
  115. },
  116. }, {
  117. 'url': 'http://index.indavideo.hu/video/2015_0728_beregszasz',
  118. 'only_matching': True,
  119. }, {
  120. 'url': 'http://auto.indavideo.hu/video/Sajat_utanfutoban_a_kis_tacsko',
  121. 'only_matching': True,
  122. }, {
  123. 'url': 'http://erotika.indavideo.hu/video/Amator_tini_punci',
  124. 'only_matching': True,
  125. }, {
  126. 'url': 'http://film.indavideo.hu/video/f_hrom_nagymamm_volt',
  127. 'only_matching': True,
  128. }, {
  129. 'url': 'http://palyazat.indavideo.hu/video/Embertelen_dal_Dodgem_egyuttes',
  130. 'only_matching': True,
  131. }]
  132. def _real_extract(self, url):
  133. display_id = self._match_id(url)
  134. webpage = self._download_webpage(url, display_id)
  135. embed_url = self._search_regex(
  136. (r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//embed\.indavideo\.hu/player/video/.+?)\1',
  137. r'<link[^>]+rel="video_src"[^>]+href="(?P<url>.+?)"'),
  138. webpage, 'embed url', group='url')
  139. return {
  140. '_type': 'url_transparent',
  141. 'ie_key': 'IndavideoEmbed',
  142. 'url': embed_url,
  143. 'display_id': display_id,
  144. }