tubearchivist / tubearchivist

Your self hosted YouTube media server

Home Page:https://www.tubearchivist.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Playlist Autoplay

cosmoneer opened this issue · comments

Hi, so I read in a closed issue where this feature is on the roadmap, so I understand you are already thinking about it. I figured I would share some thoughts I had while looking into trying to tackle this feature, based on how things are coded thus far.

I took some time to look at the webpage source to see how everything was laid out. This led me to the script.js source file, where I found the "onVideoEnded()" function call. I thought I could add a few lines of code and see if I could make something work, but I can see the challenge you're facing. In short, it isn't as simple as updating the video player source URL.

Forgive me if I get this wrong or miss some big picture issues. If I understand correctly from digging deeper, these are the challenges you face:

  1. Missing YouTube "playlist_index" in the ElasticSearch database in the ta_video table. At present, it seems the only usable sort option is publish date. Without an index in the database, it seems the only way to get the next video is to pull the entire playlist and loop through it until you find the next video ID after the one that just finished playing. Not an elegant solution.

  2. Video Playlist IDs are stuffed into a single "playlist" field only once per ID. As I understand it, since a video can exist multiple times in a playlist, this field isn't the best place to capture playlist+index. It seems an additional table is needed, plus supporting code.

I don't currently have a development environment to try an idea out on (but I may tackle this in the near future... thanks for your notes on how best to set one up), but if I did, I might tackle it this way:

  • Add a new index to ElasticSearch: ta_playlistindex (VideoID, PlaylistID, Index, DateTimeAdded)
  • Update the TA yt-dlp playlist download code to include this new index/table, thus capturing the index and multiple playlist entries
  • When playing videos in the UI from a playlist, add the playlist ID & index as parameters to the appropriate
    tag (via script.js code updates)
  • Add a function to the script.js to get the playlist index value
  • Add a function to get the next video ID in the playlist via the playlist id & playlist index value
  • Update the onVideoEnded function to
    a> Check if it is a playlist video being played. If yes, then
    b> Get the next video ID via the new function above
    c> Update the video.src =url;
    d> Trigger the video.play() method
    (As I currently understand it, triggering the "play" method via js may not work on all browsers)

Did I miss anything?

commented

So how it's indexed now, is in the video index, e.g. /ta_video/_doc/<video-id>/ you have a key playlist with an array of all playlist ids where this video is found. Then the playlists themself are indexed in /ta_playlist/_doc/<playlist-id>/, with a list of all videos, their position, and if they are downloaded or not.

So finding the "next" video of a current video is a matter of finding the current idx, then +1 and you have the next. That's also how the playlist nav at the bottom of the video page is build. So as far as I can tell, from an indexing standpoint, this should be all that's required, except if I'm missing something?

So my original thinking on how to implement that feature, was to have some sort of a temporary playlist stored in redis. This playlist could be from a youtube playlist, or could be user generated, or could be last 10 unwatched etc. So this would combine this feature with the user created playlist feature, a two in one kind of deal. :-)

This would also solve the "know in which playlist you want to find the next video" problem. YouTube for example handles that with URL parameters, e.g. watch?v=<video-id>&list=<playlist-id>, that would be another approach.

So all in all, I think you have realized, that this is a multi step problem. How about start small? Fix the issue with duplicated items in the playlist? #154. Then from there we could think about how the redis part could look like, this will also require additional API endpoints for that. Then for the frontend part, we might have to wait with that, until the rewrite in NextJS/React is finished, otherwise we duplicate the effort.

Reach out on Discord, we usually discuss these things there in #help-contribute, that's a little bit easier than in the issues here.

Hi bbilly, thanks for the detailed reply!

The docker I am running ( its an UNRAID docker available under community apps) is version 0.1.3, so it looks like I am a version behind. It sounds like version 0.1.4 has the indexes that are needed?

In the meantime, I need to stand up a Dev environment. Once I have that, I will be sure to reach out on discord.

commented

Hi there, were you able to make any progress on this one?

commented

closing this due to inactivity. Feel free to reach out if you want to work on that.

commented

This is very important feature to auto play as BGM for me. how come no one can implement it .

commented

This is very important feature to auto play as BGM for me. how come no one can implement it .

This is an open source project that is provided entirely for free. We have other things on our roadmap that have taken priority

If you'd like, you can implement this feature yourself, otherwise, it'll have to wait.