public function getDataByImdbId($id)
{
if (preg_match('/[^t0-9]/', $id, $match)) {
throw new Exception(L::get("MOVIE_ID_INVALID"));
}
$sth = $this->db->prepare("SELECT * FROM imdbinfo WHERE imdbid = ?");
$sth->bindParam(1, $id, PDO::PARAM_STR);
$sth->execute();
$res = $sth->fetch(PDO::FETCH_ASSOC);
if ($res) {
return $res;
} else {
$res = $this->fetchImdbData("http://akas.imdb.com/title/" . $id . "/");
if (strlen($res["photo"]) > 10) {
@file_put_contents($this->imdbPicturesDir . $res["imdbid"] . '.jpg', @file_get_contents($res["photo"]));
$res["photo"] = 1;
} else {
$res["photo"] = 0;
}
$sth = $this->db->prepare('INSERT INTO imdbinfo(imdbid, title, year, rating, tagline, genres, photo, director, writer, cast, runtime, seasoncount) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$sth->bindParam(1, $res["imdbid"], PDO::PARAM_STR);
$sth->bindValue(2, $res["title"] ?: '', PDO::PARAM_STR);
$sth->bindValue(3, $res["year"] ?: 0, PDO::PARAM_INT);
$sth->bindParam(4, $res["rating"], PDO::PARAM_INT);
$sth->bindParam(5, $res["tagline"], PDO::PARAM_STR);
$sth->bindParam(6, $res["genres"], PDO::PARAM_STR);
$sth->bindParam(7, $res["photo"], PDO::PARAM_INT);
$sth->bindParam(8, $res["director"], PDO::PARAM_STR);
$sth->bindParam(9, $res["writer"], PDO::PARAM_STR);
$sth->bindParam(10, $res["cast"], PDO::PARAM_STR);
$sth->bindParam(11, $res["runtime"], PDO::PARAM_INT);
$sth->bindParam(12, $res["seasoncount"], PDO::PARAM_INT);
$sth->execute();
$insertId = $this->db->lastInsertId();
$res["id"] = $insertId;
return $res;
}
}