[nuevo] Generalize nuevo extractor and add support for trollvids
[youtube-dl] / youtube_dl / extractor / nuevo.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6 from ..utils import (
7     float_or_none,
8     xpath_text
9 )
10
11
12 class NuevoBaseIE(InfoExtractor):
13     def _extract_nuevo(self, config_url, video_id):
14         tree = self._download_xml(config_url, video_id, transform_source=lambda s: s.strip())
15
16         title = xpath_text(tree, './title')
17         if title:
18             title = title.strip()
19
20         thumbnail = xpath_text(tree, './image')
21         duration = float_or_none(xpath_text(tree, './duration'))
22
23         formats = []
24         for element_name, format_id in (('file', 'sd'), ('filehd', 'hd')):
25             video_url = tree.find(element_name)
26             video_url is None or formats.append({
27                 'format_id': format_id,
28                 'url': video_url.text
29             })
30
31         return {
32             'id': video_id,
33             'title': title,
34             'thumbnail': thumbnail,
35             'duration': duration,
36             'formats': formats
37         }