baidu.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from .common import InfoExtractor
  2. from ..utils import unescapeHTML
  3. class BaiduVideoIE(InfoExtractor):
  4. IE_DESC = '百度视频'
  5. _VALID_URL = r'https?://v\.baidu\.com/(?P<type>[a-z]+)/(?P<id>\d+)\.htm'
  6. _TESTS = [{
  7. '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',
  8. 'info_dict': {
  9. 'id': '1069',
  10. 'title': '中华小当家 TV版国语',
  11. 'description': 'md5:51be07afe461cf99fa61231421b5397c',
  12. },
  13. 'playlist_count': 52,
  14. }, {
  15. 'url': 'http://v.baidu.com/show/11595.htm?frp=bdbrand',
  16. 'info_dict': {
  17. 'id': '11595',
  18. 'title': 're:^奔跑吧兄弟',
  19. 'description': 'md5:1bf88bad6d850930f542d51547c089b8',
  20. },
  21. 'playlist_mincount': 12,
  22. }]
  23. def _call_api(self, path, category, playlist_id, note):
  24. return self._download_json('http://app.video.baidu.com/%s/?worktype=adnative%s&id=%s' % (
  25. path, category, playlist_id), playlist_id, note)
  26. def _real_extract(self, url):
  27. category, playlist_id = self._match_valid_url(url).groups()
  28. if category == 'show':
  29. category = 'tvshow'
  30. if category == 'tv':
  31. category = 'tvplay'
  32. playlist_detail = self._call_api(
  33. 'xqinfo', category, playlist_id, 'Download playlist JSON metadata')
  34. playlist_title = playlist_detail['title']
  35. playlist_description = unescapeHTML(playlist_detail.get('intro'))
  36. episodes_detail = self._call_api(
  37. 'xqsingle', category, playlist_id, 'Download episodes JSON metadata')
  38. entries = [self.url_result(
  39. episode['url'], video_title=episode['title']
  40. ) for episode in episodes_detail['videos']]
  41. return self.playlist_result(
  42. entries, playlist_id, playlist_title, playlist_description)