youtube-dl/youtube_dl/extractor/sexu.py

62 lines
1.9 KiB
Python
Raw Normal View History

2014-11-13 04:41:13 +09:00
from __future__ import unicode_literals
import re
2014-11-13 04:41:13 +09:00
from .common import InfoExtractor
from ..utils import urlencode_postdata
2014-11-13 04:41:13 +09:00
class SexuIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?sexu\.com/(?P<id>\d+)'
_TEST = {
'url': 'http://sexu.com/961791/',
'md5': 'ff615aca9691053c94f8f10d96cd7884',
'info_dict': {
'id': '961791',
'ext': 'mp4',
2014-11-13 22:02:53 +09:00
'title': 'md5:4d05a19a5fc049a63dbbaf05fb71d91b',
'description': 'md5:6c7e471f9ac9bc326a9ad27be409f617',
2014-11-13 04:41:13 +09:00
'categories': list, # NSFW
'thumbnail': r're:https?://.*\.jpg$',
2014-11-13 04:41:13 +09:00
'age_limit': 18,
}
}
def _real_extract(self, url):
2014-11-13 23:20:49 +09:00
video_id = self._match_id(url)
2014-11-13 04:41:13 +09:00
webpage = self._download_webpage(url, video_id)
apiresponse = self._download_json(
'https://sexu.com/api/video-info',
video_id, data=urlencode_postdata({'videoId': video_id})
)
2014-11-13 04:41:13 +09:00
formats = [{
'url': source.get('src'),
'format_id': source.get('type'),
2017-06-09 02:30:23 +09:00
'height': int(self._search_regex(
r'^(\d+)[pP]', source.get('quality', ''), 'height',
2017-06-09 02:30:23 +09:00
default=None)),
} for source in apiresponse['sources']]
2014-11-13 04:41:13 +09:00
self._sort_formats(formats)
title = self._og_search_property('title', webpage)
2014-11-13 04:41:13 +09:00
2014-11-13 23:20:49 +09:00
description = self._html_search_meta(
'description', webpage, 'description')
2014-11-13 04:41:13 +09:00
thumbnail = self._og_search_property('image', webpage)
2014-11-13 04:41:13 +09:00
categories = re.findall(
r'(?s)<a class=[\'"]player-tags__item[\'"][^>]*>(.*?)</a>', webpage
)
2014-11-13 04:41:13 +09:00
return {
'id': video_id,
'title': title,
'description': description,
'thumbnail': thumbnail,
'categories': categories,
'formats': formats,
'age_limit': 18,
}