-
Notifications
You must be signed in to change notification settings - Fork 138
fix(FL): Update function edit_desc #1317
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -387,15 +387,15 @@ async def edit_desc(self, meta: dict[str, Any]) -> None: | |||
| desc = desc.replace('[img]', '[img]').replace('[/img]', '[/img]') | ||||
| desc = re.sub(r"(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE) | ||||
| if meta['is_disc'] != 'BDMV': | ||||
| url = "https://up.img4k.net/api/description" | ||||
| url = "https://up.img4k.net" | ||||
| mediainfo_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/MEDIAINFO_CLEANPATH.txt" | ||||
| async with aiofiles.open(mediainfo_path, encoding='utf-8') as mi_file: | ||||
| data = { | ||||
| 'mediainfo': await mi_file.read(), | ||||
| } | ||||
| if int(meta['imdb_id']) != 0: | ||||
| data['imdbURL'] = f"tt{meta['imdb_id']}" | ||||
| screen_glob = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", f"{meta['filename']}-*.png"))] | ||||
| if meta.get('imdb_id') != 0: | ||||
| data['imdb_url'] = str(meta.get('imdb_info', {}).get('imdb_url', '')) + '/' | ||||
| screen_glob = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))] | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using Proposed fix- screen_glob = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))]
+ all_png = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))]
+ unwanted_prefixes = ("FILE", "PLAYLIST", "POSTER")
+ screen_glob = [name for name in all_png if not name.upper().startswith(unwanted_prefixes)]
@@
- screen_glob = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))]
+ all_png = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))]
+ unwanted_prefixes = ("FILE", "PLAYLIST", "POSTER")
+ screen_glob = [name for name in all_png if not name.upper().startswith(unwanted_prefixes)]Also applies to: 422-422 🧰 Tools🪛 Ruff (0.15.6)[error] 398-398: Probable insecure usage of temporary file or directory: "/tmp/" (S108) 🤖 Prompt for AI Agents
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, see Upload-Assistant/src/uploadscreens.py Line 692 in 105a92f
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: Length of output: 1342
# Non-BDMV (line ~398)
all_png = glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))
unwanted_patterns = ["FILE*", "PLAYLIST*", "POSTER*"]
unwanted_files: set[str] = set()
for pattern in unwanted_patterns:
unwanted_files.update(
os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", pattern))
)
screen_glob = [os.path.basename(f) for f in all_png if os.path.basename(f) not in unwanted_files]# BDMV (line ~422)
all_png = glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))
unwanted_patterns = ["FILE*", "PLAYLIST*", "POSTER*"]
unwanted_files: set[str] = set()
for pattern in unwanted_patterns:
unwanted_files.update(
os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", pattern))
)
screen_glob = [os.path.basename(f) for f in all_png if os.path.basename(f) not in unwanted_files]This mirrors the (ᵔᴥᵔ) 🧠 Learnings used |
||||
| files: list[tuple[str, tuple[str, bytes, str]]] = [] | ||||
| for screen in screen_glob: | ||||
| screen_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/{screen}" | ||||
|
|
@@ -404,7 +404,10 @@ async def edit_desc(self, meta: dict[str, Any]) -> None: | |||
| files.append(('images', (os.path.basename(screen), image_bytes, 'image/png'))) | ||||
| async with httpx.AsyncClient(timeout=30.0) as client: | ||||
| response = await client.post(url, data=data, files=files, auth=(self.fltools['user'], self.fltools['pass'])) | ||||
| final_desc = response.text.replace('\r\n', '\n') | ||||
| soup = BeautifulSoup(response.text, 'html.parser') | ||||
| pre_tag = soup.find('pre', {'id': 'description-text'}) | ||||
| final_desc = pre_tag.get_text() if pre_tag else response.text | ||||
| final_desc = final_desc.replace('\r\n', '\n') | ||||
| else: | ||||
| # BD Description Generator | ||||
| bd_summary_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/BD_SUMMARY_EXT.txt" | ||||
|
|
@@ -415,8 +418,8 @@ async def edit_desc(self, meta: dict[str, Any]) -> None: | |||
| final_desc = final_desc.replace('DISC INFO:', '[pre][quote=BD_Info][b][color=#FF0000]DISC INFO:[/color][/b]').replace('PLAYLIST REPORT:', '[b][color=#FF0000]PLAYLIST REPORT:[/color][/b]').replace('VIDEO:', '[b][color=#FF0000]VIDEO:[/color][/b]').replace('AUDIO:', '[b][color=#FF0000]AUDIO:[/color][/b]').replace('SUBTITLES:', '[b][color=#FF0000]SUBTITLES:[/color][/b]') | ||||
| final_desc += "[/pre][/quote]\n" # Closed bbcode tags | ||||
| # Upload screens and append to the end of the description | ||||
| url = "https://up.img4k.net/api/description" | ||||
| screen_glob = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", f"{meta['filename']}-*.png"))] | ||||
| url = "https://bd.img4k.net/" | ||||
| screen_glob = [os.path.basename(f) for f in glob.glob(os.path.join(f"{meta['base_dir']}/tmp/{meta['uuid']}", "*.png"))] | ||||
| files: list[tuple[str, tuple[str, bytes, str]]] = [] | ||||
| for screen in screen_glob: | ||||
| screen_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/{screen}" | ||||
|
|
@@ -425,7 +428,10 @@ async def edit_desc(self, meta: dict[str, Any]) -> None: | |||
| files.append(('images', (os.path.basename(screen), image_bytes, 'image/png'))) | ||||
| async with httpx.AsyncClient(timeout=30.0) as client: | ||||
| response = await client.post(url, files=files, auth=(self.fltools['user'], self.fltools['pass'])) | ||||
| final_desc += response.text.replace('\r\n', '\n') | ||||
| soup = BeautifulSoup(response.text, 'html.parser') | ||||
| pre_tag = soup.find('pre', {'id': 'description-text'}) | ||||
| final_desc = pre_tag.get_text() if pre_tag else response.text | ||||
| final_desc = final_desc.replace('\r\n', '\n') | ||||
| await descfile.write(final_desc) | ||||
|
|
||||
| if self.signature is not None: | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix IMDb URL gating to avoid sending malformed
imdb_url.At Line 396,
meta.get('imdb_id') != 0is unsafe for string IDs (e.g.,"0"), and Line 397 can send"/"whenimdb_info.imdb_urlis missing.Proposed fix
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imdb_id is an int, but the forward slash should be addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Audionut, understood — sinceimdb_idis always an int, the condition is fine as-is. The only issue is the unconditional/append whenimdb_urlis empty. Here's a minimal fix:This ensures
data['imdb_url']is only set when the URL is actually present, and avoids double slashes if the URL already ends with one.(ᐢ•ᴗ•ᐢ)∫
✏️ Learnings added
🧠 Learnings used