mirror of https://github.com/yt-dlp/yt-dlp
[nuevo] Generalize nuevo extractor and add support for trollvids
Supports only the nuevo player for now (most common). [trollvids] convert duration to an int [trollvids] added a test [trollvids] made flake8 shut up Generalized the Nuevo extractor Affects: anitube, trollvids, trutube [nuevo] Complied with the code comments.pull/8/head
parent
4fcd9d147d
commit
d570746e45
@ -0,0 +1,37 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from .common import InfoExtractor
|
||||||
|
|
||||||
|
from ..utils import (
|
||||||
|
float_or_none,
|
||||||
|
xpath_text
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NuevoBaseIE(InfoExtractor):
|
||||||
|
def _extract_nuevo(self, config_url, video_id):
|
||||||
|
tree = self._download_xml(config_url, video_id, transform_source=lambda s: s.strip())
|
||||||
|
|
||||||
|
title = xpath_text(tree, './title')
|
||||||
|
if title:
|
||||||
|
title = title.strip()
|
||||||
|
|
||||||
|
thumbnail = xpath_text(tree, './image')
|
||||||
|
duration = float_or_none(xpath_text(tree, './duration'))
|
||||||
|
|
||||||
|
formats = []
|
||||||
|
for element_name, format_id in (('file', 'sd'), ('filehd', 'hd')):
|
||||||
|
video_url = tree.find(element_name)
|
||||||
|
video_url is None or formats.append({
|
||||||
|
'format_id': format_id,
|
||||||
|
'url': video_url.text
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
'id': video_id,
|
||||||
|
'title': title,
|
||||||
|
'thumbnail': thumbnail,
|
||||||
|
'duration': duration,
|
||||||
|
'formats': formats
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from .nuevo import NuevoBaseIE
|
||||||
|
|
||||||
|
from ..compat import (
|
||||||
|
compat_urllib_parse_unquote
|
||||||
|
)
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class TrollvidsIE(NuevoBaseIE):
|
||||||
|
_VALID_URL = r'http://(?:www\.)?trollvids\.com/+video/+(?P<id>[0-9]+)/+(?P<title>[^?&]+)'
|
||||||
|
IE_NAME = 'trollvids'
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
match = re.match(self._VALID_URL, url)
|
||||||
|
|
||||||
|
video_id = match.group('id')
|
||||||
|
raw_video_title = match.group('title')
|
||||||
|
url = 'http://trollvids.com/video/%s/%s' % (video_id, raw_video_title)
|
||||||
|
config_url = 'http://trollvids.com/nuevo/player/config.php?v=%s' % video_id
|
||||||
|
|
||||||
|
info = self._extract_nuevo(config_url, video_id)
|
||||||
|
|
||||||
|
info.update({
|
||||||
|
'webpage_url': url,
|
||||||
|
'age_limit': 18
|
||||||
|
})
|
||||||
|
|
||||||
|
if 'title' not in info:
|
||||||
|
info['title'] = compat_urllib_parse_unquote(raw_video_title)
|
||||||
|
|
||||||
|
return info
|
||||||
|
|
||||||
|
_TESTS = [
|
||||||
|
{
|
||||||
|
'url': 'http://trollvids.com/video/2349002/%E3%80%90MMD-R-18%E3%80%91%E3%82%AC%E3%83%BC%E3%83%AB%E3%83%95%E3%83%AC%E3%83%B3%E3%83%89-carrymeoff',
|
||||||
|
'md5': '1d53866b2c514b23ed69e4352fdc9839',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '2349002',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': "【MMD R-18】ガールフレンド carry_me_off",
|
||||||
|
'age_limit': 18,
|
||||||
|
'duration': 216.78,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
Loading…
Reference in New Issue