From e0bd46eedc18113512da9e3f3e1a9238bf640b0d Mon Sep 17 00:00:00 2001 From: "Andrew \"Akari\" Alexeyew" Date: Wed, 2 Dec 2015 06:00:47 +0200 Subject: [PATCH] [trollvids] Added a basic trollvids.com extractor. Supports only the nuevo player for now (most common). --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/trollvids.py | 52 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 youtube_dl/extractor/trollvids.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 947b83683..bbf656090 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -666,6 +666,7 @@ from .toutv import TouTvIE from .toypics import ToypicsUserIE, ToypicsIE from .traileraddict import TrailerAddictIE from .trilulilu import TriluliluIE +from .trollvids import TrollvidsIE from .trutube import TruTubeIE from .tube8 import Tube8IE from .tubitv import TubiTvIE diff --git a/youtube_dl/extractor/trollvids.py b/youtube_dl/extractor/trollvids.py new file mode 100644 index 000000000..beb93862b --- /dev/null +++ b/youtube_dl/extractor/trollvids.py @@ -0,0 +1,52 @@ +# encoding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + +from ..compat import ( + compat_urllib_parse_unquote +) + +import re +import xml.etree.ElementTree + +class TrollvidsIE(InfoExtractor): + _VALID_URL = r"http://(?:www\.)?trollvids\.com/+video/+(?P[0-9]+)/+(?P[^?&]+)" + 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') + video_title = compat_urllib_parse_unquote(raw_video_title) + url = "http://trollvids.com/video/%s/%s" % (video_id, raw_video_title) + + info = { + "id": video_id, + "title": video_title, + "webpage_url": url, + "age_limit": 18 + } + + sdformats = [] + hdformats = [] + + tree = self._download_xml("http://trollvids.com/nuevo/player/config.php?v=%s" % video_id, video_id) + + for child in tree: + tag, val = child.tag, child.text + + if tag == "file": + sdformats.append({"url": val}) + elif tag == "filehd": + hdformats.append({"url": val}) + elif tag == "duration": + info["duration"] = float(val) + elif tag == "image": + info["thumbnail"] = val + elif tag == "title": + info["title"] = val + + info["formats"] = sdformats + hdformats + return info