[rbmaradio] Fixed extractor
[youtube-dl] / youtube_dl / extractor / rbmaradio.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     clean_html
7 )
8
9
10 class RBMARadioIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?rbmaradio\.com/shows/[^/]+/episodes/(?P<id>[^/]+)$'
12     _TEST = {
13         'url': 'https://www.rbmaradio.com/shows/main-stage/episodes/ford-lopatin-live-at-primavera-sound-2011',
14         'md5': '6bc6f9bcb18994b4c983bc3bf4384d95',
15         'info_dict': {
16             'id': 'ford-lopatin-live-at-primavera-sound-2011',
17             'ext': 'mp3',
18             'description': 'Joel Ford and Daniel â€™Oneohtrix Point Never’ Lopatin fly their midified pop extravaganza to Spain. Live at Primavera Sound 2011.',
19             'title': 'Ford & Lopatin - Main Stage',
20         },
21     }
22
23     def _real_extract(self, url):
24         video_id = self._match_id(url)
25
26         webpage = self._download_webpage(url, video_id)
27         json_data = self._search_regex(r'<script>window\.__INITIAL_STATE__\s*=\s*(.+?)</script>',
28                                        webpage, 'json data')
29         data = self._parse_json(json_data, video_id)
30
31         item = None
32         for episode in data['episodes']:
33             items = data['episodes'][episode]
34             if video_id in items:
35                 item = items[video_id]
36
37         video_url = item['audioURL'] + '?cbr=256'
38
39         return {
40             'id': video_id,
41             'url': video_url,
42             'title': item.get('title') + ' - ' + item.get('showTitle'),
43             'description': clean_html(item.get('longTeaser')),
44             'thumbnail': self._proto_relative_url(item.get('imageURL', {}).get('landscape')),
45             'duration': item.get('duration'),
46         }