1
1
mirror of https://github.com/ytdl-org/youtube-dl synced 2024-11-27 15:16:57 +01:00
youtube-dl/youtube_dl/extractor/vuclip.py

71 lines
2.2 KiB
Python
Raw Normal View History

2014-04-21 15:23:30 +02:00
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import (
2014-04-21 15:23:30 +02:00
compat_urllib_parse_urlparse,
)
from ..utils import (
2014-09-29 13:07:58 +02:00
ExtractorError,
2014-04-21 15:23:30 +02:00
parse_duration,
2016-07-10 18:52:25 +02:00
remove_end,
2014-04-21 15:23:30 +02:00
)
class VuClipIE(InfoExtractor):
_VALID_URL = r'https?://(?:m\.)?vuclip\.com/w\?.*?cid=(?P<id>[0-9]+)'
2014-04-21 15:23:30 +02:00
_TEST = {
'url': 'http://m.vuclip.com/w?cid=1129900602&bu=8589892792&frm=w&z=34801&op=0&oc=843169247&section=recommend',
2014-04-21 15:23:30 +02:00
'info_dict': {
'id': '1129900602',
2014-04-21 15:23:30 +02:00
'ext': '3gp',
'title': 'Top 10 TV Convicts',
'duration': 733,
2014-04-21 15:23:30 +02:00
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
2014-09-29 21:47:57 +02:00
webpage = self._download_webpage(url, video_id)
2014-04-21 15:23:30 +02: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 13:07:58 +02: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
2016-07-10 18:52:25 +02:00
video_url = self._search_regex(
r'<a[^>]+href="([^"]+)"[^>]*><img[^>]+src="[^"]*/play\.gif',
webpage, 'video URL', default=None)
if video_url:
formats = [{
'url': video_url,
}]
else:
formats = self._parse_html5_media_entries(url, webpage, video_id)[0]['formats']
2014-04-21 15:23:30 +02:00
2016-07-10 18:52:25 +02:00
title = remove_end(self._html_search_regex(
r'<title>(.*?)-\s*Vuclip</title>', webpage, 'title').strip(), ' - Video')
2014-04-21 15:23:30 +02:00
2016-07-10 18:52:25 +02:00
duration = parse_duration(self._html_search_regex(
r'[(>]([0-9]+:[0-9]+)(?:<span|\))', webpage, 'duration', fatal=False))
2014-04-21 15:23:30 +02:00
return {
'id': video_id,
'formats': formats,
'title': title,
'duration': duration,
}