<?php include_once "PDOImplement.php"; $pdo = new PDOImplement(); $result = $pdo->ExecuteQuery("select link_channel,catagory from channel"); if (!is_null($result)) { foreach ($result as $key => $value) { $channel_link = $value["link_channel"]; $catagory = $value["catagory"]; process_channel($channel_link, $catagory, $pdo); } } function process_channel($channel_link, $catagory, $pdo) { $url = $channel_link; $html = file_get_contents($url); //var_dump($html); $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXpath($doc); $links = $xpath->query('//a[starts-with(@href, "/watch")]'); $entries = []; if (!is_null($links)) { foreach ($links as $link) { $href = $link->getAttribute('href'); $title = $link->getAttribute('title'); if ($title === '') { $title = trim($link->nodeValue); } if (!isset($entries[$href]) || strlen($entries[$href]) < strlen($title)) { $entries[$href] = $title;
* User: vanhung * Date: 6/7/15 * Time: 10:52 PM */ include_once "Dailymotion.php"; include_once "PDOImplement.php"; header('Content-Type: text/html; charset=UTF-8'); set_time_limit(0); //require_once 'sdk/Dailymotion.php'; try { $apiKey = '0c201474be2087aa73fa'; $apiSecret = '1a461e78a3747381ab735fca88421bd70380084e'; $testUser = '******'; $testPassword = '******'; $api = new Dailymotion(); $pdo = new PDOImplement(); $result = $pdo->ExecuteQuery("select type,tag, youtube_id,title,description,catagory,id from youtube"); foreach ($result as $item => $value) { $youtube_id = $value["youtube_id"]; $id = $value["id"]; $type = $value["type"]; $title = $value["title"]; $tag = explode(" ", $value["tag"]); $title = $value["title"]; $description = $value["description"]; $catagory = $value["catagory"]; if ($type == 1) { $videoFile = __DIR__ . "/files_download/" . $youtube_id . ".mp4"; } else { $videoFile = __DIR__ . "/files_download/" . $title . ".mp4"; }
} $type = 2; } } if ($type != 2) { if (empty($title)) { die("Bạn chưa nhập title cho video"); } if (empty($des)) { die("Bạn chưa nhập description"); } } if (empty($chanel)) { die("Bạn chưa nhập channel"); } $pdo = new PDOImplement(); switch ($type) { case 0: case 1: $date_create = date("Y/m/d H:i:s"); var_dump($date_create); $query = "insert into youtube(youtube_id,title,description,catagory,type,link,date_create,upload)values('{$youtube_id}','{$title}','{$des}','{$chanel}',{$type},'{$link_video}','{$date_create}',false)"; var_dump($query); $pdo->ExecuteQuery($query); break; case 2: $query = "insert into channel(link_channel,catagory)values('{$channel_link}','{$chanel}') "; $pdo->ExecuteQuery($query); break; } }
function downloadfile() { $pdo = new PDOImplement(); $result = $pdo->ExecuteQuery("select youtube_id,title,type,link from youtube where upload=0 order by date_create desc limit 3"); var_dump($result); foreach ($result as $key => $value) { $video_id = $value["youtube_id"]; $videotype = $value["type"]; $link = $value["link"]; $videotitle = $value["title"]; if ($videotype == 0) { downloadvideo("", $videotitle, $video_id, $videotype, $link); } else { if (isset($video_id)) { $my_id = $video_id; if (strlen($my_id) > 11) { $url = parse_url($my_id); $my_id = NULL; if (is_array($url) && count($url) > 0 && isset($url['query']) && !empty($url['query'])) { $parts = explode('&', $url['query']); if (is_array($parts) && count($parts) > 0) { foreach ($parts as $p) { $pattern = '/^v\\=/'; if (preg_match($pattern, $p)) { $my_id = preg_replace($pattern, '', $p); break; } } } if (!$my_id) { echo '<p>No video id passed in</p>'; exit; } } else { echo '<p>Invalid url</p>'; exit; } } } else { echo '<p>No video id passed in</p>'; exit; } $my_video_info = 'http://www.youtube.com/get_video_info?&video_id=' . $my_id . '&asv=3&el=detailpage&hl=en_US'; //video details fix *1 $my_video_info = curlGet($my_video_info); /* TODO: Check return from curl for status code */ $thumbnail_url = $title = $url_encoded_fmt_stream_map = $type = $url = ''; parse_str($my_video_info); $my_title = $title; $cleanedtitle = clean($title); if (isset($url_encoded_fmt_stream_map)) { /* Now get the url_encoded_fmt_stream_map, and explode on comma */ $my_formats_array = explode(',', $url_encoded_fmt_stream_map); } else { echo '<p>No encoded format stream found.</p>'; echo '<p>Here is what we got from YouTube:</p>'; echo $my_video_info; } if (count($my_formats_array) == 0) { echo '<p>No format stream map found - was the video id correct?</p>'; exit; } /* create an array of available download formats */ $avail_formats[] = ''; $i = 0; $ipbits = $ip = $itag = $sig = $quality = ''; $expire = time(); foreach ($my_formats_array as $format) { parse_str($format); $type = explode(';', $type); if ($type[0] == "video/mp4") { $avail_formats[0]['itag'] = $itag; $avail_formats[0]['quality'] = $quality; $avail_formats[0]['type'] = $type[0]; $avail_formats[0]['url'] = urldecode($url) . '&signature=' . $sig; parse_str(urldecode($url)); $avail_formats[0]['expires'] = date("G:i:s T", $expire); $avail_formats[0]['ipbits'] = $ipbits; $avail_formats[0]['ip'] = $ip; } $i++; } //$redirect_url="download.php?mime=". $avail_formats[0]['type'] ."&title=". urlencode($my_title) ."&token=".base64_encode($avail_formats[0]['url']); //$mime=$avail_formats[0]['type']; if ($videotype == 1) { $videotitle = urlencode($my_title); } $token = base64_encode($avail_formats[0]['url']); var_dump($my_title); downloadvideo($token, $videotitle, $video_id, $videotype, $link); } //header("Location: $redirect_url"); } }