]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/lrt.py
Imported Upstream version 2015.05.15
[youtubedl] / youtube_dl / extractor / lrt.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 determine_ext,
9 js_to_json,
10 parse_duration,
11 remove_end,
12 )
13
14
15 class LRTIE(InfoExtractor):
16 IE_NAME = 'lrt.lt'
17 _VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/irasas/(?P<id>[0-9]+)'
18 _TEST = {
19 'url': 'http://www.lrt.lt/mediateka/irasas/54391/',
20 'info_dict': {
21 'id': '54391',
22 'ext': 'mp4',
23 'title': 'Septynios Kauno dienos',
24 'description': 'md5:24d84534c7dc76581e59f5689462411a',
25 'duration': 1783,
26 },
27 'params': {
28 'skip_download': True, # HLS download
29 },
30 }
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34 webpage = self._download_webpage(url, video_id)
35
36 title = remove_end(self._og_search_title(webpage), ' - LRT')
37 thumbnail = self._og_search_thumbnail(webpage)
38 description = self._og_search_description(webpage)
39 duration = parse_duration(self._search_regex(
40 r"'duration':\s*'([^']+)',", webpage,
41 'duration', fatal=False, default=None))
42
43 formats = []
44 for js in re.findall(r'(?s)config:\s*(\{.*?\})', webpage):
45 data = self._parse_json(js, video_id, transform_source=js_to_json)
46 if 'provider' not in data:
47 continue
48 if data['provider'] == 'rtmp':
49 formats.append({
50 'format_id': 'rtmp',
51 'ext': determine_ext(data['file']),
52 'url': data['streamer'],
53 'play_path': 'mp4:%s' % data['file'],
54 'preference': -1,
55 'rtmp_real_time': True,
56 })
57 else:
58 formats.extend(
59 self._extract_m3u8_formats(data['file'], video_id, 'mp4'))
60
61 return {
62 'id': video_id,
63 'title': title,
64 'formats': formats,
65 'thumbnail': thumbnail,
66 'description': description,
67 'duration': duration,
68 }