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] yt-dlp button #84

Closed
novaexe opened this issue Oct 23, 2024 · 8 comments · Fixed by #96
Closed

[Feature Request] yt-dlp button #84

novaexe opened this issue Oct 23, 2024 · 8 comments · Fixed by #96
Labels
feature request New feature or request

Comments

@novaexe
Copy link

novaexe commented Oct 23, 2024

almost perfect, amazing work, this is all i can find that i think is missing.

@novaexe novaexe changed the title [Feature request] yt-dlp button [Feature Request] yt-dlp button Oct 23, 2024
@novaexe
Copy link
Author

novaexe commented Oct 23, 2024

i would put it before screenshot btw
378036291-57dc6e88-c222-4a62-b650-5ae6c88b4fc0

@Samillion
Copy link
Owner

I was going to add this when I was re-doing the project at the start, but I stopped because I don't have access to Mac or Linux desktops. I have a couple of Raspberry Pis and NAS enclosures that run headless, nothing with a desktop environment though.

For example, on ModernX, they use:

local function openFolder()
    local device = "linux"
    if os.getenv("windir") ~= nil then
        device = "windows"
    elseif os.execute '[ -d "/Applications" ]' == 0 and os.execute '[ -d "/Library" ]' == 0 or os.execute '[ -d "/Applications" ]' == true and os.execute '[ -d "/Library" ]' == true then
        device = "mac"
    end

    -- for ubuntu
    local url_browser_linux_cmd = "xdg-open \"$url\""
    local file_browser_linux_cmd = "dbus-send --print-reply --dest=org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:\"file:$path\" string:\"\""
    local url_browser_macos_cmd = "open \"$url\""
    local file_browser_macos_cmd = "open -a Finder -R \"$path\""

    local cmd = ""
    if device == "linux" then
        cmd = file_browser_linux_cmd
    elseif device == 'windows' then
        localpath = localpath:gsub("/", "\\")
        local ret = mp.command_native_async({
            name = "subprocess",
            args = {"explorer", localpath}
        })
    elseif device == "mac" then
        cmd = file_browser_macos_cmd
    end 
    cmd = cmd:gsub("$path", localpath)
    if device ~= 'windows' then
        os.execute(cmd)
    end
end

I would change it to:

local function open_folder(localpath)
    local device = package.config:sub(1,1) == "\\" and "windows" or (os.getenv("OSTYPE") == "darwin" and "mac" or "linux")

    local commands = {
        linux = 'dbus-send --print-reply --dest=org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:"file://%s" string:""',
        mac = 'open -R "%s"',
        windows = {"explorer", "%s"} -- handled as subprocess
    }

    -- platform-specific 
    if device == "windows" then
        localpath = localpath:gsub("/", "\\") -- convert path separators for Windows
        mp.command_native_async({
            name = "subprocess",
            args = {commands.windows[1], string.format(commands.windows[2], localpath)}
        })
    else
        os.execute(string.format(commands[device], localpath))
    end
end

But unfortunately I can't test if my simpler logic works or not for the other platforms.

I'll tinker around and see if I can come up with a solid implementation. Give me a couple of days. I can't promise anything though, but I will do my best.

@novaexe
Copy link
Author

novaexe commented Oct 23, 2024

awesome tyvm :D

@Samillion Samillion added the feature request New feature or request label Oct 24, 2024
@Samillion
Copy link
Owner

Samillion commented Oct 24, 2024

I've added the yt-dlp download feature here:
https://github.com/Samillion/ModernZ/blob/dev_ytdlp_download_241024/modernz.lua

Could you test and give feedback if you face any problems, please?

I'll bother @Keith94 and @Xurdejl in case they're interested as well.

New options:

# show download button on web videos (requires yt-dlp)
downloadbutton=yes

# the download path for videos
downloadpath=~~desktop/mpv

# optional parameteres for yt-dlp
# example "-f bestvideo[vcodec^=avc][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
ytdlpQuality=

Commit: 425c670

Process: (Detecting and downloading)

modernz: Web video detected.
modernz: Fetching file size...
modernz: File size: 52601389 B (Download size: 50.2 MB)
modernz: Executing command: yt-dlp --remux mp4 --add-metadata --embed-subs -o %(title)s -P [FULL-PATH]Desktop/mpv [URL]
modernz: Download completed

Notes:

  • I've re-written parts of the implementation from ModernX
  • I didn't include openFolder(), I find it tedious since I can never maintain it accurately because I don't have access to all platforms

Download button behavior:

  • Only will show if downloadbutton=yes and it is actually a web video.
  • "Already downloaded", "Already downloading" status checks on multiple download button clicks

@Samillion
Copy link
Owner

Ooops, there was a missing , I've updated the script, same link.

@novaexe
Copy link
Author

novaexe commented Oct 24, 2024

awesomeness, works correctly so far in mpv.net, still has that weird yt-dlp container bug with some files where you have to rename it to .mp4 manually, but otherwise great 👍

@novaexe
Copy link
Author

novaexe commented Oct 24, 2024

doesnt have the description like modernx but ey im just glad it works XD

@Samillion
Copy link
Owner

awesomeness, works correctly so far in mpv.net, still has that weird yt-dlp container bug with some files where you have to rename it to .mp4 manually, but otherwise great 👍

Update yt-dlp and ffmpeg if you can, it will be fixed.

doesnt have the description like modernx but ey im just glad it works XD

Youtube description/comments/likes is something I don't plan on adding, to be honest.

@Samillion Samillion linked a pull request Oct 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants