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.

56 lines
1.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import unescapeHTML
  6. class BaiduVideoIE(InfoExtractor):
  7. IE_DESC = '百度视频'
  8. _VALID_URL = r'https?://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版国语',
  14. 'description': 'md5:51be07afe461cf99fa61231421b5397c',
  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': 12,
  25. }]
  26. def _call_api(self, path, category, playlist_id, note):
  27. return self._download_json('http://app.video.baidu.com/%s/?worktype=adnative%s&id=%s' % (
  28. path, category, playlist_id), playlist_id, note)
  29. def _real_extract(self, url):
  30. category, playlist_id = re.match(self._VALID_URL, url).groups()
  31. if category == 'show':
  32. category = 'tvshow'
  33. if category == 'tv':
  34. category = 'tvplay'
  35. playlist_detail = self._call_api(
  36. 'xqinfo', category, playlist_id, 'Download playlist JSON metadata')
  37. playlist_title = playlist_detail['title']
  38. playlist_description = unescapeHTML(playlist_detail.get('intro'))
  39. episodes_detail = self._call_api(
  40. 'xqsingle', category, playlist_id, 'Download episodes JSON metadata')
  41. entries = [self.url_result(
  42. episode['url'], video_title=episode['title']
  43. ) for episode in episodes_detail['videos']]
  44. return self.playlist_result(
  45. entries, playlist_id, playlist_title, playlist_description)