Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/accounts_add_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
elif _origin == "sync":
plex_account = get_plex_account(uuid=_input)
if not plex_account:
# Auth failed - get_plex_account already shows notification, but log for debugging
custom_logger("error", f"Failed to authenticate via {_origin}")
exit()
replace = False
json_obj = {
Expand Down
12 changes: 10 additions & 2 deletions src/search_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ def get_subtitle(media):
}

plex_account = get_plex_account(uuid=plex_uuid)
watchlist_guids = set([elem.guid for elem in plex_account.watchlist()])
if plex_account is None:
# Auth failed - still show results but skip watchlist features
watchlist_guids = set()
else:
try:
watchlist_guids = set([elem.guid for elem in plex_account.watchlist()])
except Exception as e:
custom_logger("warning", f"Failed to fetch watchlist: {e}")
watchlist_guids = set()
filter_database = database
if watchlist == 1:
filter_database = [media for media in database if media.guid in watchlist_guids]
Expand Down Expand Up @@ -279,7 +287,7 @@ def get_subtitle(media):
}
)

if short_watchlist != "":
if short_watchlist != "" and plex_account is not None:
media_guid = media.guid
isInWatchlist = True if media_guid in watchlist_guids else False
action = "delete" if isInWatchlist else "add"
Expand Down
8 changes: 6 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ def custom_logger(level: str, message: str):


def delete_files(element):
# Files to preserve across version upgrades (user authentication data)
preserve_files = {"presets.json", "accounts.json", "servers.json"}
if os.path.exists(element):
for file in os.listdir(element):
if not file.endswith(".app") and file != "presets.json":
if not file.endswith(".app") and file not in preserve_files:
file_path = os.path.join(element, file)
try:
os.remove(file_path)
Expand Down Expand Up @@ -147,7 +149,9 @@ def delete_files(element):
config = configparser.ConfigParser()
if os.path.exists(config_file_path):
config.read(config_file_path)
if plex_app_version != config["header"]["version"]:
# Only check version if running from Alfred (env var is set)
# This prevents accidental cleanup when running scripts from terminal
if plex_app_version and plex_app_version != config["header"]["version"]:
for folder in [data_folder, cache_folder]:
delete_files(folder)

Expand Down