/** * @return Dto_MediaInformation|void */ public function retrieveInfo() { $mediaInfo = new Dto_MediaInformation(); $mediaInfo->setValid(false); /* * Create URL to retrive info from, for this provider * we only support direct id lookups for now */ $url = 'http://services.tvrage.com/feeds/showinfo.php?sid=' . $this->getSearchid() . '/'; list($http_code, $tvrage) = $this->_httpProvider->performCachedGet($url, false, 31 * 24 * 60 * 60); if (empty($tvrage)) { return $mediaInfo; } # if # fetch remote content $dom = new DomDocument(); $dom->preserveWhiteSpace = false; $dom->loadXML($tvrage); $showTitle = $dom->getElementsByTagName('showname'); /* * TV rage doesn't returns an 404 or something alike when the content is * not found, so we try to mimic this ourselves. */ # TVRage geeft geen 404 indien niet gevonden, dus vangen we dat zelf netjes op if (!@$showTitle->item(0)->nodeValue) { return $mediaInfo; } # if /* * Get the actual episode title */ $mediaInfo->setTitle($showTitle->item(0)->nodeValue); $mediaInfo->setValid(true); return $mediaInfo; }
/** * @return Dto_MediaInformation|void */ public function retrieveInfo() { $mediaInfo = new Dto_MediaInformation(); $mediaInfo->setValid(false); /* * Create URL to retrive info from, for this provider * we only support direct id lookups for now */ $url = 'http://www.imdb.com/title/tt' . $this->getSearchid() . '/'; list($http_code, $imdb) = $this->_httpProvider->performCachedGet($url, false, 31 * 24 * 60 * 60); if (empty($imdb)) { return $mediaInfo; } # if /* * Extract movie title from system */ /* preg_match('/<h1 itemprop="name" class="">([^\<]*)<span/ms', $imdb, $movieTitle); */ /* Extract the release date from the IMDB info page */ if (preg_match('/\\<a href="\\/year\\/([0-9]{4})/ms', $imdb, $movieReleaseDate)) { $mediaInfo->setReleaseYear($movieReleaseDate[1]); } # if preg_match('/\\<meta property=\'og:title\' content="([^<]*?)\\([0-9]*?\\)" \\/>/ms', $imdb, $movieTitle); if (isset($movieTitle[1])) { $movieTitle[1] = trim($movieTitle[1]); $mediaInfo->setTitle($movieTitle[1]); } # if // imdb sometimes returns the title translated, if so, pass the original title as well preg_match('/<meta name="title" content="([^<]*?)\\([0-9]*?\\)/ms', $imdb, $originalTitle); if (!empty($originalTitle) && trim($originalTitle[1]) != $movieTitle[1]) { $mediaInfo->setAlternateTitle(trim($originalTitle[1])); } # if $mediaInfo->setValid(true); return $mediaInfo; }
/** * @return Dto_MediaInformation|void */ public function retrieveInfo() { $mediaInfo = new Dto_MediaInformation(); $mediaInfo->setValid(false); /* * Create URL to retrive info from, for this provider * we only support direct id lookups for now */ if ($this->getSearchName() == "tvmaze") { $url = 'http://api.tvmaze.com/shows/' . $this->getSearchid(); } else { $url = 'http://api.tvmaze.com/lookup/shows?tvrage=' . $this->getSearchid(); } #if list($http_code, $tvmaze) = $this->_httpProvider->performCachedGet($url, false, 31 * 24 * 60 * 60); if (empty($tvmaze)) { return $mediaInfo; } # if # decode remote content $jsonoutp = json_decode($tvmaze); /* * TV maze doesn't returns an 404 or something alike when the content is * not found, so we try to mimic this ourselves. */ # TVMaze geeft geen 404 indien niet gevonden, dus vangen we dat zelf netjes op if (!$jsonoutp) { return $mediaInfo; } # if /* * Get the actual episode title */ $mediaInfo->setTitle($jsonoutp->{'name'}); $mediaInfo->setValid(true); return $mediaInfo; }
/** * Search the spotweb database for a specific piece of information * * @param $outputtype */ function search($outputtype) { # Check users' permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_perform_search, ''); $searchParams = array(); /** * Now determine what type of information we are searching for using sabnzbd */ if ($this->_params['t'] == "t" || $this->_params['t'] == "tvsearch") { $found = false; # First search on tvmazeid if present if ($found == false and $this->_params['tvmazeid'] != "") { if (!preg_match('/^[0-9]{1,6}$/', $this->_params['tvmazeid'])) { $this->showApiError(201); return; } // if /* * Actually retrieve the information from TVMaze, based on the * TVmaze ID passed by the API */ $svcMediaInfoTvmaze = new Services_MediaInformation_Tvmaze($this->_daoFactory->getCacheDao()); $svcMediaInfoTvmaze->setSearchid($this->_params['tvmazeid']); $svcMediaInfoTvmaze->setSearchName("tvmaze"); # Indicate tvmazeid usage $tvInfo = $svcMediaInfoTvmaze->retrieveInfo(); $found = $tvInfo->isValid(); } # second search on rid (rageid) if present if ($found == false and $this->_params['rid'] != "") { # validate input if (!preg_match('/^[0-9]{1,6}$/', $this->_params['rid'])) { $this->showApiError(201); return; } # if /* * Actually retrieve the information from TVMaze as long as TVrage is down, based on the * tvrage passed by the API */ $svcMediaInfoTvmaze = new Services_MediaInformation_Tvmaze($this->_daoFactory->getCacheDao()); $svcMediaInfoTvmaze->setSearchid($this->_params['rid']); $tvInfo = $svcMediaInfoTvmaze->retrieveInfo(); $svcMediaInfoTvmaze->setSearchName("tvrage"); # Indicate tvmazeid usage $found = $tvInfo->isValid(); } # third search on q (showname) if present if ($found == false and $this->_params['q'] != "") { $tvInfo = new Dto_MediaInformation(); $tvInfo->setTitle($this->_params['q']); $tvInfo->setValid(true); $found = true; } # fourth, no search information present, set emtpy if ($found == false) { if (!empty($this->_params['tvmazeid']) or !empty($this->_params['rid'])) { $this->showApiError(300); return; } $tvInfo = new Dto_MediaInformation(); $tvInfo->setTitle(""); $tvInfo->setValid(true); } /* * Try to parse the season parameter. This can be either in the form of S1, S01, 1, 2012, etc. * we try to standardize all these types of season definitions into one format. */ $episodeSearch = ''; $seasonSearch = ''; if (preg_match('/^[sS][0-9]{1,2}$/', $this->_params['season']) || preg_match('/^[0-9]{1,4}$/', $this->_params['season'])) { /* * Did we get passed a 4 digit season (most likely a year), or a * two digit season? */ if (strlen($this->_params['season']) < 3) { if (is_numeric($this->_params['season'])) { $seasonSearch = 'S' . str_pad($this->_params['season'], 2, "0", STR_PAD_LEFT); } else { $seasonSearch = $this->_params['season']; } # else } else { $seasonSearch = $this->_params['season'] . ' '; } # else } elseif ($this->_params['season'] != "") { $this->showApiError(201); return; } # if } if ($this->_params['t'] == "music") { if (empty($this->_params['artist']) && empty($this->_params['cat'])) { $this->_params['cat'] = 3000; } else { $searchParams['value'][] = "Titel:=:DEF:\"" . $this->_params['artist'] . "\""; } # if } elseif ($this->_params['t'] == "m" || $this->_params['t'] == "movie") { # validate input if ($this->_params['imdbid'] == "") { $this->showApiError(200); return; } elseif (!preg_match('/^[0-9]{1,8}$/', $this->_params['imdbid'])) { $this->showApiError(201); return; } # if /* * Actually retrieve the information from imdb, based on the * imdbid passed by the API */ $svcMediaInfoImdb = new Services_MediaInformation_Imdb($this->_daoFactory->getCacheDao()); $svcMediaInfoImdb->setSearchid($this->_params['imdbid']); $imdbInfo = $svcMediaInfoImdb->retrieveInfo(); if (!$imdbInfo->isValid()) { $this->showApiError(300); return; } # if /* Extract the release date from the IMDB info page */ if ($imdbInfo->getReleaseYear() != null) { $movieReleaseDate = '+(' . $imdbInfo->getReleaseYear() . ')'; } else { $movieReleaseDate = ''; } # else /* * Add movie title to the query */ $searchParams['value'][] = "Titel:=:OR:+\"" . $imdbInfo->getTitle() . "\" " . $movieReleaseDate; // imdb sometimes returns the title translated, if so, pass the original title as well if ($imdbInfo->getAlternateTitle() != null) { $searchParams['value'][] = "Title:=:OR:+\"" . $imdbInfo->getAlternateTitle() . "\" " . $movieReleaseDate; } # if } elseif (!empty($this->_params['q'])) { $searchTerm = str_replace(" ", " +", $this->_params['q']); $searchParams['value'][] = "Titel:=:OR:+" . $searchTerm; } # elseif /* * When a user added a maximum age for queries, convert it to * a Spotweb query as well */ if ($this->_params['maxage'] != "" && is_numeric($this->_params['maxage'])) { $searchParams['value'][] = "date:>:DEF:-" . $this->_params['maxage'] . "days"; } # if /* * We combine the "newznabapi" categories, with a custom extension for * categories so we can filter deeper than the newznab API can per default */ $tmpCat = array(); foreach (explode(",", $this->_params['cat']) as $category) { $tmpCat[] = $this->nabcat2spotcat($category); } # foreach $searchParams['tree'] = implode(",", $tmpCat) . ',' . $this->_params['spotcat']; /* * Do not retrieve spots with a filesize of zero (these are very old spots, * which have no NZB linked to it) as they are useless for a API consumer */ $searchParams['value'][] = "filesize:>:DEF:0"; /* * Gather the preference of the results per page and use it in this * system as well when no value is explicitly provided */ if (!empty($this->_params['limit']) && is_numeric($this->_params['limit']) && $this->_params['limit'] < 500) { $limit = $this->_params['limit']; } else { $limit = $this->_currentSession['user']['prefs']['perpage']; } # else if (!empty($this->_params['offset']) && is_numeric($this->_params['offset'])) { $pageNr = $this->_params['offset']; } else { $pageNr = 0; } # else /* * We get a bunch of query parameters, so now change this to the actual * search query the user requested including the required sorting */ $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings); $svcSearchQp = new Services_Search_QueryParser($this->_daoFactory->getConnection()); $parsedSearch = $svcSearchQp->filterToQuery($searchParams, array('field' => 'stamp', 'direction' => 'DESC'), $this->_currentSession, $svcUserFilter->getIndexFilter($this->_currentSession['user']['userid'])); /* * Actually fetch the spots, we always perform * this action even when the watchlist is editted */ $svcProvSpotList = new Services_Providers_SpotList($this->_daoFactory->getSpotDao()); $spotsTmp = $svcProvSpotList->fetchSpotList($this->_currentSession['user']['userid'], $pageNr, $limit, $parsedSearch); $this->showResults($spotsTmp, $pageNr * $limit, $outputtype); }