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.

82 lines
2.7 KiB

  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. ad_m = re.search(
  26. r'''value="No.*?" onClick="location.href='([^"']+)'"''', webpage)
  27. if ad_m:
  28. urlr = compat_urllib_parse_urlparse(url)
  29. adfree_url = urlr.scheme + '://' + urlr.netloc + ad_m.group(1)
  30. webpage = self._download_webpage(
  31. adfree_url, video_id, note='Download post-ad page')
  32. error_msg = self._html_search_regex(
  33. r'<p class="message">(.*?)</p>', webpage, 'error message',
  34. default=None)
  35. if error_msg:
  36. raise ExtractorError(
  37. '%s said: %s' % (self.IE_NAME, error_msg), expected=True)
  38. # These clowns alternate between two page types
  39. links_code = self._search_regex(
  40. r'''(?xs)
  41. (?:
  42. <img\s+src="/im/play.gif".*?>|
  43. <!--\ player\ end\ -->\s*</div><!--\ thumb\ end-->
  44. )
  45. (.*?)
  46. (?:
  47. <a\s+href="fblike|<div\s+class="social">
  48. )
  49. ''', webpage, 'links')
  50. title = self._html_search_regex(
  51. r'<title>(.*?)-\s*Vuclip</title>', webpage, 'title').strip()
  52. quality_order = qualities(['Reg', 'Hi'])
  53. formats = []
  54. for url, q in re.findall(
  55. r'<a\s+href="(?P<url>[^"]+)".*?>(?:<button[^>]*>)?(?P<q>[^<]+)(?:</button>)?</a>', links_code):
  56. format_id = compat_urllib_parse_urlparse(url).scheme + '-' + q
  57. formats.append({
  58. 'format_id': format_id,
  59. 'url': url,
  60. 'quality': quality_order(q),
  61. })
  62. self._sort_formats(formats)
  63. duration = parse_duration(self._search_regex(
  64. r'\(([0-9:]+)\)</span>', webpage, 'duration', fatal=False))
  65. return {
  66. 'id': video_id,
  67. 'formats': formats,
  68. 'title': title,
  69. 'duration': duration,
  70. }