forked from rreveley/plex-playlists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie-ranking.py
61 lines (53 loc) · 2.23 KB
/
movie-ranking.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
import plexapi.utils
import string, math, os
from pprint import pprint
import requests
from tenacity import wait_exponential, retry, stop_after_attempt
from plexapi.server import PlexServer
import mutagen
from mutagen.id3 import ID3, COMM, POPM
from mutagen import MutagenError
from tqdm import tqdm
from functools import cmp_to_key
def get_my_rating(movie):
my_rating = 0
if movie.userRating is not None and movie.userRating >= 8:
my_rating+=movie.userRating
my_rating = my_rating*10 + min(movie.viewCount, 10)
my_rating = my_rating*10 + movie.rating
if len(movie.collections) > 0:
my_rating+=2
genres = [genre.tag for genre in movie.genres]
if 'Science Fiction' in genres or 'Fantasy' in genres:
my_rating+=2
if 'Romance' in genres:
my_rating-=2
my_rating = my_rating*10 + movie.audienceRating
return my_rating
def movie_compare(a, b):
if get_my_rating(a) > get_my_rating(b):
return 1
return -1
cmp_items_py3 = cmp_to_key(movie_compare)
token = 'ZfxxHwnW2pyd6egLfzPi'
baseurl = 'http://192.168.1.147:32400'
if __name__ == '__main__':
plex = PlexServer(baseurl, token, timeout=200)
movies = plex.library.section('Movies')
movies_list = []
for movie in movies.search(sort='rating,audienceRating',
filters={'movie.rating>>': 0, 'movie.rating<<': 8, 'movie.audienceRating<<': 8, 'movie.year<<': 2020}):
rating = get_my_rating(movie)
movies_list.append([rating, movie])
#movies_list = sorted(movies_list, key = cmp_items_py3)
movies_list = sorted(movies_list, key=lambda x: x[0])
for movie in [tuple[1] for tuple in movies_list[:10]]:
genres = [genre.tag for genre in movie.genres]
collections = [collection.tag for collection in movie.collections]
print(f"MyRating: {get_my_rating(movie)}, Rating: {movie.rating}, \
Audience Rating: {movie.audienceRating}, Content Rating: {movie.contentRating}, \
ViewCount: {movie.viewCount}, User Rating: {movie.userRating}, \
Collections: {collections}, Genres: {genres} Title: {movie.title}, {movie.year}")
#for location in movie.locations:
#print(location)
#os.remove(location)