Skip to content

Commit

Permalink
Revert "Merge pull request #142 from mza921/performance"
Browse files Browse the repository at this point in the history
This reverts commit b9834a1, reversing
changes made to 62b1c3e.
  • Loading branch information
mza921 committed Dec 17, 2020
1 parent 9f47905 commit 5aef838
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 269 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ app/images
app/config.yml
config/config-*
config/*.pickle
config/db/*
**/cache.db*
30 changes: 0 additions & 30 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.8.0] - 2020-12-14 - [#142](https://github.com/mza921/Plex-Auto-Collections/pull/142)
### Added
- Faster initialization of a GUID mapping database for the new Plex Movie Agent using the Plex database

### Removed
- `cache` and `cache_interval` options removed from the config. Movie/Show ID lookups are now always cached on each script execution.

### Fixed
- [#132](https://github.com/mza921/Plex-Auto-Collections/issues/132) - plex_search with a range of years

## [2.7.0] - 2020-11-26 - [#115](https://github.com/mza921/Plex-Auto-Collections/pull/115)
### Added
- Added `tmdb_trending_daily` and `tmdb_trending_weekly`
- Added requirements checking with an error message telling the user to update their requirements
- [#98](https://github.com/mza921/Plex-Auto-Collections/issues/98) - Added `cache` attribute to cache the IDs of movies/shows for quicker lookup and `cache_update_interval` to determine how often to update the cache
- [#123](https://github.com/mza921/Plex-Auto-Collections/issues/123) - Added new filter `plex_collection`
- [#125](https://github.com/mza921/Plex-Auto-Collections/issues/125) - Added error message for YAML Scan Failures

### Changed
- Created a mapping for TMDb ID to Plex Rating Key once each run instead of every time tmdb, imdb, tvdb, or trakt list was run.
- [#110](https://github.com/mza921/Plex-Auto-Collections/issues/110) - Added `add_to_radarr` as a collection level attribute override
- [#121](https://github.com/mza921/Plex-Auto-Collections/issues/121) - Added paging to `tmdb_network` and `tmdb_company` for show libraries
- Upgrade tmdbv3api dependency to 1.7.1

### Fixed
- [#109](https://github.com/mza921/Plex-Auto-Collections/issues/109) - The Cache shouldn't be created unless it has to be
- [#117](https://github.com/mza921/Plex-Auto-Collections/issues/117) - Typo
- [#118](https://github.com/mza921/Plex-Auto-Collections/issues/118) - Check for to see if the tmdb attribute exists
- [#120](https://github.com/mza921/Plex-Auto-Collections/issues/120) - Sometimes the collection wasn't found

## [2.6.0] - 2020-11-12 - [#113](https://github.com/mza921/Plex-Auto-Collections/pull/113)
### Added
- [#107](https://github.com/mza921/Plex-Auto-Collections/issues/107) - Added `plex_collection`
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Plex Auto Collections
##### Version 2.8.0

##### Version 2.6.0
Plex Auto Collections is a Python 3 script that works off a configuration file to create/update Plex collections. Collection management with this tool can be automated in a varying degree of customizability. Supports IMDB, TMDb, and Trakt lists as well as built in Plex Searches using actors, genres, year, studio and more.

![https://i.imgur.com/iHAYFIZ.png](https://i.imgur.com/iHAYFIZ.png)
Expand Down Expand Up @@ -1119,16 +1118,13 @@ plex: # Req

Note that Plex does not allow a `show` to be added to a `movie` library or vice versa.

For `movie` libraries that use the new Plex Movie agent, a temporary copy of the Plex database is downloaded to facilitate the identification of movies. This occurs only during an initial run of the script, per config file. Depending on the size of the library, this can result in a large download.

This script can be run on a remote Plex server, but be sure that the `url` provided is publicly addressable and it's recommended to use `HTTPS`.

You can set the global default [Sync Mode](#sync-mode-collection-attribute) here by using `sync_mode`. Set it to `append` to only add movies/shows to the collection or set it to `sync` to add movies/shows to the collection and remove movies/shows from a collection.

| Sync Options | Description |
| :-- | :-- |
| `append` | Only Add Items to the Collection |
| `sync` | Add & Remove Items from the Collection |
##### Options
- `append` (Only Add Items to the Collection)
- `sync` (Add & Remove Items from the Collection)

Lastly, if you need help finding your Plex authentication token, please see Plex's [support article](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/).

Expand Down
141 changes: 93 additions & 48 deletions app/imdb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,45 +76,45 @@ def imdb_get_movies(config_path, plex, data):
tmdb = TMDb()
tmdb.api_key = config_tools.TMDB(config_path).apikey
movie = Movie()
movie.api_key = config_tools.TMDB(config_path).apikey
return str(movie.external_ids(tmdb_id)['imdb_id'])

def tmdb_get_tvdb(config_path, tmdb_id):
show = TV()
show.api_key = config_tools.TMDB(config_path).apikey
return str(show.external_ids(tmdb_id)['tvdb_id'])
imdb_map = {}
matched_imdb_movies = []
missing_imdb_movies = []
current_length = 0
current_count = 0
plex_tools.create_cache(config_path)
plex_movies = plex.Library.all()
for m in plex_movies:
current_count += 1
print_display = "| Processing: {}/{} {}".format(current_count, len(plex_movies), m.title)
print(adjust_space(current_length, print_display), end="\r")
current_length = len(print_display)
if 'plex://' in m.guid:
item = m
# Check cache for imdb_id
imdb_id = plex_tools.query_cache(config_path, item.guid, 'imdb_id')
if not imdb_id:
imdb_id, tmdb_id = plex_tools.alt_id_lookup(plex, item)
print(adjust_space(current_length, "| Cache | + | {} | {} | {} | {}".format(item.guid, imdb_id, tmdb_id, item.title)))
plex_tools.update_cache(config_path, item.guid, imdb_id=imdb_id, tmdb_id=tmdb_id)
elif 'themoviedb://' in m.guid:
if not tmdb.api_key == "None":
tmdb_id = m.guid.split('themoviedb://')[1].split('?')[0]
tmdbapi = movie.details(tmdb_id)
imdb_id = tmdbapi.imdb_id if hasattr(tmdbapi, 'imdb_id') else None
else:
imdb_id = None
elif 'imdb://' in m.guid:
imdb_id = m.guid.split('imdb://')[1].split('?')[0]
else:
imdb_id = None

def imdb_get_tmdb(config_path, imdb_id):
movie = Movie()
movie.api_key = config_tools.TMDB(config_path).apikey
search = movie.external(external_id=imdb_id, external_source="imdb_id")['movie_results']
if len(search) == 1:
try:
return str(search[0]['id'])
except IndexError:
return None
else:
return None
if imdb_id and imdb_id in title_ids:
imdb_map[imdb_id] = m
else:
imdb_map[m.ratingKey] = m

def tvdb_get_tmdb(config_path, tvdb_id):
movie = Movie()
movie.api_key = config_tools.TMDB(config_path).apikey
search = movie.external(external_id=tvdb_id, external_source="tvdb_id")['tv_results']
if len(search) == 1:
try:
return str(search[0]['id'])
except IndexError:
return None
else:
return None
print(adjust_space(current_length, "| Processed {} Movies".format(len(plex_movies))))

def imdb_get_movies(config_path, plex, plex_map, data):
title_ids = data[1]
print("| {} Movies found on IMDb".format(len(title_ids)))
t_movie = Movie()
t_movie.api_key = config_tools.TMDB(config_path).apikey
matched = []
missing = []
for imdb_id in title_ids:
movie = imdb_map.pop(imdb_id, None)
if movie:
Expand Down Expand Up @@ -154,9 +154,9 @@ def tmdb_get_movies(config_path, plex, data, method):
if count == amount:
break
elif method in ["tmdb_popular", "tmdb_top_rated", "tmdb_now_playing", "tmdb_trending_daily", "tmdb_trending_weekly"]:
trending = Trending()
trending.api_key = t_movie.api_key
for x in range(int(int(data) / 20) + 1):
#trending = Trending() #TURNON:Trending
#trending.api_key = t_movie.api_key #TURNON:Trending
for x in range(int(data / 20) + 1):
if method == "tmdb_popular":
tmdb_movies = t_movie.popular(x + 1)
elif method == "tmdb_top_rated":
Expand Down Expand Up @@ -231,10 +231,40 @@ def tmdb_get_movies(config_path, plex, data, method):

matched = []
missing = []
for mid in t_movs:
mid = str(mid)
if mid in plex_map:
matched.append(plex.Server.fetchItem(plex_map[mid]))
plex_tools.create_cache(config_path)
# We want to search for a match first to limit TMDb API calls
# Too many rapid calls can cause a momentary block
# If needed in future maybe add a delay after x calls to let the limit reset
for mid in t_movs: # For each TMBd ID in TMBd Collection
match = False
for m in p_m_map: # For each movie in Plex
item = m
agent_type = urlparse(m.guid).scheme.split('.')[-1]
# Plex movie agent
if agent_type == 'plex':
# Check cache for tmdb_id
tmdb_id = plex_tools.query_cache(config_path, item.guid, 'tmdb_id')
imdb_id = plex_tools.query_cache(config_path, item.guid, 'imdb_id')
if not tmdb_id:
imdb_id, tmdb_id = plex_tools.alt_id_lookup(plex, item)
print("| Cache | + | {} | {} | {} | {}".format(item.guid, imdb_id, tmdb_id, item.title))
plex_tools.update_cache(config_path, item.guid, imdb_id=imdb_id, tmdb_id=tmdb_id)
if int(tmdb_id) == int(mid):
match = True
break
elif agent_type == 'themoviedb':
if int(p_m_map[m]) == int(mid):
match = True
break
elif agent_type == 'imdb':
imdb_id = t_movie.details(mid).imdb_id
for m in p_m_map:
if "tt" in p_m_map[m]:
if p_m_map[m] == imdb_id:
match = True
break
if match:
matched.append(m)
else:
# Duplicate TMDb call?
missing.append(t_movie.details(mid).imdb_id)
Expand Down Expand Up @@ -315,9 +345,9 @@ def tmdb_get_shows(config_path, plex, data, method):
break
run_discover(data)
elif method in ["tmdb_popular", "tmdb_top_rated", "tmdb_trending_daily", "tmdb_trending_weekly"]:
trending = Trending()
trending.api_key = t_movie.api_key
for x in range(int(int(data) / 20) + 1):
#trending = Trending() #TURNON:Trending
#trending.api_key = t_movie.api_key #TURNON:Trending
for x in range(int(data / 20) + 1):
if method == "tmdb_popular":
tmdb_shows = t_tv.popular(x + 1)
elif method == "tmdb_top_rated":
Expand Down Expand Up @@ -401,8 +431,23 @@ def tmdb_get_shows(config_path, plex, data, method):

return matched, missing

def tvdb_get_shows(config_path, plex, plex_map, data):
tvdb_id = str(data)
def tvdb_get_shows(config_path, plex, data):
config_tools.TraktClient(config_path)

id = int(data)

p_tv_map = {}
for item in plex.Library.all():
guid = urlparse(item.guid)
item_type = guid.scheme.split('.')[-1]
if item_type == 'thetvdb':
tvdb_id = guid.netloc
elif item_type == 'themoviedb' and TraktClient.valid:
tvdb_id = get_tvdb_id_from_tmdb_id(guid.netloc)
else:
tvdb_id = None
p_tv_map[item] = tvdb_id

matched = []
missing = []
match = False
Expand Down
4 changes: 2 additions & 2 deletions app/plex_auto_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def check_details(check_name, check_value):
year_pair = get_method_pair_year(final_attr, collections[c][m][search_attr])
if len(year_pair[1]) > 0:
searches_used.append(final_attr[:-4] if final_attr.endswith(".not") else final_attr)
search.append(get_method_pair_int(final_attr, year_pair[1], final_attr[:-4] if final_attr.endswith(".not") else final_attr))
search.append(get_method_pair_int(final_attr, collections[c][m][search_attr], final_attr[:-4] if final_attr.endswith(".not") else final_attr))
elif final_attr in plex_searches:
if final_attr.startswith("tmdb_"):
final_attr = final_attr[5:]
Expand Down Expand Up @@ -962,7 +962,7 @@ def append_collection(config_path, config_update=None):
print("| |_| |_|\___|/_\_\ /_/ \_\\\\_,_| \__|\___/ \___|\___/|_||_|\___|\__| \__||_|\___/|_||_|/__/ |")
print("| |")
print("|===================================================================================================|")
print("| Version 2.8.0")
print("| Version 2.6.0")
print("| Locating config...")
config_path = None
app_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
Loading

0 comments on commit 5aef838

Please sign in to comment.