1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#!/usr/bin/env python3
# programmes expire, so i have to update the times in the tests every time i run them
# but thats a massive ballache, so i end up just not running them, which leads to cockups
# so, this script has the tests automatically use the latest episode as you run it, by setting dynamically generated time values
# everything else is always the same so it should be fine lol
import datetime
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, "/home/g/Downloads/yt-dlp/") # TODO: un-hardcode. has to be the source/git repo because pip doesnt carry the tests
from yt_dlp_plugins.extractor import radiko_time as rtime
MON, TUE, WED, THU, FRI, SAT, SUN = range(7)
weekdays = {0: "MON", 1: "TUE", 2: "WED", 3: "THU", 4: "FRI", 5: "SAT", 6: "SUN"}
now = rtime.RadikoTime.now(tz = rtime.JST)
UTC = datetime.timezone.utc
def get_latest_airtimes(now, weekday, hour, minute, duration):
days_after_weekday = (7 - (now.weekday() - weekday)) % 7
latest_airdate = (now + datetime.timedelta(days=days_after_weekday)).replace(hour=hour, minute=minute, second=0, microsecond=0)
if (latest_airdate + duration) > now:
latest_airdate -= datetime.timedelta(days=7)
return latest_airdate, latest_airdate + duration
def get_test_timefields(airtime, release_time):
return {
"timestamp": airtime.timestamp(),
"release_timestamp": release_time.timestamp(),
"upload_date": airtime.astimezone(UTC).strftime("%Y%m%d"),
"release_date": release_time.astimezone(UTC).strftime("%Y%m%d"),
"duration": (release_time - airtime).total_seconds(),
}
from yt_dlp_plugins.extractor.radiko import RadikoTimeFreeIE, RadikoShareIE, RadikoLiveIE, RadikoShareIE, RadikoPersonIE, RadikoStationButtonIE
RadikoTimeFreeIE._TESTS = []
# TOKYO MOON - interfm - EVERY FRI 2300
airtime, release_time = get_latest_airtimes(now, FRI, 23, 0, datetime.timedelta(hours=1))
RadikoTimeFreeIE._TESTS.append({
"url": f"https://radiko.jp/#!/ts/INT/{airtime.timestring()}",
"info_dict": {
"ext": "m4a",
"id": f"INT-{airtime.timestring()}",
**get_test_timefields(airtime, release_time),
'title': 'TOKYO MOON',
'description': 'md5:4185349a530cfc4d0580e6996a511273',
'uploader': 'interfm',
'uploader_id': 'INT',
'uploader_url': 'https://www.interfm.co.jp/',
'channel': 'interfm',
'channel_id': 'INT',
'channel_url': 'https://www.interfm.co.jp/',
'thumbnail': 'https://program-static.cf.radiko.jp/ehwtw6mcvy.jpg',
'chapters': list,
'tags': ['松浦俊夫', 'ジャズの魅力を楽しめる'],
'cast': ['松浦\u3000俊夫'],
'series': 'Tokyo Moon',
'live_status': 'was_live',
}
})
# late-night/v. early morning show, to test broadcast day handling
# this should be monday 27:00 / tuesday 03:00
airtime, release_time = get_latest_airtimes(now, TUE, 3, 0, datetime.timedelta(hours=2))
RadikoTimeFreeIE._TESTS.append({
"url": f"https://radiko.jp/#!/ts/TBS/{airtime.timestring()}",
"info_dict": {
"ext": "m4a",
"id": f"TBS-{airtime.timestring()}",
**get_test_timefields(airtime, release_time),
'title': 'CITY CHILL CLUB',
'description': r"re:^目を閉じて…リラックスして[\S\s]+chill@tbs.co.jp$",
'uploader': 'TBSラジオ',
'uploader_id': 'TBS',
'uploader_url': 'https://www.tbsradio.jp/',
'channel': 'TBSラジオ',
'channel_id': 'TBS',
'channel_url': 'https://www.tbsradio.jp/',
'thumbnail': 'https://program-static.cf.radiko.jp/nrf8fowbjo.jpg',
'chapters': list,
'tags': ['CCC905', '音楽との出会いが楽しめる', '人気アーティストトーク', '音楽プロデューサー出演', 'ドライブ中におすすめ', '寝る前におすすめ', '学生におすすめ'],
'cast': list,
'series': 'CITY CHILL CLUB',
'live_status': 'was_live',
},
})
# testing 29-hour clock handling
airtime, release_time = get_latest_airtimes(now, WED, 0, 0, datetime.timedelta(minutes=55))
share_timestring = (airtime - datetime.timedelta(days=1)).strftime("%Y%m%d") + "240000"
RadikoShareIE._TESTS = [{
"url": f"http://radiko.jp/share/?sid=FMT&t={share_timestring}",
"info_dict": {
"live_status": "was_live",
"ext": "m4a",
"id": f"FMT-{airtime.timestring()}",
**get_test_timefields(airtime, release_time),
"title": "JET STREAM",
"series": "JET STREAM",
"description": r"re:^JET STREAM・・・作家が描く世界への旅。[\s\S]+https://www.tfm.co.jp/f/jetstream/message$",
"chapters": list,
"thumbnail": "https://program-static.cf.radiko.jp/greinlrspi.jpg",
"channel": "TOKYO FM",
"channel_id": "FMT",
"channel_url": "https://www.tfm.co.jp/",
"uploader": "TOKYO FM",
"uploader_id": "FMT",
"uploader_url": "https://www.tfm.co.jp/",
"cast": ["福山雅治"],
"tags": ["福山雅治", "夜間飛行", "音楽との出会いが楽しめる", "朗読を楽しめる", "寝る前に聴きたい"],
},
}]
IEs = [
RadikoTimeFreeIE, RadikoShareIE,
RadikoLiveIE, RadikoShareIE, RadikoPersonIE, RadikoStationButtonIE
]
import test.helper as th
# override to only get testcases from our IEs
def _new_gettestcases(include_onlymatching=False):
import yt_dlp.plugins as plugins
plugins.load_all_plugins()
for ie in IEs:
yield from ie.get_testcases(include_onlymatching)
def _new_getwebpagetestcases():
import yt_dlp.plugins as plugins
plugins.load_all_plugins()
for ie in IEs:
for tc in ie.get_webpage_testcases():
tc.setdefault('add_ie', []).append('Generic')
yield tc
th.gettestcases = _new_gettestcases
th.getwebpagetestcases = _new_getwebpagetestcases
import test.test_download as td
class TestDownload(td.TestDownload):
pass
if __name__ == "__main__":
unittest.main()
|