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.

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