-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
63 lines (53 loc) · 2.11 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Main module
"""
import time
from config import cfg
from syncerr import Jellyfin, Plex, currently_playing
from syncerr.logger import logger
jellyfin = Jellyfin(
cfg.JELLYFIN_URL, username=cfg.JELLYFIN_USERNAME, password=cfg.JELLYFIN_PASSWORD
)
# Fetch currently playing media on Jellyfin
jf_media = currently_playing(jellyfin)
plex = Plex(cfg.PLEX_URL, cfg.PLEX_TOKEN)
libraries = plex.library_types()
plex_media = {}
for library in libraries:
# Interested in the shows and movies only
if library["type"] in ["movie", "show"]:
lib_key = library["key"]
plex_media[library["type"]] = plex.items(lib_key)
for show in plex_media["show"]:
logger.info("working on %s", show["title"])
show["details"] = plex.traverse_child(show["ratingKey"])
# FIX: this sleep is here to throttle the requests.
time.sleep(0.2)
for jm in jf_media:
IS_MOVIE = True
if jm["Type"] == "Episode":
IS_MOVIE = False
plex_items = plex_media["show"]
else:
plex_items = plex_media["movie"]
for pm in plex_items:
jf_media_name = jm["Name"] if IS_MOVIE else jm["SeriesName"]
if jf_media_name.lower() == pm["title"].lower():
# we found the match in plex
if IS_MOVIE:
# since media type is movie on jellyfin it is easy to push progress on plex
plex.mark_status(pm, progress=jm["percentage"])
logger.info("Movie update pushed to Plex")
else:
# we need to find the plex object
for season in pm["details"]:
if jm["SeasonName"].lower() == season["title"].lower():
# we found the correct season
for episode in season["episodes"]:
if jm["Name"].lower() == episode["title"].lower():
plex.mark_status(episode, progress=jm["percentage"])
logger.info("Episode update pushed to Plex")
break
break
break
logger.info("Done pushing data from Jellyfin to Plex")