Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Aaron's YouTube Player Creator


  • Please log in to reply
17 replies to this topic
aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Aaron's YouTube Player Creator
v0.9.2.0 (beta)
Posted Image
This one player was made by entering '400' for the width
(resulting in a 16:9 video screen with a width of 400)

Description:
This script allows the User to create his/her very own custom YouTube players
with their choice of any single YouTube video hardwired in each and every one of them.
The User can customize the contents, size and title of the player before it is created.

System Requirements:
Tested on Windows 7 32-bit so far
AHK_L and Com.ahk for script-only use (not sure why this is)

Download latest version:
Aaron's YouTube Player Creator.ahk
Aaron's YouTube Player Creator.exe (recommended)

User Requirements:
Must be able to copy/paste the code from YouTube's
"Share" button located underneath videos on the website
(<!-- m --><!-- m -->)

Instructions:
- Run "Aaron's YouTube Player Creator"
- Enter desired width of your player
- Copy/paste the "Share" code from video at YouTube
- Enter the name you want for the created player
- Choose location in which to save created player
- Play your new video in your new player! Or make ten other ones.

At 2kb each they don't take up much room.

You can make as many players as you want, if you try to create one with the same
name as an existing player, you will be prompted to overwrite.

Please report any bugs or issues.
As always, comments, suggestions and insults are welcome!

Many thanks to all of you who have provided help, ideas, input and code enough for me to learn and understand these things.

Version History:
v0.9.0.0 - built working version
v0.9.1.8 - RegExReplace now working 100% for invalid filename characters (thanks to Guest)
v0.9.1.9 - used proper 'Loop' commands instead of using 'GoSub' incorrectly (thanks to nimda)
v0.9.2.0 - URL can now be from either the browser's main address bar or the video's 'Share' button


TheGreatSwami Woo
  • Members
  • 237 posts
  • Last active: Jan 22 2012 03:31 PM
  • Joined: 26 May 2011
he he nice handy little thing to have, now I can make links to Rick Astley and "rick roll" some friends.

  • Guests
  • Last active:
  • Joined: --

I don't know how to...RegExReplace...

...I'm great with RegEx, I can do this...

I had to resort to a pile of StringReplaces instead.

...you are StringReplace'ing far too many chars, most of those are valid in filenames. The only invalid chars (on Windows computers) are: \ / : * ? " < > |

Filename1=
(LTrim %
	Testing1_begin \ / : * ? " < > | end_Testing1
)
Filename2=
(LTrim %
	Testing2_begin " \ / ; . : % ( ) @ # $ ^ & * < > ~ { } [ ] = | ' , ? end_Testing2
)

regex_InvalidFilenameChars=[\\/:*?"<>|]

Filename1_before:=Filename1
Filename1:=RegExReplace(Filename1, regex_InvalidFilenameChars)
Filename1_after:=Filename1

Filename2_before:=Filename2
Filename2:=RegExReplace(Filename2, regex_InvalidFilenameChars)
Filename2_after:=Filename2

msgbox, 64, ,
(LTrim
	regex(%regex_InvalidFilenameChars%)

	Filename1_before(%Filename1_before%)
	Filename1_after(%Filename1_after%)

	Filename2_before(%Filename2_before%)
	Filename2_after(%Filename2_after%)
)


  • Guests
  • Last active:
  • Joined: --
I get an error on a Win7 64 bit (.exe version)

Error: Call to nonexistent function.

Specifically: COM_AtlAxWinInit()


---------------------------
Test.ahk
---------------------------
Error:  Call to nonexistent function.

Specifically: COM_AtlAxWinInit()

	Line#
	002: SetWorkingDir,C:\Users\fam-mikkelsen\Desktop
	008: code = <!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><object  <object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" width="600" height="337.500000" bufferin
--->	011: COM_AtlAxWinInit()  
	012: Gui,+LastFound
	013: pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(hwnd:=WinExist(),-2,-2,604,341.500000,"Shell.Explorer"))
	020: Gui,Show,w600 h337.500000,**** dig
	022: COM_Invoke(pwb, "Navigate", "about:blank")  
	023: COM_Invoke(pwb, "document.write", code)  
	025: Return
	028: ExitApp

The program will exit.
---------------------------
OK   
---------------------------


  • Guests
  • Last active:
  • Joined: --

I get an error on a Win7 64 bit (.exe version)

Error: Call to nonexistent function.

Specifically: COM_AtlAxWinInit()


---------------------------
Test.ahk
---------------------------
Error:  Call to nonexistent function.

Specifically: COM_AtlAxWinInit()

	Line#
	002: SetWorkingDir,C:\Users\fam-mikkelsen\Desktop
	008: code = <!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><object  <object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" width="600" height="337.500000" bufferin
--->	011: COM_AtlAxWinInit()  
	012: Gui,+LastFound
	013: pwb := COM_AtlAxGetControl(COM_AtlAxCreateContainer(hwnd:=WinExist(),-2,-2,604,341.500000,"Shell.Explorer"))
	020: Gui,Show,w600 h337.500000,**** dig
	022: COM_Invoke(pwb, "Navigate", "about:blank")  
	023: COM_Invoke(pwb, "document.write", code)  
	025: Return
	028: ExitApp

The program will exit.
---------------------------
OK   
---------------------------


This was while running the generated player*

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
this looks like one of the instances where you'd need com.ahk (the ahk_L version) in your possession. Not sure why it does that. does that fix it? try compiling the player into an exe... let me know k? cool

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
@ Guest: RegExReplace works somewhat, but I can still make it glitch out on the file names. If I add all the odd characters from the StringReplaces, I can still glitch it out with odd characters... my test set is:

