vuclip.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse_urlparse,
  6. ExtractorError,
  7. parse_duration,
  8. qualities,
  9. )
  10. class VuClipIE(InfoExtractor):
  11. _VALID_URL = r'http://(?:m\.)?vuclip\.com/w\?.*?cid=(?P<id>[0-9]+)'
  12. _TEST = {
  13. 'url': 'http://m.vuclip.com/w?cid=922692425&fid=70295&z=1010&nvar&frm=index.html',
  14. 'info_dict': {
  15. 'id': '922692425',
  16. 'ext': '3gp',
  17. 'title': 'The Toy Soldiers - Hollywood Movie Trailer',
  18. 'duration': 180,
  19. }
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group('id')
  24. #webpage = self._download_webpage(url, video_id)
  25. import io
  26. webpage = io.open('922692425_http_-_m.vuclip.com_wcid=922692425_fid=70295_z=1010_nvar_frm=index.html.dump', encoding='utf-8').read()
  27. ad_m = re.search(
  28. r'''value="No.*?" onClick="location.href='([^"']+)'"''', webpage)
  29. if ad_m:
  30. urlr = compat_urllib_parse_urlparse(url)
  31. adfree_url = urlr.scheme + '://' + urlr.netloc + ad_m.group(1)
  32. webpage = self._download_webpage(
  33. adfree_url, video_id, note='Download post-ad page')
  34. error_msg = self._html_search_regex(
  35. r'<p class="message">(.*?)</p>', webpage, 'error message',
  36. default=None)
  37. if error_msg:
  38. raise ExtractorError(
  39. '%s said: %s' % (self.IE_NAME, error_msg), expected=True)
  40. # These clowns alternate between two page types
  41. links_code = self._search_regex(
  42. r'''(?xs)
  43. (?:
  44. <img\s+src="/im/play.gif".*?>|
  45. <!--\ player\ end\ -->\s*</div><!--\ thumb\ end-->
  46. )
  47. (.*?)
  48. (?:
  49. <a\s+href="fblike'|<div\s+class="social">
  50. )
  51. ''', webpage, 'links')
  52. title = self._html_search_regex(
  53. r'<title>(.*?)-\s*Vuclip</title>', webpage, 'title').strip()
  54. quality_order = qualities(['Reg', 'Hi'])
  55. formats = []
  56. for url, q in re.findall(
  57. r'<a\s+href="(?P<url>[^"]+)".*?>(?:<button[^>]*>)?(?P<q>[^<]+)(?:</button>)?</a>', links_code):
  58. format_id = compat_urllib_parse_urlparse(url).scheme + '-' + q
  59. formats.append({
  60. 'format_id': format_id,
  61. 'url': url,
  62. 'quality': quality_order(q),
  63. })
  64. self._sort_formats(formats)
  65. duration = parse_duration(self._search_regex(
  66. r'\(([0-9:]+)\)</span>', webpage, 'duration', fatal=False))
  67. return {
  68. 'id': video_id,
  69. 'formats': formats,
  70. 'title': title,
  71. 'duration': duration,
  72. }