Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Automatically Add Playlists #38

Open
2 tasks done
LordFransie opened this issue Jan 27, 2024 · 12 comments
Open
2 tasks done

[Feature Request] Automatically Add Playlists #38

LordFransie opened this issue Jan 27, 2024 · 12 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@LordFransie
Copy link

I've read the documentation.

Your Feature Request

Is your feature request related to a problem? Please describe.

It is not.

Describe the solution you'd like

I’d like TA’s Plex Plugin to automatically create playlists

Additional context

I’m aware this is on the roadmap but is not currently in development. I am creating this ticket to act as a hub to discuss the issue. I’ve already gone through the plugin’s code and I’d like to start the development on this feature.

Your help is needed!

  • Yes, I will work on this in the next few days or weeks.
@lamusmaser
Copy link
Collaborator

From my initial brain dump on this issue:
Playlists will probably become collections.
Collections should be notated whether they are plug-in created vs other (this would hopefully correct #37).
Collections that are plug-in created would then be imported/updated following the appropriate scan/ update logic.
There should be a setting to enable/ disable automatic import of playlists.

Let me know if you have specific questions and I'll try to be responsive.

@lamusmaser lamusmaser added enhancement New feature or request help wanted Extra attention is needed labels Mar 24, 2024
@lamusmaser
Copy link
Collaborator

Have you been able to work on this at all? If not, I will look into it further as potential feature with v0.2.0. Once I have more details, I can provide my notes here.

@LordFransie
Copy link
Author

LordFransie commented Aug 14, 2024

Okay, I have a rather janky script that just barely works

from plexapi.server import PlexServer
import requests
import os

# Replace with your Plex server's URL and API token
PLEX_SERVER_URL = ''  # Replace with your Plex server URL
PLEX_API_TOKEN = ''  # Replace with your Plex token
LIBRARY_NAME = 'TubeArchivist' # Replace with the name of your Plex TubeArchivist Library Name

# Get a list of all playlists
TUBEARCHIVIST_URL = ""
TUBEARCHISIT_API = ""

playlists = []

######
# Finds playlists that the particular youtube video is in
# ytid: the youtube video youtube_id
######
def findPlaylists(ytid):
    videoIn = []
    for video in playlists:
        if video["yt_id"] == ytid:
            videoIn.append(video["playlist_name"])
    return videoIn

########
# Parses the Plex File for the ytid
###########
def plexVideoID(filePath):
    return os.path.splitext(os.path.basename(filePath))[0]

###########
# Creates the list of Tube Archivist playlists and videos
###########
def populatePlaylists():
    headers = {"Authorization": "Token " + TUBEARCHISIT_API}
    response = requests.get(TUBEARCHIVIST_URL + "/api/playlist/", headers=headers).json()
    for item in response['data']:
        entries = item["playlist_entries"]
        for entry in entries:
            playlists.append({"playlist_name": item["playlist_name"], "yt_id": entry["youtube_id"]})

populatePlaylists()


# Connect to Plex server
plex = PlexServer(PLEX_SERVER_URL, PLEX_API_TOKEN)
# Get the library
library = plex.library.section(LIBRARY_NAME)
# Fetch all videos in the library
all_shows = library.all()
# Iterate through the videos and print their file names
for show in all_shows:
    episodes = show.episodes()

    for episode in episodes:
        print("-"*40)
        print(f'Episode Title: "{episode.title}"')
        print(f'Episode ID: "{plexVideoID(episode.media[-1].parts[-1].file)}"')
        print("Found in following playlists")
        print(findPlaylists(plexVideoID(episode.media[-1].parts[-1].file)))
        for collection in findPlaylists(plexVideoID(episode.media[-1].parts[-1].file)):
            episode.addCollection(collection)
            print(f'Added to the : "{collection}" Collection')
        print("")

@tehniemer
Copy link

Another option for this may be to add a playlist as a "Series" in plex, with the additional option to allow channels to be hidden if they are not subscribed in TA.

For example, I subscribe to a bunch of playlists that have content from multiple channels. All of those channels show up as individual series in my plex library with one or two videos in them, I'd rather see the subscribed playlist show up as the series and the individual channels be hidden. I'm not sure if this is possible or should have a separate feature request.

@lamusmaser
Copy link
Collaborator

@tehniemer Unfortunately, this one isn't possible. Because of how the relationship has to be associated when generating the Plex reference ID, I cannot a) associate the video in two places nor b) associate it as a Series component. This is because I generate the details based on the filesystem structure as a fallback for when the metadata isn't provided, and those are only associative to Channel/Video details. YouTube Playlists by nature will have to come in as Collections since Plex Playlists are a per-account level interaction and cannot be created by other users. Collections are the only thing that I've found that perform as expected for this area, just haven't had the development time to actually generate the functionality, although @LordFransie's work does help in this arena to lower the threshold for time requirements.

@tehniemer
Copy link

Understood, I could live with collections of individually subscribed content, playlists or channels, sounds like that's possible?

@tehniemer
Copy link

Maybe some of the methodology in this project could help with collection building?

https://github.com/Kometa-Team/Kometa

@LordFransie
Copy link
Author

Understood, I could live with collections of individually subscribed content, playlists or channels, sounds like that's possible?

So currently the script that I posted does this. It turns each playlist into their own collection, so they'll actually show up alongside the channels when you look at library. Then if you want an even easier time going through them you can just hit "collections" and it will just show you your playlists turned collection.

I have an updated version I need to post that handles pagination and also adds playlists as playlists since that works a bit easier for me for downloading purposes, though it does still have the shortfalls mentioned earlier where playlists don't show up for everyone else on the server.

Feel free to give it a rip, it's python3 and very easy to run.

@tehniemer
Copy link

Does it put each subscribed channel into its own collection also? I would personally like to be able to go to one location in plex to find only my subscribed content, both channels and playlists.

This is the example of what I'm struggling with, I don't want to see all the single video channels since I'm not actually subscribed to them, but the video is part of a playlist.
image

@LordFransie
Copy link
Author

LordFransie commented Sep 11, 2024 via email

@strese
Copy link

strese commented Oct 28, 2024

@LordFransie
I've been trying using the script but I only get a SyntaxError.

File "ta-plex-playlist.py", line 59
print(f'Episode Title: "{episode.title}"')
^
SyntaxError: invalid syntax

SOLVED: I was running the wrong Python version. It was a fubar on my part.

@strese
Copy link

strese commented Oct 31, 2024

@LordFransie
It's me again. 😂 Everything works flawlessly and it's great. Great job, really!
I have a feature request for the script. Is it possible to have it fetch metadata from the playlists from TubeArchivist as well? Metadata like playlist thumbnail, description and such and have it populated in Plex also?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants