From 474086450808541954e402dd3d58bad38b75b1d5 Mon Sep 17 00:00:00 2001 From: CkuT Date: Wed, 15 Oct 2014 18:24:32 +0200 Subject: [PATCH 1/4] [SexyKarma] Add new extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/sexykarma.py | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 youtube_dl/extractor/sexykarma.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 5e38d26630..92f38dcd00 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -316,6 +316,7 @@ from .scivee import SciVeeIE from .screencast import ScreencastIE from .servingsys import ServingSysIE +from .sexykarma import SexyKarmaIE from .shared import SharedIE from .sharesix import ShareSixIE from .sina import SinaIE diff --git a/youtube_dl/extractor/sexykarma.py b/youtube_dl/extractor/sexykarma.py new file mode 100644 index 0000000000..cd2668872b --- /dev/null +++ b/youtube_dl/extractor/sexykarma.py @@ -0,0 +1,43 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + + +class SexyKarmaIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/(?P[a-zA-Z0-9\-]+)(.html)' + _TESTS = [{ + 'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html', + 'md5': 'b9798e7d1ef1765116a8f516c8091dbd', + 'info_dict': { + 'id': 'taking-a-quick-pee-yHI70cOyIHt', + 'ext': 'mp4', + 'title': 'Taking a quick pee.', + 'uploader': 'wildginger7', + } + }, { + 'url': 'http://www.sexykarma.com/gonewild/video/pot-pixie-tribute-8Id6EZPbuHf.html', + 'md5': 'dd216c68d29b49b12842b9babe762a5d', + 'info_dict': { + 'id': 'pot-pixie-tribute-8Id6EZPbuHf', + 'ext': 'mp4', + 'title': 'pot_pixie tribute', + 'uploader': 'banffite', + } + }] + + def _real_extract(self, url): + video_id = self._match_id(url) + + # TODO more code goes here, for example ... + webpage = self._download_webpage(url, video_id) + title = self._html_search_regex(r'

(.*?)', webpage, 'title') + uploader = self._html_search_regex(r'class="aupa">\n*(.*?)', webpage, 'uploader') + url = self._html_search_regex(r'

Date: Wed, 15 Oct 2014 20:17:07 +0200 Subject: [PATCH 2/4] Few improvements --- youtube_dl/extractor/sexykarma.py | 51 +++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/youtube_dl/extractor/sexykarma.py b/youtube_dl/extractor/sexykarma.py index cd2668872b..ac7745e74e 100644 --- a/youtube_dl/extractor/sexykarma.py +++ b/youtube_dl/extractor/sexykarma.py @@ -2,42 +2,73 @@ from __future__ import unicode_literals from .common import InfoExtractor - +import re +import datetime class SexyKarmaIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/(?P[a-zA-Z0-9\-]+)(.html)' + _VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/.+\-(?P[a-zA-Z0-9\-]+)(.html)' _TESTS = [{ 'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html', 'md5': 'b9798e7d1ef1765116a8f516c8091dbd', 'info_dict': { - 'id': 'taking-a-quick-pee-yHI70cOyIHt', + 'id': 'yHI70cOyIHt', 'ext': 'mp4', 'title': 'Taking a quick pee.', - 'uploader': 'wildginger7', + 'uploader_id': 'wildginger7', + 'thumbnail': 're:^https?://.*\.jpg$', + 'duration': int, + 'view_count': int, + 'upload_date': '20141007', } }, { 'url': 'http://www.sexykarma.com/gonewild/video/pot-pixie-tribute-8Id6EZPbuHf.html', 'md5': 'dd216c68d29b49b12842b9babe762a5d', 'info_dict': { - 'id': 'pot-pixie-tribute-8Id6EZPbuHf', + 'id': '8Id6EZPbuHf', 'ext': 'mp4', 'title': 'pot_pixie tribute', - 'uploader': 'banffite', + 'uploader_id': 'banffite', + 'thumbnail': 're:^https?://.*\.jpg$', + 'duration': int, + 'view_count': int, + 'upload_date': '20141013', } }] def _real_extract(self, url): video_id = self._match_id(url) - # TODO more code goes here, for example ... webpage = self._download_webpage(url, video_id) + title = self._html_search_regex(r'

(.*?)', webpage, 'title') - uploader = self._html_search_regex(r'class="aupa">\n*(.*?)', webpage, 'uploader') + uploader_id = self._html_search_regex(r'class="aupa">\n*(.*?)', webpage, 'uploader') url = self._html_search_regex(r'

