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