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.

152 lines
5.5 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  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. float_or_none,
  8. unescapeHTML,
  9. )
  10. class TudouIE(InfoExtractor):
  11. IE_NAME = 'tudou'
  12. _VALID_URL = r'https?://(?:www\.)?tudou\.com/(?:(?:programs|wlplay)/view|(?:listplay|albumplay)/[\w-]{11})/(?P<id>[\w-]{11})'
  13. _TESTS = [{
  14. 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',
  15. 'md5': '140a49ed444bd22f93330985d8475fcb',
  16. 'info_dict': {
  17. 'id': '159448201',
  18. 'ext': 'f4v',
  19. 'title': '卡马乔国足开大脚长传冲吊集锦',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. 'timestamp': 1372113489000,
  22. 'description': '卡马乔卡家军,开大脚先进战术不完全集锦!',
  23. 'duration': 289.04,
  24. 'view_count': int,
  25. 'filesize': int,
  26. }
  27. }, {
  28. 'url': 'http://www.tudou.com/programs/view/ajX3gyhL0pc/',
  29. 'info_dict': {
  30. 'id': '117049447',
  31. 'ext': 'f4v',
  32. 'title': 'La Sylphide-Bolshoi-Ekaterina Krysanova & Vyacheslav Lopatin 2012',
  33. 'thumbnail': 're:^https?://.*\.jpg$',
  34. 'timestamp': 1349207518000,
  35. 'description': 'md5:294612423894260f2dcd5c6c04fe248b',
  36. 'duration': 5478.33,
  37. 'view_count': int,
  38. 'filesize': int,
  39. }
  40. }]
  41. _PLAYER_URL = 'http://js.tudouui.com/bin/lingtong/PortalPlayer_177.swf'
  42. def _url_for_id(self, video_id, quality=None):
  43. info_url = 'http://v2.tudou.com/f?id=' + compat_str(video_id)
  44. if quality:
  45. info_url += '&hd' + quality
  46. xml_data = self._download_xml(info_url, video_id, 'Opening the info XML page')
  47. final_url = xml_data.text
  48. return final_url
  49. def _real_extract(self, url):
  50. video_id = self._match_id(url)
  51. item_data = self._download_json(
  52. 'http://www.tudou.com/tvp/getItemInfo.action?ic=%s' % video_id, video_id)
  53. youku_vcode = item_data.get('vcode')
  54. if youku_vcode:
  55. return self.url_result('youku:' + youku_vcode, ie='Youku')
  56. title = unescapeHTML(item_data['kw'])
  57. description = item_data.get('desc')
  58. thumbnail_url = item_data.get('pic')
  59. view_count = int_or_none(item_data.get('playTimes'))
  60. timestamp = int_or_none(item_data.get('pt'))
  61. segments = self._parse_json(item_data['itemSegs'], video_id)
  62. # It looks like the keys are the arguments that have to be passed as
  63. # the hd field in the request url, we pick the higher
  64. # Also, filter non-number qualities (see issue #3643).
  65. quality = sorted(filter(lambda k: k.isdigit(), segments.keys()),
  66. key=lambda k: int(k))[-1]
  67. parts = segments[quality]
  68. result = []
  69. len_parts = len(parts)
  70. if len_parts > 1:
  71. self.to_screen('%s: found %s parts' % (video_id, len_parts))
  72. for part in parts:
  73. part_id = part['k']
  74. final_url = self._url_for_id(part_id, quality)
  75. ext = (final_url.split('?')[0]).split('.')[-1]
  76. part_info = {
  77. 'id': '%s' % part_id,
  78. 'url': final_url,
  79. 'ext': ext,
  80. 'title': title,
  81. 'thumbnail': thumbnail_url,
  82. 'description': description,
  83. 'view_count': view_count,
  84. 'timestamp': timestamp,
  85. 'duration': float_or_none(part.get('seconds'), 1000),
  86. 'filesize': int_or_none(part.get('size')),
  87. 'http_headers': {
  88. 'Referer': self._PLAYER_URL,
  89. },
  90. }
  91. result.append(part_info)
  92. return {
  93. '_type': 'multi_video',
  94. 'entries': result,
  95. 'id': video_id,
  96. 'title': title,
  97. }
  98. class TudouPlaylistIE(InfoExtractor):
  99. IE_NAME = 'tudou:playlist'
  100. _VALID_URL = r'https?://(?:www\.)?tudou\.com/listplay/(?P<id>[\w-]{11})\.html'
  101. _TESTS = [{
  102. 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo.html',
  103. 'info_dict': {
  104. 'id': 'zzdE77v6Mmo',
  105. },
  106. 'playlist_mincount': 209,
  107. }]
  108. def _real_extract(self, url):
  109. playlist_id = self._match_id(url)
  110. playlist_data = self._download_json(
  111. 'http://www.tudou.com/tvp/plist.action?lcode=%s' % playlist_id, playlist_id)
  112. entries = [self.url_result(
  113. 'http://www.tudou.com/programs/view/%s' % item['icode'],
  114. 'Tudou', item['icode'],
  115. item['kw']) for item in playlist_data['items']]
  116. return self.playlist_result(entries, playlist_id)
  117. class TudouAlbumIE(InfoExtractor):
  118. IE_NAME = 'tudou:album'
  119. _VALID_URL = r'https?://(?:www\.)?tudou\.com/album(?:cover|play)/(?P<id>[\w-]{11})'
  120. _TESTS = [{
  121. 'url': 'http://www.tudou.com/albumplay/v5qckFJvNJg.html',
  122. 'info_dict': {
  123. 'id': 'v5qckFJvNJg',
  124. },
  125. 'playlist_mincount': 45,
  126. }]
  127. def _real_extract(self, url):
  128. album_id = self._match_id(url)
  129. album_data = self._download_json(
  130. 'http://www.tudou.com/tvp/alist.action?acode=%s' % album_id, album_id)
  131. entries = [self.url_result(
  132. 'http://www.tudou.com/programs/view/%s' % item['icode'],
  133. 'Tudou', item['icode'],
  134. item['kw']) for item in album_data['items']]
  135. return self.playlist_result(entries, album_id)