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.

65 lines
2.0 KiB

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