Facebook like status url detection - php

I am wondering if there is a script similar to the facebook status update thing,
What I mean, is when for ex. I paste a youtube/other video site/image/link it automatically detects the contents of the page and associates an embed code with it (if its a video)..
So I'm wondering if there is a ready script that has a large database of websites and can associate video site url's with embed codes.
I could actually do something like that by myself but the problem is that I want to support a lot of websites, like facebook does.
Please help me find a solution.
Thanks.

Take a look at the Embedly API: http://api.embed.ly/
It gets the embed code for a lot of the popular video sites out there and also for some images sites. I highly recomend it,
you can try it out here.

You really wouldn't have to scan that large of a database. With videos, you could keep track of maybe the top three or so uploading sources (youtube, vimeo, metcafe...) and their embed codes.
As for images and links, those are pretty easy to detect and don't require any special embed code. By pretty easy, I mean very simple. Just use a simple regular expression to search for a link in their post.
If it's a picture, you can easily tell by looking at the file extension of the link (jpg, png, gif, etc.). If so, do whatever is proper to embed any old image. If it's just an ordinary old link (doesn't match any of your video sites, or doesn't end in a file extension for an image), just use the link itself.
The only marginally tricky part would be getting the unique embed codes for the video sites. But perhaps there is some external library/api that could do that small part for you (another answerer has provided has a proper API/pre-built library for this). However, images and links are mostly pretty simple.
EDIT It seems I misread your problem, and that you are only looking for pre-built libraries with video embed codes. In that case, the other answer is exactly what you want.

Related

PHP-How to check webpage(url) contain video or not?

I create website for RSS reader.
I want to add new feature in it.
For this I want to test that webpage(url)
contain video or not??
Can any one tell me that how to do this??
I just want to test that the url or webpage contain video or not??
I believe the only way to do this is to scan the source code of the page through PHP and look for likely embedded video codes. Those can vary though, so you may need to look for several patterns. Some video sharing sites embed them via iframes though, and that will be harder to deal with.
There are plenty of examples on the web on how to parse a site's generated source code, but be careful of violating their terms of use.

How do sites like Bing Search, Imgur, and Reddit generate a thumbnail of the website from a URL?

In Imgur, you can input an image URL and a few seconds later, there's a thumbnail of the image. Or in Bing Search, you can (or used to) be able to view a thumbnail of the website in the search results before visiting it.
I would love to implement something similar for my website, but I can't wrap my head around on how it is done. Moreover, are there not security concerns? I'd imagine the servers have to at least download the website, render it and take a screenshot. What if it's a malicious website, and you download something malicious on your server?
A headless Web browser engine like PhantomJS can be used for this. See example on their wiki. Yes, it would be prudent to run this in some sort of a sandbox, feeding a queue of URLs into it, then taking the generated thumbnails from the file system.
While I don't know the internal workings of any of the aforementioned services, I'd guess that they download/create a local copy of the images and generate a thumbnail from that.
Imgur, as an image hosting service, definitely needs a copy of the image prior to being able to generate thumbnails or anything else from it. The image may be stored locally or just in memory, but either way, it must be downloaded.
The search engines displaying screenshots of the sites likely have services that periodically take a screenshot of the viewable area when the content is getting indexed, and then serve those screenshots (or derivatives) along with the search results. Taking a screenshot really isn't dangerous, so there's nothing to worry about there, and whatever tools are used to load/parse/index the websites will obviously be written with security considerations in mind.
Of course, there are security concerns about the data you're downloading, too; the images can easily contain executable code (such as PHP) in their EXIF data, so you need to be careful about what you do with the images and how.

Curl preg_match

We are downloading images to our computers when we open new webpages. For example: If a webpage has an image(image.jpg), our computer downloads it while we are surfing that page.
Some webpages are using ajax methods. For example: You don't see an image on the page's source codes, however your computer downloads an image. Because, if you click a link on that page, ajax will be showing that image...
Let me show an example:
<div id="ajax_will_load_image_here"></div>
Okay, how can php curl see (or download) that image? Curl can't see that image when I try to use preg_match function. Actually there is an image. I want to download that image by using php curl. Any advice?
If i understand the question correctly there is no convinient way of doing that.
Your crawler/spider would have to parse the website and evaluate javascript.
There are libraries for that but support is very limited.
There are however methods where an actual browser is used to evaulate the page (without displaying it but setting proper environment variables like resolution etc).
Then the generated source including javascript dom modifications is available.
This is for example how the google search previews are generated.
But if you require user interaction it gets pretty specific and complicated.
I am sorry to dissapoint you, but using curl and preg metch the old school way we used to when javascript was not yet so common wont work.
However for most legit use cases this is more than sufficient and websites are today more and more designed to be non-javascript compliant. Especially the content for crawling purposes. It is a must in search engine optimization, and which website doesnt want that?

Online video streaming

I want to make a video site in which we can upload the video in any format and display it like youtube. How can I do this? My whole site is in PHP I'm a newbie in the video streaming sp plz be descriptive with your answer
Thanks
First you need a VideoPlayer written in Flash / Actionscript, there are also a lot of free ones arround in the internet, e.g.: FlowPlayer, You also could write you own. You acctually do not net to buy Flash for this. The Flash/Flex compiler mxmlc is available for free. You could also write you Flashvideoplayer in Haxe (also free).
You you do not want the users to switch within the video you could deliver the videos via HTTP, other wise you need an streaming server like: FlashMediaServer (not free). There are also open source alternatives like Red5 or haxeVideo.
You you do not have the video available in the right format you need to encode them: the best tool for this task could be ffmpeg
I suggest looking at the html5 <video> tag, this is probably the simplest way. For an example look at the the one from surfin' safari.
Be aware that some browsers support ogg and others h264, but not both.
Encoding of the video can be made using ffmpeg on the server.
One of my websites does this, and it's a MASSIVE pain.
However, there are websites out there that'll take a video and convert it to an FLV for you (for a price), for example we use a service called Hey!Watch which is reasonably reliable.
If you really want to encode it to flash yourself, you're going to need a full copy of Flash and a LOT of time =]
There is this highly underrated post with 3 great links for open source solutions that are like youtube and fits perfectly your question (and at least another one):
http://www.vidiscript.co.uk/
http://www.phpmotion.com/
http://osshare.sourceforge.net/
I'm posting this here just to point out the links. I think 2 of those 3 questions should be marked as duped anyway.

PHP Video Editing and Streaming

I am developing online video streaming website on PHP.
I need two functionalities:
Need to add title/text at bottom of the video dynamically.
Need to add background music to video dynamically.
Is it possible with PHP or any available open source library?
Can anyone guide me or provide links to this type of library ?
Thanks.
Editing video with PHP is an extremely bad idea. This idea very closely approximates impossible. At best you would need to decode the video which would be brutally slow in php.
If I had to tackle this problem, I would try to add the title and background music in the player, not to the video file itself. If you're streaming the video it is likely that you're using Flash or some other client-side player. You would need to write the player (or perhaps modify an existing one, there are several available) to add another layer over top of the movie for the title, and an audio track.
Slightly more hare-brained, but still easier than rewriting video in php, would be to layer a transparent image generated in php over top of the player using css and javascript, and embedding the audio in the page. This paragraph contains a terrible idea.
php doesn't provide any video oriented stuff to perform, but there is one CMS namely Kaltura, is designed and implemented in doing these kindaa stuff. Search it , download it and play it.
You can make your own player in Flash and add a default watermark. You don't need PHP for that.

Categories