Skip to content

Commit 7710bf1

Browse files
committed
minor tweaks
1 parent adbb0cd commit 7710bf1

File tree

6 files changed

+365
-11
lines changed

6 files changed

+365
-11
lines changed

Plex/adjust-added-dates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737

3838
logger("connection success", "info", "a")
3939

40-
plogger(f"Adjusting future dates only: {config.get_bool("adjust_date.futures_only", False)}", "info", "a")
40+
plogger(f"Adjusting future dates only: {config.get_bool('adjust_date.futures_only', False)}", "info", "a")
4141

42-
plogger(f"Adjusting epoch dates only: {config.get_bool("adjust_date.epoch_only", False)}", "info", "a")
42+
plogger(f"Adjusting epoch dates only: {config.get_bool('adjust_date.epoch_only', False)}", "info", "a")
4343

4444
EPOCH_DATE = datetime(1970, 1, 1, 0, 0, 0)
4545

@@ -178,7 +178,7 @@ def is_epoch(the_date):
178178

179179
else:
180180
blogger(
181-
f"skipping {item.title}: EPOCH_ONLY {config.get_bool("adjust_date.epoch_only", False)}, originally available date {orig_date}",
181+
f"skipping {item.title}: EPOCH_ONLY {config.get_bool('adjust_date.epoch_only', False)}, originally available date {orig_date}",
182182
"info",
183183
"a",
184184
bar,

Plex/apply-all-status.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# DONE 0.1.1: guard against empty library map
1919
# DONE 0.2.0: config class
2020

21+
print("CURRENTLY BROKEN")
22+
exit()
23+
2124
# current dateTime
2225
now = datetime.now()
2326

@@ -32,9 +35,9 @@
3235

3336
config = Config('../config.yaml')
3437

35-
PLEX_OWNER = config.get("target.plex_owner")
38+
PLEX_OWNER = config.get("status.plex_owner")
3639

37-
LIBRARY_MAP = config.get("target.library_map", "{}")
40+
LIBRARY_MAP = config.get("status.library_map", "{}")
3841

3942
try:
4043
lib_map = json.loads(LIBRARY_MAP)

Plex/grab-all-posters.py

Lines changed: 183 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@
7373
# 0.8.9b change one blogger to plogger since there's no bar in that context
7474
# 0.8.9c use sanitize_filename on illegal names and actually use that name
7575
# 0.8.9d add JUNK reason to filename for visibility outside superchat
76+
# 0.9.0 change to config class instead of env
7677

7778
SCRIPT_NAME = Path(__file__).stem
7879

79-
VERSION = "0.8.9c"
80+
VERSION = "0.9.0"
8081

8182
config = Config('../config.yaml')
8283

@@ -153,6 +154,7 @@ def superchat(msg, level, logfile):
153154
# GRAB_BACKGROUNDS = config.get_bool('image_download.what_to_grab.backgrounds', True)
154155
GRAB_SEASONS = config.get_bool('image_download.what_to_grab.seasons', True)
155156
GRAB_EPISODES = config.get_bool('image_download.what_to_grab.episodes', True)
157+
GRAB_LOGOS = config.get_bool('image_download.what_to_grab.logos', True)
156158

157159
ONLY_CURRENT = config.get_bool('image_download.what_to_grab.only_current', False)
158160

@@ -470,7 +472,7 @@ def get_progress_string(item):
470472
return ret_val
471473

472474

473-
def get_image_name(params, tgt_ext, background=False):
475+
def get_image_name(params, tgt_ext, background=False, logo=False):
474476
ret_val = ""
475477

476478
item_type = params["type"]
@@ -491,6 +493,8 @@ def get_image_name(params, tgt_ext, background=False):
491493

492494
if background:
493495
ret_val = f"_background{base_name}"
496+
elif logo:
497+
ret_val = f"_logo{base_name}"
494498
else:
495499
if item_type == "season":
496500
# _Season##.ext
@@ -511,6 +515,8 @@ def get_image_name(params, tgt_ext, background=False):
511515

512516
if background:
513517
ret_val = f"background-{base_name}"
518+
elif logo:
519+
ret_val = f"logo-{base_name}"
514520
else:
515521
if item_type == "season" or item_type == "episode":
516522
ret_val = f"{item_se_str}-{safe_name}-{base_name}"
@@ -542,6 +548,7 @@ def process_the_thing(params):
542548
# assets/One Show/Adam-12 Collection
543549

544550
background = params["background"]
551+
logo = params["logo"]
545552
src_URL = params["src_URL"]
546553
provider = params["provider"]
547554
source = params["source"]
@@ -554,7 +561,7 @@ def process_the_thing(params):
554561
result["status"] = "Nothing happened"
555562

556563
tgt_ext = ".dat" if ID_FILES else ".jpg"
557-
tgt_filename = get_image_name(params, tgt_ext, background)
564+
tgt_filename = get_image_name(params, tgt_ext, background, logo)
558565
# in asset case, I have '_poster.ext'
559566
superchat(f"target filename {tgt_filename}", "info", "a")
560567

@@ -668,6 +675,173 @@ def __init__(self, provider, key):
668675
self.provider = provider
669676
self.key = key
670677

678+
# property logoUrl
679+
# lockLogo()[source]
680+
# unlockLogo()[source]
681+
# logos()[source]
682+
# uploadLogo(url=None, filepath=None)[source]
683+
684+
def get_logo(item, artwork_path, tmid, tvid, uuid, lib_title):
685+
global SCRIPT_STRING
686+
687+
superchat(
688+
f"entering get_logo {item.title}, {artwork_path}, {tmid}, {tvid}, {uuid}, {lib_title}",
689+
"info",
690+
"a",
691+
)
692+
693+
attempts = 0
694+
if ONLY_CURRENT:
695+
all_logos = []
696+
all_logos.append(poster_placeholder("current", item.logoUrl))
697+
else:
698+
all_logos = item.logos()
699+
700+
if USE_ASSET_NAMING:
701+
logo_path = artwork_path
702+
else:
703+
logo_path = Path(artwork_path, "logos")
704+
705+
while attempts < 5:
706+
try:
707+
progress_str = f"{get_progress_string(item)} - {len(all_logos)} logos"
708+
709+
blogger(progress_str, "info", "a", bar)
710+
711+
import fnmatch
712+
713+
if ONLY_CURRENT:
714+
no_point_in_looking = False
715+
else:
716+
count = 0
717+
logos_to_go = 0
718+
719+
if os.path.exists(logo_path):
720+
# if I'm using asset naming, the names all start with `logo``
721+
if USE_ASSET_NAMING:
722+
count = len(
723+
fnmatch.filter(os.listdir(logo_path), "logo*.*")
724+
)
725+
else:
726+
count = len(fnmatch.filter(os.listdir(logo_path), "*.*"))
727+
logger(f"{count} files in {logo_path}", "info", "a")
728+
729+
logos_to_go = count - POSTER_DEPTH
730+
731+
if logos_to_go < 0:
732+
logo_to_go = abs(logos_to_go)
733+
else:
734+
logo_to_go = 0
735+
736+
logger(
737+
f"{logo_to_go} needed to reach depth {POSTER_DEPTH}", "info", "a"
738+
)
739+
740+
no_more_to_get = count >= len(all_logos)
741+
full_for_now = count >= POSTER_DEPTH and POSTER_DEPTH > 0
742+
no_point_in_looking = full_for_now or no_more_to_get
743+
if no_more_to_get:
744+
logger(
745+
f"Grabbed all available logos: {no_more_to_get}", "info", "a"
746+
)
747+
if full_for_now:
748+
logger(
749+
f"full_for_now: {full_for_now} - {POSTER_DEPTH} image(s) retrieved already",
750+
"info",
751+
"a",
752+
)
753+
754+
if not no_point_in_looking:
755+
idx = 1
756+
for logo in all_logos:
757+
if logo.key is not None:
758+
if POSTER_DEPTH > 0 and idx > POSTER_DEPTH:
759+
logger(
760+
f"Reached max depth of {POSTER_DEPTH}; exiting loop",
761+
"info",
762+
"a",
763+
)
764+
break
765+
766+
art_params = {}
767+
art_params["tmid"] = tmid
768+
art_params["tvid"] = tvid
769+
art_params["idx"] = idx
770+
art_params["path"] = logo_path
771+
art_params["provider"] = logo.provider
772+
art_params["source"] = "remote"
773+
art_params["uuid"] = uuid
774+
art_params["lib_title"] = lib_title
775+
776+
art_params["type"] = item.TYPE
777+
art_params["title"] = item.title
778+
779+
try:
780+
art_params["seasonNumber"] = item.seasonNumber
781+
except:
782+
art_params["seasonNumber"] = None
783+
784+
try:
785+
art_params["episodeNumber"] = item.episodeNumber
786+
except:
787+
art_params["episodeNumber"] = None
788+
789+
art_params["se_str"] = get_SE_str(item)
790+
791+
art_params["logo"] = True
792+
art_params["background"] = False
793+
794+
src_URL = logo.key
795+
if src_URL[0] == "/":
796+
src_URL = f"{config.get('plex_api.auth_server.base_url')}{logo.key}&X-Plex-Token={config.get('plex_api.auth_server.token')}"
797+
art_params["source"] = "local"
798+
799+
art_params["src_URL"] = src_URL
800+
801+
bar.text = f"{progress_str} - {idx}"
802+
logger(f"processing {progress_str} - {idx}", "info", "a")
803+
804+
superchat(
805+
f"Built out params for {item.title}: {art_params}",
806+
"info",
807+
"a",
808+
)
809+
if not TRACK_URLS or (
810+
TRACK_URLS and not check_url(src_URL, uuid)
811+
):
812+
if THREADED_DOWNLOADS:
813+
future = executor.submit(
814+
process_the_thing, art_params
815+
) # does not block
816+
# append it to the queue
817+
my_futures.append(future)
818+
superchat(
819+
f"Added {item.title} to the download queue",
820+
"info",
821+
"a",
822+
)
823+
else:
824+
superchat(
825+
f"Downloading {item.title} directly", "info", "a"
826+
)
827+
process_the_thing(art_params)
828+
else:
829+
logger(
830+
f"SKIPPING {item.title} as its URL was found in the URL tracking table: {src_URL} ",
831+
"info",
832+
"a",
833+
)
834+
835+
else:
836+
logger("skipping empty internal art object", "info", "a")
837+
838+
idx += 1
839+
840+
attempts = 6
841+
except Exception as ex:
842+
progress_str = f"EX: {ex} {item.title}"
843+
logger(progress_str, "info", "a")
844+
attempts += 1
671845

672846
def get_art(item, artwork_path, tmid, tvid, uuid, lib_title):
673847
global SCRIPT_STRING
@@ -777,6 +951,7 @@ def get_art(item, artwork_path, tmid, tvid, uuid, lib_title):
777951
art_params["se_str"] = get_SE_str(item)
778952

779953
art_params["background"] = True
954+
art_params["logo"] = False
780955

781956
src_URL = art.key
782957
if src_URL[0] == "/":
@@ -1038,6 +1213,7 @@ def get_posters(lib, item, uuid, title):
10381213
art_params["se_str"] = get_SE_str(item)
10391214

10401215
art_params["background"] = False
1216+
art_params["logo"] = False
10411217

10421218
src_URL = poster.key
10431219

@@ -1094,6 +1270,10 @@ def get_posters(lib, item, uuid, title):
10941270

10951271
if config.get_bool('image_download.what_to_grab.backgrounds', True):
10961272
get_art(item, artwork_path, tmid, tvid, uuid, lib_title)
1273+
1274+
if config.get_bool('image_download.what_to_grab.logos', True):
1275+
get_logo(item, artwork_path, tmid, tvid, uuid, lib_title)
1276+
10971277
else:
10981278
plogger(
10991279
"Skipping {item.title}, error determining target subdirectory", "info", "a"

Plex/grab-imdb-posters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
level=logging.INFO,
2828
)
2929

30-
logging.info(f"Starting {SCRIPT_NAME} {VERSION} at {RUNTIME_STR}", "info", "a")
30+
logging.info(f"Starting {SCRIPT_NAME} {VERSION} at {RUNTIME_STR}")
3131
print(f"Starting {SCRIPT_NAME} {VERSION} at {RUNTIME_STR}", "info", "a")
3232

3333
config = Config('../config.yaml')
@@ -72,7 +72,7 @@ def progress(count, total, status=""):
7272

7373
for item in items:
7474
item_count = item_count + 1
75-
imdb_id, tmdb_id, tvdb_id = get_ids(item.guids, TMDB_KEY)
75+
imdb_id, tmdb_id, tvdb_id = get_ids(item.guids)
7676

7777
tmpDict = {}
7878
tmpDict["title"] = item.title

Plex/list-item-ids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from alive_progress import alive_bar
88
from config import Config
99
from helpers import (get_all_from_library, get_ids, get_plex,
10-
get_target_libraries)
10+
get_target_libraries, get_redaction_list)
1111
from logs import logger, plogger, setup_logger
1212

1313
SCRIPT_NAME = Path(__file__).stem

0 commit comments

Comments
 (0)