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.

73 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_request,
  7. compat_urllib_parse,
  8. )
  9. class SinaIE(InfoExtractor):
  10. _VALID_URL = r'''(?x)https?://(.*?\.)?video\.sina\.com\.cn/
  11. (
  12. (.+?/(((?P<pseudo_id>\d+).html)|(.*?(\#|(vid=)|b/)(?P<id>\d+?)($|&|\-))))
  13. |
  14. # This is used by external sites like Weibo
  15. (api/sinawebApi/outplay.php/(?P<token>.+?)\.swf)
  16. )
  17. '''
  18. _TESTS = [
  19. {
  20. 'url': 'http://video.sina.com.cn/news/vlist/zt/chczlj2013/?opsubject_id=top12#110028898',
  21. 'md5': 'd65dd22ddcf44e38ce2bf58a10c3e71f',
  22. 'info_dict': {
  23. 'id': '110028898',
  24. 'ext': 'flv',
  25. 'title': '《中国新闻》 朝鲜要求巴拿马立即释放被扣船员',
  26. }
  27. },
  28. {
  29. 'url': 'http://video.sina.com.cn/v/b/101314253-1290078633.html',
  30. 'info_dict': {
  31. 'id': '101314253',
  32. 'ext': 'flv',
  33. 'title': '军方提高对朝情报监视级别',
  34. },
  35. },
  36. ]
  37. def _extract_video(self, video_id):
  38. data = compat_urllib_parse.urlencode({'vid': video_id})
  39. url_doc = self._download_xml('http://v.iask.com/v_play.php?%s' % data,
  40. video_id, 'Downloading video url')
  41. image_page = self._download_webpage(
  42. 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?%s' % data,
  43. video_id, 'Downloading thumbnail info')
  44. return {'id': video_id,
  45. 'url': url_doc.find('./durl/url').text,
  46. 'ext': 'flv',
  47. 'title': url_doc.find('./vname').text,
  48. 'thumbnail': image_page.split('=')[1],
  49. }
  50. def _real_extract(self, url):
  51. mobj = re.match(self._VALID_URL, url)
  52. video_id = mobj.group('id')
  53. if mobj.group('token') is not None:
  54. # The video id is in the redirected url
  55. self.to_screen('Getting video id')
  56. request = compat_urllib_request.Request(url)
  57. request.get_method = lambda: 'HEAD'
  58. (_, urlh) = self._download_webpage_handle(request, 'NA', False)
  59. return self._real_extract(urlh.geturl())
  60. elif video_id is None:
  61. pseudo_id = mobj.group('pseudo_id')
  62. webpage = self._download_webpage(url, pseudo_id)
  63. video_id = self._search_regex(r'vid:\'(\d+?)\'', webpage, 'video id')
  64. return self._extract_video(video_id)