Beispiel #1
0
function FetchSaveMovie($id, $lookup)
{
    $debug = 0;
    $video = runSQL('SELECT * FROM ' . TBL_DATA . ' WHERE id = ' . $id);
    // get fields (according to list) from db to be saved later
    if ($debug) {
        echo "\n=================== Video DB Data ============================\n";
        print_r($video[0]);
        echo "\n=================== Video DB Data ============================\n";
    }
    $imdbID = $video[0]['imdbID'];
    echo "Movie/imdb -- " . $video[0]['title'] . "/" . $video[0]['imdbID'] . "\n";
    if (empty($imdbID)) {
        echo "No imdbID\n";
        return;
    }
    if (empty($engine)) {
        $engine = engineGetEngine($imdbID);
    }
    if ($debug) {
        echo "IMDBID = {$imdbID}, engine = {$engine}\n";
    }
    $imdbdata = engineGetData($imdbID, $engine);
    # removed due to performance issues of is_utf8
    // fix erroneous IMDB encoding issues
    if (!is_utf8($imdbdata)) {
        echo "Applying encoding fix\n";
        $imdbdata = fix_utf8($imdbdata);
    }
    if (empty($imdbdata[title])) {
        echo "Fetch failed , try again...\n";
        $imdbdata = engineGetData($imdbID, $engine);
    }
    if (empty($imdbdata[title])) {
        echo "Fetch failed again , next movie";
        return;
    }
    if ($debug) {
        echo "\n===================  IMDB Data ============================\n";
        print_r($imdbdata);
        echo "\n===================  IMDB Data ============================\n";
    }
    if (!empty($imdbdata[title])) {
        //
        // NOTE: comment out any of the following lines if you do not want them updated
        //
        $video[0][title] = $imdbdata[title];
        $video[0][subtitle] = $imdbdata[subtitle];
        $video[0][year] = $imdbdata[year];
        $video[0][imgurl] = $imdbdata[coverurl];
        $video[0][runtime] = $imdbdata[runtime];
        $video[0][director] = $imdbdata[director];
        $video[0][rating] = $imdbdata[rating];
        $video[0][country] = $imdbdata[country];
        $video[0][language] = $imdbdata[language];
        $video[0][actors] = $imdbdata[cast];
        $video[0][plot] = $imdbdata[plot];
    }
    if (count($genres) == 0 || $lookup > 1) {
        $genres = array();
        $gnames = $imdbdata['genres'];
        if (isset($gnames)) {
            foreach ($gnames as $gname) {
                // check if genre is found- otherwise fail silently
                if (is_numeric($genre = getGenreId($gname))) {
                    $genres[] = $genre;
                } else {
                    echo "MISSING GENRE {$gname}\n";
                }
            }
        }
    }
    // custom filds , not working for now
    for ($i = 1; $i <= 4; $i++) {
        $custom = 'custom' . $i;
        $type = $config[$custom . 'type'];
        if (!empty($type)) {
            // copy imdb data into corresponding custom field
            $video[0][$custom] = $imdbdata[$type];
            echo "CUSTOM {$custom} {$type} = {$imdbdata[$type]}\n";
        }
    }
    //  -------- SAVE
    $SETS = prepareSQL($video[0]);
    if ($debug) {
        echo "\n===================  Final Data ============================\n";
        echo "SETS = {$SETS} \n";
        echo "\n===================  Final Data ============================\n";
    }
    $id = updateDB($SETS, $id);
    // save genres
    setItemGenres($id, $genres);
    // set seen for currently logged in user
    set_userseen($id, $seen);
}
Beispiel #2
0
function InsertMovie($imdb_id, &$ret_title, $seen, $mediatype)
{
    $imdb_set_fields = array('md5', 'title', 'subtitle', 'language', 'diskid', 'mediatype', 'comment', 'disklabel', 'imdbID', 'year', 'imgurl', 'director', 'actors', 'runtime', 'country', 'plot', 'filename', 'filesize', 'filedate', 'audio_codec', 'video_codec', 'video_width', 'video_height', 'istv', 'custom1', 'custom2', 'custom3', 'custom4');
    //fetching all the data
    $imdbdata = engineGetData($imdb_id);
    if ($imdbdata['title'] == '') {
        return 0;
    }
    //sorting needed things
    //genres--------------------------
    $genres = array();
    $gnames = $imdbdata['genres'];
    if (isset($gnames)) {
        foreach ($gnames as $gname) {
            // check if genre is found- otherwise fail silently
            if (is_numeric($genre = getGenreId($gname))) {
                $genres[] = $genre;
            }
        }
    }
    //--------------------------------
    //actors
    $actors = $imdbdata['cast'];
    //movie owner---------------------
    if (check_permission(PERM_WRITE, $_COOKIE['VDBuserid'])) {
        $owner_id = $_COOKIE['VDBuserid'];
    } else {
        $owner_id = 0;
    }
    //--------------------------------
    //cover
    $imgurl = $imdbdata['coverurl'];
    // lookup all other fields
    foreach (array_keys($imdbdata) as $name) {
        if (in_array($name, array('coverurl', 'genres', 'cast', 'id'))) {
            continue;
        }
        ${$name} = $imdbdata[$name];
    }
    //year
    if (empty($year)) {
        $year = '0000';
    }
    // set owner
    if (!empty($owner_id)) {
        $SETS = 'owner_id = ' . addslashes($owner_id);
    }
    $imdbID = $imdb_id;
    // update all fields according to list
    foreach ($imdb_set_fields as $name) {
        // sanitize input
        ${$name} = removeEvilTags(${$name});
        // make sure no formatting contained in basic data
        if (in_array($name, array('title', 'subtitle'))) {
            ${$name} = trim(strip_tags(${$name}));
            // string leading articles?
            if ($config['removearticles']) {
                foreach ($articles as $article) {
                    if (preg_match("/^{$article}+/i", ${$name})) {
                        ${$name} = trim(preg_replace("/(^{$article})(.+)/i", "\$2, \$1", ${$name}));
                        break;
                    }
                }
            }
        }
        $SET = "{$name} = '" . addslashes(${$name}) . "'";
        if (empty(${$name})) {
            if (in_array($name, $db_null_fields)) {
                $SET = "{$name} = NULL";
            } elseif (in_array($name, $db_zero_fields)) {
                $SET = "{$name} = 0";
            }
        }
        if ($SETS) {
            $SETS .= ', ';
        }
        $SETS .= $SET;
    }
    //inserting into database--------------------
    $INSERT = 'INSERT INTO ' . TBL_DATA . ' SET ' . $SETS . ', created = NOW()';
    //print_r($INSERT);
    //echo "<br><br>";
    $id = runSQL($INSERT);
    // save genres
    setItemGenres($id, $genres);
    //-------------------------------------------
    // insert userseen data
    $INSERTSEEN = 'INSERT INTO `userseen` (`video_id`, `user_id`) VALUES (' . $id . ',' . $owner_id . ')';
    runSQL($INSERTSEEN);
    $ret_title = $title;
    return 1;
}
Beispiel #3
0
     $engine = engineGetEngine($imdbID);
 }
 // get external data
 $imdbdata = engineGetData($imdbID, $engine);
 // lookup cover
 if (empty($imgurl) || $lookup > 1) {
     $imgurl = $imdbdata['coverurl'];
 }
 // lookup genres
 if (count($genres) == 0 || $lookup > 1) {
     $genres = array();
     $gnames = $imdbdata['genres'];
     if (isset($gnames)) {
         foreach ($gnames as $gname) {
             // check if genre is found- otherwise fail silently
             if (is_numeric($genre = getGenreId($gname))) {
                 $genres[] = $genre;
             }
         }
     }
 }
 // lookup actors
 if (empty($actors) || $lookup > 1) {
     $actors = $imdbdata['cast'];
 }
 // lookup all other fields
 foreach (array_keys($imdbdata) as $name) {
     if (in_array($name, array('coverurl', 'genres', 'cast', 'id'))) {
         continue;
     }
     // use !$$ as empty($$) doesn't seem to work
Beispiel #4
0
function save()
{
    global $form_eps;
    global $form_tvcomid;
    global $form_id;
    global $form_subtitle;
    global $form_plot;
    global $form_year;
    global $form_director;
    global $form_cast;
    global $form_rating;
    global $form_coverurl;
    global $form_genres;
    global $form_fastmode;
    global $cfg_rating_col;
    print '<h2>Updating database...</h2>';
    $fastmode = formvar($form_fastmode);
    foreach ($form_eps as $ep) {
        $id = $form_id[$ep];
        if (empty($id)) {
            continue;
        }
        $tvcomid = addslashes($form_tvcomid[$ep]);
        $subtitle = addslashes($form_subtitle[$ep]);
        $plot = addslashes($form_plot[$ep]);
        $year = addslashes($form_year[$ep]);
        $director = addslashes($form_director[$ep]);
        $cast = addslashes($form_cast[$ep]);
        $rating = addslashes($form_rating[$ep]);
        $coverurl = addslashes($form_coverurl[$ep]);
        if (!$fastmode) {
            $genres = mapGenres(explode(", ", addslashes($form_genres[$ep])));
        }
        print $form_subtitle[$ep] . '... ';
        $SQL = "UPDATE " . TBL_DATA . "\n               SET imdbID = '{$tvcomid}',\n                   istv = 1,\n                   lastupdate = NOW()";
        if (!$fastmode) {
            $SQL .= ",   plot = '{$plot}',\n                   year = '{$year}',\n                   director = '{$director}',\n                   actors = '{$cast}'";
            if (!empty($cfg_rating_col)) {
                $SQL .= ", {$cfg_rating_col} = '{$rating}'";
            }
            if (!empty($coverurl)) {
                $SQL .= ", imgurl = '{$coverurl}'";
            }
        }
        $SQL .= " WHERE id = {$id}";
        runSQL($SQL);
        // Genres
        if (!$fastmode && !empty($genres)) {
            $genre_ids = array();
            foreach ($genres as $g) {
                if ($gid = getGenreId($g)) {
                    $genre_ids[] = $gid;
                }
            }
            setItemGenres($id, $genre_ids);
        }
        print "done.<br>\n";
    }
    print '<p>back to <a href="tvtome.php">the importer</a> or to <a href="../index.php">the movies</a></p>';
}