Opening CMD and pasting link

Get help with using AutoHotkey and its commands and hotkeys
Jeahween3
Posts: 3
Joined: 16 May 2019, 19:06

Opening CMD and pasting link

16 May 2019, 19:30

My ideal scenario is to copy a youtube link and hit my hotkey to run the script. The script would open up youtube-dl in CMD and paste that copied link. It would run youtube-dl and the video would be downloaded.

Currently what I have is:

Code: Select all

^t::
   #s::run, %comspec% , c:\Users\jeah\Desktop\Youtube-DL\

Return
This only opens up CMD for youtube-dl. To complete the results I'm looking for I have to manually type "youtube-dl" and paste the youtube link. I'd like to minimize the manually entries.
tmplinshi
Posts: 1410
Joined: 01 Oct 2013, 14:57

Re: Opening CMD and pasting link

16 May 2019, 23:15

Code: Select all

^t::
#s::
run, %comspec% /k youtube-dl https://www.youtube.com/watch?v=IvUU8joBb1Q, c:\Users\jeah\Desktop\Youtube-DL\
Return
garry
Posts: 1834
Joined: 22 Dec 2013, 12:50

Re: Opening CMD and pasting link

17 May 2019, 05:27

EDIT : removed wrong parameter
added comments / if (winactive("YouTube")) /
if not work , update youtube-dl.exe , update :
RunWait, %comspec% /k youtube-dl.exe -U

youtube-dl.org/latest/youtube-dl.exe

also an example , copy youtube url , download shoul'd start

Code: Select all

;- youtube-dl.org/latest/youtube-dl.exe
#warn
#persistent
#singleinstance,force
setworkingdir,%a_scriptdir%
settitlematchmode,2
clipboard=
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
;--format FORMAT              Video format code
;--all-formats                Download all available video formats
}
return
;--------------
esc::exitapp
;--------------
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%
  RunWait, %comspec% /k %sp1% %url%
url=
id=
}
return
;==========================================
Last edited by garry on 18 May 2019, 02:57, edited 3 times in total.
Jeahween3
Posts: 3
Joined: 16 May 2019, 19:06

Re: Opening CMD and pasting link

17 May 2019, 13:38

garry wrote:
17 May 2019, 05:27
also an example , copy youtube url , download shoul'd start
It's not working for me. One thing I tried was to point to the directory - youtubedl:=a_scriptdir . "c:\Users\jeah\Desktop\Youtube-DL\youtube-dl.exe"

The full code looks like this.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^d::
#persistent
clipboard=
youtubedl:=a_scriptdir . "c:\Users\sbuck\Desktop\Youtube-DL\youtube-dl.exe"
ifexist,%youtubedl%
{
loop,%youtubedl%        
   SP1:=A_loopFileShortPath
;RunWait, %comspec% /k %sp1% -U              ;- Update youtube-dl.exe
}
return
esc::exitapp

OnClipboardChange:
{
If (A_EventInfo=1)
 {
 if (instr(clipboard, "https www.youtube.com "))  Broken Link for safety
   {
   Loop,parse,clipboard, `n, `r
     {
     x= %a_loopfield%
     if x=
     continue
        Loop, Parse,x,`/`=`&`?%a_space%`#`:  
          {
          id=
          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%  Broken Link for safety
ifexist,%youtubedl%
RunWait, %comspec% /k %sp1% -best %url%
url=
id=
}
return
garry
Posts: 1834
Joined: 22 Dec 2013, 12:50

Re: Opening CMD and pasting link

18 May 2019, 01:23

sorry , there was a wrong parameter in the script ( -best) , I removed / changed script above
copy youtube url , download shoul'd start
Jeahween3
Posts: 3
Joined: 16 May 2019, 19:06

Re: Opening CMD and pasting link

18 May 2019, 14:35

I made sure my youtubedl was updated, but it's still not working. Here's the code I have:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^d::
;- youtube-dl.org/latest/youtube-dl.exe
#warn
#persistent
#singleinstance,force
setworkingdir,%a_scriptdir%
settitlematchmode,2
clipboard=
youtubedl:=a_scriptdir . "c:\Users\jeah\Desktop\Youtube-DL\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  Broken Link for safety  ;- 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
;--format FORMAT              Video format code
;--all-formats                Download all available video formats
}
return
;--------------
esc::exitapp
;--------------
OnClipboardChange:
{
id:=""
L:=""
If (A_EventInfo=1)
 {
if (winactive("YouTube"))
  {
 if (instr(clipboard, "https www.youtube.com "))  Broken Link for safety
    {
    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%  Broken Link for safety
ifexist,%youtubedl%
  RunWait, %comspec% /k %sp1% %url%
url=
id=
}
return
;==========================================

Edit: I found another code that solved my problem. Thanks for the help!

Code: Select all

Try
    Run, youtube-dl, , Min
Catch
{
    URLDownloadToFile, https yt-dl.org /latest/youtube-dl.exe,  Broken Link for safety youtube-dl.exe
    IfNotExist, youtube-dl.exe
        ExitApp, 1
}
#Persistent
Return

OnClipboardChange:
    IfNotInString, Clipboard, https www.youtube.com /watch?v=  Broken Link for safety
        IfNotInString, Clipboard, https youtu.be /  Broken Link for safety
            Return
    Run, youtube-dl %Clipboard%, , Min
Return
garry
Posts: 1834
Joined: 22 Dec 2013, 12:50

Re: Opening CMD and pasting link

19 May 2019, 05:17

this is wrong , you'll have to remove > 'a_scriptdir . '
youtubedl:=a_scriptdir . "c:\Users\jeah\Desktop\Youtube-DL\youtube-dl.exe"
correct :
youtubedl:="c:\Users\jeah\Desktop\Youtube-DL\youtube-dl.exe"
check with msgbox , what happens :
msgbox,%youtubedl%
Last edited by garry on 20 May 2019, 02:04, edited 1 time in total.
garry
Posts: 1834
Joined: 22 Dec 2013, 12:50

Re: Opening CMD and pasting link

20 May 2019, 02:04

--- added to scripts&functions ----------------------
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=64683

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], flyingDman, Google [Bot], Odius, ubercoo, vsub, Xtra and 150 guests