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.

60 lines
1.9 KiB

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