4 from .common
import InfoExtractor
13 class JoqrAgIE(InfoExtractor
):
14 IE_DESC
= '超!A&G+ 文化放送 (f.k.a. AGQR) Nippon Cultural Broadcasting, Inc. (JOQR)'
15 _VALID_URL
= [r
'https?://www\.uniqueradio\.jp/agplayer5/(?:player|inc-player-hls)\.php',
16 r
'https?://(?:www\.)?joqr\.co\.jp/ag/',
17 r
'https?://(?:www\.)?joqr\.co\.jp/qr/ag(?:daily|regular)program/?(?:$|[#?])']
19 'url': 'https://www.uniqueradio.jp/agplayer5/player.php',
25 'live_status': 'is_live',
26 'release_timestamp': int,
29 'skip_download': True,
30 'ignore_no_formats_error': True,
33 'url': 'https://www.uniqueradio.jp/agplayer5/inc-player-hls.php',
34 'only_matching': True,
36 'url': 'https://www.joqr.co.jp/ag/article/103760/',
37 'only_matching': True,
39 'url': 'http://www.joqr.co.jp/qr/agdailyprogram/',
40 'only_matching': True,
42 'url': 'http://www.joqr.co.jp/qr/agregularprogram/',
43 'only_matching': True,
46 def _extract_metadata(self
, variable
, html
):
47 return clean_html(urllib
.parse
.unquote_plus(self
._search
_regex
(
48 rf
'var\s+{variable}\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1',
49 html
, 'metadata', group
='value', default
=''))) or None
51 def _extract_start_timestamp(self
, video_id
, is_live
):
52 def extract_start_time_from(date_str
):
53 dt_
= datetime_from_str(date_str
) + dt
.timedelta(hours
=9)
54 date
= dt_
.strftime('%Y%m%d')
55 start_time
= self
._search
_regex
(
56 r
'<h3[^>]+\bclass="dailyProgram-itemHeaderTime"[^>]*>[\s\d:]+–\s*(\d{1,2}:\d{1,2})',
57 self
._download
_webpage
(
58 f
'https://www.joqr.co.jp/qr/agdailyprogram/?date={date}', video_id
,
59 note
=f
'Downloading program list of {date}', fatal
=False,
60 errnote
=f
'Failed to download program list of {date}') or '',
61 'start time', default
=None)
63 return unified_timestamp(f
'{dt_.strftime("%Y/%m/%d")} {start_time} +09:00')
66 start_timestamp
= extract_start_time_from('today')
67 if not start_timestamp
:
70 if not is_live
or start_timestamp
< datetime_from_str('now').timestamp():
71 return start_timestamp
73 return extract_start_time_from('yesterday')
75 def _real_extract(self
, url
):
78 metadata
= self
._download
_webpage
(
79 'https://www.uniqueradio.jp/aandg', video_id
,
80 note
='Downloading metadata', errnote
='Failed to download metadata')
81 title
= self
._extract
_metadata
('Program_name', metadata
)
83 if not title
or title
== '放送休止':
85 live_status
= 'is_upcoming'
86 release_timestamp
= self
._extract
_start
_timestamp
(video_id
, False)
87 msg
= 'This stream is not currently live'
89 msg
+= (' and will start at '
90 + dt
.datetime
.fromtimestamp(release_timestamp
).strftime('%Y-%m-%d %H:%M:%S'))
91 self
.raise_no_formats(msg
, expected
=True)
93 m3u8_path
= self
._search
_regex
(
94 r
'<source\s[^>]*\bsrc="([^"]+)"',
95 self
._download
_webpage
(
96 'https://www.uniqueradio.jp/agplayer5/inc-player-hls.php', video_id
,
97 note
='Downloading player data', errnote
='Failed to download player data'),
99 formats
= self
._extract
_m
3u8_formats
(
100 urljoin('https://www.uniqueradio.jp/', m3u8_path
), video_id
)
101 live_status
= 'is_live'
102 release_timestamp
= self
._extract
_start
_timestamp
(video_id
, True)
108 'description': self
._extract
_metadata
('Program_text', metadata
),
110 'live_status': live_status
,
111 'release_timestamp': release_timestamp
,