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.

83 lines
2.6 KiB

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