1

The idea of the code is to add to existent playlist unwatched EPs by index order, ep 1 Show X, ep 1 Show Z, regardless of air date:

    from plexapi.server import PlexServer
    baseurl = 'http://0.0.0.0:0000/'
    token = '0000000000000'
    plex = PlexServer(baseurl, token)
    
episode = 0

first_ep_name = []
for x in plex.library.section('Anime').search(unwatched=True):
    try:
        for y in plex.library.section('Anime').get(x.title).episodes()[episode]:
            if plex.library.section('Anime').get(x.title).episodes()[episode].isWatched:
                episode +=1
                first_ep_name.append(y)

            else:
                episode = 0
                first_ep_name.append(y)

    except:
        continue

plex.playlist('Anime Playlist').addItems(first_ep_name)

But when I run it, it will always add watched EPs but if I debug the code in Thoni IDE it seems that is doing its purpose so I am not sure whats wrong with that code.

Any ideas?

Im thinking that the error might be here:

plex.playlist('Anime Playlist').addItems(first_ep_name)

but according to the documentation addItems should be a list but my list "first_ep_name " its already appending unwatched episodes in the correct order, in theory addItems should recognize the specific episode and not only the series name but I am not sure anymore.

Baffometo
  • 41
  • 6

1 Answers1

1

is somebody out there is having the same issue with plexapi I was able to find a way to get this project working properly:

from plexapi.server import PlexServer
baseurl = 'insert plex url here'
token = 'plex token here'
plex = PlexServer(baseurl, token)
anime_plex = []
scrapped_playlist = []

for x in plex.library.section('Anime').search(unwatched=True):
    anime_plex.append(x)

while len(anime_plex) >0:
    episode_list = []
    for y in plex.library.section('Anime').get(anime_plex[0].title).episodes():
        episode_list.append(y)
    
    ep_checker = True 
    while ep_checker:
        if episode_list[0].isWatched:
            episode_list.pop(0)
        else:
            scrapped_playlist.append(episode_list[0])
            episode_list.clear()
            ep_checker = False
    anime_plex.pop(0)
    

# plex.playlist('Anime Playlist').addItems(scrapped_playlist)


plex.playlist('Anime Playlist').delete()
plex.createPlaylist('Anime Playlist', section='Anime', items= scrapped_playlist)

Basically, what I am doing with that code I am looping through each anime series I have and if EP # X is watched then pop from the list until it finds a boolean FALSE then that will append into an empty list that later I will use for creating/adding to playlist.

The last lines of the code can be commented on for whatever purpose, creating the playlist anime or adding items.

Baffometo
  • 41
  • 6