fix overview parser new line

This commit is contained in:
simon 2023-04-07 12:25:14 +07:00
parent 7df3ad3f08
commit ea2da3c967
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 26 additions and 9 deletions

View File

@ -105,3 +105,13 @@ def env_check() -> None:
if not os.path.exists(CONFIG["ta_video_path"]):
raise FileNotFoundError("failed to access ta_video_path")
def clean_overview(overview_raw: str) -> str:
"""parse and clean raw overview text"""
if len(overview_raw) > 500:
overview_raw = overview_raw[:500] + " ..."
desc_clean: str = overview_raw.replace("\n", "<br>")
return desc_clean

View File

@ -2,7 +2,7 @@
from datetime import datetime
from src.connect import Jellyfin, TubeArchivist
from src.connect import Jellyfin, TubeArchivist, clean_overview
from src.static_types import TAVideo
@ -58,8 +58,5 @@ class Episode:
if not raw_desc:
return False
desc_clean: str = raw_desc.replace("\n", "<br>")
if len(raw_desc) > 500:
return desc_clean[:500] + " ..."
desc_clean: str = clean_overview(raw_desc)
return desc_clean

View File

@ -5,7 +5,7 @@ import os
from time import sleep
from src.config import get_config
from src.connect import Jellyfin, TubeArchivist
from src.connect import Jellyfin, TubeArchivist, clean_overview
from src.episode import Episode
from src.static_types import JFEpisode, JFShow, TAChannel, TAVideo
@ -172,16 +172,26 @@ class Show:
def update_metadata(self, ta_channel: TAChannel) -> None:
"""update channel metadata"""
path: str = "Items/" + self.show["Id"]
data = {
data: dict = {
"Id": self.show["Id"],
"Name": ta_channel["channel_name"],
"Overview": ta_channel["channel_description"],
"Overview": self._get_desc(ta_channel),
"Genres": [],
"Tags": [],
"ProviderIds": {},
}
Jellyfin().post(path, data)
def _get_desc(self, ta_channel: TAChannel) -> str | bool:
"""get parsed description"""
raw_desc: str = ta_channel["channel_description"]
if not raw_desc:
return False
desc_clean: str = clean_overview(raw_desc)
return desc_clean
def update_artwork(self, ta_channel: TAChannel) -> None:
"""set channel artwork"""
jf_id: str = self.show["Id"]
@ -205,7 +215,7 @@ class Show:
print(f"[show][{showname}] no new videos found")
return
print(f"[show][{showname}] found {len(new_episodes)} new videos")
print(f"[show][{showname}] indexing {len(new_episodes)} videos")
for video in new_episodes:
youtube_id: str = os.path.split(video["Path"])[-1][9:20]
Episode(youtube_id, video["Id"]).sync()