/** * 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, groupid 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_OTHER, \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 = Utility::runCmd($this->_killString . $this->pdo->getSetting('mediainfopath') . '" --Output=XML "' . $fileLocation . '"'); if (is_array($xmlArray)) { // Convert to array. $arrXml = 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 (NN_RENAME_MUSIC_MEDIAINFO && $this->_release['prehashid'] == 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($rQuery['groupid'], $newName); } } $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->updateRelease($this->_release['id'], $this->pdo); // Echo the changed name. if ($this->_echoCLI) { \NameFixer::echoChangedReleaseName(['new_name' => $newName, 'old_name' => $rQuery['searchname'], 'new_category' => $newCat, 'old_category' => $rQuery['id'], 'group' => $rQuery['groupid'], '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. 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; }
public static function objectsIntoArray($arrObjData, $arrSkipIndices = []) { $arrData = []; // If input is object, convert into array. if (is_object($arrObjData)) { $arrObjData = get_object_vars($arrObjData); } if (is_array($arrObjData)) { foreach ($arrObjData as $index => $value) { // Recursive call. if (is_object($value) || is_array($value)) { $value = Utility::objectsIntoArray($value, $arrSkipIndices); } if (in_array($index, $arrSkipIndices)) { continue; } $arrData[$index] = $value; } } return $arrData; }
public function getRageMatch($showInfo) { $title = $showInfo['cleanname']; // Full search gives us the akas. $xml = Utility::getUrl(['url' => $this->xmlFullSearchUrl . urlencode(strtolower($title))]); if ($xml !== false) { $arrXml = @Utility::objectsIntoArray(simplexml_load_string($xml)); if (isset($arrXml['show']) && is_array($arrXml)) { // We got a valid xml response $titleMatches = $urlMatches = $akaMatches = []; 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 = []; $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][] = ['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][] = ['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][] = ['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][] = ['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; } }
/** * Add releasevideo/audio/subs for a release based on the mediainfo xml. */ public function addFromXml($releaseID, $xml) { $xmlObj = @simplexml_load_string($xml); $arrXml = \newznab\utility\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"]; } $gendata = $track; } elseif ($track["@attributes"]["type"] == "Video") { $videoduration = ""; $videoformat = ""; $videocodec = ""; $videowidth = ""; $videoheight = ""; $videoaspect = ""; $videoframerate = ""; $videolibrary = ""; $gendata = ""; $viddata = ""; $audiodata = ""; 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"]; } $viddata = $track; $this->addVideo($releaseID, $containerformat, $overallbitrate, $videoduration, $videoformat, $videocodec, $videowidth, $videoheight, $videoaspect, $videoframerate, $videolibrary); } elseif ($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"]; } $audiodata = $track; $this->addAudio($releaseID, $audioID, $audioformat, $audiomode, $audiobitratemode, $audiobitrate, $audiochannels, $audiosamplerate, $audiolibrary, $audiolanguage, $audiotitle); } elseif ($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); } } } } }
public function getRageMatch($showInfo) { $title = $showInfo['cleanname']; $lookupUrl = $this->xmlFullSearchUrl . urlencode(strtolower($title)); $xml = $this->fetchCache($lookupUrl); if ($xml === false) { $xml = Utility::getUrl(['url' => $lookupUrl, 'verifycert' => false]); } if ($xml !== false) { $this->storeCache($lookupUrl, $xml); $xml = str_replace('<genre></genre>', '', $xml); $xmlObj = @simplexml_load_string($xml); $arrXml = Utility::objectsIntoArray($xmlObj); if (isset($arrXml['show']) && is_array($arrXml['show'])) { // we got a valid xml response $titleMatches = array(); $urlMatches = array(); $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) { $titlepct = $urlpct = $akapct = 0; // 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' => $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' => $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'])) { 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' => $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' => $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 'TVRage : Found 100% match: "' . $titleMatches[100][0]['title'] . '"' . "\n"; } return $titleMatches[100][0]; } // look for 100% url matches next if (isset($urlMatches[100])) { if ($this->echooutput) { echo 'TVRage : Found 100% url match: "' . $urlMatches[100][0]['title'] . '"' . "\n"; } return $urlMatches[100][0]; } // look for 100% aka matches next if (isset($akaMatches[100])) { if ($this->echooutput) { echo 'TVRage : Found 100% aka match: "' . $akaMatches[100][0]['title'] . '"' . "\n"; } 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 'TVRage : Found ' . $mk . '% match: "' . $titleMatches[$mk][0]['title'] . '"' . "\n"; } 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 'TVRage : Found ' . $ak . '% aka match: "' . $akaMatches[$ak][0]['title'] . '"' . "\n"; } return $akaMatches[$ak][0]; } return false; } else { return false; } } else { if ($this->echooutput) { echo 'TVRage : Error connecting to tvrage' . "\n"; } return -1; } if ($this->echooutput) { echo 'TVRage : No match found online' . "\n"; } return false; }