c56.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from .common import InfoExtractor
  2. from ..utils import js_to_json
  3. class C56IE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:(?:www|player)\.)?56\.com/(?:.+?/)?(?:v_|(?:play_album.+-))(?P<textid>.+?)\.(?:html|swf)'
  5. IE_NAME = '56.com'
  6. _TESTS = [{
  7. 'url': 'http://www.56.com/u39/v_OTM0NDA3MTY.html',
  8. 'md5': 'e59995ac63d0457783ea05f93f12a866',
  9. 'info_dict': {
  10. 'id': '93440716',
  11. 'ext': 'flv',
  12. 'title': '网事知多少 第32期:车怒',
  13. 'duration': 283.813,
  14. },
  15. }, {
  16. 'url': 'http://www.56.com/u47/v_MTM5NjQ5ODc2.html',
  17. 'md5': '',
  18. 'info_dict': {
  19. 'id': '82247482',
  20. 'title': '爱的诅咒之杜鹃花开',
  21. },
  22. 'playlist_count': 7,
  23. 'add_ie': ['Sohu'],
  24. }]
  25. def _real_extract(self, url):
  26. mobj = self._match_valid_url(url)
  27. text_id = mobj.group('textid')
  28. webpage = self._download_webpage(url, text_id)
  29. sohu_video_info_str = self._search_regex(
  30. r'var\s+sohuVideoInfo\s*=\s*({[^}]+});', webpage, 'Sohu video info', default=None)
  31. if sohu_video_info_str:
  32. sohu_video_info = self._parse_json(
  33. sohu_video_info_str, text_id, transform_source=js_to_json)
  34. return self.url_result(sohu_video_info['url'], 'Sohu')
  35. page = self._download_json(
  36. f'http://vxml.56.com/json/{text_id}/', text_id, 'Downloading video info')
  37. info = page['info']
  38. formats = [
  39. {
  40. 'format_id': f['type'],
  41. 'filesize': int(f['filesize']),
  42. 'url': f['url'],
  43. } for f in info['rfiles']
  44. ]
  45. return {
  46. 'id': info['vid'],
  47. 'title': info['Subject'],
  48. 'duration': int(info['duration']) / 1000.0,
  49. 'formats': formats,
  50. 'thumbnail': info.get('bimg') or info.get('img'),
  51. }