From 474086450808541954e402dd3d58bad38b75b1d5 Mon Sep 17 00:00:00 2001 From: CkuT Date: Wed, 15 Oct 2014 18:24:32 +0200 Subject: [PATCH 1/3] [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 5e38d2663..92f38dcd0 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -316,6 +316,7 @@ from .sbs import SBSIE 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 000000000..cd2668872 --- /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/3] 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 cd2668872..ac7745e74 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/3] 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 ac7745e74..629499e72 100644 --- a/youtube_dl/extractor/sexykarma.py +++ b/youtube_dl/extractor/sexykarma.py @@ -56,6 +56,8 @@ class SexyKarmaIE(InfoExtractor): 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 @@ class SexyKarmaIE(InfoExtractor): 'duration': duration, 'view_count': view_count, 'upload_date': upload_date, + 'categories': categories, } def _to_seconds(self, timestr):