Skip to content

Commit

Permalink
Fix tests to include partially watched jellyfin and emby
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi311 committed Jun 3, 2024
1 parent 3fdcc99 commit 4185f5f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
25 changes: 15 additions & 10 deletions src/jellyfin_emby.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ def __init__(self, server_type, baseurl, token, headers):
self.session = requests.Session()
self.users = self.get_users()

def query(
self, query, query_type, identifiers=None, json=None
):
def query(self, query, query_type, identifiers=None, json=None):
try:
results = None

Expand All @@ -148,7 +146,10 @@ def query(

elif query_type == "post":
response = self.session.post(
self.baseurl + query, headers=self.headers, json=json, timeout=self.timeout
self.baseurl + query,
headers=self.headers,
json=json,
timeout=self.timeout,
)
if response.status_code not in [200, 204]:
raise Exception(
Expand Down Expand Up @@ -626,12 +627,13 @@ def update_user_watched(
if not dryrun:
logger(msg, 5)
playback_position_payload = {
"PlaybackPositionTicks": movie_status['time'] * 10_000,
"PlaybackPositionTicks": movie_status["time"]
* 10_000,
}
self.query(
f"/Users/{user_id}/Items/{jellyfin_video_id}/UserData",
"post",
json=playback_position_payload
json=playback_position_payload,
)
else:
logger(msg, 6)
Expand Down Expand Up @@ -755,16 +757,19 @@ def update_user_watched(
f"{self.server_type}: {jellyfin_episode['SeriesName']} {jellyfin_episode['SeasonName']} Episode {jellyfin_episode.get('IndexNumber')} {jellyfin_episode.get('Name')}"
+ f" as partially watched for {floor(episode_status['time'] / 60_000)} minutes for {user_name} in {library}"
)

if not dryrun:
logger(msg, 5)
playback_position_payload = {
"PlaybackPositionTicks": episode_status['time'] * 10_000,
"PlaybackPositionTicks": episode_status[
"time"
]
* 10_000,
}
self.query(
f"/Users/{user_id}/Items/{jellyfin_episode_id}/UserData",
"post",
json=playback_position_payload
json=playback_position_payload,
)
else:
logger(msg, 6)
Expand All @@ -773,7 +778,7 @@ def update_user_watched(
user_name,
library,
jellyfin_episode.get("SeriesName"),
jellyfin_episode.get('Name'),
jellyfin_episode.get("Name"),
duration=floor(episode_status["time"] / 60_000),
)
else:
Expand Down
4 changes: 3 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ def main_loop():
# Start server_2 at the next server in the list
for server_2 in servers[servers.index(server_1) + 1 :]:
# Check if server 1 and server 2 are going to be synced in either direction, skip if not
if not should_sync_server(server_1[0], server_2[0]) and not should_sync_server(server_2[0], server_1[0]):
if not should_sync_server(
server_1[0], server_2[0]
) and not should_sync_server(server_2[0], server_1[0]):
continue

logger(f"Server 1: {server_1[0].capitalize()}: {server_1[1].info()}", 0)
Expand Down
50 changes: 39 additions & 11 deletions test/validate_ci_marklog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@


def parse_args():
parser = argparse.ArgumentParser(description="Check the mark.log file that is generated by the CI to make sure it contains the expected values")
parser.add_argument("--dry", action="store_true", help="Check the mark.log file for dry-run")
parser.add_argument("--write", action="store_true", help="Check the mark.log file for write-run")
parser.add_argument("--plex", action="store_true", help="Check the mark.log file for Plex")
parser.add_argument("--jellyfin", action="store_true", help="Check the mark.log file for Jellyfin")
parser.add_argument("--emby", action="store_true", help="Check the mark.log file for Emby")
parser = argparse.ArgumentParser(
description="Check the mark.log file that is generated by the CI to make sure it contains the expected values"
)
parser.add_argument(
"--dry", action="store_true", help="Check the mark.log file for dry-run"
)
parser.add_argument(
"--write", action="store_true", help="Check the mark.log file for write-run"
)
parser.add_argument(
"--plex", action="store_true", help="Check the mark.log file for Plex"
)
parser.add_argument(
"--jellyfin", action="store_true", help="Check the mark.log file for Jellyfin"
)
parser.add_argument(
"--emby", action="store_true", help="Check the mark.log file for Emby"
)

return parser.parse_args()

Expand Down Expand Up @@ -72,20 +84,25 @@ def main():
"jellyplex_watched/TV Shows/Monarch: Legacy of Monsters/Departure/300741",
# Plex -> Jellyfin
"JellyUser/Movies/Big Buck Bunny",
"JellyUser/Movies/Killers of the Flower Moon/4",
"JellyUser/Shows/Doctor Who/The Unquiet Dead",
"JellyUser/Shows/Doctor Who/Aliens of London (1)/4",
"JellyUser/Shows/Monarch: Legacy of Monsters/Secrets and Lies",
"JellyUser/Shows/Monarch: Legacy of Monsters/Parallels and Interiors/4",
# Emby -> Plex
"jellyplex_watched/Movies/Tears of Steel",
"jellyplex_watched/TV shows/Doctor Who (2005)/World War Three (2)",
"jellyplex_watched/TV shows/Monarch: Legacy of Monsters/Parallels and Interiors/240429",
# Plex -> Emby
"jellyplex_watched/Movies/Big Buck Bunny",
"jellyplex_watched/Movies/The Family Plan",
"jellyplex_watched/Movies/Killers of the Flower Moon/4",
# Emby -> Jellyfin
"JellyUser/Movies/Tears of Steel",
# Jellyfin -> Emby
"jellyplex_watched/Movies/The Family Plan",
"jellyplex_watched/Movies/Five Nights at Freddy's"
"jellyplex_watched/Movies/Five Nights at Freddy's",
"jellyplex_watched/Movies/The Hunger Games: The Ballad of Songbirds & Snakes/5",
],
"write": [
"jellyplex_watched/Movies/Five Nights at Freddy's",
Expand All @@ -95,24 +112,34 @@ def main():
"jellyplex_watched/TV Shows/Monarch: Legacy of Monsters/Aftermath",
"jellyplex_watched/TV Shows/Monarch: Legacy of Monsters/Departure/300741",
"JellyUser/Movies/Big Buck Bunny",
"JellyUser/Movies/Killers of the Flower Moon/4",
"JellyUser/Shows/Doctor Who/The Unquiet Dead",
"JellyUser/Shows/Doctor Who/Aliens of London (1)/4",
"JellyUser/Shows/Monarch: Legacy of Monsters/Secrets and Lies",
"JellyUser/Shows/Monarch: Legacy of Monsters/Parallels and Interiors/4",
"jellyplex_watched/Movies/Tears of Steel",
"jellyplex_watched/TV shows/Doctor Who (2005)/World War Three (2)",
"jellyplex_watched/TV shows/Monarch: Legacy of Monsters/Parallels and Interiors/240429",
"jellyplex_watched/Movies/Big Buck Bunny",
"jellyplex_watched/Movies/The Family Plan",
"jellyplex_watched/Movies/Five Nights at Freddy's",
"jellyplex_watched/Movies/The Hunger Games: The Ballad of Songbirds & Snakes/5",
"jellyplex_watched/Movies/Killers of the Flower Moon/4",
"JellyUser/Movies/Tears of Steel",
"JellyUser/Shows/Monarch: Legacy of Monsters/Parallels and Interiors/4",
"jellyplex_watched/TV shows/Doctor Who (2005)/World War Three (2)",
"jellyplex_watched/TV shows/Monarch: Legacy of Monsters/Parallels and Interiors/240429"
"jellyplex_watched/TV shows/Monarch: Legacy of Monsters/Parallels and Interiors/240429",
],
"plex": [
"JellyUser/Movies/Big Buck Bunny",
"JellyUser/Movies/Killers of the Flower Moon/4",
"JellyUser/Shows/Doctor Who/The Unquiet Dead",
"JellyUser/Shows/Doctor Who/Aliens of London (1)/4",
"JellyUser/Shows/Monarch: Legacy of Monsters/Secrets and Lies",
"JellyUser/Shows/Monarch: Legacy of Monsters/Parallels and Interiors/4",
"jellyplex_watched/Movies/Big Buck Bunny",
"jellyplex_watched/Movies/The Family Plan",
"jellyplex_watched/Movies/Killers of the Flower Moon/4",
],
"jellyfin": [
"jellyplex_watched/Movies/Five Nights at Freddy's",
Expand All @@ -122,14 +149,15 @@ def main():
"jellyplex_watched/TV Shows/Monarch: Legacy of Monsters/Aftermath",
"jellyplex_watched/TV Shows/Monarch: Legacy of Monsters/Departure/300741",
"jellyplex_watched/Movies/The Family Plan",
"jellyplex_watched/Movies/Five Nights at Freddy's"
"jellyplex_watched/Movies/Five Nights at Freddy's",
"jellyplex_watched/Movies/The Hunger Games: The Ballad of Songbirds & Snakes/5",
],
"emby": [
"jellyplex_watched/Movies/Tears of Steel",
"jellyplex_watched/TV shows/Doctor Who (2005)/World War Three (2)",
"jellyplex_watched/TV shows/Monarch: Legacy of Monsters/Parallels and Interiors/240429",
"JellyUser/Movies/Tears of Steel"
]
"JellyUser/Movies/Tears of Steel",
],
}

# Expected values for the mark.log file, dry-run is slightly different than write-run
Expand Down

0 comments on commit 4185f5f

Please sign in to comment.