Esempio n. 1
0
    /**
     * Fetch MediaInfo and a OGG sample for a Audio file.
     *
     * @param string $fileLocation
     * @param string $fileExtension
     *
     * @return bool
     */
    protected function _getAudioInfo($fileLocation, $fileExtension)
    {
        // Return values.
        $retVal = $audVal = false;
        // Check if audio sample fetching is on.
        if ($this->_processAudioSample === false) {
            $audVal = true;
        }
        // Check if media info fetching is on.
        if ($this->_processAudioInfo === false) {
            $retVal = true;
        }
        // Make sure the category is music or other.
        $rQuery = $this->pdo->queryOneRow(sprintf('SELECT searchname, categoryid AS id, group_id FROM releases WHERE proc_pp = 0 AND id = %d', $this->_release['id']));
        $musicParent = (string) \Category::CAT_PARENT_MUSIC;
        if ($rQuery === false || !preg_match(sprintf('/%d\\d{3}|%d|%d|%d/', $musicParent[0], \Category::CAT_MISC, \Category::CAT_MOVIE_OTHER, \Category::CAT_TV_OTHER), $rQuery['id'])) {
            return false;
        }
        if (is_file($fileLocation)) {
            // Check if media info is enabled.
            if ($retVal === false) {
                // Get the media info for the file.
                $xmlArray = \nzedb\utility\runCmd($this->_killString . $this->pdo->getSetting('mediainfopath') . '" --Output=XML "' . $fileLocation . '"');
                if (is_array($xmlArray)) {
                    // Convert to array.
                    $arrXml = \nzedb\utility\objectsIntoArray(@simplexml_load_string(implode("\n", $xmlArray)));
                    if (isset($arrXml['File']['track'])) {
                        foreach ($arrXml['File']['track'] as $track) {
                            if (isset($track['Album']) && isset($track['Performer'])) {
                                if (nZEDb_RENAME_MUSIC_MEDIAINFO && $this->_release['preid'] == 0) {
                                    // Make the extension upper case.
                                    $ext = strtoupper($fileExtension);
                                    // Form a new search name.
                                    if (!empty($track['Recorded_date']) && preg_match('/(?:19|20)\\d\\d/', $track['Recorded_date'], $Year)) {
                                        $newName = $track['Performer'] . ' - ' . $track['Album'] . ' (' . $Year[0] . ') ' . $ext;
                                    } else {
                                        $newName = $track['Performer'] . ' - ' . $track['Album'] . ' ' . $ext;
                                    }
                                    // Get the category or try to determine it.
                                    if ($ext === 'MP3') {
                                        $newCat = \Category::CAT_MUSIC_MP3;
                                    } else {
                                        if ($ext === 'FLAC') {
                                            $newCat = \Category::CAT_MUSIC_LOSSLESS;
                                        } else {
                                            $newCat = $this->_categorize->determineCategory($newName, $rQuery['group_id']);
                                        }
                                    }
                                    $newTitle = $this->pdo->escapeString(substr($newName, 0, 255));
                                    // Update the search name.
                                    $this->pdo->queryExec(sprintf('
											UPDATE releases
											SET searchname = %s, categoryid = %d, iscategorized = 1, isrenamed = 1, proc_pp = 1
											WHERE id = %d', $newTitle, $newCat, $this->_release['id']));
                                    $this->sphinx->updateReleaseSearchName($this->_release['id'], $newTitle);
                                    // Echo the changed name.
                                    if ($this->_echoCLI) {
                                        \NameFixer::echoChangedReleaseName(array('new_name' => $newName, 'old_name' => $rQuery['searchname'], 'new_category' => $newCat, 'old_category' => $rQuery['id'], 'group' => $rQuery['group_id'], 'release_id' => $this->_release['id'], 'method' => 'ProcessAdditional->_getAudioInfo'));
                                    }
                                }
                                // Add the media info.
                                $this->_releaseExtra->addFromXml($this->_release['id'], $xmlArray);
                                $retVal = true;
                                $this->_foundAudioInfo = true;
                                if ($this->_echoCLI) {
                                    $this->_echo('a', 'primaryOver', false);
                                }
                                break;
                            }
                        }
                    }
                }
            }
            // Check if creating audio samples is enabled.
            if ($audVal === false) {
                // File name to store audio file.
                $audioFileName = $this->_release['guid'] . '.ogg';
                // Create an audio sample.
                \nzedb\utility\runCmd($this->_killString . $this->pdo->getSetting('ffmpegpath') . '" -t 30 -i "' . $fileLocation . '" -acodec libvorbis -loglevel quiet -y "' . $this->tmpPath . $audioFileName . '"');
                // Check if the new file was created.
                if (is_file($this->tmpPath . $audioFileName)) {
                    // Try to move the temp audio file.
                    $renamed = rename($this->tmpPath . $audioFileName, $this->_audioSavePath . $audioFileName);
                    if (!$renamed) {
                        // Try to copy it if it fails.
                        $copied = copy($this->tmpPath . $audioFileName, $this->_audioSavePath . $audioFileName);
                        // Delete the old file.
                        unlink($this->tmpPath . $audioFileName);
                        // If it didn't copy continue.
                        if (!$copied) {
                            return false;
                        }
                    }
                    // Try to set the file perms.
                    @chmod($this->_audioSavePath . $audioFileName, 0764);
                    // Update DB to said we got a audio sample.
                    $this->pdo->queryExec(sprintf('
							UPDATE releases
							SET audiostatus = 1
							WHERE id = %d', $this->_release['id']));
                    $audVal = $this->_foundAudioSample = true;
                    if ($this->_echoCLI) {
                        $this->_echo('A', 'primaryOver', false);
                    }
                }
            }
        }
        return $retVal && $audVal;
    }
Esempio n. 2
0
 public function getRageMatch($showInfo)
 {
     $title = $showInfo['cleanname'];
     // Full search gives us the akas.
     $xml = nzedb\utility\getUrl($this->xmlFullSearchUrl . urlencode(strtolower($title)));
     if ($xml !== false) {
         $arrXml = @nzedb\utility\objectsIntoArray(simplexml_load_string($xml));
         if (isset($arrXml['show']) && is_array($arrXml)) {
             // We got a valid xml response
             $titleMatches = $urlMatches = $akaMatches = array();
             if (isset($arrXml['show']['showid'])) {
                 // We got exactly 1 match so lets convert it to an array so we can use it in the logic below.
                 $newArr = array();
                 $newArr[] = $arrXml['show'];
                 unset($arrXml);
                 $arrXml['show'] = $newArr;
             }
             foreach ($arrXml['show'] as $arr) {
                 $tvrlink = '';
                 // Get a match percentage based on our name and the name returned from tvr.
                 $titlepct = $this->checkMatch($title, $arr['name']);
                 if ($titlepct !== false) {
                     $titleMatches[$titlepct][] = array('title' => $arr['name'], 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr);
                 }
                 // Get a match percentage based on our name and the url returned from tvr.
                 if (isset($arr['link']) && preg_match('/tvrage\\.com\\/((?!shows)[^\\/]*)$/i', $arr['link'], $tvrlink)) {
                     $urltitle = str_replace('_', ' ', $tvrlink[1]);
                     $urlpct = $this->checkMatch($title, $urltitle);
                     if ($urlpct !== false) {
                         $urlMatches[$urlpct][] = array('title' => $urltitle, 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr);
                     }
                 }
                 // Check if there are any akas for this result and get a match percentage for them too.
                 if (isset($arr['akas']['aka'])) {
                     if (is_array($arr['akas']['aka'])) {
                         // Multuple akas.
                         foreach ($arr['akas']['aka'] as $aka) {
                             $akapct = $this->checkMatch($title, $aka);
                             if ($akapct !== false) {
                                 $akaMatches[$akapct][] = array('title' => $aka, 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr);
                             }
                         }
                     } else {
                         // One aka.
                         $akapct = $this->checkMatch($title, $arr['akas']['aka']);
                         if ($akapct !== false) {
                             $akaMatches[$akapct][] = array('title' => $arr['akas']['aka'], 'showid' => $arr['showid'], 'country' => $this->countryCode($arr['country']), 'genres' => $arr['genres'], 'tvr' => $arr);
                         }
                     }
                 }
             }
             // Reverse sort our matches so highest matches are first.
             krsort($titleMatches);
             krsort($urlMatches);
             krsort($akaMatches);
             // Look for 100% title matches first.
             if (isset($titleMatches[100])) {
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found 100% match: "' . $titleMatches[100][0]['title'] . '"');
                 }
                 return $titleMatches[100][0];
             }
             // Look for 100% url matches next.
             if (isset($urlMatches[100])) {
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found 100% url match: "' . $urlMatches[100][0]['title'] . '"');
                 }
                 return $urlMatches[100][0];
             }
             // Look for 100% aka matches next.
             if (isset($akaMatches[100])) {
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found 100% aka match: "' . $akaMatches[100][0]['title'] . '"');
                 }
                 return $akaMatches[100][0];
             }
             // No 100% matches, loop through what we got and if our next closest match is more than TvRage::MATCH_PROBABILITY % of the title lets take it.
             foreach ($titleMatches as $mk => $mv) {
                 // Since its not 100 match if we have country info lets use that to make sure we get the right show.
                 if (isset($showInfo['country']) && !empty($showInfo['country']) && !empty($mv[0]['country'])) {
                     if (strtolower($showInfo['country']) != strtolower($mv[0]['country'])) {
                         continue;
                     }
                 }
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found ' . $mk . '% match: "' . $titleMatches[$mk][0]['title'] . '"');
                 }
                 return $titleMatches[$mk][0];
             }
             // Same as above but for akas.
             foreach ($akaMatches as $ak => $av) {
                 if (isset($showInfo['country']) && !empty($showInfo['country']) && !empty($av[0]['country'])) {
                     if (strtolower($showInfo['country']) != strtolower($av[0]['country'])) {
                         continue;
                     }
                 }
                 if ($this->echooutput) {
                     echo $this->pdo->log->primary('Found ' . $ak . '% aka match: "' . $akaMatches[$ak][0]['title'] . '"');
                 }
                 return $akaMatches[$ak][0];
             }
             if ($this->echooutput) {
                 echo $this->pdo->log->primary('No match found on TVRage trying Trakt.');
             }
             return false;
         } else {
             if ($this->echooutput) {
                 echo $this->pdo->log->primary('Nothing returned from tvrage.');
             }
             return false;
         }
     } else {
         return -1;
     }
 }
