vuclip.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import re
  2. import urllib.parse
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. parse_duration,
  7. remove_end,
  8. )
  9. class VuClipIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:m\.)?vuclip\.com/w\?.*?cid=(?P<id>[0-9]+)'
  11. _TEST = {
  12. 'url': 'http://m.vuclip.com/w?cid=1129900602&bu=8589892792&frm=w&z=34801&op=0&oc=843169247&section=recommend',
  13. 'info_dict': {
  14. 'id': '1129900602',
  15. 'ext': '3gp',
  16. 'title': 'Top 10 TV Convicts',
  17. 'duration': 733,
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. webpage = self._download_webpage(url, video_id)
  23. ad_m = re.search(
  24. r'''value="No.*?" onClick="location.href='([^"']+)'"''', webpage)
  25. if ad_m:
  26. urlr = urllib.parse.urlparse(url)
  27. adfree_url = urlr.scheme + '://' + urlr.netloc + ad_m.group(1)
  28. webpage = self._download_webpage(
  29. adfree_url, video_id, note='Download post-ad page')
  30. error_msg = self._html_search_regex(
  31. r'<p class="message">(.*?)</p>', webpage, 'error message',
  32. default=None)
  33. if error_msg:
  34. raise ExtractorError(
  35. f'{self.IE_NAME} said: {error_msg}', expected=True)
  36. # These clowns alternate between two page types
  37. video_url = self._search_regex(
  38. r'<a[^>]+href="([^"]+)"[^>]*><img[^>]+src="[^"]*/play\.gif',
  39. webpage, 'video URL', default=None)
  40. if video_url:
  41. formats = [{
  42. 'url': video_url,
  43. }]
  44. else:
  45. formats = self._parse_html5_media_entries(url, webpage, video_id)[0]['formats']
  46. title = remove_end(self._html_search_regex(
  47. r'<title>(.*?)-\s*Vuclip</title>', webpage, 'title').strip(), ' - Video')
  48. duration = parse_duration(self._html_search_regex(
  49. r'[(>]([0-9]+:[0-9]+)(?:<span|\))', webpage, 'duration', fatal=False))
  50. return {
  51. 'id': video_id,
  52. 'formats': formats,
  53. 'title': title,
  54. 'duration': duration,
  55. }