bokecc.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from .common import InfoExtractor
  2. from ..compat import compat_parse_qs
  3. from ..utils import ExtractorError
  4. class BokeCCBaseIE(InfoExtractor):
  5. def _extract_bokecc_formats(self, webpage, video_id, format_id=None):
  6. player_params_str = self._html_search_regex(
  7. r'<(?:script|embed)[^>]+src=(?P<q>["\'])(?:https?:)?//p\.bokecc\.com/(?:player|flash/player\.swf)\?(?P<query>.+?)(?P=q)',
  8. webpage, 'player params', group='query')
  9. player_params = compat_parse_qs(player_params_str)
  10. info_xml = self._download_xml(
  11. 'http://p.bokecc.com/servlet/playinfo?uid=%s&vid=%s&m=1' % (
  12. player_params['siteid'][0], player_params['vid'][0]), video_id)
  13. formats = [{
  14. 'format_id': format_id,
  15. 'url': quality.find('./copy').attrib['playurl'],
  16. 'quality': int(quality.attrib['value']),
  17. } for quality in info_xml.findall('./video/quality')]
  18. return formats
  19. class BokeCCIE(BokeCCBaseIE):
  20. _IE_DESC = 'CC视频'
  21. _VALID_URL = r'https?://union\.bokecc\.com/playvideo\.bo\?(?P<query>.*)'
  22. _TESTS = [{
  23. 'url': 'http://union.bokecc.com/playvideo.bo?vid=E0ABAE9D4F509B189C33DC5901307461&uid=FE644790DE9D154A',
  24. 'info_dict': {
  25. 'id': 'FE644790DE9D154A_E0ABAE9D4F509B189C33DC5901307461',
  26. 'ext': 'flv',
  27. 'title': 'BokeCC Video',
  28. },
  29. }]
  30. def _real_extract(self, url):
  31. qs = compat_parse_qs(self._match_valid_url(url).group('query'))
  32. if not qs.get('vid') or not qs.get('uid'):
  33. raise ExtractorError('Invalid URL', expected=True)
  34. video_id = '%s_%s' % (qs['uid'][0], qs['vid'][0])
  35. webpage = self._download_webpage(url, video_id)
  36. return {
  37. 'id': video_id,
  38. 'title': 'BokeCC Video', # no title provided in the webpage
  39. 'formats': self._extract_bokecc_formats(webpage, video_id),
  40. }