1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-05 00:17:43 +00:00
youtube-dl/youtube_dl/extractor/vuclip.py

84 lines
2.6 KiB
Python
Raw Normal View History

2014-04-21 13:23:30 +00:00
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import (
2014-04-21 13:23:30 +00:00
compat_urllib_parse_urlparse,
)
from ..utils import (
2014-09-29 11:07:58 +00:00
ExtractorError,
2014-04-21 13:23:30 +00:00
parse_duration,
qualities,
)
class VuClipIE(InfoExtractor):
2014-04-21 14:14:21 +00:00
_VALID_URL = r'http://(?:m\.)?vuclip\.com/w\?.*?cid=(?P<id>[0-9]+)'
2014-04-21 13:23:30 +00:00
_TEST = {
2014-09-29 11:07:58 +00:00
'url': 'http://m.vuclip.com/w?cid=922692425&fid=70295&z=1010&nvar&frm=index.html',
2014-04-21 13:23:30 +00:00
'info_dict': {
2014-09-29 11:07:58 +00:00
'id': '922692425',
2014-04-21 13:23:30 +00:00
'ext': '3gp',
2014-09-29 11:07:58 +00:00
'title': 'The Toy Soldiers - Hollywood Movie Trailer',
'duration': 180,
2014-04-21 13:23:30 +00:00
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
2014-09-29 19:47:57 +00:00
webpage = self._download_webpage(url, video_id)
2014-04-21 13:23:30 +00:00
ad_m = re.search(
r'''value="No.*?" onClick="location.href='([^"']+)'"''', webpage)
if ad_m:
urlr = compat_urllib_parse_urlparse(url)
adfree_url = urlr.scheme + '://' + urlr.netloc + ad_m.group(1)
webpage = self._download_webpage(
adfree_url, video_id, note='Download post-ad page')
2014-09-29 11:07:58 +00:00
error_msg = self._html_search_regex(
r'<p class="message">(.*?)</p>', webpage, 'error message',
default=None)
if error_msg:
raise ExtractorError(
'%s said: %s' % (self.IE_NAME, error_msg), expected=True)
# These clowns alternate between two page types
2014-04-21 13:23:30 +00:00
links_code = self._search_regex(
2014-09-29 11:07:58 +00:00
r'''(?xs)
(?:
2015-05-18 15:39:15 +00:00
<img\s+src="[^"]*/play.gif".*?>|
2014-09-29 11:07:58 +00:00
<!--\ player\ end\ -->\s*</div><!--\ thumb\ end-->
)
(.*?)
(?:
2014-09-29 19:48:44 +00:00
<a\s+href="fblike|<div\s+class="social">
2014-09-29 11:07:58 +00:00
)
''', webpage, 'links')
2014-04-21 13:23:30 +00:00
title = self._html_search_regex(
r'<title>(.*?)-\s*Vuclip</title>', webpage, 'title').strip()
quality_order = qualities(['Reg', 'Hi'])
formats = []
for url, q in re.findall(
2014-09-29 11:07:58 +00:00
r'<a\s+href="(?P<url>[^"]+)".*?>(?:<button[^>]*>)?(?P<q>[^<]+)(?:</button>)?</a>', links_code):
2014-04-21 13:23:30 +00:00
format_id = compat_urllib_parse_urlparse(url).scheme + '-' + q
formats.append({
'format_id': format_id,
'url': url,
'quality': quality_order(q),
})
self._sort_formats(formats)
duration = parse_duration(self._search_regex(
2014-09-29 11:07:58 +00:00
r'\(([0-9:]+)\)</span>', webpage, 'duration', fatal=False))
2014-04-21 13:23:30 +00:00
return {
'id': video_id,
'formats': formats,
'title': title,
'duration': duration,
}