1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2026-04-27 09:13:26 +00:00
Files
youtube-dl/youtube_dl/extractor/cloudy.py
T

98 lines
2.8 KiB
Python
Raw Normal View History

2014-09-14 00:12:36 +03:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import (
2014-09-14 00:12:36 +03:00
compat_parse_qs,
compat_HTTPError,
2014-09-14 00:12:36 +03:00
)
from ..utils import (
ExtractorError,
HEADRequest,
remove_end,
)
2014-09-14 00:12:36 +03:00
class CloudyIE(InfoExtractor):
2016-07-16 01:21:20 +08:00
_IE_DESC = 'cloudy.ec'
2014-09-14 00:12:36 +03:00
_VALID_URL = r'''(?x)
2016-07-16 01:21:20 +08:00
https?://(?:www\.)?cloudy\.ec/
2014-09-14 00:12:36 +03:00
(?:v/|embed\.php\?id=)
(?P<id>[A-Za-z0-9]+)
'''
2016-07-16 01:21:20 +08:00
_EMBED_URL = 'http://www.cloudy.ec/embed.php?id=%s'
_API_URL = 'http://www.cloudy.ec/api/player.api.php'
_MAX_TRIES = 2
2016-07-16 01:21:20 +08:00
_TEST = {
'url': 'https://www.cloudy.ec/v/af511e2527aac',
'md5': '5cb253ace826a42f35b4740539bedf07',
'info_dict': {
'id': 'af511e2527aac',
'ext': 'flv',
'title': 'Funny Cats and Animals Compilation june 2013',
2014-09-14 00:12:36 +03:00
}
2016-07-16 01:21:20 +08:00
}
2014-09-14 00:12:36 +03:00
2016-07-16 01:21:20 +08:00
def _extract_video(self, video_id, file_key, error_url=None, try_num=0):
2014-09-14 00:12:36 +03:00
if try_num > self._MAX_TRIES - 1:
raise ExtractorError('Unable to extract video URL', expected=True)
2014-09-14 00:12:36 +03:00
form = {
2014-09-14 00:12:36 +03:00
'file': video_id,
'key': file_key,
}
if error_url:
form.update({
'numOfErrors': try_num,
'errorCode': '404',
'errorUrl': error_url,
})
2014-09-14 00:12:36 +03:00
player_data = self._download_webpage(
2016-07-16 01:21:20 +08:00
self._API_URL, video_id, 'Downloading player data', query=form)
2014-09-14 00:12:36 +03:00
data = compat_parse_qs(player_data)
try_num += 1
2014-09-14 00:12:36 +03:00
if 'error' in data:
raise ExtractorError(
'%s error: %s' % (self.IE_NAME, ' '.join(data['error_msg'])),
expected=True)
title = data.get('title', [None])[0]
if title:
2014-09-14 05:01:25 +07:00
title = remove_end(title, '&asdasdas').strip()
2014-09-14 00:12:36 +03:00
2014-09-14 05:01:25 +07:00
video_url = data.get('url', [None])[0]
2014-09-14 05:01:25 +07:00
if video_url:
try:
self._request_webpage(HEADRequest(video_url), video_id, 'Checking video URL')
except ExtractorError as e:
if isinstance(e.cause, compat_HTTPError) and e.cause.code in [404, 410]:
self.report_warning('Invalid video URL, requesting another', video_id)
2016-07-16 01:21:20 +08:00
return self._extract_video(video_id, file_key, video_url, try_num)
2014-09-14 00:12:36 +03:00
return {
'id': video_id,
'url': video_url,
2014-09-14 00:12:36 +03:00
'title': title,
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
2016-07-16 01:21:20 +08:00
url = self._EMBED_URL % video_id
webpage = self._download_webpage(url, video_id)
file_key = self._search_regex(
2015-03-15 22:42:13 +06:00
[r'key\s*:\s*"([^"]+)"', r'filekey\s*=\s*"([^"]+)"'],
webpage, 'file_key')
2016-07-16 01:21:20 +08:00
return self._extract_video(video_id, file_key)