OK.. this is something that I plan to write a long time ago. I'm quite busy with my freelancing work. Now, I have plenty of spare time, so I decide to write this simple tutorial. As you know, I've created Youtube online video downloader and converter, I applied scrapping method on the site. I scrape Youtube video link, find the video URL, download to my own host and convert it to desired format.
Some of you maybe know that I've cloned video2mp3.net (what an attitude -- bad attitude, don't follow my path) to create my own Youtube online video donwloader and converter. The original always has much power over its clone! Video2mp3.net has feature that not only grabbing/scraping video from Youtube, they also provide grabbing video from Dailymotion and other video networking sites. Can't I do that on my site? Sure, I can, but I didn't have plan to integrate it on my site. So, here I am, instead of creating Dailymotion video grabber, integrate it on Youtube online video downloader and converter and keep it for myself, I decided to write the tutorial here on my blog, so you can write your own code (obviously, if you're a PHP programmer).
Let's begin the tutorial, of course I'll use PHP as the programming language. Dailymotion video URL will look something like this:
http://www.dailymotion.com/gb/featured/channel/animals/video/xa6peu_turtles-having-sex-d_funand maybe some other formats
or this:
http://www.dailymotion.com/tag/funny/video/x3qcq8_regis-fait-du-fenwick_fun
As we (scraper) work, we will access those URL using cURL (its better for anonymity to mimic normal browser activities)
view the source .. look at it carefully, find suspecting codes (look at flash player codes)
for example, this is the codes for video for the first URL above:
so1323913094.addVariable("video", "http%3A%2F%2Fwww.dailymotion.com%2Fcdn%2FFLV-320x240%2Fvideo%2Fxa6peu%3Fauth%3D1253493884-2e17ab4caaef077c3ca56479aebb09f7%40%40spark%7C%7Chttp%3A%2F%2Fwww.dailymotion.com%2Fcdn%2FFLV-80x60%2Fvideo%2Fxa6peu%3Fauth%3D1253493884-6aec3e08374bf452359d46d7f464d85f%40%40spark-mini%7C%7Chttp%3A%2F%2Fwww.dailymotion.com%2Fcdn%2FH264-848x480%2Fvideo%2Fxa6peu%3Fauth%3D1253493884-37ecd90e6d07910788842b1ff80a5da7%40%40h264-hq%7C%7Chttp%3A%2F%2Fwww.dailymotion.com%2Fcdn%2FH264-512x384%2Fvideo%2Fxa6peu%3Fauth%3D1253493884-181a7bf56303ac7903de52bd67a93728%40%40h264");WTF is that?!!! That's all video URL(s) that we needed. Let's
disassemble it! You know, that is an URL in encoded format. ( %3A = : , %2F = / , %3F = ? , etc.).
Scraper can use ' addVariable("video", ' keyword to find that line.
NOTES: some reference on URL encoded chars: http://www.e-planning.net/support/url_encoding.html
Daily motion is very generous, they provide us with all video format URL that we wanted. If you're smart enough, you'll see these formats: spark (FLV 320x240), spark-mini (FLV 80x60), h264-hq (848x480), h264 normal (512x384). Did you see it?
NOTES: not all Dailymotion video URL has all of those video format, like on second URL, it only has spark and spark-mini format
Those video URL(s) is separated by %7C%7C (||), so, scraper will use this chars to explode the encoded URL. Disassembling (explode - ing) the encoded URL, after urldecode, we got 4 video URL(s) like this (you may try this URL directly from browser to test it):
- http://www.dailymotion.com/cdn/FLV-320x240/video/xa6peu?auth=1253493884-2e17ab4caaef077c3ca56479aebb09f7@@spark
- http://www.dailymotion.com/cdn/FLV-80x60/video/xa6peu?auth=1253493884-6aec3e08374bf452359d46d7f464d85f@@spark-mini
- http://www.dailymotion.com/cdn/H264-848x480/video/xa6peu?auth=1253493884-37ecd90e6d07910788842b1ff80a5da7@@h264-hq
- http://www.dailymotion.com/cdn/H264-512x384/video/xa6peu?auth=1253493884-181a7bf56303ac7903de52bd67a93728@@h264
There you are, we have successfully scrapping/grabbing video URL from Dailymotion in various format. You may serve it to user or download it on your own server.
Ok.. that's it for now. I will write another video scraper-tutorial again if I have much time. LOL!



0 komentar:
Post a Comment