05-05-2009, 12:47 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Nov 2008
Location: Sweden
Posts: 36
Thanks: 1
|
c&c and best practise.
Hey guys,
I've been lurking this forum on and off for some time, never really had the time to take part and take my programming seriously. Time has changed and motivation is there so it's hella fun.
Some things like abstract classes, protected, private, singletons, error handling etc hasn't really stuck in my head yet. It's been more reading then actually putting anything down on paper so to say :)
I don't expect you guys to try and explain, that i have a couple of books for  but i would like some criticism.
PHP Code:
<?php
/*
-- Crawl
*/
class Crawl{
public $markup;
public $url;
public function __construct($url){
$this->url = $url;
$this->markup = $this->fetchMarkup();
$siteName = $this->siteName();
/* What site to be crawled */
$this->crawl = new Crawl_method($this->markup);
$this->method = $this->crawl->$siteName();
}
/*
- extract what site we are on and choose method accordingly.
- temp solution, me regepx suxxors ;)
*/
public function siteName(){
$name = explode(".", $this->url);
return $name[1];
}
/*
- grab markup from url.
*/
public function fetchMarkup(){
return file_get_contents($this->url);
}
/*
- save the file.
*/
public function saveFile(){
set_time_limit(0);
$uniqid = uniqid();
//create dir
mkdir("uploads/{$uniqid}", 0777, true);
//grab content
$contents = file_get_contents($this->method);
//create .flv file
file_put_contents("uploads/{$uniqid}/{$uniqid}.flv", $contents);
}
}
/*
- what method to retrieve our .flv file.
*/
class Crawl_method{
public $markup;
public function __construct($markup){
$this->markup = $markup;
}
/*
- grab url to youtube .flv file
*/
public function youtube(){
//video_id
preg_match('/"video_id": "(.*?)"/', $this->markup, $match);
$id = $match[1];
//t
preg_match('/"t": "(.*?)"/', $this->markup, $match);
$t = $match[1];
$url = "http://www.youtube.com/get_video?video_id={$id}&t={$t}";
return $url;
}
}
?>
Thanks, Hjalmar
|
|
|
|