MattsShack / JellyPoster

JellyPoster for Jellyfin displays the current playing Movie or TV show poster on a screen.
GNU General Public License v3.0
6 stars 3 forks source link

multiple libraries #5

Open binarygeek119 opened 2 years ago

binarygeek119 commented 2 years ago

i like to able to select which library i like to show 3d movies movies classic movies kids movies as well as tv shows in setting i see this. libraries (names of libraries){ "3d movies", "movies", "classic movies", "kids movies", "tv shows", } this will let jellyposter see where to pull from. also be able to limit the sources.

666Warlock666 commented 2 years ago

ALWAYS MAKE A BACKUP OF ORIGINAL CODE BEFORE ADDING NEW CODE As i can't %100 guarantee it will work or may be not want you are wanting

Added option for film rating (i.e PG-13) and library selection (ie 3d movies, movies, classic movies, etc

Add this to config section

jellyposter_rating = '[Film Rating]'            #'GB-PG', 'GB-12A', 'GB-U', 'GB-15', '', 'PG-13', 'GB-18', 'GB-12', 'R', 'TV-MA', 'TV-14', 'TV-PG', 'PG', 'G', 'NR', 'M', 'TV-G', 'TV-Y7'

jellyfin_selected_library = '[Library]'                 #Add library Name ie 'Movies'`

Replace existing get_RANDOM with this section below:

def get_libaries(jellyfin_selected_library):
    #When run will list available libraries
    response = requests.get(f'{jellyfin_url}/Users/{jellyfin_userid}/Items?api_key={jellyfin_api_key}')
    response = response.json()
    library={}
    print()
    print()
    for item in response['Items']:
        print(item['Name'])
        library[item['Name']] = item['Id']   
    #select library from 

    return(library.get(jellyfin_selected_library,''))

def get_RANDOM():
    if not jellyfin_selected_library == '':
        jellyfin_selected_library_Id = get_libaries(jellyfin_selected_library)
        ran_url=(f'{jellyfin_url}/Items?Userid={jellyfin_userid}&limit=1&Recursive=true&IncludeItemTypes=Movie&IsPlayed=False&sortBy=Random&maxOfficialRating={jellyposter_rating}&ParentId={jellyfin_selected_library_Id}&api_key={jellyfin_api_key}') #Use if library selection is found
    else:
        ran_url=(f'{jellyfin_url}/Items?Userid={jellyfin_userid}&limit=1&Recursive=true&IncludeItemTypes=Movie&IsPlayed=False&sortBy=Random&maxOfficialRating={jellyposter_rating}&api_key={jellyfin_api_key}') # use if no library is assigned or wrong
    get_random_movie_poster = requests.get(ran_url)
    random_movie_poster = get_random_movie_poster.json()
    if not jellyposter_rating == '' or not jellyposter_rating == None:
        while random_movie_poster['Items'][0].get('OfficialRating','') == '':
            get_random_movie_poster = requests.get(ran_url)
            random_movie_poster = get_random_movie_poster.json()
            print(random_movie_poster['Items'][0].get('OfficialRating',''))

    #Setup Variable
    jellyfin_movie_id = random_movie_poster['Items'][0]['Id']
    jellyfin_playback_poster = (f'{jellyfin_url}/items/{jellyfin_movie_id}/Images/Primary')
    jellyposter_top = jellyposter_top_text_idle
    jellyposter_middle = jellyfin_playback_poster
    jellyposter_bottom =  jellyposter_bottom_text_idle
    return jellyposter_top, jellyposter_middle, jellyposter_bottom,jellyposter_bottom_text_font_size_idle