mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 21:39:49 +00:00
static cache file path building, #498
This commit is contained in:
@@ -287,7 +287,10 @@ class Reindex(ReindexBase):
|
|||||||
es_meta = video.json_data.copy()
|
es_meta = video.json_data.copy()
|
||||||
|
|
||||||
# get new
|
# get new
|
||||||
video.build_json()
|
media_url = os.path.join(
|
||||||
|
self.config["application"]["videos"], es_meta["media_url"]
|
||||||
|
)
|
||||||
|
video.build_json(media_path=media_url)
|
||||||
if not video.youtube_meta:
|
if not video.youtube_meta:
|
||||||
video.deactivate()
|
video.deactivate()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -231,18 +231,24 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
|||||||
def build_dl_cache_path(self):
|
def build_dl_cache_path(self):
|
||||||
"""find video path in dl cache"""
|
"""find video path in dl cache"""
|
||||||
cache_dir = self.app_conf["cache_dir"]
|
cache_dir = self.app_conf["cache_dir"]
|
||||||
cache_path = f"{cache_dir}/download/"
|
video_id = self.json_data["youtube_id"]
|
||||||
all_cached = os.listdir(cache_path)
|
cache_path = f"{cache_dir}/download/{video_id}.mp4"
|
||||||
for file_cached in all_cached:
|
if os.path.exists(cache_path):
|
||||||
if self.youtube_id in file_cached:
|
return cache_path
|
||||||
vid_path = os.path.join(cache_path, file_cached)
|
|
||||||
return vid_path
|
channel_path = os.path.join(
|
||||||
|
self.app_conf["videos"],
|
||||||
|
self.json_data["channel"]["channel_id"],
|
||||||
|
f"{video_id}.mp4",
|
||||||
|
)
|
||||||
|
if os.path.exists(channel_path):
|
||||||
|
return channel_path
|
||||||
|
|
||||||
raise FileNotFoundError
|
raise FileNotFoundError
|
||||||
|
|
||||||
def add_player(self, media_path=False):
|
def add_player(self, media_path=False):
|
||||||
"""add player information for new videos"""
|
"""add player information for new videos"""
|
||||||
vid_path = self._get_vid_path(media_path)
|
vid_path = media_path or self.build_dl_cache_path()
|
||||||
|
|
||||||
duration_handler = DurationConverter()
|
duration_handler = DurationConverter()
|
||||||
duration = duration_handler.get_sec(vid_path)
|
duration = duration_handler.get_sec(vid_path)
|
||||||
@@ -259,7 +265,7 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
|||||||
|
|
||||||
def add_streams(self, media_path=False):
|
def add_streams(self, media_path=False):
|
||||||
"""add stream metadata"""
|
"""add stream metadata"""
|
||||||
vid_path = self._get_vid_path(media_path)
|
vid_path = media_path or self.build_dl_cache_path()
|
||||||
media = MediaStreamExtractor(vid_path)
|
media = MediaStreamExtractor(vid_path)
|
||||||
self.json_data.update(
|
self.json_data.update(
|
||||||
{
|
{
|
||||||
@@ -268,28 +274,6 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_vid_path(self, media_path=False):
|
|
||||||
"""get path of media file"""
|
|
||||||
if media_path:
|
|
||||||
return media_path
|
|
||||||
|
|
||||||
try:
|
|
||||||
# when indexing from download task
|
|
||||||
vid_path = self.build_dl_cache_path()
|
|
||||||
except FileNotFoundError as err:
|
|
||||||
# when reindexing needs to handle title rename
|
|
||||||
channel = os.path.split(self.json_data["media_url"])[0]
|
|
||||||
channel_dir = os.path.join(self.app_conf["videos"], channel)
|
|
||||||
all_files = os.listdir(channel_dir)
|
|
||||||
for file in all_files:
|
|
||||||
if self.youtube_id in file and file.endswith(".mp4"):
|
|
||||||
vid_path = os.path.join(channel_dir, file)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise FileNotFoundError("could not find video file") from err
|
|
||||||
|
|
||||||
return vid_path
|
|
||||||
|
|
||||||
def add_file_path(self):
|
def add_file_path(self):
|
||||||
"""build media_url for where file will be located"""
|
"""build media_url for where file will be located"""
|
||||||
self.json_data["media_url"] = os.path.join(
|
self.json_data["media_url"] = os.path.join(
|
||||||
|
|||||||
Reference in New Issue
Block a user