[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 .common import InfoExtractor
|
||||||
|
|
||||||
from ..utils import float_or_none
|
from ..utils import (
|
||||||
|
float_or_none,
|
||||||
|
xpath_text
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NuevoBaseIE(InfoExtractor):
|
class NuevoBaseIE(InfoExtractor):
|
||||||
def _extract_nuevo(self, config_url, video_id, info=None, ignore_hd=False):
|
def _extract_nuevo(self, config_url, video_id):
|
||||||
if info is None:
|
|
||||||
info = {}
|
|
||||||
|
|
||||||
sdformats, hdformats = [], []
|
|
||||||
tree = self._download_xml(config_url, video_id, transform_source=lambda s: s.strip())
|
tree = self._download_xml(config_url, video_id, transform_source=lambda s: s.strip())
|
||||||
|
|
||||||
for child in tree:
|
title = xpath_text(tree, './title')
|
||||||
tag, val = child.tag, child.text
|
if title:
|
||||||
|
title = title.strip()
|
||||||
|
|
||||||
if tag == "file":
|
thumbnail = xpath_text(tree, './image')
|
||||||
sdformats.append({"url": val})
|
duration = float_or_none(xpath_text(tree, './duration'))
|
||||||
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()
|
|
||||||
|
|
||||||
info["id"] = video_id
|
formats = []
|
||||||
info["formats"] = sdformats + hdformats
|
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):
|
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'
|
IE_NAME = 'trollvids'
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
@ -19,17 +19,20 @@ class TrollvidsIE(NuevoBaseIE):
|
|||||||
|
|
||||||
video_id = match.group('id')
|
video_id = match.group('id')
|
||||||
raw_video_title = match.group('title')
|
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)
|
||||||
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
|
||||||
config_url = "http://trollvids.com/nuevo/player/config.php?v=%s" % video_id
|
|
||||||
|
|
||||||
info = {
|
info = self._extract_nuevo(config_url, video_id)
|
||||||
"title": video_title,
|
|
||||||
"webpage_url": url,
|
|
||||||
"age_limit": 18
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = [
|
_TESTS = [
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,11 @@ 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
|
config_url = 'https://trutube.tv/nuevo/player/config.php?v=%s' % video_id
|
||||||
|
|
||||||
# filehd is always 404
|
info = self._extract_nuevo(config_url, video_id)
|
||||||
return self._extract_nuevo(config_url, video_id, ignore_hd=True)
|
|
||||||
|
# filehd always 404s
|
||||||
|
info['formats'] = info['formats'][:1]
|
||||||
|
|
||||||
|
return info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user