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