[cjsw] Add extractor
[youtube-dl] / youtube_dl / extractor / cjsw.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class CJSWIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)?cjsw\.com/program/\S+/(?P<id>[0-9]+)'
9     IE_NAME = 'cjsw'
10     _TEST = {
11         'url': 'http://cjsw.com/program/freshly-squeezed/episode/20170620',
12         'md5': 'cee14d40f1e9433632c56e3d14977120',
13         'info_dict': {
14             'id': '20170620',
15             'ext': 'mp3',
16             'title': 'Freshly Squeezed',
17             'description': 'Sled Island artists featured // Live session with Phi Pho, followed by a live session with Sinzere & The Late Nights! // Stay Fresh Y\'all!!',
18         }
19     }
20
21     def _real_extract(self, url):
22         episode_id = self._match_id(url)
23
24         webpage = self._download_webpage(url, episode_id)
25
26         title = self._search_regex(
27             r'<button[^>]+data-showname=(["\'])(?P<title>(?!\1).+?)\1[^>]*>', webpage, 'title', group='title')
28         description = self._html_search_regex(
29             r'<p>(?P<description>.+?)</p>', webpage, 'description', fatal=False)
30         formats = [{
31             'url': self._search_regex(
32                 r'<button[^>]+data-audio-src=(["\'])(?P<audio_url>(?!\1).+?)\1[^>]*>', webpage, 'audio_url', group='audio_url'),
33             'ext': 'mp3',
34             'vcodec': 'none',
35         }]
36         return {
37             'id': episode_id,
38             'title': title,
39             'description': description,
40             'formats': formats,
41         }