falarious Posted April 25, 2008 Share Posted April 25, 2008 Hello guys! This is part of a script that grabs the latest videos and thumbnails of a popular video website. It worked well until they changed layouts. I fixed some stuff up, but my coding skills are limited. If one of you guys could look over it for errors that would be great! I bolded the parts that have possible errors. function fetch_new() { global $page_no, $fetched, $new; $page = @file_get_contents("http://www.stupidvideos.com/videos/all/new/$page_no"); preg_match_all("#<div class=\"video_box\"><a href=\"/video/all/([^/]*)/\" title=\".*\"><img src=\"http://images.stupidvideos.com/images/([^\"]*)\" width=\"120\" height=\"90\" alt=\"\"></a></div>#", $page, $matches); $new2 = get_new_elements($matches[1], $fetched); $new = array_merge($new, $new2); $new = array_unique($new); } /* done fncs */ $no = 0 + $_GET['no']; if(empty($no)) { $no = 5; } elseif($no > 20) { $no = 20; } $page = @file_get_contents("http://www.stupidvideos.com/videos/all/new/1"); preg_match_all("#<div class=\"video_box\"><a href=\"/video/all/([^/]*)/\" title=\".*\"><img src=\"http://images.stupidvideos.com/images/([^\"]*)\" width=\"120\" height=\"90\" alt=\"\"></a></div>#", $page, $matches); $file = @file_get_contents('files/videos/videos/fetchlog'); $fetched = explode("\r\n", trim($file)); $new = get_new_elements($matches[1], $fetched); $page_no = floor((count($fetched)/20)); while(count($new) < $no) { fetch_new(); $page_no++; } $new = array_values($new); require_once('config.php'); if(@mysql_connect(DBHOST, DBUSER, DBPASS)) { @mysql_select_db(DB); } for($i=0; ($i<$no && $i<count($new)); $i++) { @file_put_contents('files/videos/videos/fetchlog', $new[$i] . "\r\n", FILE_APPEND); $page = @file_get_contents("http://www.stupidvideos.com/video/all/$new[$i]/?m=new"); if(!preg_match("/<META name=\"description\" content=\"([^\"]*)\"><meta name=\"title\" content=\"([^\"]*)\"\/>.*<link rel=\"videothumbnail\" href=\"([^\"]*)\" type=\"image\/jpeg\"\/>/", $page, $matches)) { continue; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.