/** * Execute the console command. * * @return void */ public function handle() { // Get the list of tracks that need classification $tracks = DB::table('mlpma_tracks')->orderBy('id')->get(); $this->comment('Importing tracks...'); $totalTracks = sizeof($tracks); $fileToStartAt = (int) $this->option('startAt') - 1; $this->comment("Skipping {$fileToStartAt} files..." . PHP_EOL); $tracks = array_slice($tracks, $fileToStartAt); $this->currentTrack = $fileToStartAt; foreach ($tracks as $track) { $this->currentTrack++; $this->comment('[' . $this->currentTrack . '/' . $totalTracks . '] Classifying track [' . $track->filename . ']...'); $parsedTags = json_decode($track->parsed_tags, true); //========================================================================================================== // Original, show song remix, fan song remix, show audio remix, or ponified song? //========================================================================================================== $sanitizedTrackTitle = $parsedTags['title']; $sanitizedTrackTitle = str_replace(['-', '+', '~', 'ft.', '*', '(', ')', '.'], ' ', $sanitizedTrackTitle); $queriedTitle = DB::connection()->getPdo()->quote($sanitizedTrackTitle); $officialSongs = ShowSong::select(['id', 'title'])->whereRaw("\n MATCH (title)\n AGAINST ({$queriedTitle} IN BOOLEAN MODE)\n ")->get(); // If it has "Ingram" in the name, it's definitely an official song remix. if (Str::contains(Str::lower($track->filename), 'ingram')) { $this->info('This is an official song remix!'); list($trackType, $linkedSongIds) = $this->classifyTrack($track->filename, $officialSongs, true, $parsedTags); // If it has "remix" in the name, it's definitely a remix. } else { if (Str::contains(Str::lower($sanitizedTrackTitle), 'remix')) { $this->info('This is some kind of remix!'); list($trackType, $linkedSongIds) = $this->classifyTrack($track->filename, $officialSongs, false, $parsedTags); // No idea what this is. Have the pony at the terminal figure it out! } else { list($trackType, $linkedSongIds) = $this->classifyTrack($track->filename, $officialSongs, false, $parsedTags); } } //========================================================================================================== // Attach the data and publish the track! //========================================================================================================== $track = Track::find($track->track_id); $track->track_type_id = $trackType; $track->published_at = $parsedTags['released_at']; $track->save(); if (sizeof($linkedSongIds) > 0) { $track->showSongs()->sync($linkedSongIds); } echo PHP_EOL; } }
public function getAll() { return \Response::json(['licenses' => License::all()->toArray(), 'genres' => Genre::select('genres.*', DB::raw('(SELECT COUNT(id) FROM tracks WHERE tracks.genre_id = genres.id AND tracks.published_at IS NOT NULL) AS track_count'))->orderBy('name')->get()->toArray(), 'track_types' => TrackType::select('track_types.*', DB::raw('(SELECT COUNT(id) FROM tracks WHERE tracks.track_type_id = track_types.id AND tracks.published_at IS NOT NULL) AS track_count'))->where('id', '!=', TrackType::UNCLASSIFIED_TRACK)->get()->toArray(), 'show_songs' => ShowSong::select('title', 'id', 'slug', DB::raw('(SELECT COUNT(tracks.id) FROM show_song_track INNER JOIN tracks ON tracks.id = show_song_track.track_id WHERE show_song_track.show_song_id = show_songs.id AND tracks.published_at IS NOT NULL) AS track_count'))->get()->toArray()], 200); }