]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/la7.py
Merge tag 'upstream/2014.12.01'
[youtubedl] / 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'''(?x)
14 https?://(?:www\.)?la7\.tv/
15 (?:
16 richplayer/\?assetid=|
17 \?contentId=
18 )
19 (?P<id>[0-9]+)'''
20
21 _TEST = {
22 'url': 'http://www.la7.tv/richplayer/?assetid=50355319',
23 'file': '50355319.mp4',
24 'md5': 'ec7d1f0224d20ba293ab56cf2259651f',
25 'info_dict': {
26 'title': 'IL DIVO',
27 'description': 'Un film di Paolo Sorrentino con Toni Servillo, Anna Bonaiuto, Giulio Bosetti e Flavio Bucci',
28 'duration': 6254,
29 },
30 'skip': 'Blocked in the US',
31 }
32
33 def _real_extract(self, url):
34 mobj = re.match(self._VALID_URL, url)
35 video_id = mobj.group('id')
36
37 xml_url = 'http://www.la7.tv/repliche/content/index.php?contentId=%s' % video_id
38 doc = self._download_xml(xml_url, video_id)
39
40 video_title = doc.find('title').text
41 description = doc.find('description').text
42 duration = parse_duration(doc.find('duration').text)
43 thumbnail = doc.find('img').text
44 view_count = int(doc.find('views').text)
45
46 prefix = doc.find('.//fqdn').text.strip().replace('auto:', 'http:')
47
48 formats = [{
49 'format': vnode.find('quality').text,
50 'tbr': int(vnode.find('quality').text),
51 'url': vnode.find('fms').text.strip().replace('mp4:', prefix),
52 } for vnode in doc.findall('.//videos/video')]
53 self._sort_formats(formats)
54
55 return {
56 'id': video_id,
57 'title': video_title,
58 'description': description,
59 'thumbnail': thumbnail,
60 'duration': duration,
61 'formats': formats,
62 'view_count': view_count,
63 }