From 91ebb17ede283208f71969db6f20fafb345fc923 Mon Sep 17 00:00:00 2001 From: Naglis Jonaitis Date: Tue, 9 Sep 2014 22:17:33 +0300 Subject: [hostingbulk] Add new extractor --- youtube_dl/extractor/hostingbulk.py | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 youtube_dl/extractor/hostingbulk.py (limited to 'youtube_dl/extractor/hostingbulk.py') diff --git a/youtube_dl/extractor/hostingbulk.py b/youtube_dl/extractor/hostingbulk.py new file mode 100644 index 000000000..a07dd4962 --- /dev/null +++ b/youtube_dl/extractor/hostingbulk.py @@ -0,0 +1,88 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import re + +from .common import InfoExtractor +from ..utils import ( + ExtractorError, + compat_urllib_request, + int_or_none, + urlencode_postdata, +) + + +class HostingBulkIE(InfoExtractor): + _VALID_URL = r'''(?x) + https?://(?:www\.)?hostingbulk\.com/ + (?:embed-)?(?P[A-Za-z0-9]{12})(?:-\d+x\d+)?\.html''' + _FILE_DELETED_REGEX = r'File Not Found' + _TEST = { + 'url': 'http://hostingbulk.com/n0ulw1hv20fm.html', + 'md5': '6c8653c8ecf7ebfa83b76e24b7b2fe3f', + 'info_dict': { + 'id': 'n0ulw1hv20fm', + 'ext': 'mp4', + 'title': 'md5:5afeba33f48ec87219c269e054afd622', + 'filesize': 6816081, + 'thumbnail': 're:^http://.*\.jpg$', + } + } + + def _real_extract(self, url): + mobj = re.match(self._VALID_URL, url) + video_id = mobj.group('id') + + url = 'http://hostingbulk.com/{0:}.html'.format(video_id) + + # Custom request with cookie to set language to English, so our file + # deleted regex would work. + request = compat_urllib_request.Request( + url, headers={'Cookie': 'lang=english'}) + webpage = self._download_webpage(request, video_id) + + if re.search(self._FILE_DELETED_REGEX, webpage) is not None: + raise ExtractorError('Video %s does not exist' % video_id, + expected=True) + + title = self._html_search_regex(r'

(.*?)

', webpage, 'title') + filesize = int_or_none( + self._search_regex( + r'\((\d+)\sbytes?\)', + webpage, + 'filesize', + fatal=False + ) + ) + thumbnail = self._search_regex( + r'', webpage, 'rand') + + fields = { + 'id': video_id, + 'method_free': '', + 'method_premium': '', + 'op': 'download2', + 'rand': rand, + 'referer': '', + } + request = compat_urllib_request.Request(url, urlencode_postdata(fields)) + request.add_header('Content-type', 'application/x-www-form-urlencoded') + response = self._request_webpage(request, video_id, + 'Submiting download request') + video_url = response.geturl() + + formats = [{ + 'format_id': 'sd', + 'filesize': filesize, + 'url': video_url, + }] + + return { + 'id': video_id, + 'title': title, + 'thumbnail': thumbnail, + 'formats': formats, + } -- cgit v1.2.3 From 6899f2fe9ed2347255f216cfcfc954dd716e5e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Wed, 10 Sep 2014 19:13:22 +0700 Subject: [hostingbulk] Simplify --- youtube_dl/extractor/hostingbulk.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'youtube_dl/extractor/hostingbulk.py') diff --git a/youtube_dl/extractor/hostingbulk.py b/youtube_dl/extractor/hostingbulk.py index a07dd4962..8e812b669 100644 --- a/youtube_dl/extractor/hostingbulk.py +++ b/youtube_dl/extractor/hostingbulk.py @@ -57,17 +57,13 @@ class HostingBulkIE(InfoExtractor): thumbnail = self._search_regex( r'', webpage, 'rand') - fields = { - 'id': video_id, - 'method_free': '', - 'method_premium': '', - 'op': 'download2', - 'rand': rand, - 'referer': '', - } + fields = dict(re.findall(r'''(?x)