Page 1 of 1

Stream Movie From Youtube

Posted: Mon Dec 29, 2014 1:09 am
by maxs
I typed in this address into the filename and source of a qt player object. But all I got was a Livecode movie. How do I stream a movie?

https://www.youtube.com/watch?v=Y41zVzg ... e=youtu.be



--To stream a movie from an Internet server, set the fileName property to the URL address of the stream.

Re: Stream Movie From Youtube

Posted: Mon Dec 29, 2014 4:02 pm
by Klaus
Hi Max,

the link you posted is the URL of the embedding HTML page and not the URL of the actual movie! 8)

No idea how to extract the actual movie url from here, maybe you will find some answers in the
YouTube API documentation!

Best

Klaus

Re: Stream Movie From Youtube

Posted: Mon Dec 29, 2014 5:38 pm
by jiml
Instead of using a player object, you could use a LiveCode browser object and set it load the URL you gave.
That would display Youtube's entire HTML page including the movie.

Jim Lambert

Re: Stream Movie From Youtube

Posted: Mon Dec 29, 2014 5:49 pm
by jacque
I don't believe utube video can be streamed directly, you have to use the embedding code provided on each web page. You'll need to parse the html of the page to extract the code and then use that in a browser object to show it. Jim's idea of showing the whole web page is probably simpler. Utube has protections in place that prevent playback by any other method.

Re: Stream Movie From Youtube

Posted: Tue Dec 30, 2014 12:29 am
by jiml
You could parse the page's HTML and get a direct URL for the movie (which is usually available in multiple formats.)
However Jacque is right about YouTube protections.
That direct movie file URL is restricted by access location and has a timeout.

But you can parse the youtube HTML within a LiveCode client and set the filename of a player to the movie URL.
Just remember the file URL has a limited lifespan. So you may need to reparse after YouTube's timeout expires.
Or, You can just download the movie file.

Here's some rough code.

Code: Select all

on mouseUp
   set cursor to busy
   put "" into fld purl
   set the filename of player 1 to ""
   put isotomac(url fld "ytUrl") into temp
   set cursor to busy
   replace "\u0026" with "&" in temp
   replace "http" with cr & "http" in temp
   replace "\/" with "/" in temp
   replace comma with cr in temp
   replace "|" with cr in temp
   set cursor to busy
   put urldecode(temp) into temp
   filter temp with "http*"
   filter temp with "*videoplayback*"
   filter temp with "*itag?18*"
   if ";" is in temp then
      delete char offset(";",temp) to -1 of temp
   end if
   set the filename of player 1 to line 1 of temp
   put temp into fld chtml
   set cursor to busy
   set the topleft of player 1 to the topleft of this card
   set the topleft of the owner of me to the topright of player 1
end mouseUp

That script will take a youtube page URL like:
http://www.youtube.com/watch?v=6b4ZZQkc ... AAAAAAAAAA

And parse out a URL which can be used to set the filename of a player

Code: Select all

http://r17---sn-nwj7knek.googlevideo.com/videoplayback?id=o-ADUHWW8JR97x11AT2vy2UTMUsN194h2jIX0O046Sc60j&ms=au&mt=1419893544&mv=m&expire=1419915209&sver=3&ip=63.156.201.140&mime=video%2Fmp4&initcwndbps=613750&dur=68.823&source=youtube&mm=31&itag=18&signature=F9494CFEB6C0817A26DA2B99A2425413849ED3DB.5B8D0C9675D4B93544B10E5C0378745A63EEDF3F&fexp=900718%2C927622%2C932404%2C939936%2C939937%2C9405711%2C9405921%2C943917%2C946008%2C947209%2C947218%2C948124%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&upn=C8MfwxY4Th4&key=yt5&ipbits=0&ratebypass=yes&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cratebypass%2Csource%2Cupn%2Cexpire&type=video/mp4
Remember this parsed URL will usually only work for the client that does the parsing and only for a certain time.
So no parsing on your server and sending the movie URL to a client somewhere else. It won't work for them.

Attached is a stack the does all this and optionally will download a copy of the movie.
Play YouTube 2.livecode.zip
(169.48 KiB) Downloaded 501 times
Note that I'm filtering for a movie format tag that works on the Mac. You can change this.

Jim Lambert

Re: Stream Movie From Youtube

Posted: Tue Dec 30, 2014 12:54 am
by maxs
Wow, Thank you Jim and Jacque.

I've been wondering this for the longest time, and I assume the answer is no. ( But many things can be done in LC.}

1.Graphics cannot appear above a movie while it is playing.
2. Movies cannot have a transparent background. (Like the movies that use green screen.)

Any thoughts?

Max

Re: Stream Movie From Youtube

Posted: Tue Dec 30, 2014 6:02 pm
by jiml
Max,

If you set the always buffer of a video player to true, you can place objects on top a player.
You can also place objects underneath the player and apply an ink effect to the player.
Thais somewhat like green screening.

Just be aware that buffering the movie frames is a bit more processor intensive.

Jim Lambert

Re: Stream Movie From Youtube

Posted: Tue Dec 30, 2014 6:26 pm
by maxs
Thanks Jim,

I had that question on my mind for years. Such a simple solution. Max

Re: Stream Movie From Youtube

Posted: Sun Apr 26, 2015 5:50 am
by pkmittal
Hi, I downloaded the stack and tried opening in Live code 5.0.2 and Live Code 7.0.4 .. the stack does not open.. Any can can help?

Thanks