[ie/dplay] Fix extractors (#10471)
[yt-dlp3.git] / yt_dlp / extractor / cjsw.py
blobb80236a7ee147fdf3d18bf3ad6548c9159bea40d
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 unescapeHTML,
8 class CJSWIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?cjsw\.com/program/(?P<program>[^/]+)/episode/(?P<id>\d+)'
10 _TESTS = [{
11 'url': 'http://cjsw.com/program/freshly-squeezed/episode/20170620',
12 'md5': 'cee14d40f1e9433632c56e3d14977120',
13 'info_dict': {
14 'id': '91d9f016-a2e7-46c5-8dcb-7cbcd7437c41',
15 'ext': 'mp3',
16 'title': 'Freshly Squeezed – Episode June 20, 2017',
17 'description': 'md5:c967d63366c3898a80d0c7b0ff337202',
18 'series': 'Freshly Squeezed',
19 'episode_id': '20170620',
21 }, {
22 # no description
23 'url': 'http://cjsw.com/program/road-pops/episode/20170707/',
24 'only_matching': True,
27 def _real_extract(self, url):
28 mobj = self._match_valid_url(url)
29 program, episode_id = mobj.group('program', 'id')
30 audio_id = f'{program}/{episode_id}'
32 webpage = self._download_webpage(url, episode_id)
34 title = unescapeHTML(self._search_regex(
35 (r'<h1[^>]+class=["\']episode-header__title["\'][^>]*>(?P<title>[^<]+)',
36 r'data-audio-title=(["\'])(?P<title>(?:(?!\1).)+)\1'),
37 webpage, 'title', group='title'))
39 audio_url = self._search_regex(
40 r'<button[^>]+data-audio-src=(["\'])(?P<url>(?:(?!\1).)+)\1',
41 webpage, 'audio url', group='url')
43 audio_id = self._search_regex(
44 r'/([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})\.mp3',
45 audio_url, 'audio id', default=audio_id)
47 formats = [{
48 'url': audio_url,
49 'ext': determine_ext(audio_url, 'mp3'),
50 'vcodec': 'none',
53 description = self._html_search_regex(
54 r'<p>(?P<description>.+?)</p>', webpage, 'description',
55 default=None)
56 series = self._search_regex(
57 r'data-showname=(["\'])(?P<name>(?:(?!\1).)+)\1', webpage,
58 'series', default=program, group='name')
60 return {
61 'id': audio_id,
62 'title': title,
63 'description': description,
64 'formats': formats,
65 'series': series,
66 'episode_id': episode_id,