@ Guest... here is the script with the RegExReplace in the 'BuildHTML' subroutine:
#NoEnv
SetWorkingDir %A_ScriptDir%
#SingleInstance Ignore
; Aaron's YouTube Player Creator (16:9 default screen)
EnterWidth:
InputBox, w, YouTube Video Player Creator, Please enter desired width of player`n(height will be calculated automatically)`nFor example '1024' will result in 1024x768 video size.,, 350, 200
If ErrorLevel = 1
ExitApp
If w is not number ; If User enters anything but numbers
{
MsgBox, You entered an invalid number.`nPlease try again
GoSub, EnterWidth
Return
}
If w >1920 ; If User enters a number higher than 1920
{
MsgBox, You entered an invalid number.`nPlease try again
GoSub, EnterWidth
Return
}
If w <400 ; If User enters a number lower than 400
{
MsgBox, You entered an invalid number.`nPlease try again
GoSub, EnterWidth
Return
}
h := w*9/16 ; Height equals width times 9/16 (for 16:9 screen ratio)
htmlwidth := w+4 ; Creates proper dimensions for the html container (the 4 extra pixels are because the HTML container is offset 2px every side to avoid a border)
htmlheight := h+4
InputBoxShareURL:
InputBox, url, YouTube Video Player Creator, Copy/paste the YouTube Video's "Share" code here:,, 350, 200 ; URL for YouTube video, from the "Share" button at YouTube
If ErrorLevel = 1
ExitApp
IfNotInString, url, http://youtu.be/
{
MsgBox,4,, The "Share URL" you entered does not seem to`nmatch the format which YouTube offers.`nAre you sure you want to try this URL?
IfMsgBox Yes
{
GoSub BuildHTML
}
IfMsgBox No
{
GoSub InputBoxShareURL
}
}
StringReplace, url, url, http://youtu.be/, http://www.youtube.com/v/, All ; Changes out "Share" URL with proper embed URL
BuildHTML:
InputBox, PlayerName, YouTube Video Player Creator, Please enter the name you wish to appear on the player:,, 450, 200
If ErrorLevel = 1
ExitApp
WeirdCharacters = [\\/:*?"<>|]
Filename=
( LTrim %
test!@#$%^&*()_+-={}|[]\:";'<>?,./
)
Filename:=RegExReplace(Filename, WeirdCharacters)
FileAppend, %Filename%, %A_ScriptDir%\%FileName%.txt
url = %url%&version=3&border=0&controls=1&modestbranding=1&iv_load_policy=3&showsearch=0&autoplay=0&autohide=1&showinfo=1&rel=0 ; Adds YouTube tags after URL
ObjDetails = <object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" width="%w%" height="%h%" bufferingtime="5" scale="aspect">
RemainingParamNames =<param name="width" value="%w%"><param name="height" value="%h%"><param name="bufferingtime" value="5"><param name="enableContextMenu" value="0"><param name="ShowDisplay" value="0"><param name="scale" value="aspect"><param name="showControls" value="0">
HTMLbegin = <!DOCTYPE html><html><head><title>Television GUI</title><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><style type="text/css"> html { overflow: hidden; } body { background-color: #000000; margin: 0px 0px 0px 0px; } .fixed { position:fixed; } .over { position:fixed; z-order:2; } .under { z-order:-100; }</style></head><body> ; The beginning of the displayed HTML document, all the way to the opening quotation mark for URL variable
HTMLend = <param name="Filename" value="%url%">%RemainingParamNames%</object></body></html> ; The end of the displayed HTML document, starting from the closing quotation mark on URL variable
SelectNewPlayerLocation:
FileSelectFolder, SelectedSaveLocation, *%A_MyDocuments%, 3, Please select a location to save your new file: ; Asks User where the file should be saved
If ErrorLevel
{
MsgBox,4,, There has been an error.`nDo you want to try again?
IfMsgBox Yes
{
GoSub SelectNewPlayerLocation
Return
}
IfMsgBox No
{
MsgBox, Operation cancelled. Program will now exit.
ExitApp
}
}
IfExist, %SelectedSaveLocation%\%PlayerName%.ahk
{
MsgBox,4,, A file with the same name already exists in this location!`nDo you want to overwrite it?
IfMsgBox Yes
{
FileDelete, %SelectedSaveLocation%\%PlayerName%.ahk
}
IfMsgBox No
{
MsgBox, File will not be overwritten. Try a different title.
GoSub, BuildHTML
Return
}
}
FileAppend, ; Writes final and completed information into a new AHK script named by User
(
#NoEnv
SetWorkingDir %A_ScriptDir%
; Aaron's version of YouTube Player (16:9 default screen)
; ----------------------------------------------------------------------------------------->>
; puts it all together into the "code" variable
code = %HTMLbegin%<object %id% %ObjDetails% src="%url%">%HTMLend%
; -----------------------------------------------------------------------------------------<<
COM_AtlAxWinInit()
Gui, +LastFound
pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(hwnd:=WinExist()
,-2 ; left by 2 pixels to hide the border
,-2 ; top by 2 pixels to hide the border
,%htmlwidth% ; width of html container, calculated from width variable
,%htmlheight% ; height of html container, calculated from height variable
,"Shell.Explorer"))
Gui, Show, w%w% h%h%, %PlayerName% ; Shows main window and title
COM_Invoke(pwb, "Navigate", "about:blank")
COM_Invoke(pwb, "document.write", code)
Return
GuiClose:
ExitApp
), %SelectedSaveLocation%\%PlayerName%.ahk
MsgBox,4,, Player created successfully in:`n%SelectedSaveLocation%`nWould you like to open it?
IfMsgBox Yes
{
Run, %SelectedSaveLocation%\%PlayerName%.ahk
If Errorlevel
{
MsgBox, You may have to download and use Com.ahk`nif this script does not work alone.`nProgram will now exit.
ExitApp
}
ExitApp
}
IfMsgBox No
ExitApp
Return
GuiClose:
ExitApp
It appends the text file perfectly with whatever is left over from removing characters... but the player.ahk file is not written. This might be a difference between ahk and ahk_L but I am not sure at all.