Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add flags to control the direction of syncing between the servers #48

Merged
merged 2 commits into from
Mar 9, 2023
Merged
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
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ PLEX_TOKEN = "SuperSecretToken, SuperSecretToken2"
## Set to True if running into ssl certificate errors
SSL_BYPASS = "False"

## control the direction of syncing. e.g. SYNC_FROM_PLEX_TO_JELLYFIN set to true will cause the updates from plex
## to be updated in jellyfin. SYNC_FROM_PLEX_TO_PLEX set to true will sync updates between multiple plex servers
SYNC_FROM_PLEX_TO_JELLYFIN = "True"
SYNC_FROM_JELLYFIN_TO_PLEX = "True"
SYNC_FROM_PLEX_TO_PLEX = "True"
SYNC_FROM_JELLYFIN_TO_JELLYFIN = "True"


# Jellyfin
Expand Down
59 changes: 45 additions & 14 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,35 @@ def update_server_watched(
)


def should_sync_server(server_1_type, server_2_type):
sync_from_plex_to_jellyfin = str_to_bool(
os.getenv("SYNC_FROM_PLEX_TO_JELLYFIN", "True"))
sync_from_jelly_to_plex = str_to_bool(
os.getenv("SYNC_FROM_JELLYFIN_TO_PLEX", "True"))
sync_from_plex_to_plex = str_to_bool(
os.getenv("SYNC_FROM_PLEX_TO_PLEX", "True"))
sync_from_jelly_to_jellyfin = str_to_bool(
os.getenv("SYNC_FROM_JELLYFIN_TO_JELLYFIN", "True"))

if server_1_type == "plex" and server_2_type == "plex" and not sync_from_plex_to_plex:
logger("Sync between plex and plex is disabled", 1)
return False

if server_1_type == "plex" and server_2_type == "jellyfin" and not sync_from_jelly_to_plex:
logger("Sync from jellyfin to plex disabled", 1)
return False

if server_1_type == "jellyfin" and server_2_type == "jellyfin" and not sync_from_jelly_to_jellyfin:
logger("Sync between jellyfin and jellyfin is disabled", 1)
return False

if server_1_type == "jellyfin" and server_2_type == "plex" and not sync_from_plex_to_jellyfin:
logger("Sync from plex to jellyfin is disabled", 1)
return False

return True


def main_loop():
logfile = os.getenv("LOGFILE", "log.log")
# Delete logfile if it exists
Expand Down Expand Up @@ -370,21 +399,23 @@ def main_loop():
1,
)

update_server_watched(
server_1,
server_2_watched_filtered,
user_mapping,
library_mapping,
dryrun,
)
if should_sync_server(server_1[0], server_2[0]):
update_server_watched(
server_1,
server_2_watched_filtered,
user_mapping,
library_mapping,
dryrun,
)

update_server_watched(
server_2,
server_1_watched_filtered,
user_mapping,
library_mapping,
dryrun,
)
if should_sync_server(server_2[0], server_1[0]):
update_server_watched(
server_2,
server_1_watched_filtered,
user_mapping,
library_mapping,
dryrun,
)


def main():
Expand Down