[\n\s]*Time: [\n\s]*(.+)\n*', webpage, 'duration') + duration = self._to_seconds(str_duration) + + str_views = self._html_search_regex(r'[\n\s]*Views: [\n\s]*(.+)', webpage, 'view_count') + view_count = int(str_views) + # print view_count + + date = self._html_search_regex(r'class="aup">Added: (.*?)', webpage, 'date') + d = datetime.datetime.strptime(date, '%B %d, %Y') + upload_date = d.strftime('%Y%m%d') return { 'id': video_id, 'title': title, - 'uploader': uploader, - 'url': url + 'uploader_id': uploader_id, + 'url': url, + 'thumbnail': thumbnail, + 'duration': duration, + 'view_count': view_count, + 'upload_date': upload_date, } + + def _to_seconds(self, timestr): + seconds= 0 + for part in timestr.split(':'): + seconds= seconds*60 + int(part) + return seconds From 7da224c907627b5b0233c7eb4eea733f5f97ae90 Mon Sep 17 00:00:00 2001 From: CkuT Date: Wed, 15 Oct 2014 22:34:35 +0200 Subject: [PATCH 3/4] Add categories --- youtube_dl/extractor/sexykarma.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/youtube_dl/extractor/sexykarma.py b/youtube_dl/extractor/sexykarma.py index ac7745e74e..629499e723 100644 --- a/youtube_dl/extractor/sexykarma.py +++ b/youtube_dl/extractor/sexykarma.py @@ -56,6 +56,8 @@ def _real_extract(self, url): d = datetime.datetime.strptime(date, '%B %d, %Y') upload_date = d.strftime('%Y%m%d') + categories = re.findall(r'http://www.sexykarma.com/gonewild/search/video/(?:.+?)">(.*?)', webpage) + return { 'id': video_id, 'title': title, @@ -65,6 +67,7 @@ def _real_extract(self, url): 'duration': duration, 'view_count': view_count, 'upload_date': upload_date, + 'categories': categories, } def _to_seconds(self, timestr): From 95fa5fb569c9a29d1dfb7da744022373d279fcb7 Mon Sep 17 00:00:00 2001 From: Sergey M Date: Sun, 19 Oct 2014 00:48:05 +0700 Subject: [PATCH 4/4] [sexykarma] Improve and simplify --- youtube_dl/extractor/sexykarma.py | 99 ++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 35 deletions(-) diff --git a/youtube_dl/extractor/sexykarma.py b/youtube_dl/extractor/sexykarma.py index 629499e723..4a6345758a 100644 --- a/youtube_dl/extractor/sexykarma.py +++ b/youtube_dl/extractor/sexykarma.py @@ -1,77 +1,106 @@ # coding: utf-8 from __future__ import unicode_literals -from .common import InfoExtractor import re -import datetime + +from .common import InfoExtractor +from ..utils import ( + unified_strdate, + parse_duration, + int_or_none, +) + class SexyKarmaIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/.+\-(?P[a-zA-Z0-9\-]+)(.html)' + _VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/(?P[^/]+)-(?P[a-zA-Z0-9]+)\.html' _TESTS = [{ 'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html', 'md5': 'b9798e7d1ef1765116a8f516c8091dbd', 'info_dict': { 'id': 'yHI70cOyIHt', + 'display_id': 'taking-a-quick-pee', 'ext': 'mp4', 'title': 'Taking a quick pee.', - 'uploader_id': 'wildginger7', + 'description': '', 'thumbnail': 're:^https?://.*\.jpg$', - 'duration': int, - 'view_count': int, + 'uploader': 'wildginger7', 'upload_date': '20141007', + 'duration': 81, + 'view_count': int, + 'comment_count': int, + 'categories': list, } }, { 'url': 'http://www.sexykarma.com/gonewild/video/pot-pixie-tribute-8Id6EZPbuHf.html', 'md5': 'dd216c68d29b49b12842b9babe762a5d', 'info_dict': { 'id': '8Id6EZPbuHf', + 'display_id': 'pot-pixie-tribute', 'ext': 'mp4', 'title': 'pot_pixie tribute', - 'uploader_id': 'banffite', + 'description': 'tribute', 'thumbnail': 're:^https?://.*\.jpg$', - 'duration': int, - 'view_count': int, + 'uploader': 'banffite', 'upload_date': '20141013', + 'duration': 16, + 'view_count': int, + 'comment_count': int, + 'categories': list, } }] def _real_extract(self, url): - video_id = self._match_id(url) + mobj = re.match(self._VALID_URL, url) + video_id = mobj.group('id') + display_id = mobj.group('display_id') - webpage = self._download_webpage(url, video_id) - - title = self._html_search_regex(r'

(.*?)', webpage, 'title') - uploader_id = self._html_search_regex(r'class="aupa">\n*(.*?)', webpage, 'uploader') - url = self._html_search_regex(r'

[\n\s]*Time: [\n\s]*(.+)\n*', webpage, 'duration') - duration = self._to_seconds(str_duration) + webpage = self._download_webpage(url, display_id) - str_views = self._html_search_regex(r'[\n\s]*Views: [\n\s]*(.+)', webpage, 'view_count') - view_count = int(str_views) - # print view_count + video_url = self._html_search_regex( + r'

Save this video to your computer:

Added: (.*?)', webpage, 'date') - d = datetime.datetime.strptime(date, '%B %d, %Y') - upload_date = d.strftime('%Y%m%d') + title = self._html_search_regex( + r'

(.*?)', + webpage, 'title') + description = self._html_search_meta( + 'description', webpage, 'description', fatal=False, default='') + thumbnail = self._html_search_regex( + r'(.*?)', webpage) + uploader = self._html_search_regex( + r'class="aupa">\s*(.*?)', + webpage, 'uploader') + upload_date = unified_strdate(self._html_search_regex( + r'Added: (.+?)', webpage, 'upload date', fatal=False)) + + duration = parse_duration(self._search_regex( + r'Time:\s*\s*\s*(.+?)\s*', + webpage, 'duration', fatal=False)) + + view_count = int_or_none(self._search_regex( + r'Views:\s*\s*\s*(\d+)\s*', + webpage, 'view count', fatal=False)) + comment_count = int_or_none(self._search_regex( + r'Comments:\s*\s*\s*(\d+)\s*', + webpage, 'comment count', fatal=False)) + + categories = self._html_search_meta( + 'keywords', webpage, 'categories', + fatal=False, default='').split(',') return { 'id': video_id, + 'display_id': display_id, + 'url': video_url, 'title': title, - 'uploader_id': uploader_id, - 'url': url, + 'description': description, 'thumbnail': thumbnail, + 'uploader': uploader, + 'upload_date': upload_date, 'duration': duration, 'view_count': view_count, - 'upload_date': upload_date, + 'comment_count': comment_count, 'categories': categories, } - - def _to_seconds(self, timestr): - seconds= 0 - for part in timestr.split(':'): - seconds= seconds*60 + int(part) - return seconds