for youtube

Post your working scripts, libraries and tools for AHK v1.1 and older
garry
Posts: 3790
Joined: 22 Dec 2013, 12:50

for youtube

Post by garry » 19 May 2019, 13:01

get video or audio

Hotkeys copy url in Firefox and Chrome ( or copy url with ctrl+c or use script from atnbueno for other browsers )
Finds out the URL of the current (active) browser tab for most of the modern browsers.
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702

F4= VIDEO needs youtube-dl.exe https://youtube-dl.org/latest/youtube-dl.exe
F5= AUDIO MP3 192k needs also ffmpeg.exe https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.zip

Code: Select all

/*
MODIFIED =20200607  ^l copies url in firefox and chrome
MODIFIED =20190521
F4= video          needs      youtube-dl.exe https://youtube-dl.org/latest/youtube-dl.exe
F5= audio MP3 192k needs also ffmpeg.exe     https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.zip
https://youtube-dl.org/
ffmpeg for AUDIO :
https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.zip
https://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.zip
https://ffmpeg.zeranoe.com/builds/win32/static/
http://ffmpeg.org/download.html#build-windows
*/
#warn
#persistent
#singleinstance,force
;#IfWinActive YouTube
setworkingdir,%a_scriptdir%
settitlematchmode,2
clipboard=
mp3x=0
youtubedl:=a_scriptdir . "\youtube-dl.exe"
ifexist,%youtubedl%
{
loop,%youtubedl%        
   SP1:=A_loopFileShortPath
;RunWait, %comspec% /k %sp1% -U                    ;- Update youtube-dl.exe
;------------------------------
;fhelp=%a_scriptdir%\%a_now%_youtube-dl_Help.txt
;runwait,%comspec% /k %sp1% --help >"%fhelp%"      ;- see help file
;url9=https://www.youtube.com/watch?v=aqz-KE-bpKQ  ;- for test big bucks bunny
;runwait,%comspec% /k %sp1% %url9% -F
;runwait,%comspec% /k %sp1% %url9% --get-format    ;- 315 webm best
;runwait,%comspec% /k %sp1% %url9% --format 315    ;- this 10* bigger then FHD fmt=22
;runwait,%comspec% /k %sp1% %url9% --youtube-skip-dash-manifest  ;- if no format defined makes fmt=22
;runWait,%comspec% /k %sp1% %url9% --verbose --youtube-skip-dash-manifest --write-auto-sub --sub-lang de -o "%fdmp4%\`%(title)s$`%(uploader)s$`%(id)s.`%(ext)s"
;--format FORMAT              Video format code
;--all-formats                Download all available video formats
}
else
  run,https://youtube-dl.org/latest/youtube-dl.exe
return
;--------------
esc::exitapp
;--------------
;------- VIDEO -------
$f4::
if (winactive("YouTube"))
{
mp3x=0
send,^l
sleep,500
send,^c
}
return
;----------------------
;----- AUDIO MP3 192k ---------
$f5::
if (winactive("YouTube"))
{
mp3x=1
send,^l
sleep,500
send,^c
}
return
;---------------------
OnClipboardChange:
{
id:=""
L:=""
If (A_EventInfo=1)
 {
if (winactive("YouTube"))
  {
 if (instr(clipboard, "https://www.youtube.com"))
    {
    Loop,parse,clipboard, `n, `r
       {
     x= %a_loopfield%
     if x=
     continue
        Loop, Parse,x,`/`=`&`?%a_space%`#`:  
          {
          id:= A_LoopField
          stringlen,L,id
          if (L=11)
            break
          }
       }
    }
  }
if (L=11)
  goto,download
else
  return
 }
}
return
;--------------
Download:
if (ID<>"")
{
clipboard=
url=https://www.youtube.com/watch?v=%id%
ifexist,%youtubedl%
  {
  if (mp3x=0)
  RunWait, %comspec% /k %sp1% %url%
  else
  RunWait, %comspec% /k %sp1% %url% -x --audio-format mp3 --audio-quality 192k  ;- needs ffmpeg.exe
  }
url=
id=
}
return
;==========================================
Last edited by garry on 07 Jun 2020, 13:57, edited 3 times in total.
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: for youtube

Post by carno » 20 May 2019, 01:31

Thanks for the update of your YouTube script series. Tested and works great! :D
Last edited by carno on 25 May 2019, 15:15, edited 1 time in total.
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: for youtube

Post by rommmcek » 21 May 2019, 14:25

Hi!

- I like triggering download via monitoring Clipboard. So should be possible to get action from e.g. Virtual Machine.
- In your script is a small bug. Global variable mp3x should be assigned in autoexec section, to avoid Waring when manually copying url.
- There is script to programmatically Get Url
- youtube-dl can download from variety of sites, not just YouTube
- while downloading, it's not possible to trigger new download or stack url to buffer to be downloaded subsequently.
- no (option) downloading subtitles

bye!
garry
Posts: 3790
Joined: 22 Dec 2013, 12:50

Re: for youtube

Post by garry » 21 May 2019, 15:02

thank you rommmcek , small corrections made :
-mp3x=0 ;- at begin , so with ctrl+c downloads video
-run,https://youtube-dl.org/latest/youtube-dl.exe ;- https:// was missing

it was just a short example to download MP4 or MP3
have you a more complexed example with youtube-dl ?
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: for youtube

Post by rommmcek » 21 May 2019, 15:58

Not much more, then described above. The code is a real mess so it's not to publish (and have no time to clean it up). If you're interested, I can send you a PM?
User avatar
adegard
Posts: 90
Joined: 24 Nov 2017, 05:58
Contact:

Re: for youtube

Post by adegard » 07 Jun 2020, 10:56

Great! than you
I just changed send,^l (instead of !s) for chrome
garry
Posts: 3790
Joined: 22 Dec 2013, 12:50

Re: for youtube

Post by garry » 07 Jun 2020, 14:01

@adegard , thanx, modified , ^l works with Firefox and Chrome
Post Reply

Return to “Scripts and Functions (v1)”