[la7] Add support
[youtube-dl] / youtube_dl / extractor / la7.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     parse_duration,
8 )
9
10
11 class LA7IE(InfoExtractor):
12     IE_NAME = 'la7.tv'
13     _VALID_URL = r'https?://(?:www\.)?la7\.tv/richplayer/\?assetid=(?P<id>[0-9]+)'
14
15     _TEST = {
16         'url': 'http://www.la7.tv/richplayer/?assetid=50355319',
17         'file': '50355319.mp4',
18         'md5': 'ec7d1f0224d20ba293ab56cf2259651f',
19         'info_dict': {
20             'title': 'IL DIVO',
21             'description': 'Un film di Paolo Sorrentino con Toni Servillo, Anna Bonaiuto, Giulio Bosetti  e Flavio Bucci',
22             'duration': 6254,
23         }
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group('id')
29
30         xml_url = 'http://www.la7.tv/repliche/content/index.php?contentId=%s' % video_id
31         doc = self._download_xml(xml_url, video_id)
32
33         video_title = doc.find('title').text
34         description = doc.find('description').text
35         duration = parse_duration(doc.find('duration').text)
36         thumbnail = doc.find('img').text
37         view_count = int(doc.find('views').text)
38
39         prefix = doc.find('.//fqdn').text.strip().replace('auto:', 'http:')
40
41         formats = [{
42             'format': vnode.find('quality').text,
43             'tbr': int(vnode.find('quality').text),
44             'url': vnode.find('fms').text.strip().replace('mp4:', prefix),
45         } for vnode in doc.findall('.//videos/video')]
46         self._sort_formats(formats)
47
48         return {
49             'id': video_id,
50             'title': video_title,
51             'description': description,
52             'thumbnail': thumbnail,
53             'duration': duration,
54             'formats': formats,
55             'view_count': view_count,
56         }