From 3b5741c2fb72f2eebe1ae000eff96702a2aa21b5 Mon Sep 17 00:00:00 2001 From: mhdzumair Date: Tue, 31 Dec 2024 18:24:19 +0530 Subject: [PATCH] Ensure file_name uses basename and replace quote_plus with quote This update ensures that the `file_name` always uses its basename for consistency and correctness. Additionally, `quote_plus` was replaced with `quote` to simplify URL encoding --- streaming_providers/routes.py | 2 ++ utils/parser.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/streaming_providers/routes.py b/streaming_providers/routes.py index 8293b90..50387e7 100644 --- a/streaming_providers/routes.py +++ b/streaming_providers/routes.py @@ -1,5 +1,6 @@ import logging from os import path +from os.path import basename from typing import Annotated from fastapi import ( @@ -100,6 +101,7 @@ async def get_or_create_video_url( episode_data = stream.get_episode(season, episode) if not filename: filename = episode_data.filename if episode_data else stream.filename + filename = basename(filename) if filename else None file_index = episode_data.file_index if episode_data else stream.file_index get_video_url = mapper.GET_VIDEO_URL_FUNCTIONS.get( diff --git a/utils/parser.py b/utils/parser.py index 8c58aed..d7a4a4b 100644 --- a/utils/parser.py +++ b/utils/parser.py @@ -6,7 +6,8 @@ import math import re from datetime import datetime, timezone from typing import Optional, List, Any -from urllib.parse import quote_plus +from os.path import basename +from urllib.parse import quote from thefuzz import fuzz @@ -259,6 +260,9 @@ async def parse_stream_data( file_name = stream_data.filename file_index = stream_data.file_index + # make sure file_name is basename + file_name = basename(file_name) if file_name else None + if show_full_torrent_name: torrent_name = ( f"{stream_data.torrent_name}/{episode_data.title or episode_data.filename or ''}" @@ -341,7 +345,7 @@ async def parse_stream_data( if episode_data: stream_details["url"] += f"/{season}/{episode}" if file_name: - stream_details["url"] += f"/{quote_plus(file_name)}" + stream_details["url"] += f"/{quote(file_name)}" stream_details["behaviorHints"]["notWebReady"] = True else: stream_details["infoHash"] = stream_data.id