Parse YouTube URL
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Parse YouTube URL
Hello, I would like to parse YouTube URL. I am gettting little confused and not sure how to use ReplaceText or some other command to get it.
Lets say the Orginal URL is
http://www.youtube.com/watch?v=wRn__ibJ ... ure=relmfu or can be any valid YouTube URL which user can enter.
Now I would basically like to get the vID (Video ID) and then form the following URLs
Video URL
http://www.youtube.com/v/U8qV6OhrtUA/
Snapshot URL
http://img.youtube.com/vi/U8qV6OhrtUA/default.jpg
Can you please suggest me how to get the vId from the you tube URL.. Basically how get data which is between /watch?v= and &
Thanks
Best Regards
Pradeep
Lets say the Orginal URL is
http://www.youtube.com/watch?v=wRn__ibJ ... ure=relmfu or can be any valid YouTube URL which user can enter.
Now I would basically like to get the vID (Video ID) and then form the following URLs
Video URL
http://www.youtube.com/v/U8qV6OhrtUA/
Snapshot URL
http://img.youtube.com/vi/U8qV6OhrtUA/default.jpg
Can you please suggest me how to get the vId from the you tube URL.. Basically how get data which is between /watch?v= and &
Thanks
Best Regards
Pradeep
Re: Parse YouTube URL
in the PHP, this is how it has been done...
http://webgarb.com/tutorials/how-to-get ... rfect-way/
Anyone can help me the perfect way of getting YouTube ID from valid you tube URLS...(in LiveCode)
Thanks
Pradeep
http://webgarb.com/tutorials/how-to-get ... rfect-way/
Anyone can help me the perfect way of getting YouTube ID from valid you tube URLS...(in LiveCode)
Thanks
Pradeep
Re: Parse YouTube URL
While there may be more elegant solutions, the stack file I've attached shows at least one way to do what you want...
I've also added some options in the stack to automatically launch the freshly parsed URL's using your browser and/or to auto start the video playback based on instructions provided in the YouTube API documentation.
-Doc-
I've also added some options in the stack to automatically launch the freshly parsed URL's using your browser and/or to auto start the video playback based on instructions provided in the YouTube API documentation.
-Doc-
- Attachments
-
- YouTubeURLParsing.zip
- (1.52 KiB) Downloaded 283 times
Re: Parse YouTube URL
Hi Pradeep,
a quick and dirty solution:
...
answer get_VideoID("http://www.youtube.com/watch?v=wRn__ibJ ... ure=relmfu")
...
I'm sure you can now create the necessary video and image urls from that by yourself
Check "offset" and other terms in the docs to get more info and to fully understand this script!
Best
Klaus
a quick and dirty solution:
Code: Select all
function get_VideoID tUrl
put "/watch?v=" into tDelimiter1
put length(tDelimiter1) into tOffset2Add
## Will give us the number of the fiorst char of tDelimiter1 in the URL
put offset(tDelimiter1,tURL) into tStartChar
## Now we need to add the number of chars of tDelimiter1
## in order to only get everything AFTER that strings
## char -1 is the LAST char in a strings, same for char -2, the last but one etc...
put char (tStartChar + tOffset2Add) to -1 of tUrl into tUrl2
## Good old ITEMDELIMITER, always helpful :-)
set itemdel to "&"
return item 1 of tURL2
end get_VideoID
answer get_VideoID("http://www.youtube.com/watch?v=wRn__ibJ ... ure=relmfu")
...
I'm sure you can now create the necessary video and image urls from that by yourself

