public function testSync() { $this->expectsEvents(LibraryChanged::class); $media = new Media(); $media->sync($this->mediaPath); // Standard mp3 files under root path should be recognized $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/full.mp3']); // Ogg files and audio files in subdirectories should be recognized $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/subdir/back-in-black.ogg']); // File search shouldn't be case-sensitive. $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/subdir/no-name.MP3']); // Non-audio files shouldn't be recognized $this->notSeeInDatabase('songs', ['path' => $this->mediaPath . '/rubbish.log']); // Broken/corrupted audio files shouldn't be recognized $this->notSeeInDatabase('songs', ['path' => $this->mediaPath . '/fake.mp3']); // Artists should be created $this->seeInDatabase('artists', ['name' => 'Cuckoo']); $this->seeInDatabase('artists', ['name' => 'Koel']); // Albums should be created $this->seeInDatabase('albums', ['name' => 'Koel Testing Vol. 1']); // Albums and artists should be correctly linked $album = Album::whereName('Koel Testing Vol. 1')->first(); $this->assertEquals('Koel', $album->artist->name); $currentCover = $album->cover; $song = Song::orderBy('id', 'desc')->first(); // Modified file should be recognized touch($song->path, $time = time()); $media->sync($this->mediaPath); $song = Song::find($song->id); $this->assertEquals($time, $song->mtime); // Albums with a non-default cover should have their covers overwritten $this->assertEquals($currentCover, Album::find($album->id)->cover); }
/** * Construct our File object. * Upon construction, we'll set the path, hash, and associated Song object (if any). * * @param string|SplFileInfo $path Either the file's path, or a SplFileInfo object * @param getID3 $getID3 A getID3 object for DI (and better performance) */ public function __construct($path, $getID3 = null) { $this->splFileInfo = $path instanceof SplFileInfo ? $path : new SplFileInfo($path); $this->setGetID3($getID3); $this->mtime = $this->splFileInfo->getMTime(); $this->path = $this->splFileInfo->getPathname(); $this->hash = self::getHash($this->path); $this->song = Song::find($this->hash); }
public function testSingleUpdateSomeInfoNoCompilation() { $song = Song::orderBy('id', 'desc')->first(); $originalArtistId = $song->album->artist->id; $this->actingAs(factory(User::class, 'admin')->create())->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => '', 'artistName' => '', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 0]])->seeStatusCode(200); // We don't expect the song's artist to change $this->assertEquals($originalArtistId, Song::find($song->id)->album->artist->id); // But we expect a new album to be created for this artist and contain this song $this->assertEquals('One by One', Song::find($song->id)->album->name); }
/** * Construct our File object. * Upon construction, we'll set the path, hash, and associated Song object (if any). * * @param string|SplFileInfo $path Either the file's path, or a SplFileInfo object * @param getID3 $getID3 A getID3 object for DI (and better performance) */ public function __construct($path, $getID3 = null) { $this->splFileInfo = $path instanceof SplFileInfo ? $path : new SplFileInfo($path); $this->setGetID3($getID3); // Workaround for #344, where getMTime() fails for certain files with Unicode names // on Windows. // Yes, beloved Windows. try { $this->mtime = $this->splFileInfo->getMTime(); } catch (Exception $e) { // Not worth logging the error. Just use current stamp for mtime. $this->mtime = time(); } $this->path = $this->splFileInfo->getPathname(); $this->hash = self::getHash($this->path); $this->song = Song::find($this->hash); $this->syncError = ''; }
public function testSync() { $this->expectsEvents(LibraryChanged::class); $media = new Media(); $media->sync($this->mediaPath); // Standard mp3 files under root path should be recognized $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/full.mp3', 'track' => 5]); // Ogg files and audio files in subdirectories should be recognized $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/subdir/back-in-black.ogg']); // GitHub issue #380. folder.png should be copied and used as the cover for files // under subdir/ $song = Song::wherePath($this->mediaPath . '/subdir/back-in-black.ogg')->first(); $this->assertNotNull($song->album->cover); // File search shouldn't be case-sensitive. $this->seeInDatabase('songs', ['path' => $this->mediaPath . '/subdir/no-name.MP3']); // Non-audio files shouldn't be recognized $this->notSeeInDatabase('songs', ['path' => $this->mediaPath . '/rubbish.log']); // Broken/corrupted audio files shouldn't be recognized $this->notSeeInDatabase('songs', ['path' => $this->mediaPath . '/fake.mp3']); // Artists should be created $this->seeInDatabase('artists', ['name' => 'Cuckoo']); $this->seeInDatabase('artists', ['name' => 'Koel']); // Albums should be created $this->seeInDatabase('albums', ['name' => 'Koel Testing Vol. 1']); // Albums and artists should be correctly linked $album = Album::whereName('Koel Testing Vol. 1')->first(); $this->assertEquals('Koel', $album->artist->name); // Compilation albums, artists and songs must be recognized $song = Song::whereTitle('This song belongs to a compilation')->first(); $this->assertNotNull($song->contributing_artist_id); $this->assertTrue($song->album->is_compilation); $this->assertEquals(Artist::VARIOUS_ID, $song->album->artist_id); $currentCover = $album->cover; $song = Song::orderBy('id', 'desc')->first(); // Modified file should be recognized touch($song->path, $time = time()); $media->sync($this->mediaPath); $song = Song::find($song->id); $this->assertEquals($time, $song->mtime); // Albums with a non-default cover should have their covers overwritten $this->assertEquals($currentCover, Album::find($album->id)->cover); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($society, $id, $mode = "view") { $data['soc'] = Society::find($society); $data['song'] = Song::find($id); $data['lyrics'] = ""; $data['chords'] = $this->_getChords($data['song']->lyrics); $lines = explode(PHP_EOL, $data['song']->lyrics); foreach ($lines as $line) { $line = str_replace("\r", '', $line); $line = str_replace("\n", '', $line); if (strpos($line, ']')) { $line = "<chordline>" . $line . "</chordline>"; $line = str_replace('[', '<chord>', $line); $line = str_replace(']', '</chord>', $line); } $line = $line . "<br>"; $line = str_replace('{', '<strong>', $line); $line = str_replace('}', '</strong>', $line); $data['lyrics'] = $data['lyrics'] . $line; } if ($mode == "view") { return View::make('songs.show', $data); } else { $this->pdf($data); } }
/** * Calculate Song Freshness (0...100%) * * ... based on the * - amount of times this song was used in general * - amount of times this song was used by this leader * - time span since the song was last used */ function calculateSongFreshness($song_id, $leader_id, $planDate) { $song = Song::find($song_id); $used_by_all = $song->plansUsingThisSong()->count(); $used_by_leader = $song->leadersUsingThisSong($leader_id)->count(); $last_time_used = $song->lastTimeUsed; $daysLapsed = 0; if ($last_time_used != null) { $daysLapsed = $last_time_used->diffInDays($planDate); } $a = 100 - $used_by_all; $b = 100 - $used_by_leader * 2; $c = 0 + min(100, $daysLapsed); $result = ($a + $b + $c) / 3; Log::debug("Freshness calc.: song_id {$song_id}, usage: {$used_by_all}, by leader: {$used_by_leader}, last time: {$daysLapsed} - ({$a} + {$b} + {$c}) / 3 = {$result}"); return $result; }
public function addtoQueue($id) { $song = \App\Models\Song::find($id); $songpath = env('SONGURL') . "/" . $song->id_singer . '/' . $song->id . "." . $song->url; \Queue::push(new Reproduce($songpath)); }
/** * Remove the specified resource from storage. Note: SoftDeletes !! * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Request $request, $id) { // // find a single resource by ID $output = Song::find($id); if ($output) { $output->delete(); flash('Song "' . $output->title . '" deleted.'); return \Redirect::back(); } // flash('Error! Song with ID "' . $id . '" not found'); return \Redirect::back(); }