Il giorno Tue, 12 Mar 2024 12:38:03 +0100, brianks®
Post by brianks®Ho trovato questo BAT per automatizzare yt-dlp, ma secondo gli esperti
di BAT, si può migliorare? ad esempio audio e video non possono essere
riselezionati nella stessa sessione.
Mi ero fatto uno script .vbs ai tempi di YoutubeDownloader e poi l'ho adattato a
yt-dlp.exe
Per comodità e semplicità lo script deve essere nella stessa cartella di
"yt-dlp.exe" e scaricherà i vari files sempre nella stessa cartella.
Scrive anche un paio di files di controllo e di errore, e un file di .log nella
cartella %Temp%, tutte cose che sono servite per il debug e che a me non danno
noia ma che si possono eventualmente togliere.
Il vantaggio principale è che basta avere nella ClipBoard il link del video,
anche "sporco" e cliccare sul file .VBS.
Io per comodità ho messo un collegamento al.vbs sul dektop. per cui sul browser
mi basta cliccare su "Copia Collegamento" e poi andare sul collegamento al .vbs.
Copiare il testo sotto la linea su un notepad e salvare come "Ytdl.vbs"
Attenzione agli a capo involontari, per sicurezza l'ho messo anche su DropBox
https://www.dropbox.com/scl/fi/qso2fo96ggszb1y7nfhmg/YtDl.vbs?rlkey=nxptfnf5ne4wv18bil0jxiv3g&dl=0
o https://shorturl.at/eqWX2
Enjoy!
___________________________________________
Const ForAppending = 8, ForReading = 1, ForWriting = 2, TemporaryFolder = 2, V =
""""
Set oShell = CreateObject("WScript.Shell")
Set Fso = CreateObject("Scripting.FileSystemObject")
Set sApi = CreateObject("sapi.spvoice")
'DestDir = oShell.SpecialFolders("Desktop")
CurDir = oShell.CurrentDirectory & "\"
Flog = Fso.GetSpecialFolder(TemporaryFolder)&"\"&
Fso.GetBaseName(WScript.ScriptName) &".log"
Stms = VbCrLf & Now & VbCrLf
YoutubeDL = CurDir & "yt-dlp.exe"
If Fso.FileExists(YoutubeDL) Then
CmdYT = VV(YoutubeDL)
Else
MsgBox YoutubeDL & VbCr & "UNFOUND" :Wscript.Quit
End If
'"D:\Apps\youtube-dl\youtube-dl.exe -U " per aggiornare
' https://www.facebook.com/FIPufficiale/videos/563118931611907
'youtube-dl --write-sub --sub-lang en --skip-download URL
'youtube-dl --write-auto-sub --skip-download URL
Set File = Fso.GetFile(YoutubeDL)
If DateDiff("d",File.DateLastModified,Now) > 60 Then '+ di 60 giorni
oShell.Run YoutubeDL & " --update " ,1 ,True
WScript.Sleep 3000
End If
Do: Lnk = Trim(GetClipboard)
If Left(Lnk,4) = "http" Then Exit Do
If MsgBox (Lnk & VbCr &" NON È UN LINK" & VbCr &"CONTINUARE ?",
VbQuestion or VbOkCancel Or VbDefaultButton2, WScript.ScriptFullName) = VbCancel
Then WScript.Quit
Loop 'per aggiornare la clipboard
If InStr(Lnk,"&") Then Lnk = Mid(Lnk, 1, InStr(Lnk,"&")-1) 'per i link
lunghi
'VIDEO
Cmdn = CmdYT &" "& Lnk
' oShell.Run Cmd ,1 ,False
'VIDEO AVI
' Cmdn = CmdYT &" "& Lnk &" --recode-video avi "
'VIDEO E SOTTOTITOLI SRT
' Cmdn = CmdYT &" --write-auto-sub --convert-subs=srt "& Lnk
'SOLO SOTTOTITOLI SRT
' Cmdn = CmdYT &" --write-auto-sub --convert-subs=srt --skip-download "& Lnk
'SOLO AUDIO MP3
' Cmdn = CmdYT &" --extract-audio --audio-format mp3 "
'https://web.whatsapp.com/c7e5568e-9526-4ac1-862b-9c44c823c8a1
' Cmd = "Cmd /v /c (>> " & LogF &" "& Cmdn & " & exit !errorlevel!)" 'con
file LOG
' Cmd = "Cmd /k " & Cmdn 'resta la finestra
' Cmd = "Cmd /v /k " & Cmdn 'resta la finestra
Cmd = "Cmd /v /c " & Cmdn 'termina
'*** alternative exe per leggere la console
' FilA= Fso.GetSpecialFolder(TemporaryFolder)&"\Ydl.txt"
FilA= CurDir &"Ydl.txt"
Set File_W = Fso.OpenTextFile(FilA, ForAppending, True)
File_W.WriteLine(VbCrLf & Now)
File_W.WriteLine(Cmdn) : File_W.Close
Set Exec = oShell.Exec(Cmd)
StrNm ="[Merger] Merging formats into "
Do While Not Exec.StdOut.AtEndOfStream
strT = Exec.StdOut.Readall
If Len(strT) Then
strText = strText & strT
Set File_W = Fso.OpenTextFile(FilA, ForAppending, True)
File_W.Write(strT) : File_W.Close
If InStr(strText,StrNm) Then
X1 = InStr(strT,StrNm)+ Len(StrNm)+1 : X2 = InStr(X1, strT, V)
On Error Resume Next
FilVid = Mid(strT, X1, X2-X1) : WriteLog VV(FilVid)
Exit Do
End If
End If
outErr = Exec.StdErr.ReadAll
If Len(outErr)>0 Then
FileE = CurDir &"Err.txt"
Set File_E = Fso.OpenTextFile(FileE, ForAppending, True)
File_E.WriteLine(VbCrLf & Now & " ERR: ")
File_E.WriteLine(outErr) : File_E.Close
Exit Do
End If
If InStr(strText,"100%") Then Exit Do
Loop
http://youtu.be/EKNmZQLbqVo
If Len(FilVid) Then
Do
If Fso.FileExists(CurDir & FilVid) Then
Sapi.Speak " FINITO"
oShell.Popup "FINITO"& VbCr & FilNam, 4,, VbInformation :
WScript.Quit
End If
WScript.Sleep 500 : K=K+1
If K > 60 Then
oShell.Popup CurDir & FilVid &" NOT FOUND", 10
WriteLog VV(CurDir & FilVid) & VbCrLf &" NOT FOUND"
: WScript.Quit
End If
Loop
Else
MsgBox "NO FILE VIDEO" : WScript.Quit
End If
Wscript.Quit
Function GetClipboard()
GetClipboard = CreateObject( "HTMLFile"
).parentWindow.clipboardData.getData( "Text" )
If IsNull(GetClipboard)Then GetClipboard = ""
End Function
Function VV(NamStr)
VV = V & NamStr & V
End Function
Sub WriteLog (Txt)
Set File_W = FSO.OpenTextFile (Flog, ForAppending, True)
File_W.Write Stms & Txt & VbCrLf : File_W.Close
Stms =""' VbCrLf
End Sub
______________________________________-
--
ciao
Stefano