From 5a317c9e0e04bc683c1c08e68839db7d795c8093 Mon Sep 17 00:00:00 2001 From: Tormy Van Cool <32305535+tormyvancool@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:32:15 +0100 Subject: [PATCH 1/7] Release YOUTUBE Downloader v2.9 1.0 2024-26-10 # First Release 1.1 2024-26-10 + Processes Notifications - /Video/ + /Videos/ 1.2 2024-26-10 - --merge-output-format mp4 + -S vcodec:h264,res,acodec:aac 1.3 2024-26-10 - 10 + 2 1.4 2024-26-10 - 2 + 5 1.5 2024-26-10 - 5 + 1 # Unified Update 1.6 2024-26-10 - 1 + 2 + Version 1.7 2024-27-10 - 'start "" "' from all O.S.s + 'start "UPDATE & DOWNLOAD" "' Win 1.8 2024-27-10 - GGGGG = '' - 1 + Start = '"' + 2 1.9 2024-27-10 + Check saved project - 1 + 2 2.0 2024-27-10 - "chmod +x " .. MainPath + 'chmod +x "' .. MainPath .. '"' # Ordered Variables - 2 + 1 + Apple Trial 2.3 2024-27-10 # Linux execution correction + Credits # 2.1 and 2.2 just trials due issues with Linux and Apple 2.31 2024-28-10 # Binaries directly form the source 2.32 2024-28-10 - yt-dlp + yt-dlp_linux 2.4 2024-29-10 # Adjusted header style for production 2.5 2024-11-04 - Various + VideoPath = 'Video' 2.6 2024-11-05 + check for temrination of temporary file upfrotn import the video 2.7 2024-11-05 - Check Routine 2.8 2024-11-06 + Detects Nework Interruptions during download + Removes leftovers + URLs as filename: forbidden + Limitation to only alphanumerical characters 2.9 2024-11-06 + Check IfFileExists: Overwrite, Newname, Exit --- Video/tormyvancool_YOUTUBE Downloader.lua | 367 ++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 Video/tormyvancool_YOUTUBE Downloader.lua diff --git a/Video/tormyvancool_YOUTUBE Downloader.lua b/Video/tormyvancool_YOUTUBE Downloader.lua new file mode 100644 index 000000000..0af60a518 --- /dev/null +++ b/Video/tormyvancool_YOUTUBE Downloader.lua @@ -0,0 +1,367 @@ +-- @description YOUTUBE Downloader +-- @author Tormy Van Cool +-- @version 2.9 +-- @changelog +-- 1.0 2024-26-10 +-- # First Release +-- 1.1 2024-26-10 +-- + Processes Notifications +-- - /Video/ +-- + /Videos/ +-- 1.2 2024-26-10 +-- - --merge-output-format mp4 +-- + -S vcodec:h264,res,acodec:aac +-- 1.3 2024-26-10 +-- - 10 +-- + 2 +-- 1.4 2024-26-10 +-- - 2 +-- + 5 +-- 1.5 2024-26-10 +-- - 5 +-- + 1 +-- # Unified Update +-- 1.6 2024-26-10 - 1 +-- + 2 +-- + Version +-- 1.7 2024-27-10 +-- - 'start "" "' from all O.S.s +-- + 'start "UPDATE & DOWNLOAD" "' Win +-- 1.8 2024-27-10 +-- - GGGGG = '' +-- - 1 +-- + Start = '"' +-- + 2 +-- 1.9 2024-27-10 +-- + Check saved project +-- - 1 +-- + 2 +-- 2.0 2024-27-10 +-- - "chmod +x " .. MainPath +-- + 'chmod +x "' .. MainPath .. '"' +-- # Ordered Variables +-- - 2 +-- + 1 +-- + Apple Trial +-- 2.3 2024-27-10 +-- # Linux execution correction +-- + Credits +-- # 2.1 and 2.2 just trials due issues with Linux and Apple +-- 2.31 2024-28-10 +-- # Binaries directly form the source +-- 2.32 2024-28-10 +-- - yt-dlp +-- + yt-dlp_linux +-- 2.4 2024-29-10 +-- # Adjusted header style for production +-- 2.5 2024-11-04 +-- - Various +-- + VideoPath = 'Video' +-- 2.6 2024-11-05 +-- + check for temrination of temporary file upfrotn import the video +-- 2.7 2024-11-05 +-- - Check Routine +-- 2.8 2024-11-06 +-- + Detects Nework Interruptions during download +-- + Removes leftovers +-- + URLs as filename: forbidden +-- + Limitation to only alphanumerical characters +-- 2.9 2024-11-06 +-- + Check IfFileExists: Overwrite, Newname, Exit +-- @provides +-- [windows] yt-dlp/yt-dlp.exe https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe +-- [linux] yt-dlp/yt-dlp_linux https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp +-- [darwin] yt-dlp/yt-dlp_macos https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos +-- @donation Pay me a drink https://bit.ly/Pay_Me_a_Drink +-- @about +-- # Import VIDEOs directly in TimeLine from YouTUBE, VIMEO, PATREONS and thousand other ones. +-- +-- Key Features: +-- +-- - 4 click operation: Start the script, enter the URL, give a title, click on OK +-- - Import any Video in TimeLine by giving just the URL +-- - Videos are saved into the project folder under the dedicated /Videos/ folder +-- - Videos are imported into a new track, having the given name, and at the cursor position +-- - Auto-update of the binaries "yt-dlp" each time the script is invoked, to ensure top quality at each use +-- - Compatible with about thousand platforms included: +-- - YouTUBE +-- - Vimeo +-- - Patreons +-- and several other ones ... +-- +-- [Full list here](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md) +-- +-- #Credits: +-- Stefano marcantoni and Talagan - to have helped for MAC implementation +-- Paolo Saggese - to have helped for Linux implementation + +reaper.ClearConsole() + +--------------------------------------------- +-- MAIN VARIABLES +--------------------------------------------- +local LF = "\n" +local pipe = "|" +local colon = ":" +local quote = '"' +local slash = '\\' +local backslash = '/' +local clock = os.clock +local debug = false +local ver = 2.9 +local InputVariable = "" +local dlpWin = 'yt-dlp.exe' +local dlpMac = 'yt-dlp_macos' +local dlpLnx = 'yt-dlp_linux' +local version = reaper.GetAppVersion() +local pj_name_ = reaper.GetProjectName(0, "") +local ProjDir = reaper.GetProjectPathEx(0) +local ResourcePATH = reaper.GetResourcePath() +local VideoPath = 'Video' +local CallPath = ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. VideoPath .. '/yt-dlp/' -- Get FullPath to yt-dlp + +--------------------------------------------- +-- FUNCTIONS +--------------------------------------------- + + -- SLEEP(SECONDS) + function sleep(n) + local t0 = clock() + while clock() - t0 <= n do end + end + + -- IDENTIFIES THE O.S. + function getOS() + local OS = reaper.GetOS() + local a = {} + local MainPath = '' + if OS == "Win32" or OS == "Win64" then + MainPath = '"' .. ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. VideoPath .. '/yt-dlp/' .. dlpWin .. '"' + Start = 'start /b /wait "UPDATE & DOWNLOAD" ' + OpSys = 1 + end + if OS == "OSX32" or OS == "OSX64" or OS == "macOS-arm64" then + MainPath = './yt-dlp_macos' + Start = 'cd "' .. CallPath .. '" && chmod +x ' .. dlpMac .. ' && ' + os.execute('chmod +x "' .. MainPath .. '"') + OpSys = 2 + end + if OS == "Other" then + -- MainPath = ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/Various/yt-dlp/' .. dlpLnx .. '"' + -- Start = '"' + -- os.execute('chmod +x "' .. MainPath .. '"') + MainPath = '"' .. ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. VideoPath .. '/yt-dlp/' .. dlpLnx .. '"' + Start = '' + os.execute('chmod +x ' .. MainPath) + OpSys = 3 + end + return MainPath + end + + -- GET FILE SIZE + function get_file_size(filename) + local file = io.open(filename, "rb") + if not file then return 0 end + local size = file:seek("end") + file:close() + return size + end + + local MainPath = getOS() + + -- FILTER OUT PROHIITED CHARACTERS + function GetRid(chappy, seed, subs) -- Get rid of not-admitted characters to prevent any error by user + local ridchap + if subs == nil then subs = "" end + if chappy == nil then return end + local ridchap = string.gsub (chappy, seed, subs) + return ridchap + end + + -- CHECK FOR URL VALIDITY + function is_valid_url(url) + -- Pattern to match a basic URL structure + local pattern = "^https?://[%w-_%.%?%.:/%+=&]+$" + return url:match(pattern) ~= nil + end + + local minVersion = '7.27' + if minVersion > version then + reaper.MB('your Reaper verions is '..version..'\nPlease update REAPER to the last version!', 'ERROR: REAPER '..version..' OUTDATED', 0) + goto done + end +--------------------------------------------- +-- INTERACTIONS +--------------------------------------------- + + -- CHECK WHETHER PROJECT IS SAVED + if pj_name_ == "" then + reaper.MB("YOU MUST SAVE THE PROJECT FIRST! Then relaunch this script!",'WARNING',0) + return + end + + -- GET URL + repeat + retval, url=reaper.GetUserInputs("DOWNLOAD VIDEO", 1, "Paste URL,extrawidth=400", InputVariable) + if retval==false then return end + if retval then + t = {} + i = 0 + for line in url:gmatch("[^" .. LF .. "]*") do + i = i + 1 + t[i] = line + end + end + if t[1]== "" then + reaper.MB("VIDEO URL is MANDATORY","ERROR",0,0) + end + if is_valid_url(t[1]) == false then + reaper.MB("URL NOT VALID","ERROR",0,0) + end + until( t[1] ~= "" and is_valid_url(t[1]) == true) + + + -- GET FILENAME + ::getfilename:: + repeat + retval_1, FileName=reaper.GetUserInputs("DOWNLOAD VIDEO", 1, "Insert FILE NAME,extrawidth=400", InputVariable) + FileName = GetRid(GetRid(GetRid(GetRid(GetRid(FileName, pipe), colon), quote), slash), backslash) -- No reserved characters can be written + FileName = FileName:gsub("http", "") + + if retval_1==false then return end + if retval_1 then + t = {} + i = 0 + for line in FileName:gmatch("[^" .. LF .. "]*") do + i = i + 1 + t[i] = line + end + end + + -- NO EMPTY TITLE ADMITTED + if t[1]== "" then + reaper.MB("VIDEO TITLE is MANDATORY","ERROR",0,0) + end + + -- NO URLS AND NOT ALPHANUMERICAL CHARACTERS ADMITTED + if t[1]:match("[^%w%s]") then + reaper.MB("ONLY ALPHANUMERIC CHARACTERS ADMITTED","ERROR",0,0) + t[1]="" + end + until( t[1] ~= "") + +--------------------------------------------- +-- ARGS & TRIGGERS +--------------------------------------------- + + if FileName ~= "" + then + if string.find(FileName, ".mp4") == nil then + FileTemp = FileName .. '.f137.mp4.part' + FileName = FileName .. ".mp4" + end + argument = ' -o "' .. FileName .. '"' + FileTemp = FileName:sub(1, -5) .. '.f137.mp4.part' + end + + -- ARGS + args = " --update-to master -S vcodec:h264,res,acodec:aac " .. url .. ' -P "' .. ProjDir .. '/Videos/"' .. argument .. " --force-overwrite" + upArgs = " --update-to master" + + -- TRIGGERS + Update = Start .. MainPath .. upArgs + Video = Start .. MainPath .. args + Destination = ProjDir ..'/Videos/' .. FileName + Destination = Destination:gsub('\\','/') + + +--cd ~/Library/"Application Support"/REAPER/Scripts/Tormy\ Van\ Cool\ ReaPack\ Scripts/Various/yt-dlp/ && ./yt-dlp_macos + +--------------------------------------------- +-- UPDATE AND IMPORT VIDEO +--------------------------------------------- + + if url ~= "" then + + if debug == true then + reaper.ShowConsoleMsg("FileName: " .. FileTemp .. "\n") + reaper.ShowConsoleMsg("Destination: " .. Destination .. "\n") + end + + -- CHECK IF FILE EXISTS + local checkfile = reaper.file_exists(Destination) + local answer = nil + if checkfile == true then + answer = reaper.MB("A file with the same filename exists\nWould you want to overwrite it?\n\nYES => Go on\nNO => Rewrite the filname\nCANCEL => Exit",'WARNING: FILENAME EXISTS',3) + end + if answer == 7 then + goto getfilename + elseif answer == 2 then + goto done + end + + reaper.MB("STARTED THE FOLLOWING PROCESSES v" .. ver .. ":\n\n1. Update YT-DLP\n2. Downlaod the video: " ..url .. "\n3. Naming the video: " .. FileName .. ".mp4 \n4. Saving the video into " .. ProjDir .. "/Videos/\n5. Import the video into the project\n\nHEY it will take a little while. DON'T PANIC!\n\nCLICK ON \"OK\" TO CONTINUE", "PROCESS STARTED. PROCESSES LISTED HERE BELOW",0) + + -- DIFFERENTIATE EXECUTION BASED ON O.S. + if OpSys == 2 then + os.execute(Update) + os.execute(Video) + elseif OpSys == 1 or OpSys == 3 then + os.execute(Start .. MainPath .. upArgs .. args) + end + + + --------------------------------------------- + -- NETWORK DISRUPTION + --------------------------------------------- + + -- GET RESIDUAL FILES + local ResFiles + if OpSys == 2 or OpSys == 3 then + ResFiles = "ls -a " .. ProjDir .."/Videos/*.mp4.part" + ResDel = 'rm "' .. ProjDir .. '\\Videos\\*.mp4.part"' + elseif OpSys == 1 then + ResFiles = 'dir /b "' .. ProjDir .. '\\Videos\\*.mp4.part"' + ResDel = 'del "' .. ProjDir .. '\\Videos\\*.mp4.part"' + end + + local handle = io.popen(ResFiles) + + if handle == nil then + return + end + local stdout = handle:read("*all") + success = handle:close() + + -- REMOVE RESIDUAL FILES + if success then + if debug == true then reaper.ShowConsoleMsg('output is: \n' .. tostring(stdout) .. "\n") end + local retQuery = reaper.MB("Due a Network Error, the video was not properly downloaded.\nBY CLICKING OK THESE LEFTOVERS WILL BE REMOVED\n\nLeftovers:\n\n" .. tostring(stdout), "NETWORK ERROR", 0) + if retQuery == 1 then + handle = io.popen(ResDel) + success = handle:close() + end + else + if debug == true then reaper.ShowConsoleMsg('error when executing command' .. ResFiles) end + reaper.InsertMedia(Destination, 1) + end + + if debug == true then + local stable = false + local last_size = get_file_size(Destination) + while not stable or io.open(FileTemp, "rb") do + + local new_size = get_file_size(Destination) + + if new_size > 0 and new_size == last_size then + stable = true + else + last_size = new_size + end + end + end + + + end + +::done:: From 38eabbca1b1b4c2a3f38f6a00d9dbff1c01a6f64 Mon Sep 17 00:00:00 2001 From: Tormy Van Cool <32305535+tormyvancool@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:17:02 +0100 Subject: [PATCH 2/7] Update tormyvancool_YOUTUBE Downloader.lua Download admittend only on supported O.S.es --- Video/tormyvancool_YOUTUBE Downloader.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Video/tormyvancool_YOUTUBE Downloader.lua b/Video/tormyvancool_YOUTUBE Downloader.lua index 0af60a518..45d68611c 100644 --- a/Video/tormyvancool_YOUTUBE Downloader.lua +++ b/Video/tormyvancool_YOUTUBE Downloader.lua @@ -69,9 +69,14 @@ -- 2.9 2024-11-06 -- + Check IfFileExists: Overwrite, Newname, Exit -- @provides --- [windows] yt-dlp/yt-dlp.exe https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe +-- [win64] yt-dlp/yt-dlp.exe https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -- [linux] yt-dlp/yt-dlp_linux https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp --- [darwin] yt-dlp/yt-dlp_macos https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos +-- [darwin64] yt-dlp/yt-dlp_macos https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos +-- [darwin-arm64] yt-dlp/yt-dlp_macos https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos +-- [win64] . +-- [linux] . +-- [darwin64] . +-- [darwin-arm64] . -- @donation Pay me a drink https://bit.ly/Pay_Me_a_Drink -- @about -- # Import VIDEOs directly in TimeLine from YouTUBE, VIMEO, PATREONS and thousand other ones. @@ -140,7 +145,7 @@ local CallPath = ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. V Start = 'start /b /wait "UPDATE & DOWNLOAD" ' OpSys = 1 end - if OS == "OSX32" or OS == "OSX64" or OS == "macOS-arm64" then + if OS == "OSX64" or OS == "macOS-arm64" then MainPath = './yt-dlp_macos' Start = 'cd "' .. CallPath .. '" && chmod +x ' .. dlpMac .. ' && ' os.execute('chmod +x "' .. MainPath .. '"') From 9fbc2ea4c0643a13b09c8eee02bb5796254d3f56 Mon Sep 17 00:00:00 2001 From: Tormy Van Cool <32305535+tormyvancool@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:49:01 +0100 Subject: [PATCH 3/7] Update tormyvancool_YOUTUBE Downloader.lua Implemented OS independent code to check for leftovers and remove them --- Video/tormyvancool_YOUTUBE Downloader.lua | 225 ++++++++++------------ 1 file changed, 106 insertions(+), 119 deletions(-) diff --git a/Video/tormyvancool_YOUTUBE Downloader.lua b/Video/tormyvancool_YOUTUBE Downloader.lua index 45d68611c..922b51107 100644 --- a/Video/tormyvancool_YOUTUBE Downloader.lua +++ b/Video/tormyvancool_YOUTUBE Downloader.lua @@ -1,73 +1,95 @@ -- @description YOUTUBE Downloader -- @author Tormy Van Cool -- @version 2.9 --- @changelog --- 1.0 2024-26-10 --- # First Release --- 1.1 2024-26-10 --- + Processes Notifications --- - /Video/ --- + /Videos/ --- 1.2 2024-26-10 --- - --merge-output-format mp4 --- + -S vcodec:h264,res,acodec:aac --- 1.3 2024-26-10 --- - 10 --- + 2 --- 1.4 2024-26-10 --- - 2 --- + 5 --- 1.5 2024-26-10 --- - 5 --- + 1 --- # Unified Update --- 1.6 2024-26-10 - 1 --- + 2 --- + Version --- 1.7 2024-27-10 --- - 'start "" "' from all O.S.s --- + 'start "UPDATE & DOWNLOAD" "' Win --- 1.8 2024-27-10 --- - GGGGG = '' --- - 1 --- + Start = '"' --- + 2 --- 1.9 2024-27-10 --- + Check saved project --- - 1 --- + 2 --- 2.0 2024-27-10 --- - "chmod +x " .. MainPath --- + 'chmod +x "' .. MainPath .. '"' --- # Ordered Variables --- - 2 --- + 1 --- + Apple Trial --- 2.3 2024-27-10 --- # Linux execution correction --- + Credits --- # 2.1 and 2.2 just trials due issues with Linux and Apple --- 2.31 2024-28-10 --- # Binaries directly form the source --- 2.32 2024-28-10 --- - yt-dlp --- + yt-dlp_linux --- 2.4 2024-29-10 --- # Adjusted header style for production --- 2.5 2024-11-04 --- - Various --- + VideoPath = 'Video' --- 2.6 2024-11-05 --- + check for temrination of temporary file upfrotn import the video --- 2.7 2024-11-05 --- - Check Routine --- 2.8 2024-11-06 --- + Detects Nework Interruptions during download --- + Removes leftovers --- + URLs as filename: forbidden --- + Limitation to only alphanumerical characters --- 2.9 2024-11-06 --- + Check IfFileExists: Overwrite, Newname, Exit +-- @Changelog: +-- 1.0 2024-26-10 +-- # First Release +-- 1.1 2024-26-10 +-- + Processes Notifications +-- - /Video/ +-- + /Videos/ +-- 1.2 2024-26-10 +-- - --merge-output-format mp4 +-- + -S vcodec:h264,res,acodec:aac +-- 1.3 2024-26-10 +-- - 10 +-- + 2 +-- 1.4 2024-26-10 +-- - 2 +-- + 5 +-- 1.5 2024-26-10 +-- - 5 +-- + 1 +-- # Unified Update +-- 1.6 2024-26-10 - 1 +-- + 2 +-- + Version +-- 1.7 2024-27-10 +-- - 'start "" "' from all O.S.s +-- + 'start "UPDATE & DOWNLOAD" "' Win +-- 1.8 2024-27-10 +-- - GGGGG = '' +-- - 1 +-- + Start = '"' +-- + 2 +-- 1.9 2024-27-10 +-- + Check saved project +-- - 1 +-- + 2 +-- 2.0 2024-27-10 +-- - "chmod +x " .. MainPath +-- + 'chmod +x "' .. MainPath .. '"' +-- # Ordered Variables +-- - 2 +-- + 1 +-- + Apple Trial +-- 2.3 2024-27-10 +-- # Linux execution correction +-- + Credits +-- # 2.1 and 2.2 just trials due issues with Linux and Apple +-- 2.31 2024-28-10 +-- # Binaries directly form the source +-- 2.32 2024-28-10 +-- - yt-dlp +-- + yt-dlp_linux +-- 2.4 2024-29-10 +-- # Adjusted header style for production +-- 2.5 2024-11-04 +-- - Various +-- + VideoPath = 'Video' +-- 2.6 2024-11-05 +-- + check for temrination of temporary file upfrotn import the video +-- 2.7 2024-11-05 +-- - Check Routine +-- 2.8 2024-11-06 +-- + Detects Nework Interruptions during download +-- + Removes leftovers +-- + URLs as filename: forbidden +-- + Limitation to only alphanumerical characters +-- 2.9 2024-11-06 +-- + Check IfFileExists: Overwrite, Newname, Exit +-- @about: +-- # Import VIDEOs directly in TimeLine from YouTUBE, VIMEO, PATREONS and thousand other ones. +-- +-- Key Features: +-- +-- - 4 click operation: Start the script, enter the URL, give a title, click on OK +-- - Import any Video in TimeLine by giving just the URL +-- - Videos are saved into the project folder under the dedicated /Videos/ folder +-- - Videos are imported into a new track, having the given name, and at the cursor position +-- - Auto-update of the binaries "yt-dlp" each time the script is invoked, to ensure top quality at each use +-- - Compatible with about thousand platforms included: +-- - YouTUBE +-- - Vimeo +-- - Patreons +-- and several other ones ... +-- +-- [Full list here](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md) +-- +-- Credits: +-- Stefano marcantoni and Ben Talagan - to have helped for MAC implementation +-- Paolo Saggese PMS67 - to have helped for Linux implementation +-- cfillion - for his support during general debug -- @provides -- [win64] yt-dlp/yt-dlp.exe https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -- [linux] yt-dlp/yt-dlp_linux https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp @@ -77,28 +99,6 @@ -- [linux] . -- [darwin64] . -- [darwin-arm64] . --- @donation Pay me a drink https://bit.ly/Pay_Me_a_Drink --- @about --- # Import VIDEOs directly in TimeLine from YouTUBE, VIMEO, PATREONS and thousand other ones. --- --- Key Features: --- --- - 4 click operation: Start the script, enter the URL, give a title, click on OK --- - Import any Video in TimeLine by giving just the URL --- - Videos are saved into the project folder under the dedicated /Videos/ folder --- - Videos are imported into a new track, having the given name, and at the cursor position --- - Auto-update of the binaries "yt-dlp" each time the script is invoked, to ensure top quality at each use --- - Compatible with about thousand platforms included: --- - YouTUBE --- - Vimeo --- - Patreons --- and several other ones ... --- --- [Full list here](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md) --- --- #Credits: --- Stefano marcantoni and Talagan - to have helped for MAC implementation --- Paolo Saggese - to have helped for Linux implementation reaper.ClearConsole() @@ -280,8 +280,6 @@ local CallPath = ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. V Destination = Destination:gsub('\\','/') ---cd ~/Library/"Application Support"/REAPER/Scripts/Tormy\ Van\ Cool\ ReaPack\ Scripts/Various/yt-dlp/ && ./yt-dlp_macos - --------------------------------------------- -- UPDATE AND IMPORT VIDEO --------------------------------------------- @@ -320,35 +318,24 @@ local CallPath = ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. V -- NETWORK DISRUPTION --------------------------------------------- - -- GET RESIDUAL FILES - local ResFiles - if OpSys == 2 or OpSys == 3 then - ResFiles = "ls -a " .. ProjDir .."/Videos/*.mp4.part" - ResDel = 'rm "' .. ProjDir .. '\\Videos\\*.mp4.part"' - elseif OpSys == 1 then - ResFiles = 'dir /b "' .. ProjDir .. '\\Videos\\*.mp4.part"' - ResDel = 'del "' .. ProjDir .. '\\Videos\\*.mp4.part"' - end - - local handle = io.popen(ResFiles) - - if handle == nil then - return - end - local stdout = handle:read("*all") - success = handle:close() - - -- REMOVE RESIDUAL FILES - if success then - if debug == true then reaper.ShowConsoleMsg('output is: \n' .. tostring(stdout) .. "\n") end - local retQuery = reaper.MB("Due a Network Error, the video was not properly downloaded.\nBY CLICKING OK THESE LEFTOVERS WILL BE REMOVED\n\nLeftovers:\n\n" .. tostring(stdout), "NETWORK ERROR", 0) - if retQuery == 1 then - handle = io.popen(ResDel) - success = handle:close() - end + -- GET RESIDUAL FILES AND REMOVE THEM + local ResFiles ="" + a=0 + test = "" + repeat + if test:find(".mp4.part") then + returned = test + end + test = reaper.EnumerateFiles( ProjDir .. "/Videos", a) + a = a + 1 + until(test == nil) + if returned ~= nil then + local retQuery = reaper.MB("Due a Network Error, the video was not properly downloaded.\nBY CLICKING OK THESE LEFTOVERS WILL BE REMOVED\n\nLeftovers:\n\n" .. returned, "NETWORK ERROR", 0) + if retQuery == 1 then + os.remove(ProjDir .. "/Videos/" .. returned) + end else - if debug == true then reaper.ShowConsoleMsg('error when executing command' .. ResFiles) end - reaper.InsertMedia(Destination, 1) + reaper.InsertMedia(Destination, 1) end if debug == true then From 5311ce49f534e8d420da0f4d2a912af35cf3276f Mon Sep 17 00:00:00 2001 From: Tormy Van Cool <32305535+tormyvancool@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:34:05 +0100 Subject: [PATCH 4/7] Update tormyvancool_YOUTUBE Downloader.lua As discussed here https://github.com/ReaTeam/ReaScripts/pull/1457#discussion_r1834571785 --- Video/tormyvancool_YOUTUBE Downloader.lua | 26 ++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Video/tormyvancool_YOUTUBE Downloader.lua b/Video/tormyvancool_YOUTUBE Downloader.lua index 922b51107..c681f5b51 100644 --- a/Video/tormyvancool_YOUTUBE Downloader.lua +++ b/Video/tormyvancool_YOUTUBE Downloader.lua @@ -68,6 +68,7 @@ -- + Limitation to only alphanumerical characters -- 2.9 2024-11-06 -- + Check IfFileExists: Overwrite, Newname, Exit +-- + check if the subdir for yt-dlp exists. if not it warns the user and stops the script -- @about: -- # Import VIDEOs directly in TimeLine from YouTUBE, VIMEO, PATREONS and thousand other ones. -- @@ -85,11 +86,11 @@ -- and several other ones ... -- -- [Full list here](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md) --- --- Credits: +-- @Credits: -- Stefano marcantoni and Ben Talagan - to have helped for MAC implementation -- Paolo Saggese PMS67 - to have helped for Linux implementation -- cfillion - for his support during general debug +-- smandrap - for his key suggestoin to that helped to improve the reliability. Topic https://forum.cockos.com/showthread.php?t=96087 -- @provides -- [win64] yt-dlp/yt-dlp.exe https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -- [linux] yt-dlp/yt-dlp_linux https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp @@ -123,8 +124,27 @@ local pj_name_ = reaper.GetProjectName(0, "") local ProjDir = reaper.GetProjectPathEx(0) local ResourcePATH = reaper.GetResourcePath() local VideoPath = 'Video' -local CallPath = ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. VideoPath .. '/yt-dlp/' -- Get FullPath to yt-dlp +_,ScriptName = reaper.get_action_context() +local ScriptPath = ScriptName:match('^.+[\\/]') -- Script Path +local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp + -- CHECK IF YT-DLP FOLDER IS CREATED BY REAPACK AS EXPECTED + a=0 + CheckForDir = "" + repeat + if CheckForDir == "yt-dlp" then + returnedDir = CheckForDir + end + CheckForDir = reaper.EnumerateSubdirectories( ScriptPath, a) + a = a + 1 + until(CheckForDir == nil) + if returnedDir == nil then + local retQuery = reaper.MB("This script must be isntalled from a Reapack Repository.\n\nClick \"OK\", remove it and install it as it should!\n", "INSTALLATION ERROR", 0) + if retQuery == 1 then + goto done + end + end + --------------------------------------------- -- FUNCTIONS --------------------------------------------- From b550e01cd538e9abf947c51e1dd716ebdee1dbe7 Mon Sep 17 00:00:00 2001 From: Tormy Van Cool <32305535+tormyvancool@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:15:08 +0100 Subject: [PATCH 5/7] Update tormyvancool_YOUTUBE Downloader.lua Fixed the function getOS() --- Video/tormyvancool_YOUTUBE Downloader.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Video/tormyvancool_YOUTUBE Downloader.lua b/Video/tormyvancool_YOUTUBE Downloader.lua index c681f5b51..125f5c613 100644 --- a/Video/tormyvancool_YOUTUBE Downloader.lua +++ b/Video/tormyvancool_YOUTUBE Downloader.lua @@ -161,7 +161,7 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp local a = {} local MainPath = '' if OS == "Win32" or OS == "Win64" then - MainPath = '"' .. ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. VideoPath .. '/yt-dlp/' .. dlpWin .. '"' + MainPath = '"' ..CallPath .. dlpWin .. '"' Start = 'start /b /wait "UPDATE & DOWNLOAD" ' OpSys = 1 end @@ -172,17 +172,15 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp OpSys = 2 end if OS == "Other" then - -- MainPath = ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/Various/yt-dlp/' .. dlpLnx .. '"' - -- Start = '"' - -- os.execute('chmod +x "' .. MainPath .. '"') - MainPath = '"' .. ResourcePATH .. '/Scripts/Tormy Van Cool ReaPack Scripts/' .. VideoPath .. '/yt-dlp/' .. dlpLnx .. '"' + MainPath = '"' ..CallPath .. dlpLnx .. '"' Start = '' os.execute('chmod +x ' .. MainPath) OpSys = 3 end return MainPath end - + + -- GET FILE SIZE function get_file_size(filename) local file = io.open(filename, "rb") From 96e27c6f944668751359c02b7fff14166c3129d9 Mon Sep 17 00:00:00 2001 From: Tormy Van Cool <32305535+tormyvancool@users.noreply.github.com> Date: Sat, 9 Nov 2024 10:40:55 +0100 Subject: [PATCH 6/7] Update tormyvancool_YOUTUBE Downloader.lua Implemented the solution here, to detect the script's folder https://forums.cockos.com/showpost.php?p=2821129&postcount=11 --- Video/tormyvancool_YOUTUBE Downloader.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Video/tormyvancool_YOUTUBE Downloader.lua b/Video/tormyvancool_YOUTUBE Downloader.lua index 125f5c613..af52ec2f8 100644 --- a/Video/tormyvancool_YOUTUBE Downloader.lua +++ b/Video/tormyvancool_YOUTUBE Downloader.lua @@ -125,7 +125,7 @@ local ProjDir = reaper.GetProjectPathEx(0) local ResourcePATH = reaper.GetResourcePath() local VideoPath = 'Video' _,ScriptName = reaper.get_action_context() -local ScriptPath = ScriptName:match('^.+[\\/]') -- Script Path +local ScriptPath = ScriptName:match('^.+' .. package.config:sub(1, 1)) -- Script Path local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp -- CHECK IF YT-DLP FOLDER IS CREATED BY REAPACK AS EXPECTED @@ -148,7 +148,8 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp --------------------------------------------- -- FUNCTIONS --------------------------------------------- - + + -- SLEEP(SECONDS) function sleep(n) local t0 = clock() From f3c9e79d097bd86b0dc7875065c8bb25558eee3a Mon Sep 17 00:00:00 2001 From: Tormy Van Cool <32305535+tormyvancool@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:12:06 +0100 Subject: [PATCH 7/7] Update tormyvancool_YOUTUBE Downloader.lua Added a check: if the supposed downloaded file doesn't exists OR it is 0 bytes sized, the script informs the operator and just by clicking OG ends up. No empty track - or track with 0 bytes file - will be created in Reaper --- Video/tormyvancool_YOUTUBE Downloader.lua | 30 ++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Video/tormyvancool_YOUTUBE Downloader.lua b/Video/tormyvancool_YOUTUBE Downloader.lua index af52ec2f8..163f22e6d 100644 --- a/Video/tormyvancool_YOUTUBE Downloader.lua +++ b/Video/tormyvancool_YOUTUBE Downloader.lua @@ -67,8 +67,9 @@ -- + URLs as filename: forbidden -- + Limitation to only alphanumerical characters -- 2.9 2024-11-06 --- + Check IfFileExists: Overwrite, Newname, Exit --- + check if the subdir for yt-dlp exists. if not it warns the user and stops the script +-- + Checks IfFileExists: Overwrite, Newname, Exit +-- + Checks if the subdir for yt-dlp exists. if not it warns the user and stops the script +-- + If the video wasn't downloaded or the donloaded file is 0 bytes size, the script stops and doesn't generate any new track -- @about: -- # Import VIDEOs directly in TimeLine from YouTUBE, VIMEO, PATREONS and thousand other ones. -- @@ -139,7 +140,7 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp a = a + 1 until(CheckForDir == nil) if returnedDir == nil then - local retQuery = reaper.MB("This script must be isntalled from a Reapack Repository.\n\nClick \"OK\", remove it and install it as it should!\n", "INSTALLATION ERROR", 0) + local retQuery = reaper.MB('This script must be isntalled from a Reapack Repository.\n\nClick \"OK\", remove it and install it as it should!\n', 'INSTALLATION ERROR', 0) if retQuery == 1 then goto done end @@ -220,13 +221,13 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp -- CHECK WHETHER PROJECT IS SAVED if pj_name_ == "" then - reaper.MB("YOU MUST SAVE THE PROJECT FIRST! Then relaunch this script!",'WARNING',0) + reaper.MB('YOU MUST SAVE THE PROJECT FIRST! Then relaunch this script!','WARNING',0) return end -- GET URL repeat - retval, url=reaper.GetUserInputs("DOWNLOAD VIDEO", 1, "Paste URL,extrawidth=400", InputVariable) + retval, url=reaper.GetUserInputs('DOWNLOAD VIDEO: URL', 1, "Paste URL,extrawidth=400", InputVariable) if retval==false then return end if retval then t = {} @@ -248,7 +249,7 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp -- GET FILENAME ::getfilename:: repeat - retval_1, FileName=reaper.GetUserInputs("DOWNLOAD VIDEO", 1, "Insert FILE NAME,extrawidth=400", InputVariable) + retval_1, FileName=reaper.GetUserInputs('DOWNLOAD VIDEO:TITLE', 1, "Insert FILE NAME,extrawidth=400", InputVariable) FileName = GetRid(GetRid(GetRid(GetRid(GetRid(FileName, pipe), colon), quote), slash), backslash) -- No reserved characters can be written FileName = FileName:gsub("http", "") @@ -264,12 +265,12 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp -- NO EMPTY TITLE ADMITTED if t[1]== "" then - reaper.MB("VIDEO TITLE is MANDATORY","ERROR",0,0) + reaper.MB('VIDEO TITLE is MANDATORY','ERROR',0,0) end -- NO URLS AND NOT ALPHANUMERICAL CHARACTERS ADMITTED if t[1]:match("[^%w%s]") then - reaper.MB("ONLY ALPHANUMERIC CHARACTERS ADMITTED","ERROR",0,0) + reaper.MB('ONLY ALPHANUMERIC CHARACTERS ADMITTED','ERROR',0,0) t[1]="" end until( t[1] ~= "") @@ -314,7 +315,7 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp local checkfile = reaper.file_exists(Destination) local answer = nil if checkfile == true then - answer = reaper.MB("A file with the same filename exists\nWould you want to overwrite it?\n\nYES => Go on\nNO => Rewrite the filname\nCANCEL => Exit",'WARNING: FILENAME EXISTS',3) + answer = reaper.MB('A file with the same filename exists\nWould you want to overwrite it?\n\nYES => Go on\nNO => Rewrite the filname\nCANCEL => Exit','WARNING: FILENAME EXISTS',3) end if answer == 7 then goto getfilename @@ -349,12 +350,19 @@ local CallPath = ScriptPath .. 'yt-dlp/' -- Get FullPath to yt-dlp a = a + 1 until(test == nil) if returned ~= nil then - local retQuery = reaper.MB("Due a Network Error, the video was not properly downloaded.\nBY CLICKING OK THESE LEFTOVERS WILL BE REMOVED\n\nLeftovers:\n\n" .. returned, "NETWORK ERROR", 0) + local retQuery = reaper.MB('Due a Network Error, the video was not properly downloaded.\nBY CLICKING OK THESE LEFTOVERS WILL BE REMOVED\n\nLeftovers:\n\n' .. returned, 'NETWORK ERROR', 0) if retQuery == 1 then os.remove(ProjDir .. "/Videos/" .. returned) end else - reaper.InsertMedia(Destination, 1) + if not reaper.file_exists(Destination) or get_file_size(Destination) == 0 then + local retQuery = reaper.MB('Something went wrong during the download of this video.\nNo video were downloaded.\n\nBy clicking on \"OK\" the script will stop.', 'AN ERROR OCCURRED', 0) + if retQuery == 1 then + goto done + end + else + reaper.InsertMedia(Destination, 1) + end end if debug == true then