The solution to problems with embedding Youtube videos?, page 1
Pages:
ATS Members have flagged this thread 3 times
Topic started on 5-11-2011 @ 08:15 AM by PhoenixOD
Hi , i think its great that we can embed Youtube videos here at ATS but its clear that many people seem to have problems getting the correct video number which just makes the threads messy not to mention frustrating for the users.

I'm a programmer and i don't understand why the good people in charge of this site don't just implement a simple algorithm that strips out everything but the Youtube video number automatically thus allowing a person posting the video to just enter the entire YouTube URL.

Here are 3 examples of the different complexities of youtube URL's with the "www." prefix removed so i can display them here.

youtube.com/watch?v=iDb1oyVKnP4

youtube.com/watch?v=BZ5sWfhkpE0&feature=relmfu

youtube.com/watch?v=vioZf4TjoUI&feature=BFa&list=AVLtX9JtELkW26DMGzQ-CQylpSHBGCxzrQ4giVTBh-jfiMQm1oWUWpSKdSxvZIjm54&lf=list_related

The layman's terms the code to get the number would be :

1 - Search the String from left to right to look for the first instance of the character "="
2 - If "=" is found Remove everything in the string to the left of (and including) the "="
3 - In the remaining string search from the left to the right for the first instance of the character "&"
4 - If "&" is found then remove everything from the string to the right of (and including) the "&"

Of course some people might prefer the old method for some reason but with this code people could still use the old system of using the exact youtube number or they could input the entire URL. It will work with both methods without throwing up errors

Im not sure who is responsible for the coding at ATS but im sure this would make the whole process of posting a youtube video much more user friendly for your site

edit on 5-11-2011 by PhoenixOD because: (no reason given)



reply posted on 5-11-2011 @ 10:38 AM by LightSpeedDriver
reply to post by PhoenixOD


I think the makers of the forum software that I guess ATS are using, along with other sites should be the one to add this fairly simple logic when someone posts a video. I am a member of one other forum and it also works the same way, no full URL just the "code". It is a good idea but I think it should more be directed to forum software makers than ATS.

I do reserve the right to be wrong though
ETA: I know from personal experience that custom modifications invariably either cause problems or just don't work on the next major software upgrade. I like the KISS principle. I am also lazy...
edit on 5/11/11 by LightSpeedDriver because: ETA
edit on 5/11/11 by LightSpeedDriver because: Typo



reply posted on 5-11-2011 @ 10:51 AM by PhoenixOD
reply to post by LightSpeedDriver



I was under the impression that the ATS board was a custom job.



reply posted on 5-11-2011 @ 12:31 PM by LightSpeedDriver
reply to post by PhoenixOD


My bad then. I just assumed they used some random software such as invision power board or something similar.


reply posted on 5-11-2011 @ 01:46 PM by PhoenixOD
reply to post by LightSpeedDriver



I could be wrong, maybe one of the MOD's here could clarify


reply posted on 5-11-2011 @ 03:30 PM by ignorant_ape
reply to post by PhoenixOD



its not rocket science - its a string of numbers

if people cannot sucessfully cut and past a block of text - thier thread deserves to be a vid free mess


reply posted on 5-11-2011 @ 06:48 PM by LightSpeedDriver
reply to post by ignorant_ape


To be fair, I can understand how someone that is perhaps not quite so computer/web savvy might not understand how youtube url's work and/or that it is only the code part that is needed. Or even what a url is, for that matter.

Put differently, if the dipstick in a car engine wasn't clearly labelled or recognisable, I would have trouble finding it or reinserting it if already removed. To each his own. To me a car is a plug and play device. When it doesn't work I need a mechanic. Obviously after checking fuel, oil and water levels and checking on the dashboard for any warning lamps that might be trying to tell me something.


reply posted on 5-11-2011 @ 07:48 PM by Kr0nZ
This site is based on PHP so why not just use php's built in function parse_url?
This would make an array and the 'watch' varible in that array would contain the vid id number, no need to manually parse anything

php.net...

EDIT: scratch that, thats the wrong function, but there is a function that does what i said, i have used it on one of my sites awhile ago... letme see if i can find it... but there is a function that will do it
edit on 5-11-2011 by Kr0nZ because: (no reason given)



reply posted on 6-11-2011 @ 05:43 AM by PhoenixOD
reply to post by Kr0nZ



This looks like it would do the job in PHP

Step 1 URL validation:

$urlData = parse_url($ytURL);
if($urlData["host"] == 'www.youtube.com')
{
// Move ahead
}
else
{
return 0;
}


Step 2 function for extraction of youtube number:

function getYTid($ytURL)
{
$ytvIDlen = 11; // This is the length of YouTube's video IDs

// The ID string starts after "v=", which is usually right after
// "youtube.com/watch?" in the URL
$idStarts = strpos($ytURL, "?v=");

// In case the "v=" is NOT right after the "?" (not likely, but I like to keep my
// bases covered), it will be after an "&":
if($idStarts === FALSE)
$idStarts = strpos($ytURL, "&v=");
// If still FALSE, URL doesn't have a vid ID
if($idStarts === FALSE)
die("YouTube video ID not found. Please double-check your URL.");

// Offset the start location to match the beginning of the ID string
$idStarts +=3;

// Get the ID string and return it
$ytvID = substr($ytURL, $idStarts, $ytvIDlen);

return $ytvID;

}


edit on 6-11-2011 by PhoenixOD because: (no reason given)

Pages:     ^^TOP^^