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.

69 lines
2.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. class BaiduVideoIE(InfoExtractor):
  7. IE_DESC = '百度视频'
  8. _VALID_URL = r'http://v\.baidu\.com/(?P<type>[a-z]+)/(?P<id>\d+)\.htm'
  9. _TESTS = [{
  10. 'url': 'http://v.baidu.com/comic/1069.htm?frp=bdbrand&q=%E4%B8%AD%E5%8D%8E%E5%B0%8F%E5%BD%93%E5%AE%B6',
  11. 'info_dict': {
  12. 'id': '1069',
  13. 'title': '中华小当家 TV版 (全52集)',
  14. 'description': 'md5:395a419e41215e531c857bb037bbaf80',
  15. },
  16. 'playlist_count': 52,
  17. }, {
  18. 'url': 'http://v.baidu.com/show/11595.htm?frp=bdbrand',
  19. 'info_dict': {
  20. 'id': '11595',
  21. 'title': 're:^奔跑吧兄弟',
  22. 'description': 'md5:1bf88bad6d850930f542d51547c089b8',
  23. },
  24. 'playlist_mincount': 3,
  25. }]
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. playlist_id = mobj.group('id')
  29. category = category2 = mobj.group('type')
  30. if category == 'show':
  31. category2 = 'tvshow'
  32. webpage = self._download_webpage(url, playlist_id)
  33. playlist_title = self._html_search_regex(
  34. r'title\s*:\s*(["\'])(?P<title>[^\']+)\1', webpage,
  35. 'playlist title', group='title')
  36. playlist_description = self._html_search_regex(
  37. r'<input[^>]+class="j-data-intro"[^>]+value="([^"]+)"/>', webpage,
  38. playlist_id, 'playlist description')
  39. site = self._html_search_regex(
  40. r'filterSite\s*:\s*["\']([^"]*)["\']', webpage,
  41. 'primary provider site')
  42. api_result = self._download_json(
  43. 'http://v.baidu.com/%s_intro/?dtype=%sPlayUrl&id=%s&site=%s' % (
  44. category, category2, playlist_id, site),
  45. playlist_id, 'Get playlist links')
  46. entries = []
  47. for episode in api_result[0]['episodes']:
  48. episode_id = '%s_%s' % (playlist_id, episode['episode'])
  49. redirect_page = self._download_webpage(
  50. compat_urlparse.urljoin(url, episode['url']), episode_id,
  51. note='Download Baidu redirect page')
  52. real_url = self._html_search_regex(
  53. r'location\.replace\("([^"]+)"\)', redirect_page, 'real URL')
  54. entries.append(self.url_result(
  55. real_url, video_title=episode['single_title']))
  56. return self.playlist_result(
  57. entries, playlist_id, playlist_title, playlist_description)