New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ie/joqrag] Add extractor #8384
Changes from 16 commits
4f478a9
988329c
d5c6e48
e9f8f3e
3c90db7
11eb240
c2c195d
dcc0c86
b2920d0
0d5d575
2113492
d63976e
a388f7d
aa9b253
0207600
9361343
a330815
c839381
ef39027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,113 @@ | ||||||||||||||||||||||||||||||
import datetime | ||||||||||||||||||||||||||||||
import urllib.parse | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
from .common import InfoExtractor | ||||||||||||||||||||||||||||||
from ..utils import ( | ||||||||||||||||||||||||||||||
clean_html, | ||||||||||||||||||||||||||||||
datetime_from_str, | ||||||||||||||||||||||||||||||
unified_timestamp, | ||||||||||||||||||||||||||||||
urljoin, | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
class JoqrAgIE(InfoExtractor): | ||||||||||||||||||||||||||||||
IE_DESC = '超!A&G+ 文化放送 Nippon Cultural Broadcasting, Inc. (JOQR, AGQR)' | ||||||||||||||||||||||||||||||
_VALID_URL = [r'https?://www\.uniqueradio\.jp/agplayer5/player\.php', | ||||||||||||||||||||||||||||||
r'https?://www\.uniqueradio\.jp/agplayer5/inc-player-hls\.php', | ||||||||||||||||||||||||||||||
r'https?://(?:www\.)?joqr\.co\.jp/ag/', | ||||||||||||||||||||||||||||||
r'https?://(?:www\.)?joqr\.co\.jp/qr/ag(?:daily|regular)program/?(?:$|[#?])'] | ||||||||||||||||||||||||||||||
_TESTS = [{ | ||||||||||||||||||||||||||||||
'url': 'https://www.uniqueradio.jp/agplayer5/player.php', | ||||||||||||||||||||||||||||||
'info_dict': { | ||||||||||||||||||||||||||||||
'id': 'live', | ||||||||||||||||||||||||||||||
'title': str, | ||||||||||||||||||||||||||||||
'channel': '超!A&G+', | ||||||||||||||||||||||||||||||
'description': str, | ||||||||||||||||||||||||||||||
'live_status': 'is_live', | ||||||||||||||||||||||||||||||
'release_timestamp': int, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
'params': { | ||||||||||||||||||||||||||||||
'skip_download': True, | ||||||||||||||||||||||||||||||
'ignore_no_formats_error': True, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, { | ||||||||||||||||||||||||||||||
'url': 'https://www.uniqueradio.jp/agplayer5/inc-player-hls.php', | ||||||||||||||||||||||||||||||
'only_matching': True, | ||||||||||||||||||||||||||||||
}, { | ||||||||||||||||||||||||||||||
'url': 'https://www.joqr.co.jp/ag/article/103760/', | ||||||||||||||||||||||||||||||
'only_matching': True, | ||||||||||||||||||||||||||||||
}, { | ||||||||||||||||||||||||||||||
'url': 'http://www.joqr.co.jp/qr/agdailyprogram/', | ||||||||||||||||||||||||||||||
'only_matching': True, | ||||||||||||||||||||||||||||||
}, { | ||||||||||||||||||||||||||||||
'url': 'http://www.joqr.co.jp/qr/agregularprogram/', | ||||||||||||||||||||||||||||||
'only_matching': True, | ||||||||||||||||||||||||||||||
}] | ||||||||||||||||||||||||||||||
pzhlkj6612 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def _extract_metadata(self, variable, html, name): | ||||||||||||||||||||||||||||||
return clean_html(urllib.parse.unquote_plus(self._search_regex( | ||||||||||||||||||||||||||||||
rf'var\s+{variable}\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1', | ||||||||||||||||||||||||||||||
html, name, group='value', default=''))) or None | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's always non-fatal so the
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def _extract_start_timestamp(self, video_id, is_live): | ||||||||||||||||||||||||||||||
def extract_start_time_from(date_str): | ||||||||||||||||||||||||||||||
dt = datetime_from_str(date_str) + datetime.timedelta(hours=9) | ||||||||||||||||||||||||||||||
date = dt.strftime('%Y%m%d') | ||||||||||||||||||||||||||||||
start_time = self._search_regex( | ||||||||||||||||||||||||||||||
r'<h3[^>]+\bclass="dailyProgram-itemHeaderTime"[^>]*>[\s\d:]+–\s*(?P<time>\d{1,2}:\d{1,2})', | ||||||||||||||||||||||||||||||
self._download_webpage( | ||||||||||||||||||||||||||||||
f'https://www.joqr.co.jp/qr/agdailyprogram/?date={date}', video_id, | ||||||||||||||||||||||||||||||
note=f'Downloading program list of {date}', fatal=False, | ||||||||||||||||||||||||||||||
errnote=f'Failed to download program list of {date}') or '', | ||||||||||||||||||||||||||||||
'start time of the first program', default=None, group='time') | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could make this a little less busy
Suggested change
|
||||||||||||||||||||||||||||||
if start_time: | ||||||||||||||||||||||||||||||
return unified_timestamp(f'{dt.strftime("%Y/%m/%d")} {start_time} +09:00') | ||||||||||||||||||||||||||||||
return None | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
start_timestamp = extract_start_time_from('today') | ||||||||||||||||||||||||||||||
if not start_timestamp: | ||||||||||||||||||||||||||||||
return None | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if not is_live or start_timestamp < datetime_from_str('now').timestamp(): | ||||||||||||||||||||||||||||||
return start_timestamp | ||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||
return extract_start_time_from('yesterday') | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def _real_extract(self, url): | ||||||||||||||||||||||||||||||
video_id = 'live' | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
metadata = self._download_webpage( | ||||||||||||||||||||||||||||||
'https://www.uniqueradio.jp/aandg', video_id, | ||||||||||||||||||||||||||||||
note='Downloading metadata', errnote='Failed to download metadata') | ||||||||||||||||||||||||||||||
title = self._extract_metadata('Program_name', metadata, 'program title') | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if title == '放送休止': | ||||||||||||||||||||||||||||||
formats = [] | ||||||||||||||||||||||||||||||
live_status = 'is_upcoming' | ||||||||||||||||||||||||||||||
release_timestamp = self._extract_start_timestamp(video_id, False) | ||||||||||||||||||||||||||||||
msg = 'This stream is not currently live' | ||||||||||||||||||||||||||||||
if release_timestamp: | ||||||||||||||||||||||||||||||
msg += (' and will start at ' | ||||||||||||||||||||||||||||||
+ datetime.datetime.fromtimestamp(release_timestamp).strftime('%Y-%m-%d %H:%M:%S')) | ||||||||||||||||||||||||||||||
self.raise_no_formats(msg, expected=True) | ||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||
m3u8_path = self._search_regex( | ||||||||||||||||||||||||||||||
r'<source\s[^>]*\bsrc="([^"]+)"', | ||||||||||||||||||||||||||||||
self._download_webpage( | ||||||||||||||||||||||||||||||
'https://www.uniqueradio.jp/agplayer5/inc-player-hls.php', video_id, | ||||||||||||||||||||||||||||||
note='Downloading player data', errnote='Failed to download player data'), | ||||||||||||||||||||||||||||||
'm3u8 url') | ||||||||||||||||||||||||||||||
formats = self._extract_m3u8_formats( | ||||||||||||||||||||||||||||||
urljoin('https://www.uniqueradio.jp/', m3u8_path), video_id) | ||||||||||||||||||||||||||||||
live_status = 'is_live' | ||||||||||||||||||||||||||||||
release_timestamp = self._extract_start_timestamp(video_id, True) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||
'id': video_id, | ||||||||||||||||||||||||||||||
'title': title, | ||||||||||||||||||||||||||||||
'channel': '超!A&G+', | ||||||||||||||||||||||||||||||
'description': self._extract_metadata('Program_text', metadata, 'program description'), | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
'formats': formats, | ||||||||||||||||||||||||||||||
'live_status': live_status, | ||||||||||||||||||||||||||||||
'release_timestamp': release_timestamp, | ||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.