Esempio n. 1
0
    /**
     * Process each game, updating game information from Giantbomb
     *
     * @param $gameInfo
     *
     * @return bool
     */
    public function updateGamesInfo($gameInfo)
    {
        $gen = new \Genres(['Settings' => $this->pdo]);
        $ri = new \ReleaseImage($this->pdo);
        $con = array();
        // Process Steam first before giantbomb
        // Steam has more details
        $this->_gameResults = [];
        $this->_getGame = new \Steam();
        $this->_classUsed = "steam";
        $this->_getGame->cookie = $this->cookie;
        $this->_getGame->searchTerm = $gameInfo['title'];
        if ($this->_getGame->search() !== false) {
            $this->_gameResults = $this->_getGame->getAll();
        }
        if (count($this->_gameResults) < 1) {
            $this->_getGame = new \Desura();
            $this->_classUsed = "desura";
            $this->_getGame->cookie = $this->cookie;
            $this->_getGame->searchTerm = $gameInfo['title'];
            if ($this->_getGame->search() !== false) {
                $this->_gameResults = $this->_getGame->getAll();
            }
        }
        if (count($this->_gameResults) < 1) {
            $this->_getGame = new \Greenlight();
            $this->_classUsed = "gl";
            $this->_getGame->cookie = $this->cookie;
            $this->_getGame->searchTerm = $gameInfo['title'];
            if ($this->_getGame->search() !== false) {
                $this->_gameResults = $this->_getGame->getAll();
            }
        }
        if (count($this->_gameResults) < 1) {
            $this->_gameResults = (array) $this->fetchGiantBombID($gameInfo['title']);
            if ($this->maxHitRequest === true) {
                return false;
            }
        }
        if (empty($this->_gameResults['title'])) {
            return false;
        }
        if (!is_array($this->_gameResults)) {
            return false;
        }
        if (count($this->_gameResults) > 1) {
            $genreName = '';
            switch ($this->_classUsed) {
                case "desura":
                    if (isset($this->_gameResults['cover'])) {
                        $con['coverurl'] = (string) $this->_gameResults['cover'];
                    }
                    if (isset($this->_gameResults['backdrop'])) {
                        $con['backdropurl'] = (string) $this->_gameResults['backdrop'];
                    }
                    $con['title'] = (string) $this->_gameResults['title'];
                    $con['asin'] = $this->_gameResults['desuragameid'];
                    $con['url'] = (string) $this->_gameResults['directurl'];
                    if (isset($this->_gameResults['gamedetails']['Publisher'])) {
                        $con['publisher'] = (string) $this->_gameResults['gamedetails']['Publisher'];
                    } else {
                        $con['publisher'] = "Unknown";
                    }
                    if (isset($this->_gameResults['rating'])) {
                        $con['esrb'] = (string) $this->_gameResults['rating'];
                    } else {
                        $con['esrb'] = "Not Rated";
                    }
                    if (isset($this->_gameResults['description'])) {
                        $con['review'] = trim(strip_tags((string) $this->_gameResults['description']));
                    }
                    if (isset($this->_gameResults['trailer'])) {
                        $con['trailer'] = (string) $this->_gameResults['trailer'];
                    }
                    if (isset($this->_gameResults['gamedetails']['Genre'])) {
                        $genres = (string) $this->_gameResults['gamedetails']['Genre'];
                        $genreName = $this->_matchGenre($genres);
                    }
                    break;
                case "gb":
                    $con['coverurl'] = (string) $this->_gameResults['image']['super_url'];
                    $con['title'] = (string) $this->_gameResults['name'];
                    $con['asin'] = $this->_gameID;
                    $con['url'] = (string) $this->_gameResults['site_detail_url'];
                    if (is_array($this->_gameResults['publishers'])) {
                        while (list($key) = each($this->_gameResults['publishers'])) {
                            if ($key == 0) {
                                $con['publisher'] = (string) $this->_gameResults['publishers'][$key]['name'];
                            }
                        }
                    } else {
                        $con['publisher'] = "Unknown";
                    }
                    if (is_array($this->_gameResults['original_game_rating'])) {
                        $con['esrb'] = (string) $this->_gameResults['original_game_rating'][0]['name'];
                    } else {
                        $con['esrb'] = (string) $this->_gameResults['original_game_rating']['name'];
                    }
                    $con['releasedate'] = (string) $this->_gameResults['original_release_date'];
                    if (isset($this->_gameResults['description'])) {
                        $con['review'] = trim(strip_tags((string) $this->_gameResults['description']));
                    }
                    if (isset($this->_gameResults['genres'][0]['name'])) {
                        $genres = (string) $this->_gameResults['genres'][0]['name'];
                        $genreName = $this->_matchGenre($genres);
                    }
                    break;
                case "gl":
                    if (isset($this->_gameResults['cover'])) {
                        $con['coverurl'] = (string) $this->_gameResults['cover'];
                    }
                    if (isset($this->_gameResults['backdrop'])) {
                        $con['backdropurl'] = (string) $this->_gameResults['backdrop'];
                    }
                    $con['title'] = (string) $this->_gameResults['title'];
                    $con['asin'] = $this->_gameResults['greenlightgameid'];
                    $con['url'] = (string) $this->_gameResults['directurl'];
                    $con['publisher'] = "Unknown";
                    $con['esrb'] = "Not Rated";
                    if (isset($this->_gameResults['description'])) {
                        $con['review'] = trim(strip_tags((string) $this->_gameResults['description']));
                    }
                    if (isset($this->_gameResults['trailer'])) {
                        $con['trailer'] = (string) $this->_gameResults['trailer'];
                    }
                    if (isset($this->_gameResults['gamedetails']['Genre'])) {
                        $genres = (string) $this->_gameResults['gamedetails']['Genre'];
                        $genreName = $this->_matchGenre($genres);
                    }
                    break;
                case "steam":
                    if (isset($this->_gameResults['cover'])) {
                        $con['coverurl'] = (string) $this->_gameResults['cover'];
                    }
                    if (isset($this->_gameResults['backdrop'])) {
                        $con['backdropurl'] = (string) $this->_gameResults['backdrop'];
                    }
                    $con['title'] = (string) $this->_gameResults['title'];
                    $con['asin'] = $this->_gameResults['steamgameid'];
                    $con['url'] = (string) $this->_gameResults['directurl'];
                    if (isset($this->_gameResults['gamedetails']['Publisher'])) {
                        $con['publisher'] = (string) $this->_gameResults['gamedetails']['Publisher'];
                    } else {
                        $con['publisher'] = "Unknown";
                    }
                    if (isset($this->_gameResults['rating'])) {
                        $con['esrb'] = (string) $this->_gameResults['rating'];
                    } else {
                        $con['esrb'] = "Not Rated";
                    }
                    if (!empty($this->_gameResults['gamedetails']['Release Date'])) {
                        $dateReleased = $this->_gameResults['gamedetails']['Release Date'];
                        if (!preg_match('#^\\s*(?P<month>\\w+)\\s+(?P<day>\\d{1,2}),?\\s+(?P<year>\\d{4})\\s*$#', $dateReleased)) {
                            if (preg_match('#^\\s*(?P<month>\\w+)\\s+(?P<year>\\d{4})\\s*$#', $dateReleased, $matches)) {
                                $dateReleased = "{$matches['month']} 1, {$matches['year']}";
                            }
                        }
                        $date = \DateTime::createFromFormat('M/j/Y', $dateReleased);
                        if ($date instanceof \DateTime) {
                            $con['releasedate'] = (string) $date->format('Y-m-d');
                        }
                    }
                    if (isset($this->_gameResults['description'])) {
                        $con['review'] = trim(strip_tags((string) $this->_gameResults['description']));
                    }
                    if (isset($this->_gameResults['trailer'])) {
                        $con['trailer'] = (string) $this->_gameResults['trailer'];
                    }
                    if (isset($this->_gameResults['gamedetails']['Genre'])) {
                        $genres = (string) $this->_gameResults['gamedetails']['Genre'];
                        $genreName = $this->_matchGenre($genres);
                    }
                    break;
                default:
                    return false;
            }
        } else {
            return false;
        }
        // Load genres.
        $defaultGenres = $gen->getGenres(\Genres::GAME_TYPE);
        $genreassoc = array();
        foreach ($defaultGenres as $dg) {
            $genreassoc[$dg['id']] = strtolower($dg['title']);
        }
        // Prepare database values.
        if (isset($con['coverurl'])) {
            $con['cover'] = 1;
        } else {
            $con['cover'] = 0;
        }
        if (isset($con['backdropurl'])) {
            $con['backdrop'] = 1;
        } else {
            $con['backdrop'] = 0;
        }
        if (!isset($con['trailer'])) {
            $con['trailer'] = 0;
        }
        if (empty($con['title'])) {
            $con['title'] = $gameInfo['title'];
        }
        if (!isset($con['releasedate'])) {
            $con['releasedate'] = "";
        }
        if ($con['releasedate'] == "''") {
            $con['releasedate'] = "";
        }
        if (!isset($con['review'])) {
            $con['review'] = 'No Review';
        }
        $con['classused'] = $this->_classUsed;
        if (empty($genreName)) {
            $genreName = 'Unknown';
        }
        if (in_array(strtolower($genreName), $genreassoc)) {
            $genreKey = array_search(strtolower($genreName), $genreassoc);
        } else {
            $genreKey = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\tINSERT INTO genres (title, type)\n\t\t\t\t\tVALUES (%s, %d)", $this->pdo->escapeString($genreName), \Genres::GAME_TYPE));
        }
        $con['gamesgenre'] = $genreName;
        $con['gamesgenreID'] = $genreKey;
        $check = $this->pdo->queryOneRow(sprintf('
				SELECT id
				FROM gamesinfo
				WHERE asin = %s', $this->pdo->escapeString($con['asin'])));
        if ($check === false) {
            $gamesId = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\tINSERT INTO gamesinfo\n\t\t\t\t\t\t(title, asin, url, publisher, genre_id, esrb, releasedate, review, cover, backdrop, trailer, classused, createddate, updateddate)\n\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %s, %s, NOW(), NOW())", $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $this->pdo->escapeString($con['publisher']), $con['gamesgenreID'] == -1 ? "null" : $con['gamesgenreID'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover'], $con['backdrop'], $this->pdo->escapeString($con['trailer']), $this->pdo->escapeString($con['classused'])));
        } else {
            $gamesId = $check['id'];
            $this->pdo->queryExec(sprintf('
					UPDATE gamesinfo
					SET
						title = %s, asin = %s, url = %s, publisher = %s, genre_id = %s,
						esrb = %s, releasedate = %s, review = %s, cover = %d, backdrop = %d, trailer = %s, classused = %s, updateddate = NOW()
					WHERE id = %d', $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $this->pdo->escapeString($con['publisher']), $con['gamesgenreID'] == -1 ? "null" : $con['gamesgenreID'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover'], $con['backdrop'], $this->pdo->escapeString($con['trailer']), $this->pdo->escapeString($con['classused']), $gamesId));
        }
        if ($gamesId) {
            if ($this->echoOutput) {
                $this->pdo->log->doEcho($this->pdo->log->header("Added/updated game: ") . $this->pdo->log->alternateOver("   Title:    ") . $this->pdo->log->primary($con['title']));
            }
            if ($con['cover'] === 1) {
                $con['cover'] = $ri->saveImage($gamesId, $con['coverurl'], $this->imgSavePath, 250, 250);
            }
            if ($con['backdrop'] === 1) {
                $con['backdrop'] = $ri->saveImage($gamesId . '-backdrop', $con['backdropurl'], $this->imgSavePath, 1920, 1024);
            }
        } else {
            if ($this->echoOutput) {
                $this->pdo->log->doEcho($this->pdo->log->headerOver("Nothing to update: ") . $this->pdo->log->primary($con['title'] . ' (PC)'));
            }
        }
        return $gamesId;
    }
