implement new media_url

pull/491/head
simon 1 year ago
parent d62b0d3f8d
commit 9d6ab6b7b3
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

@ -20,7 +20,7 @@ from home.src.index.playlist import YoutubePlaylist
from home.src.index.video import YoutubeVideo, index_new_video from home.src.index.video import YoutubeVideo, index_new_video
from home.src.index.video_constants import VideoTypeEnum from home.src.index.video_constants import VideoTypeEnum
from home.src.ta.config import AppConfig from home.src.ta.config import AppConfig
from home.src.ta.helper import clean_string, ignore_filelist from home.src.ta.helper import ignore_filelist
class DownloadPostProcess: class DownloadPostProcess:
@ -361,23 +361,16 @@ class VideoDownloader:
videos = self.config["application"]["videos"] videos = self.config["application"]["videos"]
host_uid = self.config["application"]["HOST_UID"] host_uid = self.config["application"]["HOST_UID"]
host_gid = self.config["application"]["HOST_GID"] host_gid = self.config["application"]["HOST_GID"]
channel_name = clean_string(vid_dict["channel"]["channel_name"]) # make folder
if len(channel_name) <= 3: folder = os.path.join(videos, vid_dict["channel"]["channel_id"])
# fall back to channel id if not os.path.exists(folder):
channel_name = vid_dict["channel"]["channel_id"] os.makedirs(folder)
# make archive folder with correct permissions if host_uid and host_gid:
new_folder = os.path.join(videos, channel_name) os.chown(folder, host_uid, host_gid)
if not os.path.exists(new_folder): # move media file
os.makedirs(new_folder) media_file = vid_dict["youtube_id"] + ".mp4"
if host_uid and host_gid:
os.chown(new_folder, host_uid, host_gid)
# find real filename
cache_dir = self.config["application"]["cache_dir"] cache_dir = self.config["application"]["cache_dir"]
all_cached = ignore_filelist(os.listdir(cache_dir + "/download/")) old_path = os.path.join(cache_dir, "download", media_file)
for file_str in all_cached:
if vid_dict["youtube_id"] in file_str:
old_file = file_str
old_path = os.path.join(cache_dir, "download", old_file)
new_path = os.path.join(videos, vid_dict["media_url"]) new_path = os.path.join(videos, vid_dict["media_url"])
# move media file and fix permission # move media file and fix permission
shutil.move(old_path, new_path, copy_function=shutil.copyfile) shutil.move(old_path, new_path, copy_function=shutil.copyfile)

@ -20,7 +20,7 @@ from home.src.index.video_streams import (
DurationConverter, DurationConverter,
MediaStreamExtractor, MediaStreamExtractor,
) )
from home.src.ta.helper import clean_string, randomizor from home.src.ta.helper import randomizor
from home.src.ta.ta_redis import RedisArchivist from home.src.ta.ta_redis import RedisArchivist
from ryd_client import ryd_client from ryd_client import ryd_client
@ -292,19 +292,10 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
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"""
channel_name = self.json_data["channel"]["channel_name"] self.json_data["media_url"] = os.path.join(
clean_channel_name = clean_string(channel_name) self.json_data["channel"]["channel_id"],
if len(clean_channel_name) <= 3: self.json_data["youtube_id"] + ".mp4",
# fall back to channel id )
clean_channel_name = self.json_data["channel"]["channel_id"]
timestamp = self.json_data["published"].replace("-", "")
youtube_id = self.json_data["youtube_id"]
title = self.json_data["title"]
clean_title = clean_string(title)
filename = f"{timestamp}_{youtube_id}_{clean_title}.mp4"
media_url = os.path.join(clean_channel_name, filename)
self.json_data["media_url"] = media_url
def delete_media_file(self): def delete_media_file(self):
"""delete video file, meta data""" """delete video file, meta data"""

Loading…
Cancel
Save