Skip to content

Commit

Permalink
A bit of refactoring, organizing files into folders.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjonsson committed Nov 11, 2024
1 parent 93e0cd5 commit 7f09396
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 63 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Emby MDBList Collection Creator 1.8

This tool allows you to convert lists from MDBList.com into collections within your Emby media server. MDBList aggregates content lists from various platforms including Trakt and IMDB)
This tool allows you to convert lists from MDBList.com into collections within your Emby media server. MDBList aggregates content lists from various platforms including Trakt and IMDB.

## Features

* List Conversion: Transform MDBList lists into Emby collections
* Metadata Refresh: Keep ratings up-to-date for newly released content
* Collection Images: Upload both local and remote images for collections
* Seasonal collections: Specify when a collections should be visible
* Collection Images: Upload local or remote images for collections posters
* Seasonal Collections: Specify when a collections should be visible
* Collection Ordering: Show your collections in order of which one was update
* Backup & Restore: Additional utilities to backup and restore watch history and favorites

## Prerequisites:
Expand Down
71 changes: 15 additions & 56 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import random
import time
import configparser
from emby import Emby
from item_sorting import ItemSorting
from refresher import Refresher
from mdblist import Mdblist
from datetime import datetime
from date_parser import inside_period
from db import Db
from src.emby import Emby
from src.item_sorting import ItemSorting
from src.refresher import Refresher
from src.mdblist import Mdblist
from src.date_parser import inside_period
from src.db import Db
from src.utils import find_missing_entries_in_list
from src.utils import minutes_until_2100

config_parser = configparser.ConfigParser()
config_parser.optionxform = str.lower
Expand All @@ -29,11 +30,9 @@
update_collection_sort_name = config_parser.getboolean(
"admin", "update_collection_sort_name", fallback=True
)

update_items_sort_names_default_value = config_parser.getboolean(
"admin", "update_items_sort_names_default_value", fallback=False
)

refresh_items = config_parser.getboolean(
"admin", "refresh_items_in_collections", fallback=False
)
Expand All @@ -43,7 +42,6 @@
refresh_items_max_days_since_premiered = config_parser.getint(
"admin", "refresh_items_in_collections_max_days_since_premiered", fallback=30
)

hours_between_refresh = config_parser.getint("admin", "hours_between_refresh")

newly_added = 0
Expand All @@ -58,33 +56,6 @@
db_manager = Db()


def find_missing_entries_in_list(list_to_check, list_to_find):
"""
Finds the missing entries in a list.
Args:
list_to_check (list): The list to check against.
list_to_find (list): The list to find missing entries in.
Returns:
list: A list of missing entries found in list_to_find.
"""
return [item for item in list_to_find if item not in list_to_check]


def minutes_until_2100():
"""
Used for sorting collection so that the newest show up first in Emby.
Returns:
int: The number of minutes remaining until the year 2100.
"""
today = datetime.now()
year_2100 = datetime(2100, 1, 1)
delta = year_2100 - today
minutes = delta.days * 24 * 60 + delta.seconds // 60
return minutes


def process_list(mdblist_list: dict):
global newly_added
global newly_removed
Expand Down Expand Up @@ -139,9 +110,7 @@ def process_list(mdblist_list: dict):
elif mdblist_name is not None and user_name is not None:
found_list_id = mdblist.find_list_id_by_name_and_user(mdblist_name, user_name)
if found_list_id is None:
print(
f"ERROR! Could not find list {mdblist_name} by user {user_name}. Will not process this list."
)
print(f"ERROR! List {mdblist_name} by {user_name} not found. Skipping.")
print("=========================================")
return
mdblist_imdb_ids, mdblist_mediatypes = mdblist.get_list(found_list_id)
Expand All @@ -155,16 +124,12 @@ def process_list(mdblist_list: dict):
mdblist_imdb_ids.extend(imdb_ids)
mdblist_mediatypes.extend(mediatypes)
else:
print(
f"ERROR! Must provide either list_id or both list_name and user_name for mdblist {collection_name}. Will not process this list."
)
print(f"ERROR! Must provide either id or source for {collection_name}.")
print("=========================================")
return

