[nporadio] Edit to confirm to flake8 standards
[youtube-dl] / youtube_dl / extractor / nporadio.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5
6 from .common import InfoExtractor
7
8
9 class NPORadioIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>.*)'
11     _TEST = {
12         'url': 'http://www.npo.nl/radio/radio-1',
13         'info_dict': {
14             'id': 'radio-1',
15             'ext': 'mp3',
16             'title': 'NPO Radio 1',
17         }
18     }
19
20     def _real_extract(self, url):
21         video_id = self._match_id(url)
22         webpage = self._download_webpage(url, video_id)
23
24         title = self._html_search_regex(
25             self._html_get_attribute_regex('data-channel'), webpage, 'title')
26
27         json_data = json.loads(
28             self._html_search_regex(
29                 self._html_get_attribute_regex('data-streams'), webpage, 'data-streams'))
30
31         return {
32             'id': video_id,
33             'title': title,
34             'ext': json_data['codec'],
35             'url': json_data['url']
36         }
37
38     def _html_get_attribute_regex(self, attribute):
39         return r'{0}\s*=\s*\'([^\']+)\''.format(attribute)