mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-04 10:52:53 +08:00
[nuevo] Complied with the code comments.
This commit is contained in:
parent
0dc7852080
commit
310bcd7300
@ -3,31 +3,35 @@ from __future__ import unicode_literals
|
||||
|
||||
from .common import InfoExtractor
|
||||
|
||||
from ..utils import float_or_none
|
||||
from ..utils import (
|
||||
float_or_none,
|
||||
xpath_text
|
||||
)
|
||||
|
||||
|
||||
class NuevoBaseIE(InfoExtractor):
|
||||
def _extract_nuevo(self, config_url, video_id, info=None, ignore_hd=False):
|
||||
if info is None:
|
||||
info = {}
|
||||
|
||||
sdformats, hdformats = [], []
|
||||
def _extract_nuevo(self, config_url, video_id):
|
||||
tree = self._download_xml(config_url, video_id, transform_source=lambda s: s.strip())
|
||||
|
||||
for child in tree:
|
||||
tag, val = child.tag, child.text
|
||||
title = xpath_text(tree, './title')
|
||||
if title:
|
||||
title = title.strip()
|
||||
|
||||
if tag == "file":
|
||||
sdformats.append({"url": val})
|
||||
elif tag == "filehd" and not ignore_hd:
|
||||
hdformats.append({"url": val})
|
||||
elif tag == "duration":
|
||||
info["duration"] = float_or_none(val)
|
||||
elif tag == "image":
|
||||
info["thumbnail"] = val
|
||||
elif tag == "title":
|
||||
info["title"] = val.strip()
|
||||
thumbnail = xpath_text(tree, './image')
|
||||
duration = float_or_none(xpath_text(tree, './duration'))
|
||||
|
||||
info["id"] = video_id
|
||||
info["formats"] = sdformats + hdformats
|
||||
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 info
|
||||
return {
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'thumbnail': thumbnail,
|
||||
'duration': duration,
|
||||
'formats': formats
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import re
|
||||
|
||||
|
||||
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>[0-9]+)/+(?P<title>[^?&]+)'
|
||||
IE_NAME = 'trollvids'
|
||||
|
||||
def _real_extract(self, url):
|
||||
@ -19,17 +19,20 @@ class TrollvidsIE(NuevoBaseIE):
|
||||
|
||||
video_id = match.group('id')
|
||||
raw_video_title = match.group('title')
|
||||
video_title = compat_urllib_parse_unquote(raw_video_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
|
||||
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 = {
|
||||
"title": video_title,
|
||||
"webpage_url": url,
|
||||
"age_limit": 18
|
||||
}
|
||||
info = self._extract_nuevo(config_url, video_id)
|
||||
|
||||
return self._extract_nuevo(config_url, video_id, info)
|
||||
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 = [
|
||||
{
|
||||
|
@ -21,7 +21,11 @@ class TruTubeIE(NuevoBaseIE):
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
config_url = "https://trutube.tv/nuevo/player/config.php?v=%s" % video_id
|
||||
config_url = 'https://trutube.tv/nuevo/player/config.php?v=%s' % video_id
|
||||
|
||||
# filehd is always 404
|
||||
return self._extract_nuevo(config_url, video_id, ignore_hd=True)
|
||||
info = self._extract_nuevo(config_url, video_id)
|
||||
|
||||
# filehd always 404s
|
||||
info['formats'] = info['formats'][:1]
|
||||
|
||||
return info
|
||||
|
Loading…
Reference in New Issue
Block a user