Tero

[+] Topul melodiilor - România + Inserare în baza de date

Aug 4th, 2018
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1.         function youtube_ro(){
  2.             global $_COOKIE;
  3.             $results = array();
  4.  
  5.                 $html = file_get_contents("https://www.youtube.com/playlist?list=PLFgquLnL59akxkuW7czf5TvyjzcUMgaci") ;    
  6.                 $dom = new domDocument;
  7.                 $dom->loadHTML($html);
  8.                 $dom->preserveWhiteSpace = false;
  9.                 $find_id = '/data\-video-id=\"(.*?)\"/';
  10.                 $find_title = '/data\-title=\"(.*?)\"/';
  11.                 $find_length = '/<div\sclass=\"timestamp\"\>\<span .*?\>(.*?)\<\/span\><\/div>/';
  12.                 $new_file = new DOMXpath($dom);
  13.                 $i = 0;
  14.                 if($new_file->query('//tr')->length>0)
  15.                 {
  16.                     foreach($new_file->query('//tr') as $table){
  17.                         $i++;
  18.                         preg_match($find_id, $table->C14N(), $id);
  19.                         preg_match($find_title, $table->C14N(), $title);
  20.  
  21.                         $results[$i] = array(
  22.                 "id"   => $id[1],
  23.                 "titlu"=> $title[1]
  24.                         );
  25.                         if($i>=100)break;
  26.                      }
  27.  
  28.             }
  29.             return json_encode($results);
  30.         }
  31.  
  32. $test = youtube_ro();
  33. $list = json_decode($test, true);
  34. foreach ($list as $plm) {
  35.  
  36.     if(isset($plm['id']) && isset($plm['titlu']) && $pdo->query("select * from tabel where vid='".$plm['id']."'")->rowCount()==0) {
  37.         echo "[+] ".$plm['id']." - ".$plm['titlu']."\n";
  38.             $bib = $pdo->prepare("insert into tabel(titlu, vid) values (:titlu, :vid)");
  39.             $bib->execute(array("titlu" => $plm['titlu'], "vid" => $plm['id']));
  40.             //aici e inserarea in baza
  41.     } else {
  42.         echo "[-] ".$plm['id']." - ".$plm['titlu']."\n";
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment