2013-01-02

2013-01-02 Get simple YouTube urls tool

This is a tool to create the most basic/simple form of a url showing a YouTube video
and/or an even shorter youtu.be url to that video:


input url (paste or enter here...):


simple url (copy from here):


youtu.be url (copy from here):



Sometimes, you may want to share a YouTube video (url) with others,
but the url you acquired is much longer and more complicated than it needs to be
- because it contains extra parameters and data not required
and not appropriate to use for the one[s] you want to share it with.

This overcomplicated form also causes problems in some cases,
f.e. with tools that help you embed such videos.

I wrote about that, some background to it and other aspects applicable
especially to the Chatango group chat in my post
2012-12-05 How you can and should post YouTube videos to Chatango group chat.
With that you should have been able to fix such problems "by hand".

OK - I understand that it may take some dedication to read and understand that post.

Therefore, for the ones not up to that task, or perhaps those who like some assistance
with simplifying YouTube video urls, I created this simple tool.
- Perhaps, I'll be using it myself at times. ;-)

It will attempt to extract what I call the "video id" from the given YouTube url
and create a "simple url" - the most basic way to address the video at YouTube
and a "youtu.be url" - a very short url to address a YouTube video.
Both output urls will attempt to use http, even if the input url used https ...

Assuming youtu.be urls don't necessarily work with Chatango group chat,
you should use the "simple url" for that.

If the input url is not recognized as a YouTube video url, the "simple url" will be the input url
between single quotation marks.
You can use that to perhaps show others parts of YouTube, that are not video urls as such.
The output should be compatible in that manner with Chatango group chat.

I also embedded a version of this tool on the right side of this blog.
You should be able to see it there and use it, unless it was removed or destroyed meanwhile. ;-)



As you may be using that tool more that me,
you are more probable to encounter shortcomings or errors in it.

Therefore I ask you to let me know, if you do encounter anything that should be improved.

In such a case please make sure to provide any data or examples that may be required or helpful
to reproduce and/or understand the issue.


For those who wish to implement such a tool somewhere else themselves,
this is the source code:

<script language="JavaScript">

function GetYtVidId(pUrl)
{
var pos1, pos2;

pos1 = pUrl.indexOf("youtube.com/watch?");
if (pos1 == -1)
  {return "";}
pos1 = pUrl.indexOf("?v=");
if (pos1 == -1)
  {
  pos1 = pUrl.indexOf("&v=");
  if (pos1 == -1)
    {return "";}
  }
pos1 = pos1 + 3;
pos2 = pUrl.indexOf("&", pos1);
if (pos2 == -1)
  pos2 = pUrl.indexOf("#", pos1);
  if (pos2 == -1)
    {return pUrl.slice(pos1);}
return pUrl.slice(pos1, pos2);
}

function GetSimpleYtUrl(pUrl)
{
var vidId;

vidId = GetYtVidId(pUrl);
if (vidId == "")
  {return "'" + pUrl + "'";}
return "http://www.youtube.com/watch?v=" + vidId;
}

function GetYtBeUrl(pUrl)
{
var vidId;

vidId = GetYtVidId(pUrl);
if (vidId == "")
  {return "";}
return "http://youtu.be/" + vidId;
}
</script>

<form name="ytSimpifier">
<p>input url (paste or enter here...):<br />
<input type="text" name="input" size="50" /><br />
<input type="button" name="process" value="process"
onclick="this.form.simpleYt.value=GetSimpleYtUrl(this.form.input.value);this.form.ytBe.value=GetYtBeUrl(this.form.input.value);" /><br />
simple url (copy from here):<br />
<input type="text" name="simpleYt" size="50" readonly /><br />
<p>youtu.be url (copy from here):<br />
<input type="text" name="ytBe" size="50" readonly /><br />
</p>
</p></form>


Update(2013-09-08):
I created another tool - a bookmarklet, that can be used on the YouTube video site itself
to prepare for posting that video in Chatango (group) chat.
2013-09-07 YouTube bookmarklet (for chatango)

No comments:

Post a Comment