Esempio n. 2
0
 public function updateMovieInfo($imdbId)
 {
     $ri = new ReleaseImage();
     if ($this->echooutput) {
         echo "fetching imdb info from tmdb - " . $imdbId . "\n";
     }
     //check themoviedb for imdb info
     $tmdb = $this->fetchTmdbProperties($imdbId);
     if (!$tmdb) {
         if ($this->echooutput) {
             echo "not found in tmdb\n";
         }
     }
     //check imdb for movie info
     $imdb = $this->fetchImdbProperties($imdbId);
     if (!$imdb) {
         if ($this->echooutput) {
             echo "unable to get movie info from imdb - " . $imdbId . "\n";
         }
     }
     if (!$imdb && !$tmdb) {
         return false;
     }
     $mov = array();
     $mov['imdb_id'] = $imdbId;
     $mov['tmdb_id'] = !isset($tmdb['tmdb_id']) || $tmdb['tmdb_id'] == '' ? "NULL" : $tmdb['tmdb_id'];
     //prefer tmdb cover over imdb cover
     $mov['cover'] = 0;
     if (isset($tmdb['cover']) && $tmdb['cover'] != '') {
         $mov['cover'] = $ri->saveImage($imdbId . '-cover', $tmdb['cover'], $this->imgSavePath);
     } elseif (isset($imdb['cover']) && $imdb['cover'] != '') {
         $mov['cover'] = $ri->saveImage($imdbId . '-cover', $imdb['cover'], $this->imgSavePath);
     }
     $mov['backdrop'] = 0;
     if (isset($tmdb['backdrop']) && $tmdb['backdrop'] != '') {
         $mov['backdrop'] = $ri->saveImage($imdbId . '-backdrop', $tmdb['backdrop'], $this->imgSavePath, 1024, 768);
     }
     $mov['title'] = '';
     if (isset($imdb['title']) && $imdb['title'] != '') {
         $mov['title'] = $imdb['title'];
     } elseif (isset($tmdb['title']) && $tmdb['title'] != '') {
         $mov['title'] = $tmdb['title'];
     }
     $mov['title'] = html_entity_decode($mov['title'], ENT_QUOTES, 'UTF-8');
     $mov['rating'] = '';
     if (isset($imdb['rating']) && $imdb['rating'] != '') {
         $mov['rating'] = $imdb['rating'];
     } elseif (isset($tmdb['rating']) && $tmdb['rating'] != '') {
         $mov['rating'] = $tmdb['rating'];
     }
     $mov['tagline'] = '';
     if (isset($imdb['tagline']) && $imdb['tagline'] != '') {
         $mov['tagline'] = html_entity_decode($imdb['tagline'], ENT_QUOTES, 'UTF-8');
     }
     $mov['plot'] = '';
     if (isset($imdb['plot']) && $imdb['plot'] != '') {
         $mov['plot'] = $imdb['plot'];
     } elseif (isset($tmdb['plot']) && $tmdb['plot'] != '') {
         $mov['plot'] = $tmdb['plot'];
     }
     $mov['plot'] = html_entity_decode($mov['plot'], ENT_QUOTES, 'UTF-8');
     $mov['year'] = '';
     if (isset($imdb['year']) && $imdb['year'] != '') {
         $mov['year'] = $imdb['year'];
     } elseif (isset($tmdb['year']) && $tmdb['year'] != '') {
         $mov['year'] = $tmdb['year'];
     }
     $mov['genre'] = '';
     if (isset($tmdb['genre']) && $tmdb['genre'] != '') {
         $mov['genre'] = $tmdb['genre'];
     } elseif (isset($imdb['genre']) && $imdb['genre'] != '') {
         $mov['genre'] = $imdb['genre'];
     }
     if (is_array($mov['genre'])) {
         $mov['genre'] = implode(', ', array_unique($mov['genre']));
     }
     $mov['genre'] = html_entity_decode($mov['genre'], ENT_QUOTES, 'UTF-8');
     $mov['director'] = '';
     if (isset($imdb['director']) && $imdb['director'] != '') {
         $mov['director'] = is_array($imdb['director']) ? implode(', ', array_unique($imdb['director'])) : $imdb['director'];
     }
     $mov['director'] = html_entity_decode($mov['director'], ENT_QUOTES, 'UTF-8');
     $mov['actors'] = '';
     if (isset($imdb['actors']) && $imdb['actors'] != '') {
         $mov['actors'] = is_array($imdb['actors']) ? implode(', ', array_unique($imdb['actors'])) : $imdb['actors'];
     }
     $mov['actors'] = html_entity_decode($mov['actors'], ENT_QUOTES, 'UTF-8');
     $mov['language'] = '';
     if (isset($imdb['language']) && $imdb['language'] != '') {
         $mov['language'] = is_array($imdb['language']) ? implode(', ', array_unique($imdb['language'])) : $imdb['language'];
     }
     $mov['language'] = html_entity_decode($mov['language'], ENT_QUOTES, 'UTF-8');
     $db = new DB();
     $query = sprintf("\n\t\t\tINSERT INTO movieinfo \n\t\t\t\t(imdbID, tmdbID, title, rating, tagline, plot, year, genre, director, actors, language, cover, backdrop, createddate, updateddate)\n\t\t\tVALUES \n\t\t\t\t(%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, NOW(), NOW())\n\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\timdbID=%d, tmdbID=%s, title=%s, rating=%s, tagline=%s, plot=%s, year=%s, genre=%s, director=%s, actors=%s, language=%s, cover=%d, backdrop=%d, updateddate=NOW()", $mov['imdb_id'], $mov['tmdb_id'], $db->escapeString($mov['title']), $db->escapeString($mov['rating']), $db->escapeString($mov['tagline']), $db->escapeString($mov['plot']), $db->escapeString($mov['year']), $db->escapeString($mov['genre']), $db->escapeString($mov['director']), $db->escapeString($mov['actors']), $db->escapeString($mov['language']), $mov['cover'], $mov['backdrop'], $mov['imdb_id'], $mov['tmdb_id'], $db->escapeString($mov['title']), $db->escapeString($mov['rating']), $db->escapeString($mov['tagline']), $db->escapeString($mov['plot']), $db->escapeString($mov['year']), $db->escapeString($mov['genre']), $db->escapeString($mov['director']), $db->escapeString($mov['actors']), $db->escapeString($mov['language']), $mov['cover'], $mov['backdrop']);
     $movieId = $db->queryInsert($query);
     if ($movieId) {
         if ($this->echooutput) {
             echo "added/updated movie: " . $mov['title'] . " (" . $mov['year'] . ") - " . $mov['imdb_id'] . "\n";
         }
     } else {
         if ($this->echooutput) {
             echo "nothing to update for movie: " . $mov['title'] . " (" . $mov['year'] . ") - " . $mov['imdb_id'] . "\n";
         }
     }
     return $movieId;
 }
Esempio n. 3
0
 /**
  * @param      $title
  * @param      $year
  * @param null $amazdata
  *
  * @return bool
  */
 public function updateMusicInfo($title, $year, $amazdata = null)
 {
     $gen = new \Genres(['Settings' => $this->pdo]);
     $ri = new \ReleaseImage($this->pdo);
     $titlepercent = 0;
     $mus = [];
     if ($title != '') {
         $amaz = $this->fetchAmazonProperties($title);
     } else {
         if ($amazdata != null) {
             $amaz = $amazdata;
         } else {
             $amaz = false;
         }
     }
     if (!$amaz) {
         return false;
     }
     if (isset($amaz->Items->Item->ItemAttributes->Title)) {
         $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
         if (empty($mus['title'])) {
             return false;
         }
     } else {
         return false;
     }
     // Load genres.
     $defaultGenres = $gen->getGenres(\Genres::MUSIC_TYPE);
     $genreassoc = [];
     foreach ($defaultGenres as $dg) {
         $genreassoc[$dg['id']] = strtolower($dg['title']);
     }
     // Get album properties.
     $mus['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL;
     if ($mus['coverurl'] != "") {
         $mus['cover'] = 1;
     } else {
         $mus['cover'] = 0;
     }
     $mus['asin'] = (string) $amaz->Items->Item->ASIN;
     $mus['url'] = (string) $amaz->Items->Item->DetailPageURL;
     $mus['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $mus['url']);
     $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank;
     if ($mus['salesrank'] == "") {
         $mus['salesrank'] = 'null';
     }
     $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist;
     if (empty($mus['artist'])) {
         $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Creator;
         if (empty($mus['artist'])) {
             $mus['artist'] = "";
         }
     }
     $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
     $mus['releasedate'] = $this->pdo->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate);
     if ($mus['releasedate'] == "''") {
         $mus['releasedate'] = 'null';
     }
     $mus['review'] = "";
     if (isset($amaz->Items->Item->EditorialReviews)) {
         $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
     }
     $mus['year'] = $year;
     if ($mus['year'] == "") {
         $mus['year'] = $mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y");
     }
     $mus['tracks'] = "";
     if (isset($amaz->Items->Item->Tracks)) {
         $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc;
         $tracks = $tmpTracks['Track'];
         $mus['tracks'] = is_array($tracks) && !empty($tracks) ? implode('|', $tracks) : '';
     }
     similar_text($mus['artist'] . " " . $mus['title'], $title, $titlepercent);
     if ($titlepercent < 60) {
         return false;
     }
     $genreKey = -1;
     $genreName = '';
     if (isset($amaz->Items->Item->BrowseNodes)) {
         // Had issues getting this out of the browsenodes obj.
         // Workaround is to get the xml and load that into its own obj.
         $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml();
         $amazGenresObj = simplexml_load_string($amazGenresXml);
         $amazGenres = $amazGenresObj->xpath("//BrowseNodeId");
         foreach ($amazGenres as $amazGenre) {
             $currNode = trim($amazGenre[0]);
             if (empty($genreName)) {
                 $genreMatch = $this->matchBrowseNode($currNode);
                 if ($genreMatch !== false) {
                     $genreName = $genreMatch;
                     break;
                 }
             }
         }
         if (in_array(strtolower($genreName), $genreassoc)) {
             $genreKey = array_search(strtolower($genreName), $genreassoc);
         } else {
             $genreKey = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\t\t\t\t\tINSERT INTO genres (title, type)\n\t\t\t\t\t\t\t\t\t\tVALUES (%s, %d)", $this->pdo->escapeString($genreName), \Genres::MUSIC_TYPE));
         }
     }
     $mus['musicgenre'] = $genreName;
     $mus['musicgenreid'] = $genreKey;
     $check = $this->pdo->queryOneRow(sprintf('SELECT id FROM musicinfo WHERE asin = %s', $this->pdo->escapeString($mus['asin'])));
     if ($check === false) {
         $musicId = $this->pdo->queryInsert(sprintf("INSERT INTO musicinfo (title, asin, url, salesrank, artist, publisher, " . "releasedate, review, year, genreID, tracks, cover, createddate, updateddate) VALUES " . "(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())", $this->pdo->escapeString($mus['title']), $this->pdo->escapeString($mus['asin']), $this->pdo->escapeString($mus['url']), $mus['salesrank'], $this->pdo->escapeString($mus['artist']), $this->pdo->escapeString($mus['publisher']), $mus['releasedate'], $this->pdo->escapeString($mus['review']), $this->pdo->escapeString($mus['year']), $mus['musicgenreid'] == -1 ? "null" : $mus['musicgenreid'], $this->pdo->escapeString($mus['tracks']), $mus['cover']));
     } else {
         $musicId = $check['id'];
         $this->pdo->queryExec(sprintf('UPDATE musicinfo SET title = %s, asin = %s, url = %s, salesrank = %s, artist = %s, ' . 'publisher = %s, releasedate = %s, review = %s, year = %s, genreID = %s, tracks = %s, cover = %s, ' . 'updateddate = NOW() WHERE id = %d', $this->pdo->escapeString($mus['title']), $this->pdo->escapeString($mus['asin']), $this->pdo->escapeString($mus['url']), $mus['salesrank'], $this->pdo->escapeString($mus['artist']), $this->pdo->escapeString($mus['publisher']), $mus['releasedate'], $this->pdo->escapeString($mus['review']), $this->pdo->escapeString($mus['year']), $mus['musicgenreid'] == -1 ? "null" : $mus['musicgenreid'], $this->pdo->escapeString($mus['tracks']), $mus['cover'], $musicId));
     }
     if ($musicId) {
         if ($this->echooutput) {
             $this->pdo->log->doEcho($this->pdo->log->header("\nAdded/updated album: ") . $this->pdo->log->alternateOver("   Artist: ") . $this->pdo->log->primary($mus['artist']) . $this->pdo->log->alternateOver("   Title:  ") . $this->pdo->log->primary($mus['title']) . $this->pdo->log->alternateOver("   Year:   ") . $this->pdo->log->primary($mus['year']));
         }
         $mus['cover'] = $ri->saveImage($musicId, $mus['coverurl'], $this->imgSavePath, 250, 250);
     } else {
         if ($this->echooutput) {
             if ($mus["artist"] == "") {
                 $artist = "";
             } else {
                 $artist = "Artist: " . $mus['artist'] . ", Album: ";
             }
             $this->pdo->log->doEcho($this->pdo->log->headerOver("Nothing to update: ") . $this->pdo->log->primaryOver($artist . $mus['title'] . " (" . $mus['year'] . ")"));
         }
     }
     return $musicId;
 }
Esempio n. 4
0
    protected function _updateConsoleTable($con = [])
    {
        $ri = new \ReleaseImage($this->pdo);
        $check = $this->pdo->queryOneRow(sprintf('
							SELECT id
							FROM consoleinfo
							WHERE asin = %s', $this->pdo->escapeString($con['asin'])));
        if ($check === false) {
            $consoleId = $this->pdo->queryInsert(sprintf("INSERT INTO consoleinfo (title, asin, url, salesrank, platform, publisher, genreid, esrb, releasedate, review, cover, createddate, updateddate)\n\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, NOW(), NOW())", $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $con['salesrank'], $this->pdo->escapeString($con['platform']), $this->pdo->escapeString($con['publisher']), $con['consolegenreid'] == -1 ? "null" : $con['consolegenreid'], $this->pdo->escapeString($con['esrb']), $con['releasedate'] != "" ? $this->pdo->escapeString($con['releasedate']) : "null", $this->pdo->escapeString(substr($con['review'], 0, 3000)), $con['cover']));
            if ($con['cover'] === 1) {
                $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
            }
        } else {
            $consoleId = $check['id'];
            if ($con['cover'] === 1) {
                $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
            }
            $this->update($consoleId, $con['title'], $con['asin'], $con['url'], $con['salesrank'], $con['platform'], $con['publisher'], isset($con['releasedate']) ? $con['releasedate'] : null, $con['esrb'], $con['cover'], $con['consolegenreid'], isset($con['review']) ? $con['review'] : null);
        }
        return $consoleId;
    }
 /**
  * Update musicinfo from external source
  */
 public function updateMusicInfo($artist, $album, $year)
 {
     $db = new DB();
     $gen = new Genres();
     $ri = new ReleaseImage();
     $mus = array();
     $amaz = $this->fetchAmazonProperties($artist . " " . $album);
     if (!$amaz) {
         return false;
     }
     sleep(1);
     //load genres
     $defaultGenres = $gen->getGenres(Genres::MUSIC_TYPE);
     $genreassoc = array();
     foreach ($defaultGenres as $dg) {
         $genreassoc[$dg['ID']] = strtolower($dg['title']);
     }
     //
     // get album properties
     //
     $mus['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL;
     if ($mus['coverurl'] != "") {
         $mus['cover'] = 1;
     } else {
         $mus['cover'] = 0;
     }
     $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
     if (empty($mus['title'])) {
         $mus['title'] = $album;
     }
     $mus['asin'] = (string) $amaz->Items->Item->ASIN;
     $mus['url'] = (string) $amaz->Items->Item->DetailPageURL;
     $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank;
     if ($mus['salesrank'] == "") {
         $mus['salesrank'] = 'null';
     }
     $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist;
     if (empty($mus['artist'])) {
         $mus['artist'] = $artist;
     }
     $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
     $mus['releasedate'] = $db->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate);
     if ($mus['releasedate'] == "''") {
         $mus['releasedate'] = 'null';
     }
     $mus['review'] = "";
     if (isset($amaz->Items->Item->EditorialReviews)) {
         $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
     }
     $mus['year'] = $year;
     if ($mus['year'] == "") {
         $mus['year'] = $mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y");
     }
     $mus['tracks'] = "";
     if (isset($amaz->Items->Item->Tracks)) {
         $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc;
         $tracks = $tmpTracks['Track'];
         $mus['tracks'] = is_array($tracks) && !empty($tracks) ? implode('|', $tracks) : '';
     }
     //This is to verify the result back from amazon was at least somewhat related to what was intended.
     //If you are debugging releases comment out the following code to show all info
     $match = similar_text($artist, $mus['artist'], $artistpercent);
     //echo("Matched: Artist Percentage: $artistpercent%");
     $match = similar_text($album, $mus['title'], $albumpercent);
     //echo("Matched: Album Percentage: $albumpercent%");
     //If the artist is Various Artists, assume artist is 100%
     if (preg_match('/various/i', $artist)) {
         $artistpercent = '100';
     }
     //If the Artist is less than 80% album must be 100%
     if ($artistpercent < '80') {
         if ($albumpercent != '100') {
             return false;
         }
     }
     //If the album is ever under 30%, it's probably not a match.
     if ($albumpercent < '30') {
         return false;
     }
     //This is the end of the recheck code. Comment out to this point to show all info.
     $genreKey = -1;
     $genreName = '';
     if (isset($amaz->Items->Item->BrowseNodes)) {
         //had issues getting this out of the browsenodes obj
         //workaround is to get the xml and load that into its own obj
         $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml();
         $amazGenresObj = simplexml_load_string($amazGenresXml);
         $amazGenres = $amazGenresObj->xpath("//BrowseNodeId");
         foreach ($amazGenres as $amazGenre) {
             $currNode = trim($amazGenre[0]);
             if (empty($genreName)) {
                 $genreMatch = $this->matchBrowseNode($currNode);
                 if ($genreMatch !== false) {
                     $genreName = $genreMatch;
                     break;
                 }
             }
         }
         $genreKey = $gen->getOrAddGenreKey($genreName, $genreassoc);
     }
     $mus['musicgenreID'] = $genreKey;
     $musicId = $this->addUpdateMusicInfo($mus['title'], $mus['asin'], $mus['url'], $mus['salesrank'], $mus['artist'], $mus['publisher'], $mus['releasedate'], $mus['review'], $mus['year'], $mus['musicgenreID'], $mus['tracks'], $mus['cover']);
     if ($musicId) {
         //if ($this->echooutput)
         //	echo "added/updated album: ".$mus['title']." (".$mus['year'].")\n";
         $mus['cover'] = $ri->saveImage($musicId, $mus['coverurl'], $this->imgSavePath, 250, 250);
     }
     return $musicId;
 }
Esempio n. 6
0
 public function getSample($ramdrive, $ffmpeginfo, $releaseguid)
 {
     $ri = new ReleaseImage();
     $retval = false;
     $samplefiles = glob($ramdrive . '*.*');
     if (is_array($samplefiles)) {
         foreach ($samplefiles as $samplefile) {
             if (preg_match("/\\.(" . $this->mediafileregex . ")\$/i", $samplefile)) {
                 echo "Getting Sample for {$samplefile}\n";
                 $execstring = '"' . $ffmpeginfo . '" -loglevel quiet -vframes 300 -sameq -i "' . $samplefile . '" "' . $ramdrive . 'zzzz%03d.jpg"';
                 $output = runCmd($execstring);
                 $all_files = scandir($ramdrive, 1);
                 if (preg_match("/zzzz\\d{3}\\.jpg/", $all_files[1])) {
                     echo "-Using {$all_files[1]}\n";
                     $ri->saveImage($releaseguid . '_thumb', $ramdrive . $all_files[1], $ri->imgSavePath, 800, 600);
                     $retval = true;
                 } else {
                     echo "-Failed\n";
                 }
                 //clean up all files
                 foreach (glob($ramdrive . '*.jpg') as $v) {
                     unlink($v);
                 }
             }
         }
     } else {
         echo "Couldn't open temp drive " . $ramdrive;
     }
     return $retval;
 }
 /**
  * Delete a preview associated with a release and update the release to indicate it doesnt have one.
  */
 public function deletePreview($guid)
 {
     $this->updateHasPreview($guid, 0);
     $ri = new ReleaseImage();
     $ri->delete($guid);
 }
Esempio n. 8
0
    /**
     * Deletes a single release by GUID, and all the corresponding files.
     *
     * @param array        $identifiers ['g' => Release GUID(mandatory), 'id => ReleaseID(optional, pass false)]
     * @param NZB          $nzb
     * @param ReleaseImage $releaseImage
     */
    public function deleteSingle($identifiers, $nzb, $releaseImage)
    {
        // Delete NZB from disk.
        $nzbPath = $nzb->getNZBPath($identifiers['g']);
        if ($nzbPath) {
            @unlink($nzbPath);
        }
        // Delete images.
        $releaseImage->delete($identifiers['g']);
        //Delete from sphinx.
        $this->sphinxSearch->deleteRelease($identifiers, $this->pdo);
        // Delete from DB.
        $this->pdo->queryDelete(sprintf('
				DELETE r, rn, rc, uc, rf, ra, rs, rv, re
				FROM releases r
				LEFT OUTER JOIN releasenfo rn ON rn.releaseid = r.id
				LEFT OUTER JOIN releasecomment rc ON rc.releaseid = r.id
				LEFT OUTER JOIN usercart uc ON uc.releaseid = r.id
				LEFT OUTER JOIN releasefiles rf ON rf.releaseid = r.id
				LEFT OUTER JOIN releaseaudio ra ON ra.releaseid = r.id
				LEFT OUTER JOIN releasesubs rs ON rs.releaseid = r.id
				LEFT OUTER JOIN releasevideo rv ON rv.releaseid = r.id
				LEFT OUTER JOIN releaseextrafull re ON re.releaseid = r.id
				WHERE r.guid = %s', $this->pdo->escapeString($identifiers['g'])));
    }
 /**
  * Process all untagged releases in the anime category.
  */
 public function processAnimeReleases()
 {
     $numtoProcess = 100;
     $db = new DB();
     $ri = new ReleaseImage();
     $s = new Sites();
     $site = $s->get();
     /**
      * Grab a batch of 1000 releases and process until we have finished them, or hit the max configured
      * API requests in an attempt to avoid flooding AniDB and then getting throttled.
      *
      * Most requests will be hitting our local DB, so we want to go through those as quick as possible.
      */
     $numApiRequests = 0;
     $maxApiRequests = 5;
     $numSuccess = 0;
     $totalProcessed = 0;
     $results = $db->query(sprintf("SELECT searchname, ID FROM releases WHERE anidbID IS NULL AND categoryID IN ( SELECT ID FROM category WHERE categoryID = %d ) ORDER BY postdate DESC limit %d ", Category::CAT_TV_ANIME, $numtoProcess));
     $numResults = count($results);
     if (count($results) > 0) {
         if ($this->echooutput) {
             echo "AniDB   : Processing " . $numResults . " anime releases\n";
         }
         foreach ($results as $arr) {
             if ($numApiRequests >= $maxApiRequests) {
                 break;
             }
             $totalProcessed++;
             /**
              * Anime NZB filenames during imports get their [] brackets stripped from around the release group name.
              * This causes problems with the regexes finding the real anime title.
              * This section uses the NFO file, if it exists, to look up the "Complete name" field to use instead of the filename.
              */
             if ($site->lookupnfo == 1) {
                 // Look up the nfo file for this release.
                 $nfoRes = $db->queryOneRow(sprintf("select uncompress(nfo) as nfo from releasenfo where releaseID = %d", $arr['ID']));
                 // If there is one, then check if there is a "Complete name : <name>" entry.
                 if (!empty($nfoRes)) {
                     preg_match("/Complete name[ ]*:[ ]*(?P<completeName>.+)/i", $nfoRes['nfo'], $matches);
                     $completeName = array_key_exists('completeName', $matches) ? $matches['completeName'] : "";
                     if (!empty($completeName)) {
                         // Found a complete name, use this instead of the searchname.
                         $arr['searchname'] = $completeName;
                     }
                 }
             }
             $cleanFilename = $this->cleanFilename($arr['searchname']);
             $anidbID = $this->getanidbID($cleanFilename['title']);
             if (!$anidbID) {
                 $db->exec(sprintf("update releases SET anidbID = %d, tvinfoID = %d WHERE ID = %d", -1, -2, $arr["ID"]));
                 continue;
             }
             if ($this->echooutput) {
                 echo 'AniDB   : Looking up: ' . htmlentities($arr['searchname']) . "\n";
             }
             $AniDBAPIArray = $this->getAnimeInfo($anidbID);
             $lastUpdate = isset($AniDBAPIArray['createddate']) && time() - strtotime($AniDBAPIArray['createddate']) > 604800;
             if (!$AniDBAPIArray || $lastUpdate) {
                 $numApiRequests++;
                 $AniDBAPIArray = $this->AniDBAPI($anidbID);
                 if (!$lastUpdate) {
                     $this->addTitle($AniDBAPIArray);
                 } else {
                     $this->updateTitle($AniDBAPIArray['anidbID'], $AniDBAPIArray['title'], $AniDBAPIArray['type'], $AniDBAPIArray['startdate'], $AniDBAPIArray['enddate'], $AniDBAPIArray['related'], $AniDBAPIArray['creators'], $AniDBAPIArray['description'], $AniDBAPIArray['rating'], $AniDBAPIArray['categories'], $AniDBAPIArray['characters'], $AniDBAPIArray['epnos'], $AniDBAPIArray['airdates'], $AniDBAPIArray['episodetitles']);
                 }
                 if ($AniDBAPIArray['picture']) {
                     $ri->saveImage($AniDBAPIArray['anidbID'], 'http://img7.anidb.net/pics/anime/' . $AniDBAPIArray['picture'], $this->imgSavePath);
                 }
             }
             if ($AniDBAPIArray['anidbID']) {
                 $epno = explode('|', $AniDBAPIArray['epnos']);
                 $airdate = explode('|', $AniDBAPIArray['airdates']);
                 $episodetitle = explode('|', $AniDBAPIArray['episodetitles']);
                 $offset = -1;
                 for ($i = 0; $i < count($epno); $i++) {
                     if ($cleanFilename['epno'] == $epno[$i]) {
                         $offset = $i;
                         break;
                     }
                 }
                 $airdate = isset($airdate[$offset]) ? $airdate[$offset] : $AniDBAPIArray['startdate'];
                 $episodetitle = isset($episodetitle[$offset]) ? $episodetitle[$offset] : $cleanFilename['epno'];
                 $tvtitle = $episodetitle !== 'Complete Movie' && $episodetitle !== $cleanFilename['epno'] ? $cleanFilename['epno'] . " - " . $episodetitle : $episodetitle;
                 if ($this->echooutput) {
                     echo 'AniDB   : Found ' . $AniDBAPIArray['anidbID'] . " - " . $AniDBAPIArray['title'] . "\n";
                 }
                 $db->exec(sprintf("update releases SET episode=%s, tvtitle=%s, tvairdate=%s, anidbID=%d, tvinfoID=%d WHERE ID = %d", $db->escapeString($cleanFilename['epno']), $db->escapeString($tvtitle), $db->escapeString($airdate), $AniDBAPIArray['anidbID'], -2, $arr["ID"]));
                 $numSuccess++;
             }
         }
         if ($this->echooutput) {
             echo "AniDB   : " . $numApiRequests . " AniDB API requests performed.\n";
             echo "AniDB   : " . $numSuccess . " anidbIDs parsed successfully.\n";
             echo "AniDB   : " . $totalProcessed . " anime releases processed.\n";
         }
     }
 }
Esempio n. 10
0
    public function updateBookInfo($bookInfo = '', $amazdata = null)
    {
        $ri = new \ReleaseImage($this->pdo);
        $book = [];
        $amaz = false;
        if ($bookInfo != '') {
            $amaz = $this->fetchAmazonProperties($bookInfo);
        } else {
            if ($amazdata != null) {
                $amaz = $amazdata;
            }
        }
        if (!$amaz) {
            return false;
        }
        $book['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
        $book['author'] = (string) $amaz->Items->Item->ItemAttributes->Author;
        $book['asin'] = (string) $amaz->Items->Item->ASIN;
        $book['isbn'] = (string) $amaz->Items->Item->ItemAttributes->ISBN;
        if ($book['isbn'] == '') {
            $book['isbn'] = 'null';
        }
        $book['ean'] = (string) $amaz->Items->Item->ItemAttributes->EAN;
        if ($book['ean'] == '') {
            $book['ean'] = 'null';
        }
        $book['url'] = (string) $amaz->Items->Item->DetailPageURL;
        $book['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $book['url']);
        $book['salesrank'] = (string) $amaz->Items->Item->SalesRank;
        if ($book['salesrank'] == '') {
            $book['salesrank'] = 'null';
        }
        $book['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
        if ($book['publisher'] == '') {
            $book['publisher'] = 'null';
        }
        $book['publishdate'] = date('Y-m-d', strtotime((string) $amaz->Items->Item->ItemAttributes->PublicationDate));
        if ($book['publishdate'] == '') {
            $book['publishdate'] = 'null';
        }
        $book['pages'] = (string) $amaz->Items->Item->ItemAttributes->NumberOfPages;
        if ($book['pages'] == '') {
            $book['pages'] = 'null';
        }
        if (isset($amaz->Items->Item->EditorialReviews->EditorialReview->Content)) {
            $book['overview'] = strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content);
            if ($book['overview'] == '') {
                $book['overview'] = 'null';
            }
        } else {
            $book['overview'] = 'null';
        }
        if (isset($amaz->Items->Item->BrowseNodes->BrowseNode->Name)) {
            $book['genre'] = (string) $amaz->Items->Item->BrowseNodes->BrowseNode->Name;
            if ($book['genre'] == '') {
                $book['genre'] = 'null';
            }
        } else {
            $book['genre'] = 'null';
        }
        $book['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL;
        if ($book['coverurl'] != '') {
            $book['cover'] = 1;
        } else {
            $book['cover'] = 0;
        }
        $check = $this->pdo->queryOneRow(sprintf('SELECT id FROM bookinfo WHERE asin = %s', $this->pdo->escapeString($book['asin'])));
        if ($check === false) {
            $bookId = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\t\t\t\tINSERT INTO bookinfo\n\t\t\t\t\t\t\t\t\t(title, author, asin, isbn, ean, url, salesrank, publisher, publishdate, pages,\n\t\t\t\t\t\t\t\t\toverview, genre, cover, createddate, updateddate)\n\t\t\t\t\t\t\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())", $this->pdo->escapeString($book['title']), $this->pdo->escapeString($book['author']), $this->pdo->escapeString($book['asin']), $this->pdo->escapeString($book['isbn']), $this->pdo->escapeString($book['ean']), $this->pdo->escapeString($book['url']), $book['salesrank'], $this->pdo->escapeString($book['publisher']), $this->pdo->escapeString($book['publishdate']), $book['pages'], $this->pdo->escapeString($book['overview']), $this->pdo->escapeString($book['genre']), $book['cover']));
        } else {
            $bookId = $check['id'];
            $this->pdo->queryExec(sprintf('
							UPDATE bookinfo
							SET title = %s, author = %s, asin = %s, isbn = %s, ean = %s, url = %s, salesrank = %s, publisher = %s,
								publishdate = %s, pages = %s, overview = %s, genre = %s, cover = %d, updateddate = NOW()
							WHERE id = %d', $this->pdo->escapeString($book['title']), $this->pdo->escapeString($book['author']), $this->pdo->escapeString($book['asin']), $this->pdo->escapeString($book['isbn']), $this->pdo->escapeString($book['ean']), $this->pdo->escapeString($book['url']), $book['salesrank'], $this->pdo->escapeString($book['publisher']), $this->pdo->escapeString($book['publishdate']), $book['pages'], $this->pdo->escapeString($book['overview']), $this->pdo->escapeString($book['genre']), $book['cover'], $bookId));
        }
        if ($bookId) {
            if ($this->echooutput) {
                $this->pdo->log->doEcho($this->pdo->log->header("Added/updated book: "));
                if ($book['author'] !== '') {
                    $this->pdo->log->doEcho($this->pdo->log->alternateOver("   Author: ") . $this->pdo->log->primary($book['author']));
                }
                echo $this->pdo->log->alternateOver("   Title: ") . $this->pdo->log->primary(" " . $book['title']);
                if ($book['genre'] !== 'null') {
                    $this->pdo->log->doEcho($this->pdo->log->alternateOver("   Genre: ") . $this->pdo->log->primary(" " . $book['genre']));
                }
            }
            $book['cover'] = $ri->saveImage($bookId, $book['coverurl'], $this->imgSavePath, 250, 250);
        } else {
            if ($this->echooutput) {
                $this->pdo->log->doEcho($this->pdo->log->header('Nothing to update: ') . $this->pdo->log->header($book['author'] . ' - ' . $book['title']));
            }
        }
        return $bookId;
    }
Esempio n. 11
0
 /**
  * Determine if a bookinfo can be found locally, if not query amazon, strip out it 
  * properties and update the database.
  */
 public function updateBookInfo($author, $title)
 {
     $db = new DB();
     $ri = new ReleaseImage();
     $mus = array();
     $amaz = $this->fetchAmazonProperties($author . " " . $title);
     if (!$amaz) {
         //echo "tried to lookup ".$author." ".$title;
         return false;
     }
     sleep(1);
     //
     // get album properties
     //
     $item = array();
     $item["asin"] = (string) $amaz->Items->Item->ASIN;
     $item["url"] = (string) $amaz->Items->Item->DetailPageURL;
     $item["coverurl"] = (string) $amaz->Items->Item->LargeImage->URL;
     if ($item['coverurl'] != "") {
         $item['cover'] = 1;
     } else {
         $item['cover'] = 0;
     }
     $item["author"] = (string) $amaz->Items->Item->ItemAttributes->Author;
     $item["dewey"] = (string) $amaz->Items->Item->ItemAttributes->DeweyDecimalNumber;
     $item["ean"] = (string) $amaz->Items->Item->ItemAttributes->EAN;
     $item["isbn"] = (string) $amaz->Items->Item->ItemAttributes->ISBN;
     $item["publisher"] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
     $item["publishdate"] = (string) $amaz->Items->Item->ItemAttributes->PublicationDate;
     $item["pages"] = (string) $amaz->Items->Item->ItemAttributes->NumberOfPages;
     $item["title"] = (string) $amaz->Items->Item->ItemAttributes->Title;
     $item["review"] = "";
     if (isset($amaz->Items->Item->EditorialReviews)) {
         $item["review"] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
     }
     //This is to verify the result back from amazon was at least somewhat related to what was intended.
     //If you are debugging releases comment out the following code to show all info
     $match = similar_text($author, $item["author"], $authorpercent);
     $match = similar_text($title, $item['title'], $titlepercent);
     //If the author is less than 80% album must be 100%
     if ($authorpercent < '60') {
         if ($titlepercent != '100') {
             //echo "\nAuthor Under 80 Title Under 100 \n".$author." - ".$item['author']." - ".$authorpercent."\n";
             $temptitle = $title;
             $tempauthor = $author;
             $title = $tempauthor;
             $author = $temptitle;
             $match = similar_text($author, $item['author'], $authorpercent);
             $match = similar_text($title, $item['title'], $titlepercent);
             if ($authorpercent < '60') {
                 if ($titlepercent != '100') {
                     //echo "\nAuthor Under 80 Title Under 100 second check\n".$author." - ".$item['author']." - ".$authorpercent."\n";
                     //echo $title." - ".$item['title']." - ".$titlepercent."\n";
                     return false;
                 }
             }
         }
     }
     //If the title is ever under 30%, it's probably not a match.
     if ($titlepercent < '30') {
         //echo "Title Under 30 ".$title." - ".$item['title']." - ".$titlepercent;
         return false;
     }
     $bookId = $this->addUpdateBookInfo($item['title'], $item['asin'], $item['url'], $item['author'], $item['publisher'], $item['publishdate'], $item['review'], $item['cover'], $item['dewey'], $item['ean'], $item['isbn'], $item['pages']);
     if ($bookId) {
         $item['cover'] = $ri->saveImage($bookId, $item['coverurl'], $this->imgSavePath, 250, 250);
     }
     return $bookId;
 }
Esempio n. 12
0
 /**
  * Fetch IMDB/TMDB/TRAKT info for the movie.
  *
  * @param $imdbId
  *
  * @return bool
  */
 public function updateMovieInfo($imdbId)
 {
     if ($this->echooutput && $this->service !== '') {
         $this->pdo->log->doEcho($this->pdo->log->primary("Fetching IMDB info from TMDB and/or Trakt using IMDB id: " . $imdbId));
     }
     // Check TMDB for IMDB info.
     $tmdb = $this->fetchTMDBProperties($imdbId);
     // Check IMDB for movie info.
     $imdb = $this->fetchIMDBProperties($imdbId);
     // Check TRAKT for movie info
     $trakt = $this->fetchTraktTVProperties($imdbId);
     if (!$imdb && !$tmdb && !$trakt) {
         return false;
     }
     // Check FanArt.tv for cover nad background images.
     $fanart = $this->fetchFanartTVProperties($imdbId);
     $mov = [];
     $mov['cover'] = $mov['backdrop'] = $mov['banner'] = $movieID = 0;
     $mov['type'] = $mov['director'] = $mov['actors'] = $mov['language'] = '';
     $mov['imdbid'] = $imdbId;
     $mov['tmdbid'] = !isset($tmdb['tmdbid']) || $tmdb['tmdbid'] == '' ? 0 : $tmdb['tmdbid'];
     $mov['traktid'] = $trakt['id'];
     // Prefer Fanart.tv cover over TRAKT, TRAKT over TMDB and TMDB over IMDB.
     if ($this->checkVariable($fanart['cover'])) {
         $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $fanart['cover'], $this->imgSavePath);
     } else {
         if ($this->checkVariable($trakt['cover'])) {
             $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $trakt['cover'], $this->imgSavePath);
         } else {
             if ($this->checkVariable($tmdb['cover'])) {
                 $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $tmdb['cover'], $this->imgSavePath);
             } else {
                 if ($this->checkVariable($imdb['cover'])) {
                     $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $imdb['cover'], $this->imgSavePath);
                 }
             }
         }
     }
     // Backdrops.
     if ($this->checkVariable($fanart['backdrop'])) {
         $mov['backdrop'] = $this->releaseImage->saveImage($imdbId . '-backdrop', $fanart['backdrop'], $this->imgSavePath, 1920, 1024);
     } else {
         if ($this->checkVariable($tmdb['backdrop'])) {
             $mov['backdrop'] = $this->releaseImage->saveImage($imdbId . '-backdrop', $tmdb['backdrop'], $this->imgSavePath, 1920, 1024);
         }
     }
     // Banner
     if ($this->checkVariable($fanart['banner'])) {
         $mov['banner'] = $this->releaseImage->saveImage($imdbId . '-banner', $fanart['banner'], $this->imgSavePath);
     }
     $mov['title'] = $this->setTmdbImdbTraktVar($imdb['title'], $tmdb['title'], $trakt['title']);
     $mov['rating'] = $this->setTmdbImdbTraktVar($imdb['rating'], $tmdb['rating'], $trakt['rating']);
     $mov['plot'] = $this->setTmdbImdbTraktVar($imdb['plot'], $tmdb['plot'], $trakt['overview']);
     $mov['tagline'] = $this->setTmdbImdbTraktVar($imdb['tagline'], $tmdb['tagline'], $trakt['tagline']);
     $mov['year'] = $this->setTmdbImdbTraktVar($imdb['year'], $tmdb['year'], $trakt['year']);
     $mov['genre'] = $this->setTmdbImdbTraktVar($imdb['genre'], $tmdb['genre'], $trakt['genres']);
     if ($this->checkVariable($imdb['type'])) {
         $mov['type'] = $imdb['type'];
     }
     if ($this->checkVariable($imdb['director'])) {
         $mov['director'] = is_array($imdb['director']) ? implode(', ', array_unique($imdb['director'])) : $imdb['director'];
     }
     if ($this->checkVariable($imdb['actors'])) {
         $mov['actors'] = is_array($imdb['actors']) ? implode(', ', array_unique($imdb['actors'])) : $imdb['actors'];
     }
     if ($this->checkVariable($imdb['language'])) {
         $mov['language'] = is_array($imdb['language']) ? implode(', ', array_unique($imdb['language'])) : $imdb['language'];
     }
     if (is_array($mov['genre'])) {
         $mov['genre'] = implode(', ', array_unique($mov['genre']));
     }
     if (is_array($mov['type'])) {
         $mov['type'] = implode(', ', array_unique($mov['type']));
     }
     $mov['title'] = html_entity_decode($mov['title'], ENT_QUOTES, 'UTF-8');
     $mov['title'] = str_replace(['/', '\\'], '', $mov['title']);
     $movieID = $this->update(['actors' => html_entity_decode($mov['actors'], ENT_QUOTES, 'UTF-8'), 'backdrop' => $mov['backdrop'], 'cover' => $mov['cover'], 'director' => html_entity_decode($mov['director'], ENT_QUOTES, 'UTF-8'), 'genre' => html_entity_decode($mov['genre'], ENT_QUOTES, 'UTF-8'), 'imdbid' => $mov['imdbid'], 'language' => html_entity_decode($mov['language'], ENT_QUOTES, 'UTF-8'), 'plot' => html_entity_decode(preg_replace('/\\s+See full summary »/', ' ', $mov['plot']), ENT_QUOTES, 'UTF-8'), 'rating' => round($mov['rating'], 1), 'tagline' => html_entity_decode($mov['tagline'], ENT_QUOTES, 'UTF-8'), 'title' => $mov['title'], 'tmdbid' => $mov['tmdbid'], 'type' => html_entity_decode(ucwords(preg_replace('/[\\.\\_]/', ' ', $mov['type'])), ENT_QUOTES, 'UTF-8'), 'year' => $mov['year'], 'traktid' => $mov['traktid']]);
     if ($this->echooutput && $this->service !== '') {
         $this->pdo->log->doEcho($this->pdo->log->headerOver($movieID !== 0 ? 'Added/updated movie: ' : 'Nothing to update for movie: ') . $this->pdo->log->primary($mov['title'] . ' (' . $mov['year'] . ') - ' . $mov['imdbid']));
     }
     return $movieID === 0 ? false : true;
 }
Esempio n. 13
0
 public function processAnimeReleases()
 {
     $db = new DB();
     $ri = new ReleaseImage();
     $results = $db->queryDirect(sprintf("SELECT searchname, ID FROM releases WHERE anidbID is NULL AND categoryID IN ( SELECT ID FROM category WHERE categoryID = %d )", Category::CAT_TV_ANIME));
     if (mysql_num_rows($results) > 0) {
         if ($this->echooutput) {
             echo "Processing " . mysql_num_rows($results) . " anime releases\n";
         }
         while ($arr = mysql_fetch_assoc($results)) {
             $cleanFilename = $this->cleanFilename($arr['searchname']);
             $anidbID = $this->getanidbID($cleanFilename['title']);
             if (!$anidbID) {
                 $db->query(sprintf("UPDATE releases SET anidbID = %d, rageID = %d WHERE ID = %d", -1, -2, $arr["ID"]));
                 continue;
             }
             if ($this->echooutput) {
                 echo 'Looking up: ' . $arr['searchname'] . "\n";
             }
             $AniDBAPIArray = $this->getAnimeInfo($anidbID);
             $lastUpdate = isset($AniDBAPIArray['unixtime']) && time() - $AniDBAPIArray['unixtime'] > 604800;
             if (!$AniDBAPIArray || $lastUpdate) {
                 $AniDBAPIArray = $this->AniDBAPI($anidbID);
                 if (!$lastUpdate) {
                     $this->addTitle($AniDBAPIArray);
                 } else {
                     $this->updateTitle($AniDBAPIArray['anidbID'], $AniDBAPIArray['title'], $AniDBAPIArray['type'], $AniDBAPIArray['startdate'], $AniDBAPIArray['enddate'], $AniDBAPIArray['related'], $AniDBAPIArray['creators'], $AniDBAPIArray['description'], $AniDBAPIArray['rating'], $AniDBAPIArray['categories'], $AniDBAPIArray['characters'], $AniDBAPIArray['epnos'], $AniDBAPIArray['airdates'], $AniDBAPIArray['episodetitles']);
                 }
                 if ($AniDBAPIArray['picture']) {
                     $ri->saveImage($AniDBAPIArray['anidbID'], 'http://img7.anidb.net/pics/anime/' . $AniDBAPIArray['picture'], $this->imgSavePath);
                 }
             }
             if ($AniDBAPIArray['anidbID']) {
                 $epno = explode('|', $AniDBAPIArray['epnos']);
                 $airdate = explode('|', $AniDBAPIArray['airdates']);
                 $episodetitle = explode('|', $AniDBAPIArray['episodetitles']);
                 for ($i = 0; $i < count($epno); $i++) {
                     if ($cleanFilename['epno'] == $epno[$i]) {
                         $offset = $i;
                         break;
                     } else {
                         $offset = -1;
                     }
                 }
                 $airdate = isset($airdate[$offset]) ? $airdate[$offset] : $AniDBAPIArray['startdate'];
                 $episodetitle = isset($episodetitle[$offset]) ? $episodetitle[$offset] : $cleanFilename['epno'];
                 $tvtitle = $episodetitle !== 'Complete Movie' && $episodetitle !== $cleanFilename['epno'] ? $cleanFilename['epno'] . " - " . $episodetitle : $episodetitle;
                 if ($this->echooutput) {
                     echo '- found ' . $AniDBAPIArray['anidbID'] . "\n";
                 }
                 $db->query(sprintf("UPDATE releases SET episode=%s, tvtitle=%s, tvairdate=%s, anidbID=%d, rageID=%d WHERE ID = %d", $db->escapeString($cleanFilename['epno']), $db->escapeString($tvtitle), $db->escapeString($airdate), $AniDBAPIArray['anidbID'], -2, $arr["ID"]));
             }
         }
         if ($this->echooutput) {
             echo "Processed " . mysql_num_rows($results) . " anime releases.\n";
         }
     }
 }
Esempio n. 14
0
 /**
  * Try to get a preview image from a video file.
  *
  * @param string $fileLocation
  *
  * @return bool
  */
 protected function _getSample($fileLocation)
 {
     if (!$this->_processThumbnails) {
         return false;
     }
     if (is_file($fileLocation)) {
         // Create path to temp file.
         $fileName = $this->tmpPath . 'zzzz' . mt_rand(5, 12) . mt_rand(5, 12) . '.jpg';
         $time = $this->getVideoTime($fileLocation);
         // Create the image.
         Utility::runCmd($this->_killString . $this->pdo->getSetting('ffmpegpath') . '" -i "' . $fileLocation . '" -ss ' . ($time === '' ? '00:00:03.00' : $time) . ' -vframes 1 -loglevel quiet -y "' . $fileName . '"');
         // Check if the file exists.
         if (is_file($fileName)) {
             // Try to resize/move the image.
             $saved = $this->_releaseImage->saveImage($this->_release['guid'] . '_thumb', $fileName, $this->_releaseImage->imgSavePath, 800, 600);
             // Delete the temp file we created.
             @unlink($fileName);
             // Check if it saved.
             if ($saved === 1) {
                 if ($this->_echoCLI) {
                     $this->_echo('s', 'primaryOver', false);
                 }
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 15
0
 /**
  * Get a sample from a release using ffmpeg
  */
 public function getSample($ramdrive, $ffmpeginfo, $releaseguid)
 {
     $ri = new ReleaseImage();
     $retval = false;
     $samplefiles = glob($ramdrive . '*.*');
     if (is_array($samplefiles)) {
         foreach ($samplefiles as $samplefile) {
             if (preg_match("/\\.(" . $this->mediafileregex . ")\$/i", $samplefile)) {
                 //1.0
                 //$execstring = '"'.$ffmpeginfo.'" -sameq -i "'.$samplefile.'" -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"';
                 //1.1
                 //$execstring = '"'.$ffmpeginfo.'" -i "'.$samplefile.'" -qscale:v 1 -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"';
                 //2.0
                 //$execstring = '"'.$ffmpeginfo.'" -i "'.$samplefile.'"  -vframes 300 "'.$ramdrive.'zzzz%03d.jpg"';
                 //1.x
                 $execstring = '"' . $ffmpeginfo . '" -q:v 0 -i "' . $samplefile . '" -vframes 300 "' . $ramdrive . 'zzzz%03d.jpg"';
                 Utility::runCmd($execstring, false, true);
                 $all_files = scandir($ramdrive, 1);
                 if (preg_match("/zzzz\\d{3}\\.jpg/", $all_files[1])) {
                     $ri->saveImage($releaseguid . '_thumb', $ramdrive . $all_files[1], $ri->imgSavePath, 800, 600);
                     $retval = true;
                 }
                 //clean up all files
                 foreach (glob($ramdrive . '*.jpg') as $v) {
                     unlink($v);
                 }
             }
         }
     } else {
         echo "PostPrc: Couldn't open temp drive " . $ramdrive . "\n";
     }
     return $retval;
 }
Esempio n. 16
0
 public function getAniDBInfo($exitcount)
 {
     // Declare and set main variables
     $pdo = $this->pdo;
     $ri = new ReleaseImage($this->pdo);
     $apicount = 0;
     $this->c->doEcho($this->c->header("Start getAniDBInfo at " . date('D M d, Y G:i a')));
     $notinani = sprintf("SELECT animetitles.anidbid FROM animetitles\n\t\t\tINNER JOIN anidb ON animetitles.anidbid = anidb.anidbid");
     // Used for information purposes in main echo
     $animetitles = $pdo->query('SELECT DISTINCT anidbid FROM animetitles');
     $anidbtitles = $pdo->query('SELECT DISTINCT anidbid FROM anidb');
     $anidbjointitles = $pdo->query(sprintf("SELECT * FROM animetitles\n\t\t\t\t\tINNER JOIN anidb ON animetitles.anidbid = anidb.anidbid"));
     $anidbmissingtitles = $pdo->query(sprintf("SELECT * FROM animetitles\n\t\t\t\t\tWHERE anidbid NOT IN (%s)", $notinani));
     // Stage declarations
     $aniremovedstage0 = $pdo->query(sprintf("SELECT anidbid FROM anidb WHERE anidbid NOT IN (%s)", $notinani));
     $animissstage1 = $pdo->query(sprintf("SELECT DISTINCT anidbid FROM animetitles WHERE anidbid NOT IN (%s)", $notinani));
     $anirunnstage2 = $pdo->query('SELECT anidbid FROM anidb WHERE (startdate < CURDATE() AND (enddate > CURDATE() OR enddate IS NULL)) AND (unixtime < UNIX_TIMESTAMP(NOW()- INTERVAL 7 DAY)) ORDER BY unixtime');
     $anioldstage3 = $pdo->query('SELECT anidbid FROM anidb WHERE (unixtime < UNIX_TIMESTAMP(NOW()- INTERVAL 90 DAY)) ORDER BY unixtime');
     echo $this->c->header("Total of " . count($animetitles) . " distinct titles present in animetitles.\n" . "Total of " . count($anidbtitles) . " distinct titles present in anidb.\n" . "Total of " . count($anidbjointitles) . " titles in both anidb and animetitles.\n" . "Total of " . count($anidbmissingtitles) . " missing titles in anidb table.\n" . "Total of " . count($animissstage1) . " missing distinct titles in anidb table.\n" . "Total of " . count($aniremovedstage0) . " orphaned anime titles no longer in animetitles to be removed from anidb table.\n" . "Total of " . count($anirunnstage2) . " running anime titles in anidb table not updated for 7 days.\n" . "Total of " . count($anioldstage3) . " anime titles in anidb table not updated for 90 days.\n");
     if ($this->APIKEY == '') {
         echo $this->c->error("Error: You need an API key from AniDB.net to use this.  Try adding \"nzedb\" in Site Edit.\n");
         return;
     }
     // Show the data for 10 sec before starting
     echo $this->c->info("Starting in 10 sec...\n");
     sleep(10);
     // end debug
     // now do this list:
     // 0) remove removed anidbid's from anidb nnot in animetitles, as these can't be updated
     // 1) insert missing titles until exitcount reached
     // 2) update running shows until exitcount reached
     // 3) update show data older than xxx day's until exitcount reached
     // todo: what to do with anidb.anidbid no longer available in animetitles.anidbid?? ( I have 6 so far)
     // running series:
     // anidb.startdate NULL AND enddate NULL =>> ignore?? (why?) Can only be updated in stage 3!!!!
     // anidb.startdate > CURDATE(); // start date in the future thus it is not in progress as it has not started yet ==> ignore
     // anidb.startdate < CURDATE() AND (enddate IS NULL OR enddate > CURDATE()) => running show without enddate or date in future
     // Begin Stage 0: Remove Orphaned AniDB entries from anidb table if no longer in animetitles table
     $this->c->doEcho($this->c->header("[" . date('d-m-Y G:i') . "] Stage 0 -> Remove deleted anidbid."));
     foreach ($aniremovedstage0 as $value) {
         $anidbid = (int) $value['anidbid'];
         if ($this->echooutput) {
             // Remove AniDB ID from anidb
             echo 'Removing AniDB ID ' . $anidbid . "\n";
         }
         $this->deleteTitle($anidbid);
         $image_file = $this->imgSavePath . $anidbid;
         // Remove AniDB image if exists
         //if (!file_exists($image_file) {
         //}
     }
     // Begin Stage 1: Insert Missing AniDB entries into AniDB table from animetitles table
     $this->c->doEcho($this->c->header("[" . date('d-m-Y G:i') . "] Stage 1 -> Insert missing anidbid into anidb table."));
     foreach ($animissstage1 as $value) {
         $anidbid = (int) $value['anidbid'];
         if ($this->echooutput) {
             echo 'Adding AniDB ID ' . $anidbid . "\n";
         }
         // Pull information from AniDB for this ID and increment API counter -- if false (banned) exit
         $AniDBAPIArray = $this->AniDBAPI($anidbid);
         $apicount++;
         if ($AniDBAPIArray['banned']) {
             if ($this->echooutput) {
                 echo "AniDB Banned, import will fail, please wait 24 hours before retrying\n";
             }
             return;
         }
         $this->addTitle($AniDBAPIArray);
         // Save the image to covers directory
         if ($AniDBAPIArray['picture']) {
             $ri->saveImage($AniDBAPIArray['anidbid'], 'http://img7.anidb.net/pics/anime/' . $AniDBAPIArray['picture'], $this->imgSavePath);
         }
         // Print total count added
         if ($apicount != 0 && $this->echooutput) {
             echo $this->c->header("Processed " . $apicount . " anidb entries of a total possible of " . $exitcount . " for this session\n");
         }
         // Sleep 4 Minutes for Every 10 Records
         if ($apicount % 10 == 0 && $apicount != 0) {
             $sleeptime = 180 + rand(30, 90);
             if ($this->echooutput) {
                 $this->c->doEcho($this->c->primary("[" . date('d-m-Y G:i') . "] Start waitloop for " . $sleeptime . " seconds to prevent banning.\n"));
             }
             sleep($sleeptime);
         }
     }
     // using exitcount if this number of API calls is reached exit
     if ($apicount >= $exitcount) {
         return;
     }
     // Begin Stage 2: Update running series in anidb table -- we only update series already existing in db
     $this->c->doEcho($this->c->header("[" . date('d-m-Y G:i') . "] Stage 2 -> Update running series."));
     foreach ($anirunnstage2 as $value) {
         $anidbid = (int) $value['anidbid'];
         if ($this->echooutput) {
             echo 'Updating AniDB ID ' . $anidbid . "\n";
         }
         // actually get the information on this anime from anidb
         $AniDBAPIArrayNew = $this->AniDBAPI($anidbid);
         // if it is false we can simply exit
         if ($AniDBAPIArrayNew['banned']) {
             if ($this->echooutput) {
                 echo $this->c->error("AniDB Banned, import will fail, please wait 24 hours before retrying.\n");
             }
             return;
         }
         // increment apicount on API access
         $apicount++;
         // update the stored information with updated data
         $this->updateTitle($AniDBAPIArrayNew['anidbid'], $AniDBAPIArrayNew['title'], $AniDBAPIArrayNew['type'], $AniDBAPIArrayNew['startdate'], $AniDBAPIArrayNew['enddate'], $AniDBAPIArrayNew['related'], $AniDBAPIArrayNew['creators'], $AniDBAPIArrayNew['description'], $AniDBAPIArrayNew['rating'], $AniDBAPIArrayNew['categories'], $AniDBAPIArrayNew['characters'], $AniDBAPIArrayNew['epnos'], $AniDBAPIArrayNew['airdates'], $AniDBAPIArrayNew['episodetitles']);
         $image_file = $this->imgSavePath . $anidbid;
         // if the image is present we do not need to replace it
         if (!file_exists($image_file)) {
             if ($AniDBAPIArrayNew['picture']) {
                 // save the image to the covers page
                 $ri->saveImage($AniDBAPIArrayNew['anidbid'], 'http://img7.anidb.net/pics/anime/' . $AniDBAPIArrayNew['picture'], $this->imgSavePath);
             }
         }
         // update how many we have done of the total to do in this session
         if ($apicount != 0 && $this->echooutput) {
             echo 'Processed ' . $apicount . " anidb entries of a total possible of " . $exitcount . " for this session.\n";
         }
         // every 10 records sleep for 4 minutes before continuing
         if ($apicount % 10 == 0 && $apicount != 0) {
             $sleeptime = 180 + rand(30, 90);
         }
         if ($this->echooutput) {
             $this->c->doEcho($this->c->primary("[" . date('d-m-Y G:i') . "] Start waitloop for " . $sleeptime . " sec to prevent banning."));
         }
         sleep($sleeptime);
         // using exitcount if this number of API calls is reached exit
         if ($apicount >= $exitcount) {
             return;
         }
     }
     // now for stage 3: update rest of records not updated for a loooooong time
     // same as step2: but other for loop (so we need to make a proper function out of this?!)
     $this->c->doEcho($this->c->header("[" . date('d-m-Y G:i') . "] Stage 3 -> Update 90+ day old series."));
     foreach ($anidboldtitles as $value) {
         $anidbid = (int) $value['anidbid'];
         if ($this->echooutput) {
             echo 'Updating AniDB ID ' . $anidbid . "\n";
         }
         // actually get the information on this anime from anidb
         $AniDBAPIArrayNew = $this->AniDBAPI($anidbid);
         if ($AniDBAPIArrayNew['banned']) {
             if ($this->echooutput) {
                 echo "AniDB Banned, import will fail, please wait 24 hours before retrying\n";
             }
             return;
         }
         // increment apicount on API access
         $apicount++;
         // update the stored information with updated data
         $this->updateTitle($AniDBAPIArrayNew['anidbid'], $AniDBAPIArrayNew['title'], $AniDBAPIArrayNew['type'], $AniDBAPIArrayNew['startdate'], $AniDBAPIArrayNew['enddate'], $AniDBAPIArrayNew['related'], $AniDBAPIArrayNew['creators'], $AniDBAPIArrayNew['description'], $AniDBAPIArrayNew['rating'], $AniDBAPIArrayNew['categories'], $AniDBAPIArrayNew['characters'], $AniDBAPIArrayNew['epnos'], $AniDBAPIArrayNew['airdates'], $AniDBAPIArrayNew['episodetitles']);
         $image_file = $this->imgSavePath . $anidbid;
         // if the image is present we do not need to replace it
         if (!file_exists($image_file)) {
             if ($AniDBAPIArrayNew['picture']) {
                 // save the image to the covers page
                 $ri->saveImage($AniDBAPIArrayNew['anidbid'], 'http://img7.anidb.net/pics/anime/' . $AniDBAPIArrayNew['picture'], $this->imgSavePath);
             }
         }
         // update how many we have done of the total to do in this session
         if ($apicount != 0 && $this->echooutput) {
             echo 'Processed ' . $apicount . " anidb entries of a total possible of " . $exitcount . " for this session\n";
         }
         // every 10 records sleep for 4 minutes before continuing
         if ($apicount % 10 == 0 && $apicount != 0) {
             $sleeptime = 180 + rand(30, 90);
             if ($this->echooutput) {
                 $this->c->doEcho($this->c->primary("[" . date('d-m-Y G:i') . "] Start waitloop for " . $sleeptime . " sec to prevent banning"));
             }
             sleep($sleeptime);
         }
         // using exitcount if this number of API calls is reached exit
         if ($apicount >= $exitcount) {
             return;
         }
     }
 }
Esempio n. 17
0
File: XXX.php Progetto: Jay204/nZEDb
 /**
  * Fetch xxx info for the movie.
  *
  * @param $xxxmovie
  *
  * @return bool
  */
 public function updateXXXInfo($xxxmovie)
 {
     $res = false;
     $this->whichclass = '';
     $iafd = new IAFD();
     $iafd->searchTerm = $xxxmovie;
     if ($iafd->findme() !== false) {
         switch ($iafd->classUsed) {
             case "ade":
                 $mov = new ADE();
                 $mov->directLink = (string) $iafd->directUrl;
                 $res = $mov->getDirect();
                 $res['title'] = $iafd->title;
                 $res['directurl'] = (string) $iafd->directUrl;
                 $this->whichclass = $iafd->classUsed;
                 $this->pdo->log->doEcho($this->pdo->log->primary("Fetching XXX info from IAFD -> Adult DVD Empire"));
                 break;
             case "hm":
                 $mov = new Hotmovies();
                 $mov->directLink = (string) $iafd->directUrl;
                 $res = $mov->getDirect();
                 $res['title'] = $iafd->title;
                 $res['directurl'] = (string) $iafd->directUrl;
                 $this->whichclass = $iafd->classUsed;
                 $this->pdo->log->doEcho($this->pdo->log->primary("Fetching XXX info from IAFD -> Hot Movies"));
         }
     }
     if ($res === false) {
         $this->whichclass = "aebn";
         $mov = new AEBN();
         $mov->cookie = $this->cookie;
         $mov->searchTerm = $xxxmovie;
         $res = $mov->search();
         if ($res === false) {
             $this->whichclass = "ade";
             $mov = new ADE();
             $mov->searchTerm = $xxxmovie;
             $res = $mov->search();
         }
         if ($res === false) {
             $this->whichclass = "hm";
             $mov = new Hotmovies();
             $mov->cookie = $this->cookie;
             $mov->searchTerm = $xxxmovie;
             $res = $mov->search();
         }
         if ($res === false) {
             $this->whichclass = "pop";
             $mov = new Popporn();
             $mov->cookie = $this->cookie;
             $mov->searchTerm = $xxxmovie;
             $res = $mov->search();
         }
         // If a result is true getall information.
         if ($res !== false) {
             if ($this->echooutput) {
                 switch ($this->whichclass) {
                     case "aebn":
                         $fromstr = "Adult Entertainment Broadcast Network";
                         break;
                     case "ade":
                         $fromstr = "Adult DVD Empire";
                         break;
                     case "pop":
                         $fromstr = "PopPorn";
                         break;
                     case "hm":
                         $fromstr = "Hot Movies";
                         break;
                     default:
                         $fromstr = null;
                 }
                 $this->pdo->log->doEcho($this->pdo->log->primary("Fetching XXX info from: " . $fromstr));
             }
             $res = $mov->getAll();
         } else {
             // Nothing was found, go ahead and set to -2
             return -2;
         }
     }
     $mov = array();
     $mov['trailers'] = isset($res['trailers']) ? serialize($res['trailers']) : '';
     $mov['extras'] = isset($res['extras']) ? serialize($res['extras']) : '';
     $mov['productinfo'] = isset($res['productinfo']) ? serialize($res['productinfo']) : '';
     $mov['backdrop'] = isset($res['backcover']) ? $res['backcover'] : '';
     $mov['cover'] = isset($res['boxcover']) ? $res['boxcover'] : '';
     $res['cast'] = isset($res['cast']) ? join(",", $res['cast']) : '';
     $res['genres'] = isset($res['genres']) ? $this->getgenreid($res['genres']) : '';
     $mov['title'] = html_entity_decode($res['title'], ENT_QUOTES, 'UTF-8');
     $mov['plot'] = isset($res['sypnosis']) ? html_entity_decode($res['sypnosis'], ENT_QUOTES, 'UTF-8') : '';
     $mov['tagline'] = isset($res['tagline']) ? html_entity_decode($res['tagline'], ENT_QUOTES, 'UTF-8') : '';
     $mov['genre'] = html_entity_decode($res['genres'], ENT_QUOTES, 'UTF-8');
     $mov['director'] = isset($res['director']) ? html_entity_decode($res['director'], ENT_QUOTES, 'UTF-8') : '';
     $mov['actors'] = html_entity_decode($res['cast'], ENT_QUOTES, 'UTF-8');
     $mov['directurl'] = html_entity_decode($res['directurl'], ENT_QUOTES, 'UTF-8');
     $mov['classused'] = $this->whichclass;
     $check = $this->pdo->queryOneRow(sprintf('SELECT id FROM xxxinfo WHERE title = %s', $this->pdo->escapeString($mov['title'])));
     $xxxID = null;
     if ($check === false) {
         $xxxID = $this->pdo->queryInsert(sprintf("\n\t\t\t\t\tINSERT INTO xxxinfo\n\t\t\t\t\t\t(title, tagline, plot, genre, director, actors, extras, productinfo, trailers, directurl, classused, cover, backdrop, createddate, updateddate)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t(%s, %s, COMPRESS(%s), %s, %s, %s, %s, %s, %s, %s, %s, 0, 0, NOW(), NOW())", $this->pdo->escapeString($mov['title']), $this->pdo->escapeString($mov['tagline']), $this->pdo->escapeString($mov['plot']), $this->pdo->escapeString(substr($mov['genre'], 0, 64)), $this->pdo->escapeString($mov['director']), $this->pdo->escapeString($mov['actors']), $this->pdo->escapeString($mov['extras']), $this->pdo->escapeString($mov['productinfo']), $this->pdo->escapeString($mov['trailers']), $this->pdo->escapeString($mov['directurl']), $this->pdo->escapeString($mov['classused'])));
         if ($xxxID !== false) {
             // BoxCover.
             if (isset($mov['cover'])) {
                 $mov['cover'] = $this->releaseImage->saveImage($xxxID . '-cover', $mov['cover'], $this->imgSavePath);
             }
             // BackCover.
             if (isset($mov['backdrop'])) {
                 $mov['backdrop'] = $this->releaseImage->saveImage($xxxID . '-backdrop', $mov['backdrop'], $this->imgSavePath, 1920, 1024);
             }
             $this->pdo->queryExec(sprintf('UPDATE xxxinfo SET cover = %d, backdrop = %d  WHERE id = %d', $mov['cover'], $mov['backdrop'], $xxxID));
         }
     } else {
         // If xxxinfo title is found, update release with the current xxxinfo id because it was nulled before..
         $this->pdo->queryExec(sprintf('UPDATE releases SET xxxinfo_id = %d WHERE id = %d', $check['id'], $this->currentRelID));
         $xxxID = $check['id'];
     }
     if ($this->echooutput) {
         $this->pdo->log->doEcho($this->pdo->log->headerOver($xxxID !== false ? 'Added/updated movie: ' : 'Nothing to update for xxx movie: ') . $this->pdo->log->primary($mov['title']));
     }
     return $xxxID;
 }
Esempio n. 18
0
 public function updateMusicInfo($artist, $album, $year)
 {
     $db = new DB();
     $gen = new Genres();
     $ri = new ReleaseImage();
     $mus = array();
     $amaz = $this->fetchAmazonProperties($artist . " - " . $album);
     if (!$amaz) {
         return false;
     }
     //load genres
     $defaultGenres = $gen->getGenres(Genres::MUSIC_TYPE);
     $genreassoc = array();
     foreach ($defaultGenres as $dg) {
         $genreassoc[$dg['ID']] = strtolower($dg['title']);
     }
     //
     // get album properties
     //
     $mus['coverurl'] = (string) $amaz->Items->Item->MediumImage->URL;
     if ($mus['coverurl'] != "") {
         $mus['cover'] = 1;
     } else {
         $mus['cover'] = 0;
     }
     $mus['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
     if (empty($mus['title'])) {
         $mus['title'] = $album;
     }
     $mus['asin'] = (string) $amaz->Items->Item->ASIN;
     $mus['url'] = (string) $amaz->Items->Item->DetailPageURL;
     $mus['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $mus['url']);
     $mus['salesrank'] = (string) $amaz->Items->Item->SalesRank;
     if ($mus['salesrank'] == "") {
         $mus['salesrank'] = 'null';
     }
     $mus['artist'] = (string) $amaz->Items->Item->ItemAttributes->Artist;
     if (empty($mus['artist'])) {
         $mus['artist'] = $artist;
     }
     $mus['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
     $mus['releasedate'] = $db->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate);
     if ($mus['releasedate'] == "''") {
         $mus['releasedate'] = 'null';
     }
     $mus['review'] = "";
     if (isset($amaz->Items->Item->EditorialReviews)) {
         $mus['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
     }
     $mus['year'] = $year;
     if ($mus['year'] == "") {
         $mus['year'] = $mus['releasedate'] != 'null' ? substr($mus['releasedate'], 1, 4) : date("Y");
     }
     $mus['tracks'] = "";
     if (isset($amaz->Items->Item->Tracks)) {
         $tmpTracks = (array) $amaz->Items->Item->Tracks->Disc;
         $tracks = $tmpTracks['Track'];
         $mus['tracks'] = is_array($tracks) && !empty($tracks) ? implode('|', $tracks) : '';
     }
     //This is to verify the result back from amazon was at least somewhat related to what was intended.
     //If you are debugging releases comment out the following code to show all info
     $match = similar_text($artist, $mus['artist'], $artistpercent);
     //echo("Matched: Artist Percentage: $artistpercent%");
     $match = similar_text($album, $mus['title'], $albumpercent);
     //echo("Matched: Album Percentage: $albumpercent%");
     //If the artist is Various Artists, assume artist is 100%
     if (preg_match('/various/i', $artist)) {
         $artistpercent = '100';
     }
     //If the Artist is less than 80% album must be 100%
     if ($artistpercent < '80') {
         if ($albumpercent != '100') {
             return false;
         }
     }
     //If the album is ever under 30%, it's probably not a match.
     if ($albumpercent < '30') {
         return false;
     }
     //This is the end of the recheck code. Comment out to this point to show all info.
     $genreKey = -1;
     $genreName = '';
     if (isset($amaz->Items->Item->BrowseNodes)) {
         //had issues getting this out of the browsenodes obj
         //workaround is to get the xml and load that into its own obj
         $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml();
         $amazGenresObj = simplexml_load_string($amazGenresXml);
         $amazGenres = $amazGenresObj->xpath("//BrowseNodeId");
         foreach ($amazGenres as $amazGenre) {
             $currNode = trim($amazGenre[0]);
             if (empty($genreName)) {
                 $genreMatch = $this->matchBrowseNode($currNode);
                 if ($genreMatch !== false) {
                     $genreName = $genreMatch;
                     break;
                 }
             }
         }
         if (in_array(strtolower($genreName), $genreassoc)) {
             $genreKey = array_search(strtolower($genreName), $genreassoc);
         } else {
             $genreKey = $db->queryInsert(sprintf("INSERT INTO genres (`title`, `type`) VALUES (%s, %d)", $db->escapeString($genreName), Genres::MUSIC_TYPE));
         }
     }
     $mus['musicgenre'] = $genreName;
     $mus['musicgenreID'] = $genreKey;
     $query = sprintf("\n\t\tINSERT INTO musicinfo  (`title`, `asin`, `url`, `salesrank`,  `artist`, `publisher`, `releasedate`, `review`, `year`, `genreID`, `tracks`, `cover`, `createddate`, `updateddate`)\n\t\tVALUES (%s,        %s,        %s,        %s,        %s,        %s,        %s,        %s,        %s,        %s,        %s,        %d,        now(),        now())\n\t\t\tON DUPLICATE KEY UPDATE  `title` = %s,  `asin` = %s,  `url` = %s,  `salesrank` = %s,  `artist` = %s,  `publisher` = %s,  `releasedate` = %s,  `review` = %s,  `year` = %s,  `genreID` = %s,  `tracks` = %s,  `cover` = %d,  createddate = now(),  updateddate = now()", $db->escapeString($mus['title']), $db->escapeString($mus['asin']), $db->escapeString($mus['url']), $mus['salesrank'], $db->escapeString($mus['artist']), $db->escapeString($mus['publisher']), $mus['releasedate'], $db->escapeString($mus['review']), $db->escapeString($mus['year']), $mus['musicgenreID'] == -1 ? "null" : $mus['musicgenreID'], $db->escapeString($mus['tracks']), $mus['cover'], $db->escapeString($mus['title']), $db->escapeString($mus['asin']), $db->escapeString($mus['url']), $mus['salesrank'], $db->escapeString($mus['artist']), $db->escapeString($mus['publisher']), $mus['releasedate'], $db->escapeString($mus['review']), $db->escapeString($mus['year']), $mus['musicgenreID'] == -1 ? "null" : $mus['musicgenreID'], $db->escapeString($mus['tracks']), $mus['cover']);
     $musicId = $db->queryInsert($query);
     if ($musicId) {
         if ($this->echooutput) {
             echo "added/updated album: " . $mus['title'] . " (" . $mus['year'] . ")\n";
         }
         $mus['cover'] = $ri->saveImage($musicId, $mus['coverurl'], $this->imgSavePath, 250, 250);
     } else {
         if ($this->echooutput) {
             echo "nothing to update: " . $mus['title'] . " (" . $mus['year'] . ")\n";
         }
     }
     return $musicId;
 }
Esempio n. 19
0
 /**
  * Check whether a title is available at Amazon and store its metadata.
  */
 public function updateConsoleInfo($gameInfo)
 {
     $gen = new Genres();
     $ri = new ReleaseImage();
     $con = [];
     $amaz = $this->fetchAmazonProperties($gameInfo['title'], $gameInfo['node']);
     if (!$amaz) {
         return false;
     }
     //load genres
     $defaultGenres = $gen->getGenres(Genres::CONSOLE_TYPE);
     $genreassoc = [];
     foreach ($defaultGenres as $dg) {
         $genreassoc[$dg['id']] = strtolower($dg['title']);
     }
     //
     // get game properties
     //
     $con['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL;
     if ($con['coverurl'] != "") {
         $con['cover'] = 1;
     } else {
         $con['cover'] = 0;
     }
     $con['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
     if (empty($con['title'])) {
         $con['title'] = $gameInfo['title'];
     }
     $con['platform'] = (string) $amaz->Items->Item->ItemAttributes->Platform;
     if (empty($con['platform'])) {
         $con['platform'] = $gameInfo['platform'];
     }
     //Beginning of Recheck Code
     //This is to verify the result back from amazon was at least somewhat related to what was intended.
     //Some of the Platforms don't match Amazon's exactly. This code is needed to facilitate rechecking.
     if (preg_match('/^X360$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('X360', 'Xbox 360', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/^XBOX360$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('XBOX360', 'Xbox 360', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/^NDS$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('NDS', 'Nintendo DS', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/^PS3$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('PS3', 'PlayStation 3', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/^PSP$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('PSP', 'Sony PSP', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/^Wii$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('Wii', 'Nintendo Wii', $gameInfo['platform']);
         // baseline single quote
         $gameInfo['platform'] = str_replace('WII', 'Nintendo Wii', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/^N64$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('N64', 'Nintendo 64', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/^NES$/i', $gameInfo['platform'])) {
         $gameInfo['platform'] = str_replace('NES', 'Nintendo NES', $gameInfo['platform']);
         // baseline single quote
     }
     if (preg_match('/Super/i', $con['platform'])) {
         $con['platform'] = str_replace('Super Nintendo', 'SNES', $con['platform']);
         // baseline single quote
         $con['platform'] = str_replace('Nintendo Super NES', 'SNES', $con['platform']);
         // baseline single quote
     }
     //Remove Online Game Code So Titles Match Properly.
     if (preg_match('/\\[Online Game Code\\]/i', $con['title'])) {
         $con['title'] = str_replace(' [Online Game Code]', '', $con['title']);
         // baseline single quote
     }
     //Basically the XBLA names contain crap, this is to reduce the title down far enough to be usable
     if (preg_match('/xbla/i', $gameInfo['platform'])) {
         $gameInfo['title'] = substr($gameInfo['title'], 0, 10);
         $con['substr'] = $gameInfo['title'];
     }
     //This actual compares the two strings and outputs a percentage value.
     $titlepercent = '';
     $platformpercent = '';
     similar_text(strtolower($gameInfo['title']), strtolower($con['title']), $titlepercent);
     similar_text(strtolower($gameInfo['platform']), strtolower($con['platform']), $platformpercent);
     //Since Wii Ware games and XBLA have inconsistent original platforms, as long as title is 50% its ok.
     if (preg_match('/(wiiware|xbla)/i', $gameInfo['platform'])) {
         if ($titlepercent >= 50) {
             $platformpercent = 100;
         }
     }
     //If the release is DLC matching sucks, so assume anything over 50% is legit.
     if (isset($gameInfo['dlc']) && $gameInfo['dlc'] == 1) {
         if ($titlepercent >= 50) {
             $titlepercent = 100;
             $platformpercent = 100;
         }
     }
     //Show the Percentages
     //echo("Matched: Title Percentage: $titlepercent%");
     //echo("Matched: Platform Percentage: $platformpercent%");
     //If the Title is less than 80% Platform must be 100% unless it is XBLA
     if ($titlepercent < 70) {
         if ($platformpercent != 100) {
             return false;
         }
     }
     //If title is less than 80% then its most likely not a match
     if ($titlepercent < 70) {
         return false;
     }
     //Platform must equal 100%
     if ($platformpercent != 100) {
         return false;
     }
     $con['asin'] = (string) $amaz->Items->Item->ASIN;
     $con['url'] = (string) $amaz->Items->Item->DetailPageURL;
     $con['salesrank'] = (string) $amaz->Items->Item->SalesRank;
     if ($con['salesrank'] == "") {
         $con['salesrank'] = 'null';
     }
     $con['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
     $con['esrb'] = (string) $amaz->Items->Item->ItemAttributes->ESRBAgeRating;
     $con['releasedate'] = $this->pdo->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate);
     if ($con['releasedate'] == "''") {
         $con['releasedate'] = 'null';
     }
     $con['review'] = "";
     if (isset($amaz->Items->Item->EditorialReviews)) {
         $con['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
     }
     $genreKey = -1;
     $genreName = '';
     if (isset($amaz->Items->Item->BrowseNodes) || isset($amaz->Items->Item->ItemAttributes->Genre)) {
         if (isset($amaz->Items->Item->BrowseNodes)) {
             //had issues getting this out of the browsenodes obj
             //workaround is to get the xml and load that into its own obj
             $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml();
             $amazGenresObj = simplexml_load_string($amazGenresXml);
             $amazGenres = $amazGenresObj->xpath("//Name");
             foreach ($amazGenres as $amazGenre) {
                 $currName = trim($amazGenre[0]);
                 if (empty($genreName)) {
                     $genreMatch = $this->matchBrowseNode($currName);
                     if ($genreMatch !== false) {
                         $genreName = $genreMatch;
                         break;
                     }
                 }
             }
         }
         if (empty($genreName) && isset($amaz->Items->Item->ItemAttributes->Genre)) {
             $tmpGenre = (string) $amaz->Items->Item->ItemAttributes->Genre;
             $tmpGenre = str_replace('-', ' ', $tmpGenre);
             $tmpGenre = explode(' ', $tmpGenre);
             foreach ($tmpGenre as $tg) {
                 $genreMatch = $this->matchBrowseNode(ucwords($tg));
                 if ($genreMatch !== false) {
                     $genreName = $genreMatch;
                     break;
                 }
             }
         }
     }
     if (empty($genreName)) {
         $genreName = 'Unknown';
     }
     if (in_array(strtolower($genreName), $genreassoc)) {
         $genreKey = array_search(strtolower($genreName), $genreassoc);
     } else {
         $genreKey = $this->pdo->queryInsert(sprintf("INSERT INTO genres (`title`, `type`) VALUES (%s, %d)", $this->pdo->escapeString($genreName), Genres::CONSOLE_TYPE));
     }
     $con['consolegenre'] = $genreName;
     $con['consolegenreID'] = $genreKey;
     $query = sprintf("\n\t\tINSERT INTO consoleinfo  (`title`, `asin`, `url`, `salesrank`, `platform`, `publisher`, `genreid`, `esrb`, `releasedate`, `review`, `cover`, `createddate`, `updateddate`)\n\t\tVALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())\n\t\t\tON DUPLICATE KEY UPDATE  `title` = %s,  `asin` = %s,  `url` = %s,  `salesrank` = %s,  `platform` = %s,  `publisher` = %s,  `genreid` = %s,  `esrb` = %s,  `releasedate` = %s,  `review` = %s, `cover` = %d,  createddate = now(),  updateddate = now()", $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $con['salesrank'], $this->pdo->escapeString($con['platform']), $this->pdo->escapeString($con['publisher']), $con['consolegenreID'] == -1 ? "null" : $con['consolegenreID'], $this->pdo->escapeString($con['esrb']), $con['releasedate'], $this->pdo->escapeString($con['review']), $con['cover'], $this->pdo->escapeString($con['title']), $this->pdo->escapeString($con['asin']), $this->pdo->escapeString($con['url']), $con['salesrank'], $this->pdo->escapeString($con['platform']), $this->pdo->escapeString($con['publisher']), $con['consolegenreID'] == -1 ? "null" : $con['consolegenreID'], $this->pdo->escapeString($con['esrb']), $con['releasedate'], $this->pdo->escapeString($con['review']), $con['cover']);
     $consoleId = $this->pdo->queryInsert($query);
     if ($consoleId) {
         $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
     }
     return $consoleId;
 }
Esempio n. 20
0
 /**
  * Fetch IMDB/TMDB info for the movie.
  *
  * @param $imdbId
  *
  * @return bool
  */
 public function updateMovieInfo($imdbId)
 {
     if ($this->echooutput && $this->service !== '') {
         $this->pdo->log->doEcho($this->pdo->log->primary("Fetching IMDB info from TMDB using IMDB id: " . $imdbId));
     }
     // Check TMDB for IMDB info.
     $tmdb = $this->fetchTMDBProperties($imdbId);
     // Check IMDB for movie info.
     $imdb = $this->fetchIMDBProperties($imdbId);
     if (!$imdb && !$tmdb) {
         return false;
     }
     // Check FanArt.tv for background images.
     $fanart = $this->fetchFanartTVProperties($imdbId);
     $mov = [];
     $mov['cover'] = $mov['backdrop'] = $mov['banner'] = $movieID = 0;
     $mov['type'] = $mov['director'] = $mov['actors'] = $mov['language'] = '';
     $mov['imdbid'] = $imdbId;
     $mov['tmdbid'] = !isset($tmdb['tmdbid']) || $tmdb['tmdbid'] == '' ? 'NULL' : $tmdb['tmdbid'];
     // Prefer FanArt.tv cover over TMDB. And TMDB over IMDB.
     if ($this->checkVariable($fanart['cover'])) {
         $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $fanart['cover'], $this->imgSavePath);
     } else {
         if ($this->checkVariable($tmdb['cover'])) {
             $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $tmdb['cover'], $this->imgSavePath);
         } else {
             if ($this->checkVariable($imdb['cover'])) {
                 $mov['cover'] = $this->releaseImage->saveImage($imdbId . '-cover', $imdb['cover'], $this->imgSavePath);
             }
         }
     }
     // Backdrops.
     if ($this->checkVariable($fanart['backdrop'])) {
         $mov['backdrop'] = $this->releaseImage->saveImage($imdbId . '-backdrop', $fanart['backdrop'], $this->imgSavePath, 1920, 1024);
     } else {
         if ($this->checkVariable($tmdb['backdrop'])) {
             $mov['backdrop'] = $this->releaseImage->saveImage($imdbId . '-backdrop', $tmdb['backdrop'], $this->imgSavePath, 1920, 1024);
         }
     }
     // Banner
     if ($this->checkVariable($fanart['banner'])) {
         $mov['banner'] = $this->releaseImage->saveImage($imdbId . '-banner', $fanart['banner'], $this->imgSavePath);
     }
     $mov['title'] = $this->setTmdbImdbVar($imdb['title'], $tmdb['title']);
     $mov['rating'] = $this->setTmdbImdbVar($imdb['rating'], $tmdb['rating']);
     $mov['plot'] = $this->setTmdbImdbVar($imdb['plot'], $tmdb['plot']);
     $mov['tagline'] = $this->setTmdbImdbVar($imdb['tagline'], $tmdb['tagline']);
     $mov['year'] = $this->setTmdbImdbVar($imdb['year'], $tmdb['year']);
     $mov['genre'] = $this->setTmdbImdbVar($imdb['genre'], $tmdb['genre']);
     if ($this->checkVariable($imdb['type'])) {
         $mov['type'] = $imdb['type'];
     }
     if ($this->checkVariable($imdb['director'])) {
         $mov['director'] = is_array($imdb['director']) ? implode(', ', array_unique($imdb['director'])) : $imdb['director'];
     }
     if ($this->checkVariable($imdb['actors'])) {
         $mov['actors'] = is_array($imdb['actors']) ? implode(', ', array_unique($imdb['actors'])) : $imdb['actors'];
     }
     if ($this->checkVariable($imdb['language'])) {
         $mov['language'] = is_array($imdb['language']) ? implode(', ', array_unique($imdb['language'])) : $imdb['language'];
     }
     if (is_array($mov['genre'])) {
         $mov['genre'] = implode(', ', array_unique($mov['genre']));
     }
     if (is_array($mov['type'])) {
         $mov['type'] = implode(', ', array_unique($mov['type']));
     }
     $mov['title'] = html_entity_decode($mov['title'], ENT_QUOTES, 'UTF-8');
     $mov['plot'] = html_entity_decode(preg_replace('/\\s+See full summary »/', ' ', $mov['plot']), ENT_QUOTES, 'UTF-8');
     $mov['tagline'] = html_entity_decode($mov['tagline'], ENT_QUOTES, 'UTF-8');
     $mov['genre'] = html_entity_decode($mov['genre'], ENT_QUOTES, 'UTF-8');
     $mov['director'] = html_entity_decode($mov['director'], ENT_QUOTES, 'UTF-8');
     $mov['actors'] = html_entity_decode($mov['actors'], ENT_QUOTES, 'UTF-8');
     $mov['language'] = html_entity_decode($mov['language'], ENT_QUOTES, 'UTF-8');
     $mov['type'] = html_entity_decode(ucwords(preg_replace('/[\\.\\_]/', ' ', $mov['type'])), ENT_QUOTES, 'UTF-8');
     $mov['title'] = str_replace(array('/', '\\'), '', $mov['title']);
     $movieID = $this->pdo->queryInsert(sprintf("\n\t\t\t\tINSERT INTO movieinfo\n\t\t\t\t\t(imdbid, tmdbID, title, rating, tagline, plot, year, genre, type,\n\t\t\t\t\tdirector, actors, language, cover, backdrop, banner, createddate, updateddate)\n\t\t\t\tVALUES\n\t\t\t\t\t(%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %d, NOW(), NOW())\n\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\timdbid = %d, tmdbID = %s, title = %s, rating = %s, tagline = %s, plot = %s, year = %s, genre = %s,\n\t\t\t\t\ttype = %s, director = %s, actors = %s, language = %s, cover = %d, backdrop = %d, banner = %d, updateddate = NOW()", $mov['imdbid'], $mov['tmdbid'], $this->pdo->escapeString($mov['title']), $this->pdo->escapeString($mov['rating']), $this->pdo->escapeString($mov['tagline']), $this->pdo->escapeString($mov['plot']), $this->pdo->escapeString($mov['year']), $this->pdo->escapeString(substr($mov['genre'], 0, 64)), $this->pdo->escapeString($mov['type']), $this->pdo->escapeString($mov['director']), $this->pdo->escapeString($mov['actors']), $this->pdo->escapeString(substr($mov['language'], 0, 64)), $mov['cover'], $mov['backdrop'], $mov['banner'], $mov['imdbid'], $mov['tmdbid'], $this->pdo->escapeString($mov['title']), $this->pdo->escapeString($mov['rating']), $this->pdo->escapeString($mov['tagline']), $this->pdo->escapeString($mov['plot']), $this->pdo->escapeString($mov['year']), $this->pdo->escapeString(substr($mov['genre'], 0, 64)), $this->pdo->escapeString($mov['type']), $this->pdo->escapeString($mov['director']), $this->pdo->escapeString($mov['actors']), $this->pdo->escapeString(substr($mov['language'], 0, 64)), $mov['cover'], $mov['backdrop'], $mov['banner']));
     if ($this->echooutput && $this->service !== '') {
         $this->pdo->log->doEcho($this->pdo->log->headerOver($movieID !== 0 ? 'Added/updated movie: ' : 'Nothing to update for movie: ') . $this->pdo->log->primary($mov['title'] . ' (' . $mov['year'] . ') - ' . $mov['imdbid']));
     }
     return $movieID === 0 ? false : true;
 }
Esempio n. 21
0
 public function delete($id, $isGuid = false)
 {
     $db = new DB();
     $users = new Users();
     $s = new Sites();
     $nfo = new Nfo();
     $site = $s->get();
     $rf = new ReleaseFiles();
     $re = new ReleaseExtra();
     $rc = new ReleaseComments();
     $ri = new ReleaseImage();
     if (!is_array($id)) {
         $id = array($id);
     }
     foreach ($id as $identifier) {
         //
         // delete from disk.
         //
         $rel = $isGuid ? $this->getByGuid($identifier) : $this->getById($identifier);
         if ($rel && file_exists($site->nzbpath . $rel["guid"] . ".nzb.gz")) {
             unlink($site->nzbpath . $rel["guid"] . ".nzb.gz");
         }
         $nfo->deleteReleaseNfo($rel['ID']);
         $rc->deleteCommentsForRelease($rel['ID']);
         $users->delCartForRelease($rel['ID']);
         $rf->delete($rel['ID']);
         $re->delete($rel['ID']);
         $re->deleteFull($rel['ID']);
         $ri->delete($rel['guid']);
         $db->query(sprintf("delete from releases where id = %d", $rel['ID']));
     }
 }