[email protected]#$%^&*()_+-={}|[]\:";'<>?,./

I know some of them are allowable and some are not.

  • Guests
  • Last active:
  • Joined: --

@ Guest: RegExReplace works somewhat...

...my demo code works 100%, what code did you try?

If I add all the odd characters from the StringReplaces, I can still glitch it out with odd characters

...I did add all the "odd characters from the StringReplaces" to my test script & it doesn't "glitch out". I need to see how you incorporated the demo script with your script, to see the problem. Plus, I need to know exactly what "glitch out" means. Also, are you using AHK_L? My demo was written/tested on AHK (not L).

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
I tried:
InputBox, PlayerName, YouTube Video Player Creator, Please enter the name you wish to appear on the player:,, 450, 200
  If ErrorLevel = 1
    ExitApp
  RegExReplace(PlayerName, "[\/:*?<>|]")
but I can still use that test set from my last post and the file will not be written due to some invalid character in there. It might be the quotation mark but then the question becomes how to escape the quotation mark in the RegExReplace?
I mean "the file does not get written like it should be" when I say "gliltch out". I used AHK_L (latest version).
Like I said, I can make it write a file, but some odd character prevents the actual file from showing up due to an invalid file name. When I use the same characters as from the StringReplaces in the RegexReplace, it happens. When I use only the StringReplaces, it does not happen... the offending character(s) are removed.

  • Guests
  • Last active:
  • Joined: --

It might be the quotation mark but then the question becomes how to escape the quotation mark in the RegExReplace?

...don't escape every little char, assign a var & use the var in RegExReplace, like I do in my test script above...& this new example...

;// must use this syntax (= not :=), to avoid escaping chars
regex_InvalidFilenameChars=[\\/:*?"<>|]

;// must use this 4-line syntax, to avoid escaping chars
Filename=
(LTrim %
	[email protected]#$%^&*()_+-={}|[]\:";'<>?,./Testing
)

Filename:=RegExReplace(Filename, regex_InvalidFilenameChars)
msgbox, (%Filename%)

FileAppend, test, %A_ScriptDir%\%A_ScriptName%_B_%Filename%_A_.test

if (Errorlevel) {
	msgbox, 16, , Error writing file.
} else {
	msgbox, 64, , File written successfully.
}

I used AHK_L (latest version).

...I haven't tested in AHK_L...I know they are going to remove (or possibly already have removed) the "literal assign" syntax, if they have, I can't help...well, I could help you "escape" each little char, but I like to avoid that. My example scripts do everything they do, for a reason, I create vars to hold info & then use the vars, I don't cram everything directly into the RegExReplace line, cuz then I'd have to escape it. Please test the above script on AHK_L, if it don't work, try it on AHK 1.0.48.05 & see how it's supposed to work.

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

.I know they are going to remove (or possibly already have removed) the "literal assign" syntax, if they have, I can't help...

You're confusing AutoHotkey_L with AutoHotkey v2.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Hey cool! Doing RegExReplace with a variable seems to work. But only with a test text file and not with the actual player.ahk file. Which is weird! With this:
WeirdCharacters = [\\/:*?"<>|]

Filename=

  ( LTrim %

   [email protected]#$%^&*()_+-={}|[]\:";'<>?,./

  )

Filename:=RegExReplace(Filename, WeirdCharacters)

FileAppend, %Filename%, %A_ScriptDir%\%FileName%.txt



  • Guests
  • Last active:
  • Joined: --

You're confusing AutoHotkey_L with AutoHotkey v2.

...yes, I am. So it won't ever be removed in AHK_L?...only in v2? Is there any alternative "literal assign" syntax in v2 yet?...or planned?

But only with a test text file and not with the actual player.ahk file.

...you attempted to put that code into "Aaron's YouTube Player Creator.ahk" & it did not work? Could you upload a temp/test version, so I can look at your changes? It definitely can work. I could just take the current version, remove the StringReplace's & put in the RegExReplace, but I kinda wanna see the code you attempted.

Just a nitpick: Why did you rename the var to "WeirdCharacters"?...cuz "regex_InvalidFilenameChars" says exactly what the var is & is used for. Maybe you were just testing, but I like to name vars based on what they do.

Actually, I just noticed, I have a few more nitpicks about the code, if you'd like to hear them (I'm just trying to be helpful & improve the code)...for example...you have this code...

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
	}
...which is repetitive...it includes the same error msg under a few different cases. You can group them together & include the error msg code once...

;// unfortunately, this if cannot be combined with the one below, so I use a var
if w is not number
{
	invalidnumber=1
}
if (invalidnumber || w>1920 || w<400) {
	invalidnumber=
	MsgBox, You entered an invalid number.`nPlease try again
	GoSub, EnterWidth
	return
}
...but also it has the problem of using "GoSub, EnterWidth" when it's already inside the "EnterWidth" subroutine...& I don't know if I can explain why that's "bad" but essentially it just keeps "GoSub"ing deeper, it can be rewritten with Loop/Break (or Goto) to not make the GoSub stack keep getting bigger. You should GoSub, when you need to return to the location of the GoSub. I need to write demo code about why this is not optimal.

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
I really appreciate your input, Guest, and am glad you are taking the time to help me improve this one. I have no time ATM but tomorrow I'll continue. I replaced the var name with one I can refer to in the future and have no trouble remembering. cheers! :)

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
@ 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 %
   [email protected]#$%^&*()_+-={}|[]\:";'<>?,./
  )
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.