if mdblist_imdb_ids is None:
print(
f"ERROR! No items in mdblist {collection_name}. Will not process this list."
)
print(f"ERROR! No items in {collection_name}. Will not process this list.")
print("=========================================")
return

Expand Down Expand Up @@ -207,20 +172,15 @@ def process_list(mdblist_list: dict):
add_emby_ids = emby.get_items_with_imdb_id(missing_imdb_ids, mdblist_mediatypes)

print()
print(
f"Added {len(add_emby_ids)} new items to Collection and removed {len(remove_emby_ids)}"
)
print(f"Added {len(add_emby_ids)} new items and removed {len(remove_emby_ids)}")

if collection_id is None:
if len(add_emby_ids) == 0:
print(
f"ERROR! No items to put in mdblist {collection_name}. Will not process."
)
print(f"ERROR! No items to put in mdblist {collection_name}.")
print("=========================================")
return
collection_id = emby.create_collection(
collection_name, [add_emby_ids[0]]
) # Create the collection with the first item since you have to create with an item
# Create the collection with the first item since you have to create with an item
collection_id = emby.create_collection(collection_name, [add_emby_ids[0]])
add_emby_ids.pop(0)

if collection_id not in all_collections_ids:
Expand Down Expand Up @@ -256,7 +216,6 @@ def process_my_lists_on_mdblist():


def process_hardcoded_lists():
# Get all section from config file that are not "admin" and add to mdblist_lists
collections = []
for section in config_parser.sections():
if section == "admin":
Expand Down
2 changes: 1 addition & 1 deletion app_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import configparser
import json
from emby import Emby
from src.emby import Emby
import os

directory = "backup"
Expand Down
2 changes: 1 addition & 1 deletion app_restore_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
etc
"""

from emby import Emby
from src.emby import Emby
import ast
import sys
from argparse import ArgumentParser
Expand Down
4 changes: 2 additions & 2 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ frequency = 100
update_items_sort_names = False

# Example using a collection poster. Either a local path or an image URL.
# https://plexcollectionposters.com/ has a lot of great posters.
# https://theposterdb.com/ and https://plexcollectionposters.com/ have a lot of great posters.
[Oscars 2024]
source = https://mdblist.com/lists/squint/the-96th-academy-awards
poster = https://plexcollectionposters.com/images/2019/01/31/oscars9a7c2bc47188f883.png
Expand All @@ -107,7 +107,7 @@ update_items_sort_names = False
# Example: active_between = 09-30, 11-01.
[Best of Halloween]
source = https://mdblist.com/lists/hdlists/the-top-100-halloween-movies-of-all-time
poster = https://plexcollectionposters.com/images/2021/11/16/halloween-collectionb0b15dcb9ee4669b.jpg
poster = https://theposterdb.com/api/assets/190058/view
active_between = 09-30, 11-01
frequency = 100
update_items_sort_names = False
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from datetime import datetime


def find_missing_entries_in_list(list_to_check, list_to_find):
"""
Finds the missing entries in a list.
Args:
list_to_check (list): The list to check against.
list_to_find (list): The list to find missing entries in.
Returns:
list: A list of missing entries found in list_to_find.
"""
return [item for item in list_to_find if item not in list_to_check]


def minutes_until_2100():
"""
Used for sorting collection so that the newest show up first in Emby.
Returns:
int: The number of minutes remaining until the year 2100.
"""
today = datetime.now()
year_2100 = datetime(2100, 1, 1)
delta = year_2100 - today
minutes = delta.days * 24 * 60 + delta.seconds // 60
return minutes

0 comments on commit 7f09396

Please sign in to comment.