]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/cjsw.py
[cleanup, docs] Misc cleanup
[yt-dlp.git] / yt_dlp / extractor / cjsw.py
CommitLineData
6e925598 1# coding: utf-8
d2b9f362
CS
2from __future__ import unicode_literals
3
c319d1c4 4
d2b9f362 5from .common import InfoExtractor
c319d1c4
S
6from ..utils import (
7 determine_ext,
8 unescapeHTML,
9)
d2b9f362
CS
10
11
12class CJSWIE(InfoExtractor):
c319d1c4 13 _VALID_URL = r'https?://(?:www\.)?cjsw\.com/program/(?P<program>[^/]+)/episode/(?P<id>\d+)'
0d2f0b03 14 _TESTS = [{
d2b9f362
CS
15 'url': 'http://cjsw.com/program/freshly-squeezed/episode/20170620',
16 'md5': 'cee14d40f1e9433632c56e3d14977120',
17 'info_dict': {
c319d1c4 18 'id': '91d9f016-a2e7-46c5-8dcb-7cbcd7437c41',
d2b9f362 19 'ext': 'mp3',
c319d1c4
S
20 'title': 'Freshly Squeezed – Episode June 20, 2017',
21 'description': 'md5:c967d63366c3898a80d0c7b0ff337202',
22 'series': 'Freshly Squeezed',
23 'episode_id': '20170620',
24 },
0d2f0b03
S
25 }, {
26 # no description
27 'url': 'http://cjsw.com/program/road-pops/episode/20170707/',
28 'only_matching': True,
29 }]
d2b9f362
CS
30
31 def _real_extract(self, url):
5ad28e7f 32 mobj = self._match_valid_url(url)
c319d1c4
S
33 program, episode_id = mobj.group('program', 'id')
34 audio_id = '%s/%s' % (program, episode_id)
d2b9f362
CS
35
36 webpage = self._download_webpage(url, episode_id)
37
c319d1c4
S
38 title = unescapeHTML(self._search_regex(
39 (r'<h1[^>]+class=["\']episode-header__title["\'][^>]*>(?P<title>[^<]+)',
40 r'data-audio-title=(["\'])(?P<title>(?:(?!\1).)+)\1'),
41 webpage, 'title', group='title'))
42
43 audio_url = self._search_regex(
44 r'<button[^>]+data-audio-src=(["\'])(?P<url>(?:(?!\1).)+)\1',
45 webpage, 'audio url', group='url')
46
47 audio_id = self._search_regex(
48 r'/([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})\.mp3',
49 audio_url, 'audio id', default=audio_id)
50
d2b9f362 51 formats = [{
c319d1c4
S
52 'url': audio_url,
53 'ext': determine_ext(audio_url, 'mp3'),
d2b9f362
CS
54 'vcodec': 'none',
55 }]
c319d1c4
S
56
57 description = self._html_search_regex(
0d2f0b03
S
58 r'<p>(?P<description>.+?)</p>', webpage, 'description',
59 default=None)
c319d1c4
S
60 series = self._search_regex(
61 r'data-showname=(["\'])(?P<name>(?:(?!\1).)+)\1', webpage,
62 'series', default=program, group='name')
63
d2b9f362 64 return {
c319d1c4 65 'id': audio_id,
d2b9f362
CS
66 'title': title,
67 'description': description,
68 'formats': formats,
c319d1c4
S
69 'series': series,
70 'episode_id': episode_id,
d2b9f362 71 }