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.

96 lines
3.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. class TudouIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?tudou\.com/(?:listplay|programs(?:/view)?|albumplay)/?.*/(?P<id>[^/?#]+?)(?:\.html)?/?(?:$|[?#])'
  8. _TESTS = [{
  9. 'url': 'http://www.tudou.com/listplay/zzdE77v6Mmo/2xN2duXMxmw.html',
  10. 'md5': '140a49ed444bd22f93330985d8475fcb',
  11. 'info_dict': {
  12. 'id': '159448201',
  13. 'ext': 'f4v',
  14. 'title': '卡马乔国足开大脚长传冲吊集锦',
  15. 'thumbnail': 're:^https?://.*\.jpg$',
  16. }
  17. }, {
  18. 'url': 'http://www.tudou.com/programs/view/ajX3gyhL0pc/',
  19. 'info_dict': {
  20. 'id': '117049447',
  21. 'ext': 'f4v',
  22. 'title': 'La Sylphide-Bolshoi-Ekaterina Krysanova & Vyacheslav Lopatin 2012',
  23. 'thumbnail': 're:^https?://.*\.jpg$',
  24. }
  25. }]
  26. _PLAYER_URL = 'http://js.tudouui.com/bin/lingtong/PortalPlayer_177.swf'
  27. def _url_for_id(self, id, quality=None):
  28. info_url = "http://v2.tudou.com/f?id=" + str(id)
  29. if quality:
  30. info_url += '&hd' + quality
  31. webpage = self._download_webpage(info_url, id, "Opening the info webpage")
  32. final_url = self._html_search_regex('>(.+?)</f>', webpage, 'video url')
  33. return final_url
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. webpage = self._download_webpage(url, video_id)
  37. m = re.search(r'vcode:\s*[\'"](.+?)[\'"]', webpage)
  38. if m and m.group(1):
  39. return {
  40. '_type': 'url',
  41. 'url': 'youku:' + m.group(1),
  42. 'ie_key': 'Youku'
  43. }
  44. title = self._search_regex(
  45. r",kw:\s*['\"](.+?)[\"']", webpage, 'title')
  46. thumbnail_url = self._search_regex(
  47. r",pic:\s*[\"'](.+?)[\"']", webpage, 'thumbnail URL', fatal=False)
  48. player_url = self._search_regex(
  49. r"playerUrl\s*:\s*['\"](.+?\.swf)[\"']",
  50. webpage, 'player URL', default=self._PLAYER_URL)
  51. segs_json = self._search_regex(r'segs: \'(.*)\'', webpage, 'segments')
  52. segments = json.loads(segs_json)
  53. # It looks like the keys are the arguments that have to be passed as
  54. # the hd field in the request url, we pick the higher
  55. # Also, filter non-number qualities (see issue #3643).
  56. quality = sorted(filter(lambda k: k.isdigit(), segments.keys()),
  57. key=lambda k: int(k))[-1]
  58. parts = segments[quality]
  59. result = []
  60. len_parts = len(parts)
  61. if len_parts > 1:
  62. self.to_screen('%s: found %s parts' % (video_id, len_parts))
  63. for part in parts:
  64. part_id = part['k']
  65. final_url = self._url_for_id(part_id, quality)
  66. ext = (final_url.split('?')[0]).split('.')[-1]
  67. part_info = {
  68. 'id': '%s' % part_id,
  69. 'url': final_url,
  70. 'ext': ext,
  71. 'title': title,
  72. 'thumbnail': thumbnail_url,
  73. 'http_headers': {
  74. 'Referer': player_url,
  75. },
  76. }
  77. result.append(part_info)
  78. return {
  79. '_type': 'multi_video',
  80. 'entries': result,
  81. 'id': video_id,
  82. 'title': title,
  83. }