Passing Iframe through HTML (video)

Get help with using AutoHotkey and its commands and hotkeys
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Passing Iframe through HTML (video)

18 Sep 2020, 09:17

As of now, I can I can pass the iframe through, and it will place the iframes every time I hit the add button. The problem is, is am I on a right path? Or am I doing something wrong with passing the video into the iframe? I figured if it's passing the iframe into the html through the html divs, then why won't the video play?

Code: Select all

Gui Add, ActiveX, vWB w500 h500, Shell.Explorer
WB.Navigate("about:blank") 	; We first navigate to an empty page
								; Now we need to write the html code

html =
		(
		<!DOCTYPE html>
		<html lang="en">
		<head>
			<meta http-equiv="X-UA-Compatible" content="IE=edge" charset="utf-8">
			<title>title</title>
				<style>
				#videourl {
					display: inline;
					flex-flow: column nowrap;
					position: fixed;
		
					padding: 5px 5px 5px 5px;
				}
				div.row {
					display: inline;
					flex-flow: row nowrap;
					height: 100`%;
				}
				div.url {
					margin: 14px 14px;
					width: 100px;
					height: 150px;
				</style>
		</head>
			<body>
				<ul id="title">
					<div></div>
				</ul>
				<ul id="videourl">
					<div class="row"></div>
				</ul>		
			</body>
		</html>
		)



GUI, New
GUI Add, ActiveX, vAXWrapperObject xm y30 w550 h775, about:<!DOCTYPE html><meta http-equiv="X-UA-Compatible" content="IE=edge" charset="utf-8">
doc := AXWrapperObject.document
doc.write(html)
urls := doc.getElementsByClassName("url")
		;<><><><><><><><><><><><><><><><><><><>

GUI, +Resize
GUI, Margin, 5, 5

GUI Add, Button, x5 y5 w100 gpushURL, Add Video 

Gui, Add, Button, x400 y5 w10, Delete 
		;Gui, Add, Button, x450 y5 w10, Save  

Gui, add, button,gSubmit x500 y5,&Set
Gui, Add, Edit, x150 y5 w250 vSubmit, Enter Title

GUI, Show
rowMax := 5, columnMax := 5
rowCurrent := 0, columnCurrent := 0
cells := rowMax * columnMax
return

GUISize: ; https://www.autohotkey.com/docs/commands/Gui.htm#GuiSize
GuiControl, Move, MyButton, % "w" A_GuiWidth - 10
GuiControl, Move, AXWrapperObject, % "w" A_GuiWidth - 10 "h" A_GuiHeight - 40 ; resize the control so that it fits the new GUI dimensions
return

pushURL:
if not (urls.length < cells)
	return

playlist := "https://www.youtube.com/embed/QM8jQHE5AAk"
url  := "<iframe src=""" . playlist . """></iframe>"

	;url  := "<iframe src=""" . playlist . """></iframe>"
	;url  := "<iframe src=""http://www.youtube.com/embed/" . video . """></iframe>"
	;url  := "<iframe src=""" . playlist . "" . video . """></iframe>"
	;url  := "<iframe src="" . http://www.youtube.com/embed/QM8jQHE5AAk . ""></iframe>"


if (columnCurrent < columnMax) {
			Gosub, subLabel
			return
		} else {
			columnCurrent := 0
			doc.getElementById("videourl").innerHTML .= "<div class='row'></div>" ; create a new row
			rowCurrent++
		}
		subLabel:
		doc.getElementsByClassName("row")[rowCurrent].innerHTML .= "<div class='url'>" . url . "" ; create a new column 
		columnCurrent++
		return
		set:
		Submit:
Last edited by BoBo on 20 Sep 2020, 00:20, edited 1 time in total.
Reason: Added '(video)' to the title to make it more specific.
teadrinker
Posts: 1862
Joined: 29 Mar 2015, 09:41
Contact:

Re: Passing Iframe through HTML (video)

20 Sep 2020, 04:21

A simple example:

Code: Select all

html =
(
<!DOCTYPE html>
<html>
  <body>
   <iframe width="400" height="300"
   src="https://www.youtube.com/embed/M7lc1UVf-VE">
   </iframe>
  </body>
</html>
)
FixIE()
Gui, Add, ActiveX, w450 h350 vWB, about:<meta http-equiv="X-UA-Compatible" content="IE=edge">
WB.Navigate("about:blank")
while WB.busy || WB.ReadyState != 4
   Sleep, 10
WB.document.write(html)
Gui, Show
Return

GuiClose:
   ExitApp
   
FixIE() {
   static regKey := "HKCU\Software\Microsoft\Internet Explorer\"
                  . "MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
   SplitPath, % A_IsCompiled ? A_ScriptFullPath : A_AhkPath, exeName
   RegRead, value, % regKey, % exeName
   if (value != 11000)
      RegWrite, REG_DWORD, % regKey, % exeName, 11000
   Return !ErrorLevel
}
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

20 Sep 2020, 23:23

Thank you! Yeah, that plays the source url that is encoded within the script. It doesn't create the Iframe and then put the source in there from a button. My example has the iframe being inserted into the GUI with increments, but the source won't pass through into the html for some reason.

1. Enter Youtube URL

Press Enter... should place an iframe with the url in it and be visible. As stated, the Iframe is doing this, just can't pass the url for whatever reason. Again, thank :)
teadrinker
Posts: 1862
Joined: 29 Mar 2015, 09:41
Contact:

Re: Passing Iframe through HTML (video)

21 Sep 2020, 01:26

An example how to add frames:

Code: Select all

html =
(
<!DOCTYPE html>
<html>
   <body>
      <div></div>
   </body>
</html>
)
FixIE()
Gui, New, +LastFound
Gui, Add, Button, x10 w100 gAddFrame, Add Frame
Gui, Add, Edit, x+5 yp+1 w500
SendMessage, EM_SETCUEBANNER := 0x1501, 0, "Enter YouTube video URL or ID here", Edit1
Gui, Add, ActiveX, x10 w850 h650 vWB, about:<meta http-equiv="X-UA-Compatible" content="IE=edge">
WB.Navigate("about:blank")
while WB.busy || WB.ReadyState != 4
   Sleep, 10
Doc := WB.document
Doc.write(html)
Gui, Show
Return

AddFrame() {
   global Doc
   GuiControlGet, YouTubeUrl,, Edit1
   GuiControl,, Edit1
   if !YouTubeUrl {
      MsgBox, Enter YouTube video URL or ID
      Return
   }
   RegExMatch(YouTubeUrl, "i)(v=|/v/|embed/|youtu\.be/)\K[-\w]+|^[-\w]+$", youtubeID)
   if !youtubeID {
      MsgBox, Can't recognize YouTube ID
      Return
   }
   frame := Doc.createElement("iframe")
   frame.width := 200, frame.height := 150
   frame.src := "https://www.youtube.com/embed/" . youtubeID
   Doc.querySelector("div").appendChild(frame)
}

GuiClose:
   ExitApp
   
FixIE() {
   static regKey := "HKCU\Software\Microsoft\Internet Explorer\"
                  . "MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
   SplitPath, % A_IsCompiled ? A_ScriptFullPath : A_AhkPath, exeName
   RegRead, value, % regKey, % exeName
   if (value != 11000)
      RegWrite, REG_DWORD, % regKey, % exeName, 11000
   Return !ErrorLevel
}
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 03:12

@teadrinker

Awesome, Wasn't sure if it could be done tbh :oops: ...

Now I know how to save the song information in a text file or ini file... do I have to save the Iframe in there as well? I don't work with HTML much now a days, so at a loss for that. Thank you immensely.
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 03:52

Actually this isn't a list box... I'll have to research how to save it YAY :dance: LOL... Fun Fun
teadrinker
Posts: 1862
Joined: 29 Mar 2015, 09:41
Contact:

Re: Passing Iframe through HTML (video)

21 Sep 2020, 03:55

I think you need to save video IDs only.
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 04:33

@teadrinker

Yeah, I'm trying to get that down. I can save the ID, but it just clears when I add the next one.. working on looping it ... At least I'm trying to. I'm used to Listviews on saving. This is different for me for some reason.
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 04:36

So I'm saving the file now YAY... Now to try and get it to recall the file... I'm getting there :) Thank you for the help.

Code: Select all

	Title =  %youtubeID%
	FileAppend, `n %Title%, Youtube.txt
	MsgBox, File Saved
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 04:42

@teadrinker

I'm thinking that I will have to save the structure of the iframe into the text? Or maybe the div? This way it knows to place the video in a div? Just pondering while I work on it. Thanks
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 04:55

@teadrinker

Okay, I've added this at the beginning on load:

Code: Select all

Loop, read, Youtube.txt
{
	Clipboard = %A_LoopReadLine%
		RegExMatch(YouTubeUrl, "i)(v=|/v/|embed/|youtu\.be/)\K[-\w]+|^[-\w]+$", Clipboard)
	frame := Doc.createElement("iframe")
	frame.width := 200, frame.height := 150
	frame.src := "https://www.youtube.com/embed/" . %Clipboard%
	Doc.querySelector("div").appendChild(frame)
}
It's not recalling the ID's even though msgbox gives the ID's?
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 05:13

Okay, I think I have it figured out. We'll see... if I have any questions I'll ask. Thank you both so much... blessings.
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 06:19

Okay... Now the question is, is how to make the gui faster on load? Are there any techniques? I can't imaging it trying to load a couple hundred and not taking awhile. Any suggestions?

I have included at the top:

Code: Select all

;OPTIMIZATIONS START
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
;OPTIMIZATIONS END
Also, since there are really no windows to use wingettitle, is there another way to get the title from each loop entry?
teadrinker
Posts: 1862
Joined: 29 Mar 2015, 09:41
Contact:

Re: Passing Iframe through HTML (video)

21 Sep 2020, 09:45

Epialis wrote: how to make the gui faster on load?
It depends on your code.
Epialis wrote: is there another way to get the title from each loop entry?
What is the loop you are talking about? I can't read your thoughts. :)
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 11:56

teadrinker wrote:
21 Sep 2020, 09:45
Epialis wrote: how to make the gui faster on load?
It depends on your code.
Epialis wrote: is there another way to get the title from each loop entry?
What is the loop you are talking about? I can't read your thoughts. :)
Here is the loop that gets the ID's from the text.

Code: Select all

Loop, read, Youtube.txt
{	
	
	YouTubeUrl = %A_LoopReadLine%
	RegExMatch(YouTubeUrl, "i)(v=|/v/|embed/|youtu\.be/)\K[-\w]+|^[-\w]+$", YouTubeUrl)
	frame := Doc.createElement("iframe")
	frame.width := 204, frame.height := 125
	frame.src := "https://www.youtube.com/embed/" . YouTubeUrl
	Doc.querySelector("div").appendChild(frame)

}
teadrinker
Posts: 1862
Joined: 29 Mar 2015, 09:41
Contact:

Re: Passing Iframe through HTML (video)

21 Sep 2020, 12:07

How would you like to use it and why? What do you want to achieve?
Epialis wrote: is there another way to get the title from each loop entry?
What do you mean by "the title"?
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 12:18

teadrinker wrote:
21 Sep 2020, 12:07
How would you like to use it and why? What do you want to achieve?
Epialis wrote: is there another way to get the title from each loop entry?
What do you mean by "the title"?
The title to each one of the videos? Not sure if that's possible, since it doesn't open in chrome or any VLC player or anything.
teadrinker
Posts: 1862
Joined: 29 Mar 2015, 09:41
Contact:

Re: Passing Iframe through HTML (video)

21 Sep 2020, 12:55

Try this:

Code: Select all

youTubeID := "VJExqsrZzeA"
youTubeUrl := "https://www.youtube.com/embed/" . youTubeID
html := GetHtml(youTubeUrl)
pattern = i)\\"text\\":\\"(.+?)\\"
RegExMatch(html, pattern, title)
youTubeTitle := StrReplace(title1, "\")

MsgBox, % youTubeTitle

GetHtml(url) {
   whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   whr.Open("GET", url, false)
   whr.Send()
   status := whr.status
   if (status != 200)
      throw "html download error, status: " . status
   Return html := whr.ResponseText
}
Not sure if this is always correct.
Epialis
Posts: 366
Joined: 02 Aug 2020, 22:44

Re: Passing Iframe through HTML (video)

21 Sep 2020, 13:11

@teadrinker

Yes, that worked. Now I need to add to the textfile and find a way to put under each video. Thank you :bravo: :bravo: :dance: :dance: :bravo: :bravo:

Return to “Ask For Help”

Who is online

Users browsing this forum: Redbird, swagfag and 34 guests