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.

49 lines
1.7 KiB

  1. # coding: utf-8
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. class WeiboIE(InfoExtractor):
  6. """
  7. The videos in Weibo come from different sites, this IE just finds the link
  8. to the external video and returns it.
  9. """
  10. _VALID_URL = r'https?://video\.weibo\.com/v/weishipin/t_(?P<id>.+?)\.htm'
  11. _TEST = {
  12. u'add_ie': ['Sina'],
  13. u'url': u'http://video.weibo.com/v/weishipin/t_zjUw2kZ.htm',
  14. u'file': u'98322879.flv',
  15. u'info_dict': {
  16. u'title': u'魔声耳机最新广告“All Eyes On Us”',
  17. },
  18. u'note': u'Sina video',
  19. u'params': {
  20. u'skip_download': True,
  21. },
  22. }
  23. # Additional example videos from different sites
  24. # Youku: http://video.weibo.com/v/weishipin/t_zQGDWQ8.htm
  25. # 56.com: http://video.weibo.com/v/weishipin/t_zQ44HxN.htm
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
  28. video_id = mobj.group('id')
  29. info_url = 'http://video.weibo.com/?s=v&a=play_list&format=json&mix_video_id=t_%s' % video_id
  30. info_page = self._download_webpage(info_url, video_id)
  31. info = json.loads(info_page)
  32. videos_urls = map(lambda v: v['play_page_url'], info['result']['data'])
  33. #Prefer sina video since they have thumbnails
  34. videos_urls = sorted(videos_urls, key=lambda u: u'video.sina.com' in u)
  35. player_url = videos_urls[-1]
  36. m_sina = re.match(r'https?://video.sina.com.cn/v/b/(\d+)-\d+.html', player_url)
  37. if m_sina is not None:
  38. self.to_screen('Sina video detected')
  39. sina_id = m_sina.group(1)
  40. player_url = 'http://you.video.sina.com.cn/swf/quotePlayer.swf?vid=%s' % sina_id
  41. return self.url_result(player_url)