From 65738ef52c22760860c60921aa0faf2155344e58 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 15 Jan 2024 11:34:11 +0700 Subject: [PATCH] validate expected video ID with remote ID to avoid redirect --- tubearchivist/home/src/index/video.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tubearchivist/home/src/index/video.py b/tubearchivist/home/src/index/video.py index d06ce5e..1b258ae 100644 --- a/tubearchivist/home/src/index/video.py +++ b/tubearchivist/home/src/index/video.py @@ -177,6 +177,7 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): def _process_youtube_meta(self): """extract relevant fields from youtube""" + self._validate_id() # extract self.channel_id = self.youtube_meta["channel_id"] upload_date = self.youtube_meta["upload_date"] @@ -202,6 +203,19 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): "active": True, } + def _validate_id(self): + """validate expected video ID, raise value error on mismatch""" + remote_id = self.youtube_meta["id"] + + if not self.youtube_id == remote_id: + # unexpected redirect + message = ( + f"[reindex][{self.youtube_id}] got an unexpected redirect " + + f"to {remote_id}, you are probably getting blocked by YT. " + "See FAQ for more details." + ) + raise ValueError(message) + def _add_channel(self): """add channel dict to video json_data""" channel = ta_channel.YoutubeChannel(self.channel_id)