Ejemplo n.º 1
0
 public function registerFilters()
 {
     $this->registerSaveFilter('title', function ($intended) {
         $artist = $_POST['songArtistField'];
         $song = $intended;
         $id = $_POST["ID"];
         if (has_post_thumbnail($id)) {
             return $intended;
         }
         $term = "{$artist}+{$song}";
         $url = PostOutput::replaceVars($this->itunesSearchUrl, (object) ["entity" => 'song', "term" => str_replace(" ", "+", $term)]);
         $res = file_get_contents($url);
         if ($res) {
             $res = json_decode($res);
         }
         $song = $res->results[0];
         $imageUrl = str_replace("60", "1280", $song->artworkUrl60);
         $res = Utils::addPostImage($id, $imageUrl);
         $_POST["itunesCollectionId"] = $song->collectionId;
         $_POST["itunesTrackId"] = $song->trackId;
         return $intended;
     });
 }
Ejemplo n.º 2
0
 public function registerFilters()
 {
     $this->registerSaveFilter('title', function ($intended) {
         $artist = $_POST['albumArtistField'];
         $album = $intended;
         $id = $_POST["ID"];
         if (has_post_thumbnail($id)) {
             return $intended;
         }
         $term = "{$artist}+{$album}";
         $url = PostOutput::replaceVars($this->itunesSearchUrl, (object) ["entity" => 'album', "term" => str_replace(" ", "+", $term)]);
         $res = file_get_contents($url);
         if ($res) {
             $res = json_decode($res);
         }
         $album = $res->results[0];
         $imageUrl = str_replace("60", "1280", $album->artworkUrl60);
         $_POST['albumItunesCollectionIdField'] = $album->collectionId;
         $songs = "https://itunes.apple.com/lookup?entity=song&id=" . $album->collectionId;
         $songResponse = file_get_contents($songs);
         if ($songResponse) {
             $songResponse = json_decode($songResponse);
         }
         $songResponse = $songResponse->results;
         $temp = [];
         // first result is album
         array_shift($songResponse);
         foreach ($songResponse as $index => $value) {
             $ms = $value->trackTimeMillis;
             $len = floor($ms / 60000) . ':' . floor($ms % 60000 / 1000) . ':' . str_pad(floor($ms % 1000), 3, '0', STR_PAD_LEFT);
             $len = explode(":", $len);
             array_shift($len);
             $temp[] = ["name" => $value->trackName, "len" => implode(":", $len), "itunesStreamable" => $value->isStreamable];
         }
         $_POST['albumAlbumTracklistField'] = json_encode($temp);
         $res = Utils::addPostImage($id, $imageUrl);
         return $intended;
     });
 }