yt-dlp/youtube_dl/extractor/sexykarma.py

78 lines
3.0 KiB
Python
Raw Normal View History

2014-10-15 16:24:32 +00:00
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
2014-10-15 18:17:07 +00:00
import re
import datetime
2014-10-15 16:24:32 +00:00
class SexyKarmaIE(InfoExtractor):
2014-10-15 18:17:07 +00:00
_VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/.+\-(?P<id>[a-zA-Z0-9\-]+)(.html)'
2014-10-15 16:24:32 +00:00
_TESTS = [{
'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html',
'md5': 'b9798e7d1ef1765116a8f516c8091dbd',
'info_dict': {
2014-10-15 18:17:07 +00:00
'id': 'yHI70cOyIHt',
2014-10-15 16:24:32 +00:00
'ext': 'mp4',
'title': 'Taking a quick pee.',
2014-10-15 18:17:07 +00:00
'uploader_id': 'wildginger7',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': int,
'view_count': int,
'upload_date': '20141007',
2014-10-15 16:24:32 +00:00
}
}, {
'url': 'http://www.sexykarma.com/gonewild/video/pot-pixie-tribute-8Id6EZPbuHf.html',
'md5': 'dd216c68d29b49b12842b9babe762a5d',
'info_dict': {
2014-10-15 18:17:07 +00:00
'id': '8Id6EZPbuHf',
2014-10-15 16:24:32 +00:00
'ext': 'mp4',
'title': 'pot_pixie tribute',
2014-10-15 18:17:07 +00:00
'uploader_id': 'banffite',
'thumbnail': 're:^https?://.*\.jpg$',
'duration': int,
'view_count': int,
'upload_date': '20141013',
2014-10-15 16:24:32 +00:00
}
}]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
2014-10-15 18:17:07 +00:00
2014-10-15 16:24:32 +00:00
title = self._html_search_regex(r'<h2 class="he2"><span>(.*?)</span>', webpage, 'title')
2014-10-15 18:17:07 +00:00
uploader_id = self._html_search_regex(r'class="aupa">\n*(.*?)</a>', webpage, 'uploader')
2014-10-15 16:24:32 +00:00
url = self._html_search_regex(r'<p><a href="(.*?)" ?\n*target="_blank"><font color', webpage, 'url')
2014-10-15 18:17:07 +00:00
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')
duration = self._to_seconds(str_duration)
str_views = self._html_search_regex(r'<tr>[\n\s]*<td>Views: </td>[\n\s]*<td align="right"><span>(.+)</span>', webpage, 'view_count')
view_count = int(str_views)
# print view_count
date = self._html_search_regex(r'class="aup">Added: <strong>(.*?)</strong>', webpage, 'date')
d = datetime.datetime.strptime(date, '%B %d, %Y')
upload_date = d.strftime('%Y%m%d')
2014-10-15 16:24:32 +00:00
2014-10-15 20:34:35 +00:00
categories = re.findall(r'http://www.sexykarma.com/gonewild/search/video/(?:.+?)"><span>(.*?)</span>', webpage)
2014-10-15 16:24:32 +00:00
return {
'id': video_id,
'title': title,
2014-10-15 18:17:07 +00:00
'uploader_id': uploader_id,
'url': url,
'thumbnail': thumbnail,
'duration': duration,
'view_count': view_count,
'upload_date': upload_date,
2014-10-15 20:34:35 +00:00
'categories': categories,
2014-10-15 16:24:32 +00:00
}
2014-10-15 18:17:07 +00:00
def _to_seconds(self, timestr):
seconds= 0
for part in timestr.split(':'):
seconds= seconds*60 + int(part)
return seconds