[lrt] fix the rest of extractor
[youtube-dl] / youtube_dl / extractor / lrt.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     parse_duration,
7     remove_end,
8 )
9
10
11 class LRTIE(InfoExtractor):
12     IE_NAME = 'lrt.lt'
13     _VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/irasas/(?P<id>[0-9]+)'
14     _TEST = {
15         'url': 'http://www.lrt.lt/mediateka/irasas/54391/',
16         'info_dict': {
17             'id': '54391',
18             'ext': 'mp4',
19             'title': 'Septynios Kauno dienos',
20             'description': 'md5:24d84534c7dc76581e59f5689462411a',
21             'duration': 1783,
22         },
23         'params': {
24             'skip_download': True,  # m3u8 download
25         },
26     }
27
28     def _real_extract(self, url):
29         video_id = self._match_id(url)
30         webpage = self._download_webpage(url, video_id)
31
32         title = remove_end(self._og_search_title(webpage), ' - LRT')
33         thumbnail = self._og_search_thumbnail(webpage)
34         description = self._og_search_description(webpage)
35         duration = parse_duration(self._search_regex(
36             r"var record_len = '([0-9]+:[0-9]+:[0-9]+)';", webpage, 'record_len', fatal=False, default=None))
37
38         link = self._search_regex(r'file: "(.*)" \+ location\.hash\.substring\(1\)', webpage, 'link to m3u8')
39         formats = self._extract_m3u8_formats(link, video_id, "mp4")
40
41         return {
42             'id': video_id,
43             'title': title,
44             'formats': formats,
45             'thumbnail': thumbnail,
46             'description': description,
47             'duration': duration,
48         }