userlite
userlite

Reputation: 135

How to detect whether an HTML page contains a video?

I would like to know whether it a possible to detect whether a HTML page contains a video.

I know that one possible way is to look for ".swf" in the HTML source code. But most of the pages do not contain the file name.

For example, given following URL and possibly its source code, is it possible to find out whether it contains a video: http://www.cnn.com/video/

Upvotes: 9

Views: 7015

Answers (4)

Sukhanov Niсkolay
Sukhanov Niсkolay

Reputation: 1328

For your case (CNN site) you can parse Open Graph micro-markup for a video information.

Meta tags such as og:video:type, og:image will help you.

Video hosting services usually support micro-markup, e.g. open graph or scheme.org.

So you can parse these markups.

Upvotes: 2

Doo Dee
Doo Dee

Reputation: 75

You can also search for .flv, or .mp4 in the source code.

Upvotes: -1

Ming-Tang
Ming-Tang

Reputation: 17651

Check if an <object> tag exists in the DOM and check its content type and parameters. You will find the pattern by yourself.

Upvotes: 0

Pekka
Pekka

Reputation: 449385

There are many ways to embed Video into a HTML page - as Flash Video or instances of Platform-Specific players through <object> and <embed> tags (but not every one of those tags is a video! The same holds true for .swf - it's just the file extension of Flash files, Video or not), the new HTML 5 <video> tag... They are not impossible to find out but it's a lot of work to catch all possible player types, formats and embed codes, and will result in a lot of false positives / negatives.

Then, there are JavaScript libraries that initialize players after the containing page has loaded - those are almost impossible to detect.

It's still a very complex issue to get video into a web page reliably, and subsequently, it's even more complex to find it out. Depending on what you are trying to achieve, I would consider dropping it.

Upvotes: 10

Related Questions