[sexykarma] Improve and simplify

This commit is contained in:
Sergey M 2014-10-19 00:48:05 +07:00
parent 77c3c5c5ed
commit 95fa5fb569

View File

@ -1,77 +1,106 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor
import re import re
import datetime
from .common import InfoExtractor
from ..utils import (
unified_strdate,
parse_duration,
int_or_none,
)
class SexyKarmaIE(InfoExtractor): class SexyKarmaIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/.+\-(?P<id>[a-zA-Z0-9\-]+)(.html)' _VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/(?P<display_id>[^/]+)-(?P<id>[a-zA-Z0-9]+)\.html'
_TESTS = [{ _TESTS = [{
'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html', 'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html',
'md5': 'b9798e7d1ef1765116a8f516c8091dbd', 'md5': 'b9798e7d1ef1765116a8f516c8091dbd',
'info_dict': { 'info_dict': {
'id': 'yHI70cOyIHt', 'id': 'yHI70cOyIHt',
'display_id': 'taking-a-quick-pee',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Taking a quick pee.', 'title': 'Taking a quick pee.',
'uploader_id': 'wildginger7', 'description': '',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
'duration': int, 'uploader': 'wildginger7',
'view_count': int,
'upload_date': '20141007', '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', 'url': 'http://www.sexykarma.com/gonewild/video/pot-pixie-tribute-8Id6EZPbuHf.html',
'md5': 'dd216c68d29b49b12842b9babe762a5d', 'md5': 'dd216c68d29b49b12842b9babe762a5d',
'info_dict': { 'info_dict': {
'id': '8Id6EZPbuHf', 'id': '8Id6EZPbuHf',
'display_id': 'pot-pixie-tribute',
'ext': 'mp4', 'ext': 'mp4',
'title': 'pot_pixie tribute', 'title': 'pot_pixie tribute',
'uploader_id': 'banffite', 'description': 'tribute',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
'duration': int, 'uploader': 'banffite',
'view_count': int,
'upload_date': '20141013', 'upload_date': '20141013',
'duration': 16,
'view_count': int,
'comment_count': int,
'categories': list,
} }
}] }]
def _real_extract(self, url): 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) webpage = self._download_webpage(url, display_id)
title = self._html_search_regex(r'<h2 class="he2"><span>(.*?)</span>', webpage, 'title') video_url = self._html_search_regex(
uploader_id = self._html_search_regex(r'class="aupa">\n*(.*?)</a>', webpage, 'uploader') r'<p>Save this video to your computer: </p><p><a href="([^"]+)"',
url = self._html_search_regex(r'<p><a href="(.*?)" ?\n*target="_blank"><font color', webpage, 'url') webpage, 'url')
thumbnail = self._html_search_regex(r'<div id="player" style="z-index:1;"> <span id="edge"></span> <span id="container"><img[\n ]*src="(.+?)"', webpage, 'thumbnail')
str_duration = self._html_search_regex(r'<tr>[\n\s]*<td>Time: </td>[\n\s]*<td align="right"><span>(.+)\n*', webpage, 'duration') title = self._html_search_regex(
duration = self._to_seconds(str_duration) r'<h2 class="he2"><span>(.*?)</span>',
webpage, 'title')
description = self._html_search_meta(
'description', webpage, 'description', fatal=False, default='')
thumbnail = self._html_search_regex(
r'<span id="container"><img\s+src="([^"]+)"',
webpage, 'thumbnail', fatal=False)
str_views = self._html_search_regex(r'<tr>[\n\s]*<td>Views: </td>[\n\s]*<td align="right"><span>(.+)</span>', webpage, 'view_count') uploader = self._html_search_regex(
view_count = int(str_views) r'class="aupa">\s*(.*?)</a>',
# print view_count webpage, 'uploader')
upload_date = unified_strdate(self._html_search_regex(
r'Added: <strong>(.+?)</strong>', webpage, 'upload date', fatal=False))
date = self._html_search_regex(r'class="aup">Added: <strong>(.*?)</strong>', webpage, 'date') duration = parse_duration(self._search_regex(
d = datetime.datetime.strptime(date, '%B %d, %Y') r'<td>Time:\s*</td>\s*<td align="right"><span>\s*(.+?)\s*</span>',
upload_date = d.strftime('%Y%m%d') webpage, 'duration', fatal=False))
categories = re.findall(r'http://www.sexykarma.com/gonewild/search/video/(?:.+?)"><span>(.*?)</span>', webpage) view_count = int_or_none(self._search_regex(
r'<td>Views:\s*</td>\s*<td align="right"><span>\s*(\d+)\s*</span>',
webpage, 'view count', fatal=False))
comment_count = int_or_none(self._search_regex(
r'<td>Comments:\s*</td>\s*<td align="right"><span>\s*(\d+)\s*</span>',
webpage, 'comment count', fatal=False))
categories = self._html_search_meta(
'keywords', webpage, 'categories',
fatal=False, default='').split(',')
return { return {
'id': video_id, 'id': video_id,
'display_id': display_id,
'url': video_url,
'title': title, 'title': title,
'uploader_id': uploader_id, 'description': description,
'url': url,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'uploader': uploader,
'upload_date': upload_date,
'duration': duration, 'duration': duration,
'view_count': view_count, 'view_count': view_count,
'upload_date': upload_date, 'comment_count': comment_count,
'categories': categories, 'categories': categories,
} }
def _to_seconds(self, timestr):
seconds= 0
for part in timestr.split(':'):
seconds= seconds*60 + int(part)
return seconds