aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/yt_dlp_plugins/extractor
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2023-10-13 13:13:24 +0100
committergarret <garret@airmail.cc>2023-10-13 13:15:54 +0100
commitc2b0082ab507b06612b7138a47467b0e09a3daed (patch)
tree607e89456368c1e6ec851a2769a3fccc59dd2e35 /yt_dlp_plugins/extractor
parent94faf5b37624b228629d2487dcb3c14483562cd7 (diff)
downloadyt-dlp-rajiko-c2b0082ab507b06612b7138a47467b0e09a3daed.tar.gz
yt-dlp-rajiko-c2b0082ab507b06612b7138a47467b0e09a3daed.tar.bz2
yt-dlp-rajiko-c2b0082ab507b06612b7138a47467b0e09a3daed.zip
fix broadcast day stuff
deduped code for working it out also fixed bug in broadcast_day_end where it shifted forward by a day, but didn't also set the time to 5am
Diffstat (limited to 'yt_dlp_plugins/extractor')
-rwxr-xr-xyt_dlp_plugins/extractor/radiko_time.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/yt_dlp_plugins/extractor/radiko_time.py b/yt_dlp_plugins/extractor/radiko_time.py
index 981a966..3839d42 100755
--- a/yt_dlp_plugins/extractor/radiko_time.py
+++ b/yt_dlp_plugins/extractor/radiko_time.py
@@ -9,24 +9,29 @@ class RadikoTime():
def timestring(self):
return self.datetime.strftime("%Y%m%d%H%M%S")
- def broadcast_day(self):
+ def broadcast_day_date(self):
# timetable api counts 05:00 -> 28:59 (04:59 next day) as all the same day
# like the 30-hour day, 06:00 -> 29:59 (05:59)
# https://en.wikipedia.org/wiki/Date_and_time_notation_in_Japan#Time
# but ends earlier, presumably so the early morning programmes dont look like late night ones
- # this means we have to shift back by a day so we can get the right programme
+ # this means we have to shift back by a day so we can get the right programme for stuff past midnight
dt = self.datetime
if dt.hour < 5:
dt -= datetime.timedelta(days=1)
+ dt = dt.date() # dont care about hours/mins, we're working in days
+ return dt
+
+ def broadcast_day(self):
+
+ dt = self.broadcast_day_date()
return dt.strftime("%Y%m%d")
def broadcast_day_end(self):
- dt = self.datetime
- if dt.hour < 5:
- dt -= datetime.timedelta(days=1)
- dt += datetime.timedelta(days=1)
- dt.replace(hour=5, minute=0, second=0)
+ date = self.broadcast_day_date()
+ date += datetime.timedelta(days=1)
+
+ dt = datetime.datetime(date.year, date.month, date.day, 5, 0, 0, tzinfo=JST)
return dt
def timestamp(self):
@@ -92,6 +97,8 @@ if __name__ == "__main__":
assert RadikoSiteTime('202308240100').timestring() == "20230824005959"
# broadcast day starts at 05:00, ends at 04:59 (29:59)
assert RadikoSiteTime('20230824030000').broadcast_day() == '20230823'
+ assert RadikoSiteTime('20230824130000').broadcast_day_end() == datetime.datetime(2023, 8, 25, 5, 0, 0, tzinfo=JST)
+ assert RadikoSiteTime('20230824030000').broadcast_day_end() == datetime.datetime(2023, 8, 24, 5, 0, 0, tzinfo=JST)
# checking timezone
assert RadikoSiteTime('20230823090000').datetime.timestamp() == 1692748800