Check "offset" and other terms in the docs to get more info and to fully understand this script!
Best
Klaus
Re: Parse YouTube URL
Thanks for your response... and for sample example.. Here is the code you have mentioned.
http://www.youtube.com/watch?v=wRn__ibJ ... ure=relmfu
but it is not the case always...the url could be some thing like this...
http://www.youtube.com/watch?param1=val ... ure=relmfu
Please let me know how to handle it.. and what would be the right way of doing it...
Thanks.
Cheers
Pradeep
However it assume that first parameter in the URL is video Id...replace "=" with "~" in fld "target"
replace "&" with "~" in fld "target"
set the itemdel to "~"
-- with the tilde character now set as the delimiter, everything in front of the first "~" becomes iten 1
-- and our video ID become item 2, making it simple to parse that info for use later in building the
-- target URL's for the image and/or video
put "http://img.youtube.com/vi/" & item 2 of fld "target" & "/default.jpg" into fld "results1"
put "http://www.youtube.com/v/" & item 2 of fld "target" into fld "results2"
http://www.youtube.com/watch?v=wRn__ibJ ... ure=relmfu
but it is not the case always...the url could be some thing like this...
http://www.youtube.com/watch?param1=val ... ure=relmfu
Please let me know how to handle it.. and what would be the right way of doing it...
Thanks.
Cheers
Pradeep
Re: Parse YouTube URL
use my function and change the first line to:
At least this "v=" SEEMS to be the starting point you are looking for.
Do you have any documtentation on the YouTube URL format? Are there any standards?
If not, then all solutions might work or not
Best
Klaus
Code: Select all
function get_VideoID tURL
put "v=" into tDelimiter1
...
Do you have any documtentation on the YouTube URL format? Are there any standards?
If not, then all solutions might work or not

Best
Klaus
Re: Parse YouTube URL
Klaus, Thanks for your response.. I can not see your function...
I am looking for the simple basic SubString function... It would be sufficient enough to get the value what ever the order of parameter is.. Because we will search the value between "v=" and "&" to get the vId...
function substring(String1, String2, String3)
It should search in String1 and should return the value between String1 and String2
For example String1 = Hello How are you dear? String 2 = How String3 = dear..
So subString function should return "are"
Please let me know if any one has implemented subString function...
Thanks
I am looking for the simple basic SubString function... It would be sufficient enough to get the value what ever the order of parameter is.. Because we will search the value between "v=" and "&" to get the vId...
function substring(String1, String2, String3)
It should search in String1 and should return the value between String1 and String2
For example String1 = Hello How are you dear? String 2 = How String3 = dear..
So subString function should return "are"
Please let me know if any one has implemented subString function...
Thanks
Re: Parse YouTube URL
Oh, come on!pkmittal wrote:I can not see your function...

Only two postings of mine on this page, are you kidding?
Re: Parse YouTube URL
My sample was a simple solution based on the URL that was given by example.. and wasn't intended to accommodate every possibility or situation. I was really just trying to point out the simplicity that LiveCode offers when parsing any kind of string. As you see with Klaus' post(s), there are all kinds of different methods and possibilities. 
-Doc-

-Doc-
Re: Parse YouTube URL
EX-ACTLY! 

Re: Parse YouTube URL
Thanks a lot for your solutions... I would also try to develop an proper SubString function which is available in other languages...
Re: Parse YouTube URL
Thanks a lot and it works perfectly fine... I appreciate. Thanks everyone...
Re: Parse YouTube URL
Hi Pradeep,
Good luck
Best
Klaus
pkmittal wrote:I would also try to develop an proper SubString function which is available in other languages...
OK, but that should actually return: " are you "!For example String1 = "Hello How are you dear?" String 2 = "How" String3 = "dear"
So subString function should return "are"
Good luck

Best
Klaus
Re: Parse YouTube URL
Hi Pradeep,
after spending 5 minutes with GOOGLE, I found that YouTube vieo IDs have a lenght of 11 characters,
which makes parsing even easier:
Looks like doing a bit research about a problem is not a bad thing
Best
Klaus
after spending 5 minutes with GOOGLE, I found that YouTube vieo IDs have a lenght of 11 characters,
which makes parsing even easier:
Code: Select all
function get_VideoID tUrl
put "v=" into tDelimiter1
put length(tDelimiter1) into tOffset2Add
## Will give us the number of the fiorst char of tDelimiter1 in the URL
put offset(tDelimiter1,tURL) into tStartChar
## Now we need to add the number of chars of tDelimiter1
## in order to only get everything AFTER that strings
put tStartChar + tOffset2Add into VID_start
put VID_start + 10 into VID_stop
return char VID_start to VID_stop of tURL tURL2
end get_VideoID

Best
Klaus
Re: Parse YouTube URL
Thanks.. However your previous solution was good and it seems to work fine.... for all type of URLS... thanks for your help...
Can you please help me on this? (It is related to proper video upload script)
http://forums.runrev.com/phpBB2/viewtop ... 49&t=12954
Are there any paid script? I can be reached on pkmittal81@gmail.com
Can you please help me on this? (It is related to proper video upload script)
http://forums.runrev.com/phpBB2/viewtop ... 49&t=12954
Are there any paid script? I can be reached on pkmittal81@gmail.com