Unify coding cookie
[youtube-dl] / youtube_dl / extractor / nuevo.py
1 # coding: 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         config = self._download_xml(
15             config_url, video_id, transform_source=lambda s: s.strip())
16
17         title = xpath_text(config, './title', 'title', fatal=True).strip()
18         video_id = xpath_text(config, './mediaid', default=video_id)
19         thumbnail = xpath_text(config, ['./image', './thumb'])
20         duration = float_or_none(xpath_text(config, './duration'))
21
22         formats = []
23         for element_name, format_id in (('file', 'sd'), ('filehd', 'hd')):
24             video_url = xpath_text(config, element_name)
25             if video_url:
26                 formats.append({
27                     'url': video_url,
28                     'format_id': format_id,
29                 })
30         self._check_formats(formats, video_id)
31
32         return {
33             'id': video_id,
34             'title': title,
35             'thumbnail': thumbnail,
36             'duration': duration,
37             'formats': formats
38         }