diff options
author | robin <rderooij685@gmail.com> | 2015-02-12 19:19:55 +0100 |
---|---|---|
committer | robin <rderooij685@gmail.com> | 2015-02-12 19:19:55 +0100 |
commit | 7c24ce225d1ddb350f91b0fd78fefa40f6aa4481 (patch) | |
tree | f287c6950afcfb6726cc6a8e3a5adac5555c0e23 /youtube_dl/extractor | |
parent | 08b38d54015706d90d05371455ba86b7887cabcc (diff) | |
download | youtube-dl-7c24ce225d1ddb350f91b0fd78fefa40f6aa4481.tar.xz |
[NPORadio] Added extractor for live radio
Diffstat (limited to 'youtube_dl/extractor')
-rw-r--r-- | youtube_dl/extractor/__init__.py | 1 | ||||
-rw-r--r-- | youtube_dl/extractor/nporadio.py | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 095feabf9..b118c3d1d 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -320,6 +320,7 @@ from .npo import ( NPOLiveIE, TegenlichtVproIE, ) +from .nporadio import NPORadioIE from .nrk import ( NRKIE, NRKTVIE, diff --git a/youtube_dl/extractor/nporadio.py b/youtube_dl/extractor/nporadio.py new file mode 100644 index 000000000..dd8d97cb7 --- /dev/null +++ b/youtube_dl/extractor/nporadio.py @@ -0,0 +1,40 @@ +# coding: utf-8 +from __future__ import unicode_literals + +import json + +from .common import InfoExtractor + + +class NPORadioIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?npo\.nl/radio/(?P<id>.*)' + _TEST = { + 'url': 'http://www.npo.nl/radio/radio-1', + 'info_dict': { + 'id': 'radio-1', + 'ext': 'mp3', + 'title': 'NPO Radio 1', + } + } + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + + title = self._html_search_regex( + self._html_get_attribute_regex('data-channel'), webpage, 'title') + + json_data = json.loads( + self._html_search_regex( + self._html_get_attribute_regex('data-streams'), webpage, 'data-streams')) + + return { + 'id': video_id, + 'title': title, + 'ext': json_data['codec'], + 'url': json_data['url'] + } + + def _html_get_attribute_regex(self, attribute): + return r'{0}\s*=\s*\'([^\']+)\''.format(attribute) + |