Eisa01 / mpv-scripts

This repository contain scripts I have made for mpv media player...
BSD 2-Clause "Simplified" License
583 stars 38 forks source link

Script request: Creating playlist from within MPV and use the log manager to change and interact with them directly #57

Closed Kayizoku closed 2 years ago

Eisa01 commented 2 years ago

Why not use playlist manager? https://github.com/jonniek/mpv-playlistmanager

Kayizoku commented 2 years ago

Why not use playlist manager? https://github.com/jonniek/mpv-playlistmanager

I think I might've worded it incorrectly. But what I want is to be able to choose individual playlist-file m3u with their own playlist items directly from within mpv. Playlistmanager only allows you to interact with a single playlist and saving them and accessing others is tedious. You'll have to go to the exact directory and drag and drop it into mpv. I was thinking maybe its possible to make it easier by making all of that work directly from inside mpv. So creating a playlist and draw it inside mpv, selecting it, deleting it and updating it with new items and so on.

Kayizoku commented 2 years ago

Btw, it would be really nice if you could make logmanager its own file as well, so if people want to create their own unique script using it, that would be possible. I tried using logmanager for my own purpose but the code is overwhelming and I don't understand what to remove and include to only make the logmanager functionality work.

Eisa01 commented 2 years ago

The thing is with LogManager, it is able to read the log in the exact way I am writing it with small flexibility only. The part where it is reading the logs will need modification for different logging methods.

I'll consider making it a script to be used by others like an API. However, it will have the above limitation.

Also, for your first request, since I never use playlists, I don't know if there is a standard or something for the generated files, but do give me a sample so I can have a look.

Kayizoku commented 2 years ago

I see, it really would be a nice script to have as an API. I can see several use cases for it. I'd imagine the community would come up with many interesting things to complement what you've already made.

I use this to save my playlists currently, it also remembers the position of the files in that playlist. But the thing I can not update a pre-existing ones, change or even delete it in easy way. I have to go to exact folder and then delete it from there. But I was thinking using the log manager script you could create a interactive navigation for the playlists from within mpv. It should be able to delete them, update them, replace them or even create new playlist, all directly from MPV. So you can easily switch between your created playlists.

Visualization:

Spider-man-items_5.m3u Batman-items_12.m3u

I think a better way to visualize it would be its like bookmarking your favorites, but in addition to that you can make a separate folder for them. For example, you have one bookmark for spiderman which only shows spiderman movies and another for Batman that only shows batman movies. I apologize in advance, if there's some confusion. English is not my first language :)

Here is a example of how I save my playlist currently.

local playlist_savepath = (os.getenv('APPDATA') or os.getenv('HOME')..'/.config')..'/mpv/'..'/playlists'

local utils = require("mp.utils")
local msg = require("mp.msg")

local filename = nil
local date = os.date("*t")
local datestring = ("%02d-%02d-%02d_%02d-%02d-%02d"):format(date.year, date.month, date.day, date.hour, date.min, date.sec)

--saves the current playlist into a m3u file
function save_playlist()
  local length = mp.get_property_number('playlist-count', 0)
    if length == 0 then return end
  local savepath = utils.join_path(playlist_savepath, datestring.."-size_"..length.."-playlist.m3u")
  local file, err = io.open(savepath, "w")
  if not file then
    msg.error("Error in creating playlist file, check permissions and paths: "..(err or ""))
  else
    local i=0
    while i < length do
      local pwd = mp.get_property("working-directory")
      local filename = mp.get_property('playlist/'..i..'/filename')
      local fullpath = filename
      if not filename:match("^%a%a+:%/%/") then
        fullpath = utils.join_path(pwd, filename)
      end
      file:write(fullpath, "\n")
      i=i+1
    end
    msg.info("Playlist written to: "..savepath)
    mp.osd_message("Playlist written to: "..savepath)
    file:close()
  end
end

mp.add_key_binding("alt+s", save_playlist)
Eisa01 commented 2 years ago

https://github.com/CogentRedTester/mpv-file-browser There is an add-on for m3u playlist extensions. Let me know if this is what you are looking for

Kayizoku commented 2 years ago

Yes, that's what I am looking for but this one don't seem to work. I followed all the instructions and the file-browser script seems to crash when the m3u lua addon is there.

Kayizoku commented 2 years ago

I was able to solve the issue, I had to download wget, I used chocolatey to make the process simpler and then the addon worked like a charm. I didn't think it was already implemented. Thank you for bringing it to my attention. This was something I really needed :)

Eisa01 commented 2 years ago

Glad that its sorted.