[lrt] Improve
[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         m3u8_url = self._search_regex(
34             r'file\s*:\s*(["\'])(?P<url>.+?)\1\s*\+\s*location\.hash\.substring\(1\)',
35             webpage, 'm3u8 url', group='url')
36         formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
37
38         thumbnail = self._og_search_thumbnail(webpage)
39         description = self._og_search_description(webpage)
40         duration = parse_duration(self._search_regex(
41             r'var\s+record_len\s*=\s*(["\'])(?P<duration>[0-9]+:[0-9]+:[0-9]+)\1',
42             webpage, 'duration', default=None, group='duration'))
43
44         return {
45             'id': video_id,
46             'title': title,
47             'formats': formats,
48             'thumbnail': thumbnail,
49             'description': description,
50             'duration': duration,
51         }