Advertisement
rhcp011235

Untitled

Sep 27th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2.  
  3. // Download MKBHD wallpapers
  4. // @john011235
  5. error_reporting(E_ERROR | E_PARSE);
  6.  
  7. class MyDB extends SQLite3 {
  8.     function __construct() {
  9.        $this->open('panels.db');
  10.     }
  11.  }
  12.  
  13.  $db = new MyDB();
  14.  if(!$db) {
  15.     echo $db->lastErrorMsg();
  16.  } else {
  17.     echo "Opened database successfully\n";
  18.  }
  19.  
  20.     $sql =<<<EOF
  21.       CREATE TABLE MKBHD_PANELS
  22.       (ID INT PRIMARY KEY     NOT NULL,
  23.       URL           TEXT    NOT NULL);
  24. EOF;
  25. $ret = $db->exec($sql);
  26. if(!$ret)
  27. {
  28.     echo $db->lastErrorMsg();
  29. } else {
  30.     echo "Table created successfully\n";
  31. }
  32.  
  33. if (!file_exists('./mkbhd_walls/')) {
  34.     mkdir('./mkbhd_walls', 0777, true);
  35. }
  36.  
  37.  
  38. $walls = file_get_contents('https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s');
  39. $decoded_json = json_decode($walls, false);
  40.  
  41. $wallpapers = $decoded_json->data;
  42. $i = 0;
  43.  
  44. foreach ($wallpapers as $key => $value)
  45. {
  46.     // Only download 4K/HD images
  47.     if ($value->dhd == "") continue;
  48.    
  49.     $id = $key;
  50.     $wallpaper_URL = $value->dhd;
  51.  
  52.     $sql =<<<EOF
  53.       INSERT INTO MKBHD_PANELS (ID,URL)
  54.       VALUES ($id, '$wallpaper_URL' );
  55. EOF;
  56. $ret = $db->exec($sql);
  57.    if(!$ret) {
  58.       //echo $db->lastErrorMsg();
  59.       if ($db->lastErrorMsg() == 'UNIQUE constraint failed: MKBHD_PANELS.ID')
  60.         continue;
  61.    } else {
  62.       echo "Records created successfully\n";
  63.    }
  64.    $image = file_get_contents($wallpaper_URL);
  65.    file_put_contents("./mkbhd_walls/wall_$i.jpg", $image);
  66.    $i++;
  67. }
  68. $db->close();
  69.  
  70. ?>
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement