From e9ca3915759887e2612fd98ee032a4c83ace311e Mon Sep 17 00:00:00 2001 From: panitan103 Date: Mon, 30 Mar 2026 11:46:33 +0700 Subject: [PATCH] - handle season,episode overwrite for song,movie - Make folder for each type of title - Fix bug for discord downloader --- .gitignore | 3 ++- Unshackle-Service-SeFree | 2 +- unshackle/commands/dl.py | 7 ++++++ unshackle/core/titles/movie.py | 2 +- unshackle/core/titles/song.py | 2 +- unshackle/core/titles/title.py | 2 +- usk_downloader_discord.py | 39 +++++++++++++++++----------------- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 77da163..cbf1999 100644 --- a/.gitignore +++ b/.gitignore @@ -244,4 +244,5 @@ PRDs/ Logs/ Cookies/ Cache/ -Temp/ \ No newline at end of file +Temp/ +bot_logs/ \ No newline at end of file diff --git a/Unshackle-Service-SeFree b/Unshackle-Service-SeFree index 2d97c3d..fb12e94 160000 --- a/Unshackle-Service-SeFree +++ b/Unshackle-Service-SeFree @@ -1 +1 @@ -Subproject commit 2d97c3d34a6127e870d695ddcf96ef3d31fe98c2 +Subproject commit fb12e9444f1971b03ece52172a60af72e4713830 diff --git a/unshackle/commands/dl.py b/unshackle/commands/dl.py index 267d921..f75be30 100644 --- a/unshackle/commands/dl.py +++ b/unshackle/commands/dl.py @@ -2475,6 +2475,13 @@ class dl: final_dir = self.output_dir or config.directories.downloads final_filename = title.get_filename(media_info, show_service=not no_source,season_overwrite=int(season_overwrite) if season_overwrite else None,episode_overwrite=int(episode_overwrite) if episode_overwrite else None) audio_codec_suffix = muxed_audio_codecs.get(muxed_path) + + if isinstance(title, Movie): + final_dir = Path.joinpath(Path(final_dir),"Movie") + elif isinstance(title, Episode): + final_dir = Path.joinpath(Path(final_dir),"Series") + elif isinstance(title, Song): + final_dir = Path.joinpath(Path(final_dir),"Song") if not no_folder and isinstance(title, (Episode, Song)): final_dir /= title.get_filename(media_info, show_service=not no_source, folder=True,season_overwrite=int(season_overwrite) if season_overwrite else None) diff --git a/unshackle/core/titles/movie.py b/unshackle/core/titles/movie.py index 70088a1..4321e1b 100644 --- a/unshackle/core/titles/movie.py +++ b/unshackle/core/titles/movie.py @@ -57,7 +57,7 @@ class Movie(Title): return f"{self.name} ({self.year})" return self.name - def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True) -> str: + def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True,season_overwrite=None,episode_overwrite=None) -> str: if folder: name = f"{self.name}" if self.year: diff --git a/unshackle/core/titles/song.py b/unshackle/core/titles/song.py index e481e1b..5768aa5 100644 --- a/unshackle/core/titles/song.py +++ b/unshackle/core/titles/song.py @@ -92,7 +92,7 @@ class Song(Title): context["disc"] = f"{self.disc:02}" if self.disc > 1 else "" return context - def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True) -> str: + def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True,season_overwrite=None,episode_overwrite=None) -> str: if folder: name = f"{self.artist} - {self.album}" if self.year: diff --git a/unshackle/core/titles/title.py b/unshackle/core/titles/title.py index 97bcbfa..dfd57cd 100644 --- a/unshackle/core/titles/title.py +++ b/unshackle/core/titles/title.py @@ -175,7 +175,7 @@ class Title: return context @abstractmethod - def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True) -> str: + def get_filename(self, media_info: MediaInfo, folder: bool = False, show_service: bool = True,season_overwrite=None,episode_overwrite=None) -> str: """ Get a Filename for this Title with the provided Media Info. All filenames should be sanitized with the sanitize_filename() utility function. diff --git a/usk_downloader_discord.py b/usk_downloader_discord.py index 2da7501..6c2bcbe 100755 --- a/usk_downloader_discord.py +++ b/usk_downloader_discord.py @@ -202,7 +202,7 @@ async def download_command( url: str, keys: Optional[str] = 'False', quality: Optional[str] = '1080', - codec: Optional[str] = "h265", + codec: Optional[str] = "h.265", range_: Optional[str] = "SDR", bitrate: Optional[str] = "Max", start_season: Optional[int] = None, @@ -344,7 +344,7 @@ async def process_download(entry): bot.save_data() channel = bot.get_channel(entry['channel_id']) - cmd=['/root/unshackle/.venv/bin/unshackle','dl'] + cmd=['/root/unshackle-SeFree/.venv/bin/unshackle','dl'] if entry['proxy'] and entry['service'] not in ['HIDI']: cmd += ['--proxy', entry['proxy']] @@ -468,8 +468,8 @@ async def process_download(entry): if entry['original_language']: cmd += ['--original_lang', entry['original_language']] - if entry['android'] and entry['android'].lower() == 'true': - cmd += ['--android'] + # if entry['android'] and entry['android'].lower() == 'true': + # cmd += ['--android'] if entry['service'] == 'TVN': if entry['original_language']: @@ -485,10 +485,9 @@ async def process_download(entry): await channel.send(embed=embed) - result = await asyncio.to_thread(subprocess.run, cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) - + result = await asyncio.to_thread(subprocess.run, cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: - if '[E]' in result.stderr.decode() or "Processed all titles" not in result.stderr.decode(): + if '[E]' in result.stdout.decode() or "Processed all titles" not in result.stdout.decode(): embed = discord.Embed( title="❌ Download Failed", description="Download request has been failed.", @@ -509,9 +508,9 @@ async def process_download(entry): embed.add_field(name="📅 Timestamp", value=entry['timestamp'], inline=False) embed.set_footer(text=f"Requested by {entry['user']}") - print(result.stderr.decode()) + print(result.stdout.decode()) print(f"Error downloading {entry['url']}: ") - entry['error'] = result.stderr.decode() + entry['error'] = result.stdout.decode() entry['status'] = 'failed' await channel.send(embed=embed) @@ -583,8 +582,8 @@ async def process_download(entry): app_commands.Choice(name="BiliBili", value="BLBL"), ]) @app_commands.choices(codec=[ - app_commands.Choice(name="H264", value="H264"), - app_commands.Choice(name="H265", value="H265"), + app_commands.Choice(name="H264", value="H.264"), + app_commands.Choice(name="H265", value="H.265"), app_commands.Choice(name="AV1", value="AV1"), app_commands.Choice(name="VP9", value="VP9"), ]) @@ -642,7 +641,7 @@ async def clear_temp_command( await interaction.response.send_message(embed=embed) # Check if H265 codec is available for the given URL - os.removedirs("/root/unshackle/Temp") + os.removedirs("/root/unshackle-SeFree/Temp") embed = discord.Embed( title="🛠 Temporary Files Cleared", description="Temporary files have been successfully cleared.", @@ -661,7 +660,7 @@ def check_codec_support(url: str, codec: str, service: str, range_: str): vp9_alias=['vp9', 'VP9', 'VP9.0', 'vp9.0'] - cmd = ['/root/unshackle/.venv/bin/unshackle','dl', '--list', + cmd = ['/root/unshackle-SeFree/.venv/bin/unshackle','dl', '--list', '--wanted','s01e01', '--vcodec', codec, '--range', range_] @@ -675,26 +674,26 @@ def check_codec_support(url: str, codec: str, service: str, range_: str): result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if ("Processed all titles" not in result.stderr.decode() or any(alias in result.stderr.decode() for alias in error_alias)): - print(f"Error checking codec support for {url}: {result.stderr.decode()}") + if ("Processed all titles" not in result.stdout.decode() or any(alias in result.stdout.decode() for alias in error_alias)): + print(f"Error checking codec support for {url}: {result.stdout.decode()}") return ' '.join(cmd),'error','error' # codec check codec_available = False if codec.lower() in h264_alias: - if any(alias in result.stderr.decode() for alias in h264_alias): + if any(alias in result.stdout.decode() for alias in h264_alias): codec_available = True elif codec.lower() in h265_alias: - if any(alias in result.stderr.decode() for alias in h265_alias): + if any(alias in result.stdout.decode() for alias in h265_alias): codec_available = True elif codec.lower() in av1_alias: - if any(alias in result.stderr.decode() for alias in av1_alias): + if any(alias in result.stdout.decode() for alias in av1_alias): codec_available = True elif codec.lower() in vp9_alias: - if any(alias in result.stderr.decode() for alias in vp9_alias): + if any(alias in result.stdout.decode() for alias in vp9_alias): codec_available = True if not codec_available: @@ -707,7 +706,7 @@ def check_codec_support(url: str, codec: str, service: str, range_: str): range_available = False print(f"Checking {range_} support for {url}") - if range_ not in result.stderr.decode(): + if range_ not in result.stdout.decode(): print(f"HDR support not available for {url}") else: print(f"{range_} support available for {url}")