[fm4] Remove unused imports and minor changes
[youtube-dl] / youtube_dl / extractor / fm4.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8 # audios on fm4.orf.at are only available for 7 days, so we can't
9 # add tests.
10
11
12 class FM4IE(InfoExtractor):
13     IE_DESC = 'fm4.orf.at'
14     _VALID_URL = r'http://fm4\.orf\.at/7tage/?#(?P<date>[0-9]+)/(?P<show>\w+)'
15
16     def _real_extract(self, url):
17         mobj = re.match(self._VALID_URL, url)
18         show_date = mobj.group('date')
19         show_id = mobj.group('show')
20
21         data = self._download_json(
22             'http://audioapi.orf.at/fm4/json/2.0/broadcasts/%s/4%s' % (show_date, show_id),
23             show_id
24         )
25
26         def extract_entry_dict(info, title, subtitle):
27             return {
28                 'id': info['loopStreamId'].replace('.mp3', ''),
29                 'url': 'http://loopstream01.apa.at/?channel=fm4&id=%s' % info['loopStreamId'],
30                 'title': title,
31                 'description': subtitle,
32                 'duration': (info['end'] - info['start']) / 1000,
33                 'timestamp': info['start'] / 1000,
34                 'ext': 'mp3'
35             }
36
37         entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
38
39         return {
40             '_type': 'playlist',
41             'id': show_id,
42             'title': data['title'],
43             'description': data['subtitle'],
44             'entries': entries
45         }