[nuevo] Simplify nuevo extractors (Closes #7728)

This commit is contained in:
Sergey M․ 2016-01-23 00:04:33 +06:00
parent d570746e45
commit 10677ece81
4 changed files with 41 additions and 61 deletions

View File

@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from .nuevo import NuevoBaseIE from .nuevo import NuevoBaseIE
@ -22,12 +20,11 @@ class AnitubeIE(NuevoBaseIE):
} }
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) video_id = self._match_id(url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
key = self._search_regex( key = self._search_regex(
r'src=["\']https?://[^/]+/embed/([A-Za-z0-9_-]+)', webpage, 'key') r'src=["\']https?://[^/]+/embed/([A-Za-z0-9_-]+)', webpage, 'key')
config_url = 'http://www.anitube.se/nuevo/econfig.php?key=%s' % key return self._extract_nuevo(
return self._extract_nuevo(config_url, video_id) 'http://www.anitube.se/nuevo/econfig.php?key=%s' % key, video_id)

View File

@ -11,22 +11,23 @@ from ..utils import (
class NuevoBaseIE(InfoExtractor): class NuevoBaseIE(InfoExtractor):
def _extract_nuevo(self, config_url, video_id): def _extract_nuevo(self, config_url, video_id):
tree = self._download_xml(config_url, video_id, transform_source=lambda s: s.strip()) config = self._download_xml(
config_url, video_id, transform_source=lambda s: s.strip())
title = xpath_text(tree, './title') title = xpath_text(config, './title', 'title', fatal=True).strip()
if title: video_id = xpath_text(config, './mediaid', default=video_id)
title = title.strip() thumbnail = xpath_text(config, './image')
duration = float_or_none(xpath_text(config, './duration'))
thumbnail = xpath_text(tree, './image')
duration = float_or_none(xpath_text(tree, './duration'))
formats = [] formats = []
for element_name, format_id in (('file', 'sd'), ('filehd', 'hd')): for element_name, format_id in (('file', 'sd'), ('filehd', 'hd')):
video_url = tree.find(element_name) video_url = xpath_text(config, element_name)
video_url is None or formats.append({ if video_url:
'format_id': format_id, formats.append({
'url': video_url.text 'url': video_url,
}) 'format_id': format_id,
})
self._check_formats(formats, video_id)
return { return {
'id': video_id, 'id': video_id,

View File

@ -1,49 +1,36 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from .nuevo import NuevoBaseIE
from ..compat import (
compat_urllib_parse_unquote
)
import re import re
from .nuevo import NuevoBaseIE
class TrollvidsIE(NuevoBaseIE): class TrollvidsIE(NuevoBaseIE):
_VALID_URL = r'http://(?:www\.)?trollvids\.com/+video/+(?P<id>[0-9]+)/+(?P<title>[^?&]+)' _VALID_URL = r'http://(?:www\.)?trollvids\.com/video/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
IE_NAME = 'trollvids' IE_NAME = 'trollvids'
_TEST = {
'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,
},
}
def _real_extract(self, url): def _real_extract(self, url):
match = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
video_id = match.group('id') display_id = mobj.group('display_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 = self._extract_nuevo(
'http://trollvids.com/nuevo/player/config.php?v=%s' % video_id,
video_id)
info.update({ info.update({
'webpage_url': url, 'display_id': display_id,
'age_limit': 18 'age_limit': 18
}) })
if 'title' not in info:
info['title'] = compat_urllib_parse_unquote(raw_video_title)
return info 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,
},
},
]

View File

@ -4,7 +4,7 @@ from .nuevo import NuevoBaseIE
class TruTubeIE(NuevoBaseIE): class TruTubeIE(NuevoBaseIE):
_VALID_URL = r'https?://(?:www\.)?trutube\.tv/(?:video/|nuevo/player/embed\.php\?v=)(?P<id>[0-9]+)' _VALID_URL = r'https?://(?:www\.)?trutube\.tv/(?:video/|nuevo/player/embed\.php\?v=)(?P<id>\d+)'
_TESTS = [{ _TESTS = [{
'url': 'http://trutube.tv/video/14880/Ramses-II-Proven-To-Be-A-Red-Headed-Caucasoid-', 'url': 'http://trutube.tv/video/14880/Ramses-II-Proven-To-Be-A-Red-Headed-Caucasoid-',
'md5': 'c5b6e301b0a2040b074746cbeaa26ca1', 'md5': 'c5b6e301b0a2040b074746cbeaa26ca1',
@ -21,11 +21,6 @@ class TruTubeIE(NuevoBaseIE):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
config_url = 'https://trutube.tv/nuevo/player/config.php?v=%s' % video_id return self._extract_nuevo(
'https://trutube.tv/nuevo/player/config.php?v=%s' % video_id,
info = self._extract_nuevo(config_url, video_id) video_id)
# filehd always 404s
info['formats'] = info['formats'][:1]
return info