From 64d02399d8d2acbb55b22f789a5b54e79591b7b3 Mon Sep 17 00:00:00 2001 From: pyed Date: Fri, 8 Aug 2014 09:48:02 +0300 Subject: [PATCH 1/2] [xboxclips] Add new extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/xboxclips.py | 34 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 youtube_dl/extractor/xboxclips.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 468c7dc29..23f53ba13 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -384,6 +384,7 @@ from .wistia import WistiaIE from .worldstarhiphop import WorldStarHipHopIE from .wrzuta import WrzutaIE from .xbef import XBefIE +from .xboxclips import XboxClipsIE from .xhamster import XHamsterIE from .xnxx import XNXXIE from .xvideos import XVideosIE diff --git a/youtube_dl/extractor/xboxclips.py b/youtube_dl/extractor/xboxclips.py new file mode 100644 index 000000000..499702d0d --- /dev/null +++ b/youtube_dl/extractor/xboxclips.py @@ -0,0 +1,34 @@ +# encoding: utf-8 +import re + +from .common import InfoExtractor + +class XboxClipsIE(InfoExtractor): + _VALID_URL = r'^https?://(www\.)?xboxclips\.com/video.php\?.*vid=(?P[\w-]*)' + _TEST = { + 'url': 'https://xboxclips.com/video.php?uid=2533274823424419&gamertag=Iabdulelah&vid=074a69a9-5faf-46aa-b93b-9909c1720325', + 'md5': 'fbe1ec805e920aeb8eced3c3e657df5d', + 'info_dict': { + 'id': '074a69a9-5faf-46aa-b93b-9909c1720325', + 'ext': 'mp4', + 'title': 'Iabdulelah playing Upload Studio', + } + } + + def _real_extract(self, url): + mobj = re.match(self._VALID_URL, url) + video_id = mobj.group('id') + + webpage = self._download_webpage(url, video_id) + video_url = self._search_regex(r'Link.*?"(.*?)"', + webpage, 'video URL') + + video_title = self._html_search_regex(r'.*?\|(.*?)<', + webpage, 'title') + + return { + 'id': video_id, + 'url': video_url, + 'title': video_title, + 'ext': 'mp4', + } From 31bf213032b72069fdd14f5ace3ace33ee46eaf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= <dstftw@gmail.com> Date: Fri, 8 Aug 2014 19:21:24 +0700 Subject: [PATCH 2/2] [xboxclips] PEP8 and extract more metadata --- youtube_dl/extractor/xboxclips.py | 59 +++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/youtube_dl/extractor/xboxclips.py b/youtube_dl/extractor/xboxclips.py index 499702d0d..a9aa72e73 100644 --- a/youtube_dl/extractor/xboxclips.py +++ b/youtube_dl/extractor/xboxclips.py @@ -1,34 +1,57 @@ # encoding: utf-8 +from __future__ import unicode_literals + import re from .common import InfoExtractor +from ..utils import ( + parse_iso8601, + float_or_none, + int_or_none, +) + class XboxClipsIE(InfoExtractor): - _VALID_URL = r'^https?://(www\.)?xboxclips\.com/video.php\?.*vid=(?P<id>[\w-]*)' + _VALID_URL = r'https?://(?:www\.)?xboxclips\.com/video\.php\?.*vid=(?P<id>[\w-]{36})' _TEST = { - 'url': 'https://xboxclips.com/video.php?uid=2533274823424419&gamertag=Iabdulelah&vid=074a69a9-5faf-46aa-b93b-9909c1720325', - 'md5': 'fbe1ec805e920aeb8eced3c3e657df5d', - 'info_dict': { - 'id': '074a69a9-5faf-46aa-b93b-9909c1720325', - 'ext': 'mp4', - 'title': 'Iabdulelah playing Upload Studio', - } - } + 'url': 'https://xboxclips.com/video.php?uid=2533274823424419&gamertag=Iabdulelah&vid=074a69a9-5faf-46aa-b93b-9909c1720325', + 'md5': 'fbe1ec805e920aeb8eced3c3e657df5d', + 'info_dict': { + 'id': '074a69a9-5faf-46aa-b93b-9909c1720325', + 'ext': 'mp4', + 'title': 'Iabdulelah playing Upload Studio', + 'filesize_approx': 28101836.8, + 'timestamp': 1407388500, + 'upload_date': '20140807', + 'duration': 56, + } + } def _real_extract(self, url): mobj = re.match(self._VALID_URL, url) video_id = mobj.group('id') webpage = self._download_webpage(url, video_id) - video_url = self._search_regex(r'Link.*?"(.*?)"', - webpage, 'video URL') - video_title = self._html_search_regex(r'<title>.*?\|(.*?)<', - webpage, 'title') + video_url = self._html_search_regex( + r'>Link: <a href="([^"]+)">', webpage, 'video URL') + title = self._html_search_regex( + r'<title>XboxClips \| ([^<]+)', webpage, 'title') + timestamp = parse_iso8601(self._html_search_regex( + r'>Recorded: ([^<]+)<', webpage, 'upload date', fatal=False)) + filesize = float_or_none(self._html_search_regex( + r'>Size: ([\d\.]+)MB<', webpage, 'file size', fatal=False), invscale=1024 * 1024) + duration = int_or_none(self._html_search_regex( + r'>Duration: (\d+) Seconds<', webpage, 'duration', fatal=False)) + view_count = int_or_none(self._html_search_regex( + r'>Views: (\d+)<', webpage, 'view count', fatal=False)) return { - 'id': video_id, - 'url': video_url, - 'title': video_title, - 'ext': 'mp4', - } + 'id': video_id, + 'url': video_url, + 'title': title, + 'timestamp': timestamp, + 'filesize_approx': filesize, + 'duration': duration, + 'view_count': view_count, + }