Youtube to MP3

Post your working scripts, libraries and tools for AHK v1.1 and older
scriptor2016
Posts: 849
Joined: 21 Dec 2015, 02:34

Re: Youtube to MP3

13 Nov 2017, 00:10

can this be modified to work with Google Chrome?
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: Youtube to MP3

13 Nov 2017, 11:48

scriptor2016 wrote:can this be modified to work with Google Chrome?
Unfortunately not, only IE support automation like this
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Youtube to MP3

15 Nov 2017, 23:04

Improved and easier to work with!
  • Now Supports MP3 and MP4!
Here's my version on YT2Download
Full Code

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

Cal

Re: Youtube to MP3

16 Nov 2017, 14:33

Delta Pythagorean - I copied that code into the script, it doesn't say what the hotkey is, and I can't figure it out (very new to coding). Thanks in advance
User avatar
Wickster
Posts: 21
Joined: 19 Apr 2014, 23:02

Re: Youtube to MP3

16 Nov 2017, 14:49

edit: thanks to burque505 i just realized how much of a douche i sounded like. please forgives me delta. just didnt want to take away from HIACs hard work. :P
Last edited by Wickster on 16 Nov 2017, 15:32, edited 2 times in total.
burque505
Posts: 1732
Joined: 22 Jan 2017, 19:37

Re: Youtube to MP3

16 Nov 2017, 15:24

HIAC and Delta Pythagorean, thanks to both of you.

DP, that's a nice GUI. Took a second to realize the button was to paste the clipboard :)
Nice of you to not only give credit to HIAC in the GUI (not just the code!) but to also link HIAC's OP. Don't see that very often.
Regards,
burque505

p.s. DP, just tried to download an MP4, but only the MP3 downloaded. I'm sure the reason is that I first downloaded the MP3, then chose the same URL and tried to download the MP4 with the same name. It worked fine when I changed the name to something different than what I'd used for the MP3.
User avatar
mayalison
Posts: 4
Joined: 01 Jul 2021, 15:45

Re: Youtube to MP3

01 Jul 2021, 15:46

Thank you for your good recommendations. I found what I was looking for.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Youtube to MP3

04 Jul 2021, 08:26

I fixed the DOM path and added a wait so it works with the updated site

Code: Select all

#NoEnv
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%

pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := false


Gui, +AlwaysOnTop
Gui, Show, x200 y750 w465 h153, Youtube downloader by kovacevica00
Gui, Color, White
Gui, Font, s15, Courier New
Gui, Add, Text, x21 y16 w422 h27 +0x200, Please enter youtube song URL below:
Gui, Add, StatusBar
Gui, Font
Gui, Add, Edit, x11 y73 w442 h21 vURL,
Gui, Add, Button, Default x178 y107 w109 h22, OK
Gui, Add, Progress, vDProgress x11 y96 w442 h9 -Smooth
GuiControl, Focus, URL
Return

GuiClose:
	pwb.quit()
    ExitApp
return


F9:: ; To automatically select and copy URL from browser
clipboard =
Send, ^l
Sleep, 300
Send, ^c
If Clipboard = 
{
	Send, ^l
	Sleep, 500
	Send, ^c
}
ControlClick, OK, Youtube downloader by kovacevica00
Return

OnClipboardChange:
if RegExMatch(Clipboard, "^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/watch\?v=([^&]+)")
{
	GuiControl,, URL, %Clipboard%
	GuiControl, Focus, OK
}
Return

ButtonOK:
Gui, Submit, NoHide
if RegExMatch(URL, "^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/watch\?v=([^&]+)")
{
	If IsObject(pwb)
	{
		GuiControl, Disable, URL
		GuiControl, Disable, OK
		SB_SetText("preparing download..")
		GuiControl, , DProgress, 10
		pwb.Navigate("https://ytmp3.cc/")
		while pwb.busy or pwb.ReadyState !=4
			sleep, 100
		pwb.document.getElementById("input").value := URL
		pwb.document.getElementById("submit").click()
		while ((Inprogress := pwb.document.getElementById("file").href) = "https://ytmp3.cc/")
		{
			if ((CurrentStatus := pwb.document.getElementById("progress").innertext) = "checking video  ")
			{
				SB_SetText(CurrentStatus)
				GuiControl, , DProgress, 20
			}
			else if ((CurrentStatus := pwb.document.getElementById("progress").innertext) = "loading video  ")
			{
				SB_SetText(CurrentStatus)
				GuiControl, , DProgress, 30
			}
			else if ((CurrentStatus := pwb.document.getElementById("progress").innertext) = "converting video  ")
			{
				SB_SetText(CurrentStatus)
				GuiControl, , DProgress, 40
			}
			sleep, 100
		}
		GuiControl, , DProgress, 50
		DirectUrl :=
		while !DirectUrl {
		try DirectUrl := pwb.document.querySelectorAll("#buttons > a")[0].getAttribute("href") ; fixed 
		SB_SetText("Converting, please wait...") ; added
		sleep, 500
		}
		SongName := pwb.document.getElementById("title").innertext
		SongName := strReplace(SongName,"|") ; Removes "|" as it is unsupported character
		SongName := strReplace(SongName,":") ; Removes ":" as it is unsupported character
		GuiControl, , DProgress, 70
		SB_SetText("downloading, please wait...")
		IfNotExist, %A_MyDocuments%\Music
			FileCreateDir, %A_MyDocuments%\Music
		URLDownloadToFile, %DirectUrl%,%A_MyDocuments%\Music\%SongName%.mp3
		SB_SetText("download successful!")
		GuiControl, , DProgress, 100
		GuiControl,, URL
		GuiControl, Enable, URL
		GuiControl, Enable, OK
		GuiControl, Focus, URL
	}
	else
	{
		MsgBox,0, Error. Internet explorer failed to initialize. Relaunching.
		Reload
	}
	
}
else
{
	SB_SetText("Invalid URL")
	GuiControl,,URL
	GuiControl, Focus, URL
}
Sleep, 1500
GuiControl, , DProgress, 0
SB_SetText("")
return

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 85 guests