pbrink231 / plex_top_playlists

A python script for creating playlists and collections for all server users from sources like IMDB and Trakt
110 stars 22 forks source link

Adding collection to home screen #49

Open Mike7154 opened 3 years ago

Mike7154 commented 3 years ago

This isn't really a bug of this script, just unwanted behavior because of how plex works.

Problem: I wanted the list to show up on my home screen, but plex only gives this option for collections and NOT playlists. So I made a collection using this script instead of a playlist. The problem, my collections are set to hide items in the collection (e.g. so I don't have 30 barbie items in my library). I can set this playlist to not combine, but then each movie that is in another collection gets pulled out of that collection if it is also in this collection (ie. the most popular harry potter movies are listed next to the harry potter collection because they are also in the popular trakt list).

My solution: instead of adding 'collection' tags. I add labels. I just modified the code in collection.py to be like

def add_library_items_to_collection(title, items):
    """ Adds plex items to a collection """
    for library_item in items:
        library_item.addLabel(title)

Then I make a smart playlist based on the labels. I also had to add this somewhere in the beginning of the code to remove the old labels.

 movies = PLEX.library.section('Movies')
        for movie in movies.search(label='Featured'):
            movie.removeLabel('Featured')

This approach lets me add popular movies on trakt to my home screen. Side note: smart collections can be sorted randomly, you simply replace the &sort=asc in the url to &sort=random. So aquaman isn't always the first movie in the collection. It would be cooler if it was sorted like a playlist, but plex can't do that from what I can tell.

It would be cool if this was somehow a feature, but I don't think it should replace existing collecction operation like I did it.

Thanks

pbrink231 commented 3 years ago

This looks really cool and what I have hoped to do with this from the beginning. Being able to get a list in the Home Screen.

I am not familiar with labels so looking into it but I think from your code it won’t be hard to just add a setting.

mystardious commented 2 years ago

I was able to sort mine in order adding to Mike7154's code by changing the sort title of the movies.

def add_library_items_to_collection(title, items):
    """ Adds plex items to a collection """
    counter = 1
    for library_item in items:

        # Add custom sort order for smart collection
        # Issues can arise when item is in two different lists

        if(len(library_item.labels) == 0):
            # Add label to item
            library_item.addLabel(title)

            # Add order to item
            edits = {'titleSort.value': str(counter), 'titleSort.locked': 1}
            library_item.edit(**edits)
            library_item.reload()
            counter += 1

When I run the script I remove any previous labels

movies = PLEX.library.section('Movies')
labels = ['Top Watched (Week)']

for label in labels:
    for movie in movies.search(label=label):
        # Remove label
        movie.removeLabel(label)

        # Remove sortTitle
        edits = {'titleSort.value': movie.title, 'titleSort.locked': 0}
        movie.edit(**edits)
        movie.reload()

This is the end result: image However I can only have one list with this method, it is possible to do this with multiple list but if the same movies is on both lists order goes whack.

mystardious commented 2 years ago

Anyways I figured out to put more than one list by using non smart collections. And then ordering them using the collection.move command here is the end result. Still working on it though check my GitHub for updates. Movies Movies TV Shows Shows

def add_library_items_to_collection(title, items, plex):
    """ Adds plex items to a collection """

    ## Create/recreate the collection
    print([x for x in items])

    section = global_vars.MOVIE_LIBRARY_NAME
    if items[0].type != 'movie':
        section = global_vars.SHOW_LIBRARY_NAME

    library = plex.library.section(section) ## library short form
    libraryCollections = [x.title for x in library.collections()] ## All movie collections
    collection = None

    if title in libraryCollections: ## Check if collection exists
        collection = library.collection(title)
        collection.removeItems(collection.items()) ## Remove all items in collection
        collection.reload()
        collection.addItems(items) ## Add new items
        collection.reload()
    else:
        library.createCollection(title, items=items, smart=False) ## Create stupid collection
        library.reload()
        collection = library.collection(title)
        collection.sortUpdate('custom') ## Set sort order
        collection.reload()

    ## Correctly order collection

    # Move first item to correct place
    collection.moveItem(items[0])
    collection.reload()

    # Move remaining items to correct place
    for i in range(len(items)-1):
        collection.moveItem(items[i+1], items[i])
        collection.reload()
pbrink231 commented 2 years ago

I like this idea. We can make a new type called labels. Not to hard to add.

could you make a pull request on it? If not I can attack it in December.

mystardious commented 2 years ago

Yeah no problem, will do so soon (probably after next week).

My first post uses labels but order is not kept for more than one list since it is sorted by sortTitle, however my second post creates a collection and manually orders items as if you were dragging it in a custom order. This way I can have unlimited number of lists with the order I want (which I believe is what collection function was meant to originally do). I will also later on add the ability to sort it randomly as an extra option.

After the collection is created you can pin to home, library, etc (I aim to allow users to specify in code whether to add to home screen and possibly for other users as well as the order they appear in the library) after which you can schedule the script to run periodically and the collection is updated on your home and library.

Azswanepoel commented 2 years ago

This is really great gentleman, we look forward to the howto on how to implement. Thank you for helping us making it better for our users.

Respectfully, Alec

On Mon, Nov 8, 2021 at 8:02 PM Mohamed Maatouk @.***> wrote:

Yeah no problem, will do so soon (probably after next week).

My first post uses labels but order is not kept for more than one list since it is sorted by sortTitle, however my second post creates a collection and manually orders items as if you were dragging it in a custom order. This way I can have unlimited number of lists with the order I want. I will also later on add the ability to sort it randomly as an extra option.

After the collection is created you can pin to home, library, etc (I aim to allow users to specify in code whether to add to home screen and possibly for other users as well as the order they appear in the library)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pbrink231/plex_top_playlists/issues/49#issuecomment-963795429, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFLZVMS4S7SRNENVCIQPDDULCMMBANCNFSM45YMA7NA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Mike7154 commented 2 years ago

I like these creative approaches. Although because of how Plex works, each of these approaches will alter the library as a trade off. The first one will reorder movies in the library and the second will either force or prevent you from hiding certain movies in collections like I mentioned in the original post. I would be okay with this trade off, but some of my siblings use my server and I know they look for movies by browsing the library; I'd prefer not to hide or reorder all the popular movies and make them too difficult to find. Also, for some reason it bothers me to see Harry Potter 1 right next to the Harry Potter collection when browsing the library. But I would prefer your second approach.

But for those tradeoffs I will personally stick to labels even though the order is not ideal. Or maybe try out your second approach to see if I can get used to popular movies jumping out of their collections.

mystardious commented 2 years ago

I like these creative approaches. Although because of how Plex works, each of these approaches will alter the library as a trade off. The first one will reorder movies in the library and the second will either force or prevent you from hiding certain movies in collections like I mentioned in the original post. I would be okay with this trade off, but some of my siblings use my server and I know they look for movies by browsing the library; I'd prefer not to hide or reorder all the popular movies and make them too difficult to find. Also, for some reason it bothers me to see Harry Potter 1 right next to the Harry Potter collection when browsing the library. But I would prefer your second approach.

But for those tradeoffs I will personally stick to labels even though the order is not ideal. Or maybe try out your second approach to see if I can get used to popular movies jumping out of their collections.

I thought that might be a problem but you can individually hide collections using the plexapi as well as in plex by going Edit -> Advanced --> Collection Mode

mystardious commented 2 years ago

Ok I reread your comment and think I found a solution from a reddit post. Make all collections hidden by default, scan collections that aren't created by the program and compare them to the ones the script is adding. At this point anything in a collection is hidden from the library.

Create a dummy collection with media that you want to show which is basically putting all media that you want to see in your library by comparing collection made by script and the rest and automatically using the script adding items to that dummy collection. This way you wont see individual harry potter movies in your library and still see other items in that list.

Link to reddit post

Understandably your gonna have an extra collection in your library, although not visible unless you go to collections specifically but i think this tradeoff is better than having items appearing out of a collection you dont want the items showing.