Esempio n. 3
0
 public function addFromXml($releaseID, $xml)
 {
     $xmlObj = @simplexml_load_string($xml);
     $arrXml = nzedb\utility\objectsIntoArray($xmlObj);
     $containerformat = '';
     $overallbitrate = '';
     if (isset($arrXml['File']) && isset($arrXml['File']['track'])) {
         foreach ($arrXml['File']['track'] as $track) {
             if (isset($track['@attributes']) && isset($track['@attributes']['type'])) {
                 if ($track['@attributes']['type'] == 'General') {
                     if (isset($track['Format'])) {
                         $containerformat = $track['Format'];
                     }
                     if (isset($track['Overall_bit_rate'])) {
                         $overallbitrate = $track['Overall_bit_rate'];
                     }
                 } else {
                     if ($track['@attributes']['type'] == 'Video') {
                         $videoduration = $videoformat = $videocodec = $videowidth = $videoheight = $videoaspect = $videoframerate = $videolibrary = '';
                         if (isset($track['Duration'])) {
                             $videoduration = $track['Duration'];
                         }
                         if (isset($track['Format'])) {
                             $videoformat = $track['Format'];
                         }
                         if (isset($track['Codec_ID'])) {
                             $videocodec = $track['Codec_ID'];
                         }
                         if (isset($track['Width'])) {
                             $videowidth = preg_replace('/[^0-9]/', '', $track['Width']);
                         }
                         if (isset($track['Height'])) {
                             $videoheight = preg_replace('/[^0-9]/', '', $track['Height']);
                         }
                         if (isset($track['Display_aspect_ratio'])) {
                             $videoaspect = $track['Display_aspect_ratio'];
                         }
                         if (isset($track['Frame_rate'])) {
                             $videoframerate = str_replace(' fps', '', $track['Frame_rate']);
                         }
                         if (isset($track['Writing_library'])) {
                             $videolibrary = $track['Writing_library'];
                         }
                         $this->addVideo($releaseID, $containerformat, $overallbitrate, $videoduration, $videoformat, $videocodec, $videowidth, $videoheight, $videoaspect, $videoframerate, $videolibrary);
                     } else {
                         if ($track['@attributes']['type'] == 'Audio') {
                             $audioID = 1;
                             $audioformat = $audiomode = $audiobitratemode = $audiobitrate = $audiochannels = $audiosamplerate = $audiolibrary = $audiolanguage = $audiotitle = '';
                             if (isset($track['@attributes']['streamid'])) {
                                 $audioID = $track['@attributes']['streamid'];
                             }
                             if (isset($track['Format'])) {
                                 $audioformat = $track['Format'];
                             }
                             if (isset($track['Mode'])) {
                                 $audiomode = $track['Mode'];
                             }
                             if (isset($track['Bit_rate_mode'])) {
                                 $audiobitratemode = $track['Bit_rate_mode'];
                             }
                             if (isset($track['Bit_rate'])) {
                                 $audiobitrate = $track['Bit_rate'];
                             }
                             if (isset($track['Channel_s_'])) {
                                 $audiochannels = $track['Channel_s_'];
                             }
                             if (isset($track['Sampling_rate'])) {
                                 $audiosamplerate = $track['Sampling_rate'];
                             }
                             if (isset($track['Writing_library'])) {
                                 $audiolibrary = $track['Writing_library'];
                             }
                             if (isset($track['Language'])) {
                                 $audiolanguage = $track['Language'];
                             }
                             if (isset($track['Title'])) {
                                 $audiotitle = $track['Title'];
                             }
                             $this->addAudio($releaseID, $audioID, $audioformat, $audiomode, $audiobitratemode, $audiobitrate, $audiochannels, $audiosamplerate, $audiolibrary, $audiolanguage, $audiotitle);
                         } else {
                             if ($track['@attributes']['type'] == 'Text') {
                                 $subsID = 1;
                                 $subslanguage = 'Unknown';
                                 if (isset($track['@attributes']['streamid'])) {
                                     $subsID = $track['@attributes']['streamid'];
                                 }
                                 if (isset($track['Language'])) {
                                     $subslanguage = $track['Language'];
                                 }
                                 $this->addSubs($releaseID, $subsID, $subslanguage);
                             }
                         }
                     }
                 }
             }
         }
     }
 }