Advertisement
TangentFox

(maintained elsewhere) video-dl.lua (Lua + yt-dlp = videos how I want them)

Dec 11th, 2023 (edited)
1,368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | Source Code | 0 0
  1. #!/usr/bin/env luajit
  2.  
  3. -- THIS IS BEING MAINTAINED AT https://github.com/TangentFoxy/.lua-files
  4. -- GO THERE INSTEAD OF DOWNLOADING THIS FILE DIRECTLY.
  5. -- yt-dlp + Lua = Save videos in a format I want them in.
  6.  
  7. local helptext = [[Usage:
  8.  
  9.   ./video-dl.lua [action] <url>
  10.  
  11. [action]: What is desired.
  12.             video (default): Highest quality video (maximum 720p).
  13.             backup, clone, copy: English subtitles (including automatic
  14.               subtitles), thumbnail, description, highest quality video
  15.               (maximum 720p).
  16.             music, audio: Highest quality audio only.
  17.             metadata, meta: English subtitles (including automatic
  18.               subtitles), thumbnail, description.
  19. <url>:    Source. YouTube URL expected, but should work with anything
  20.           yt-dlp works with.
  21. ]]
  22.  
  23. local action, url
  24.  
  25. if #arg < 2 then
  26.   if arg[1]:find("help") then
  27.     print(help)
  28.     return false
  29.   end
  30.   action = "video"
  31.   url = arg[1]
  32. else
  33.   action = arg[1]
  34.   url = arg[2]
  35. end
  36.  
  37. local execute = {
  38.   backup = function()
  39.     os.execute("yt-dlp --retries 100 --write-sub --write-auto-sub --sub-lang \"en.*\" --write-thumbnail --write-description -f \"bestvideo[height<=720]+bestaudio/best[height<=720]\" \"" .. url .."\"")
  40.   end,
  41.   music = function()
  42.     os.execute("yt-dlp --retries 100 -x --audio-quality 0 \"" .. url .."\"")
  43.   end,
  44.   metadata = function()
  45.     os.execute("yt-dlp --retries 100 --write-sub --write-auto-sub --sub-lang \"en.*\" --write-thumbnail --write-description --skip-download \"" .. url .."\"")
  46.   end,
  47.   video = function()
  48.     os.execute("yt-dlp --retries 100 -f \"bestvideo[height<=720]+bestaudio/best[height<=720]\" \"" .. url .. "\"")
  49.   end,
  50. }
  51. execute.clone = execute.backup
  52. execute.copy = execute.backup
  53. execute.audio = execute.music
  54. execute.meta = execute.metadata
  55.  
  56. if execute[action] then
  57.   execute[action]()
  58. else
  59.   print("Invalid <action>")
  60.   print("Received:", "action", action, "url", url)
  61. end
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement