Inheritance: extends Illuminate\Database\Eloquent\Model
Example #1
0
 /**
  * 根据ID获取相册所有图片
  * @param $id
  * @return $this
  */
 public function GetPhoList($id)
 {
     $photoSrv = new Photo();
     $albumSrv = new Album();
     $result['photo'] = $photoSrv->GetPhoList($id);
     $result['album'] = $albumSrv->GetAlbumInfo($id);
     return view('mei.pholist')->with('result', $result);
 }
Example #2
0
 /**
  * Creates a new Album model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Album();
     if ($model->load(Yii::$app->request->post())) {
         $model->created_by = Yii::$app->user->id;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #3
0
 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);
 }
Example #4
0
 /**
  * Sync a song with all available media info against the database.
  *
  * @param SplFileInfo $file The SplFileInfo instance of the file.
  *
  * @return bool|Song A Song object on success,
  *                   true if file existing but unmodified,
  *                   or false on error.
  */
 public function syncFile(SplFileInfo $file)
 {
     if (!($info = $this->getInfo($file))) {
         return false;
     }
     if (!$this->isNewOrChanged($file)) {
         return true;
     }
     $artist = Artist::get($info['artist']);
     $album = Album::get($artist, $info['album']);
     if ($info['cover'] && !$album->has_cover) {
         try {
             $album->generateCover($info['cover']);
         } catch (Exception $e) {
             Log::error($e);
         }
     }
     $info['album_id'] = $album->id;
     unset($info['artist']);
     unset($info['album']);
     unset($info['cover']);
     $song = Song::updateOrCreate(['id' => $this->getHash($file->getPathname())], $info);
     $song->save();
     return $song;
 }
Example #5
0
 public function actionMedia($type, $cat = 0, $order = 'date', $asc = 'desc', $name = "", $desp = "", $author = "")
 {
     $query;
     $typeid;
     if ($type == 'album') {
         $query = Album::find();
         $typeid = 0;
     } else {
         if ($type == 'video') {
             $query = Video::find();
             $typeid = 1;
         } else {
             $query = Message::find();
             $typeid = 2;
         }
     }
     $pagination = new Pagination(['defaultPageSize' => 30, 'totalCount' => $query->count()]);
     $query->distinct();
     $catArr = [];
     if ($cat) {
         $query->joinWith("category");
         $catArr = explode(',', $cat);
         $query->andWhere(['or', ['bnm_category_relationships.category' => $catArr]]);
     }
     $query->joinWith("editor");
     $query->andFilterWhere(['like', 'bnm_media.name', $name]);
     $query->andFilterWhere(['like', 'bnm_media.desp', $desp]);
     $query->orderBy($order . ' ' . $asc)->offset($pagination->offset)->limit($pagination->limit);
     //->asArray()
     //
     $catQuery = Category::find()->joinWith("categoryRelationship")->andWhere(['bnm_category_relationships.type' => $typeid])->distinct();
     return $this->render('media', ['media' => $query->all(), 'categories' => $catQuery->all(), 'pagination' => $pagination, 'catArr' => $catArr, 'catUrl' => $cat, 'oldCat' => ['cat' => $cat], 'oldOrder' => ['order' => $order, 'asc' => $asc], 'oldSearch' => ['name' => $name, 'desp' => $desp, 'author' => $author], 'type' => $type, 'typeid' => $typeid, 'asc' => $asc, 'order' => $order, 'name' => $name, 'desp' => $desp, 'author' => $author]);
 }
Example #6
0
 /**
  * Fired every time a LibraryChanged event is triggered.
  * Remove empty albums and artists from our system.
  */
 public function handle()
 {
     $inUseAlbums = Song::select('album_id')->groupBy('album_id')->get()->lists('album_id');
     $inUseAlbums[] = Album::UNKNOWN_ID;
     Album::whereNotIn('id', $inUseAlbums)->delete();
     $inUseArtists = Album::select('artist_id')->groupBy('artist_id')->get()->lists('artist_id');
     $inUseArtists[] = Artist::UNKNOWN_ID;
     Artist::whereNotIn('id', $inUseArtists)->delete();
 }
 public function delete(Request $request)
 {
     $album = Album::find($request->input('id'));
     foreach ($album->photos as $photo) {
         if (File::exists($photo->image_url)) {
             File::delete($photo->image_url);
         }
     }
     $album->delete();
     return response()->json(['message' => 'Альбом удален.']);
 }
Example #8
0
 public function testSingleUpdateAllInfo()
 {
     $this->expectsEvents(LibraryChanged::class);
     $this->createSampleMediaSet();
     $song = Song::orderBy('id', 'desc')->first();
     $this->actingAs(factory(User::class, 'admin')->create())->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Foo Bar', 'artistName' => 'John Cena', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1]])->seeStatusCode(200);
     $artist = Artist::whereName('John Cena')->first();
     $this->assertNotNull($artist);
     $album = Album::whereName('One by One')->first();
     $this->assertNotNull($album);
     $this->seeInDatabase('songs', ['id' => $song->id, 'album_id' => $album->id, 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1]);
 }
Example #9
0
 /**
  * @test
  */
 function it_gets_the_total_length_of_all_songs_in_album()
 {
     // given
     $artist = Factory::create(Artist::class);
     $album = Factory::create(Album::class, ['artist_id' => $artist->id]);
     Factory::times(3)->create(Song::class, ['album_id' => $album->id, 'length' => 200]);
     // when
     $album = Album::first();
     $length = $album->getTotalLength();
     // then
     $this->assertEquals(600, $length);
 }
 /**
  * Create new photo and add it to the album.
  *
  * @param Request $request
  * @return mixed
  */
 public function create(Request $request)
 {
     //get the file from the post request
     $file = $request->file('file');
     //set file name
     $filename = uniqid() . $file->getClientOriginalName();
     //move the file to correct location
     $file->move('uploads/albums', $filename);
     //save the image details to the database
     $album = Album::find($request->input('album_id'));
     $photo = $album->photos()->create(['title' => $filename, 'image_url' => 'uploads/albums/' . $filename]);
     return $photo;
 }
Example #11
0
 /**
  * Store a new song or update an existing one with data from AWS.
  *
  * @param PutSongRequest $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function put(PutSongRequest $request)
 {
     $path = "s3://{$request->bucket}/{$request->key}";
     $tags = $request->tags;
     $artist = Artist::get(array_get($tags, 'artist'));
     $compilation = (bool) trim(array_get($tags, 'albumartist'));
     $album = Album::get($artist, array_get($tags, 'album'), $compilation);
     if ($cover = array_get($tags, 'cover')) {
         $album->writeCoverFile(base64_decode($cover['data']), $cover['extension']);
     }
     $song = Song::updateOrCreate(['id' => Media::getHash($path)], ['path' => $path, 'album_id' => $album->id, 'contributing_artist_id' => $compilation ? $artist->id : null, 'title' => trim(array_get($tags, 'title', '')), 'length' => array_get($tags, 'duration', 0), 'track' => intval(array_get($tags, 'track')), 'lyrics' => array_get($tags, 'lyrics', ''), 'mtime' => time()]);
     return response()->json($song);
 }
Example #12
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Album::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith('subTag')->joinWith('mainTag')->andFilterWhere(['id' => $this->id, 'article_type_id' => $this->article_type_id, 'sub_tag' => $this->sub_tag, 'main_tag' => $this->main_tag, 'create_date' => $this->create_date])->andFilterWhere(['like', 'album_name_ar', $this->album_name_ar])->andFilterWhere(['like', 'album_name_en', $this->album_name_en])->andFilterWhere(['like', 'status', $this->status]);
     //->andFilterWhere(['like', 'CONCAT(full_name,username)', $this->created_by]);
     return $dataProvider;
 }
Example #13
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Album::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'fecha_lanzamiento' => $this->fecha_lanzamiento]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'artista', $this->artista]);
     return $dataProvider;
 }
Example #14
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Album::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_dt' => $this->created_dt]);
     $query->andFilterWhere(['like', 'ref', $this->ref])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #15
0
 /**
  * Register any other events for your application.
  *
  * @param \Illuminate\Contracts\Events\Dispatcher $events
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     // Generate a unique hash for a song from its path to be the ID
     Song::creating(function ($song) {
         $song->id = Media::getHash($song->path);
     });
     // Remove the cover file if the album is deleted
     Album::deleted(function ($album) {
         if ($album->hasCover) {
             @unlink(app()->publicPath() . '/public/img/covers/' . $album->cover);
         }
     });
 }
Example #16
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Album::find();
     $query->joinWith(['editor']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['editor'] = ['asc' => ['bnm_users.name' => SORT_ASC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['ID' => $this->ID, 'user' => $this->user, 'date' => $this->date, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'bnm_media.name', $this->name])->andFilterWhere(['like', 'desp', $this->desp])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'bnm_users.name', $this->editor])->andFilterWhere(['like', 'thumbnail', $this->thumbnail]);
     return $dataProvider;
 }
Example #17
0
 public function oAuthSuccess($client)
 {
     $info = $client->api('/me?fields=id,name,email,birthday,gender,website,link,about', 'GET');
     $exist_user_id = FacebookLogin::getExistUserId($info['id']);
     if ($exist_user_id != "") {
         $identity = User::findOne(['id' => $exist_user_id]);
         \Yii::$app->user->login($identity, 3600 * 24 * 30);
         $this->redirect('/id' . $exist_user_id);
     } else {
         $locale = $client->api('/me?fields=locale', 'GET')['locale'];
         $location_work_education = $client->api('/me?locale=' . $locale . '&fields=work,education{school},location', 'GET');
         $name = $info['name'];
         $email = $info['email'];
         $bday = explode("/", $info['birthday']);
         $bday = $bday[2] . "-" . $bday[0] . "-" . $bday[1];
         // Стать
         $sex = $info['gender'] == 'male' ? 2 : 1;
         // Місто
         $city = $location_work_education['location']['name'];
         // Країна
         if ($location_work_education['location']['id']) {
             $country = FacebookLogin::getUserCountry($locale, $location_work_education['location']['id'], $client);
         } else {
             $country = "";
         }
         // Робота
         $work = FacebookLogin::getUserWork($location_work_education['work']);
         // Освіта
         $education = FacebookLogin::getUserEducation($location_work_education['education']);
         // Сайт
         $site = $info['website'];
         // Фейсбук сторінка
         $fb = $info['link'];
         // Аватар
         FacebookLogin::copyUserAvatar($info['id']);
         \Yii::$app->db->createCommand("\n                INSERT INTO user (name, email, bday, sex, country, city, work, education, site, fb, avatar, rating, created_at, facebook_id)\n                VALUES ('{$name}', '{$email}', '{$bday}', '{$sex}', '{$country}', '{$city}', '{$work}', '{$education}', '{$site}', '{$fb}', 'fb_user_" . $info['id'] . ".jpg', 1, '" . time() . "', '" . $info['id'] . "')\n            ")->execute();
         $user_id = \Yii::$app->db->getLastInsertID();
         $identity = User::findOne(['id' => $user_id]);
         \Yii::$app->user->login($identity);
         User::setDefaultPrivacy($user_id);
         Album::createAlbum($user_id);
         $this->redirect("/id" . $user_id);
     }
 }
Example #18
0
 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);
 }
Example #19
0
 /**
  * Finds the Album model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Album the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Album::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $album = Album::findOrFail($id);
     return response()->view('album.show', ['album' => $album]);
 }
Example #21
0
 public function testAlbum()
 {
     $album = Album::first();
     $mocked = Download::shouldReceive('from')->once()->andReturn($this->mediaPath . '/blank.mp3');
     $this->get("api/download/album/{$album->id}")->seeStatusCode(200);
 }
Example #22
0
 protected function getAlbumsInfo()
 {
     return Album::where('created_at', '<=', Carbon::now())->orderBy('created_at', 'desc')->lists('updated_at', 'id')->all();
 }
Example #23
0
 public function testSingleUpdateAllInfoYesCompilation()
 {
     $admin = factory(User::class, 'admin')->create();
     $song = Song::orderBy('id', 'desc')->first();
     $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Foo Bar', 'artistName' => 'John Cena', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 1]])->seeStatusCode(200);
     $compilationAlbum = Album::whereArtistIdAndName(Artist::VARIOUS_ID, 'One by One')->first();
     $this->assertNotNull($compilationAlbum);
     $contributingArtist = Artist::whereName('John Cena')->first();
     $this->assertNotNull($contributingArtist);
     $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id, 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1]);
     // Now try changing stuff and make sure things work.
     // Case 1: Keep compilation state and artist the same
     $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'John Cena', 'albumName' => 'Two by Two', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 2]])->seeStatusCode(200);
     $compilationAlbum = Album::whereArtistIdAndName(Artist::VARIOUS_ID, 'Two by Two')->first();
     $this->assertNotNull($compilationAlbum);
     $contributingArtist = Artist::whereName('John Cena')->first();
     $this->assertNotNull($contributingArtist);
     $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id]);
     // Case 2: Keep compilation state, but change the artist.
     $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'Foo Fighters', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 2]])->seeStatusCode(200);
     $compilationAlbum = Album::whereArtistIdAndName(Artist::VARIOUS_ID, 'One by One')->first();
     $this->assertNotNull($compilationAlbum);
     $contributingArtist = Artist::whereName('Foo Fighters')->first();
     $this->assertNotNull($contributingArtist);
     $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => $contributingArtist->id, 'album_id' => $compilationAlbum->id]);
     // Case 3: Change compilation state only
     $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'Foo Fighters', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 0]])->seeStatusCode(200);
     $artist = Artist::whereName('Foo Fighters')->first();
     $this->assertNotNull($artist);
     $album = Album::whereArtistIdAndName($artist->id, 'One by One')->first();
     $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => null, 'album_id' => $album->id]);
     // Case 3: Change compilation state and artist
     // Remember to set the compliation state back to 1
     $this->actingAs($admin)->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Barz Qux', 'artistName' => 'Foo Fighters', 'albumName' => 'One by One', 'lyrics' => 'Lorem ipsum dolor sic amet.', 'track' => 1, 'compilationState' => 1]])->put('/api/songs', ['songs' => [$song->id], 'data' => ['title' => 'Twilight of the Thunder God', 'artistName' => 'Amon Amarth', 'albumName' => 'Twilight of the Thunder God', 'lyrics' => 'Thor! Nanananananana Batman.', 'track' => 1, 'compilationState' => 0]])->seeStatusCode(200);
     $artist = Artist::whereName('Amon Amarth')->first();
     $this->assertNotNull($artist);
     $album = Album::whereArtistIdAndName($artist->id, 'Twilight of the Thunder God')->first();
     $this->assertNotNull($album);
     $this->seeInDatabase('songs', ['id' => $song->id, 'contributing_artist_id' => null, 'album_id' => $album->id, 'lyrics' => 'Thor! Nanananananana Batman.']);
 }
Example #24
0
 /**
  * Tidy up the library by deleting empty albums and artists.
  */
 public function tidy()
 {
     $inUseAlbums = Song::select('album_id')->groupBy('album_id')->get()->lists('album_id')->toArray();
     $inUseAlbums[] = Album::UNKNOWN_ID;
     Album::whereNotIn('id', $inUseAlbums)->delete();
     $inUseArtists = Album::select('artist_id')->groupBy('artist_id')->get()->lists('artist_id')->toArray();
     $contributingArtists = Song::distinct()->select('contributing_artist_id')->groupBy('contributing_artist_id')->get()->lists('contributing_artist_id')->toArray();
     $inUseArtists = array_merge($inUseArtists, $contributingArtists);
     $inUseArtists[] = Artist::UNKNOWN_ID;
     $inUseArtists[] = Artist::VARIOUS_ID;
     Artist::whereNotIn('id', $inUseArtists)->delete();
 }
Example #25
0
 /**
  * Update a single song's info.
  *
  * @param string $title
  * @param string $albumName
  * @param string $artistName
  * @param string $lyrics
  * @param int    $track
  * @param int    $compilationState
  *
  * @return self
  */
 public function updateSingle($title, $albumName, $artistName, $lyrics, $track, $compilationState)
 {
     // If the artist name is "Various Artists", it's a compilation song no matter what.
     if ($artistName === Artist::VARIOUS_NAME) {
         $compilationState = 1;
     }
     // If the complitation state is "no change," we determine it via the current
     // "contributing_artist_id" field value.
     if ($compilationState === 2) {
         $compilationState = $this->contributing_artist_id ? 1 : 0;
     }
     $album = null;
     if ($compilationState === 0) {
         // Not a compilation song
         $this->contributing_artist_id = null;
         $albumArtist = Artist::get($artistName);
         $album = Album::get($albumArtist, $albumName, false);
     } else {
         $contributingArtist = Artist::get($artistName);
         $this->contributing_artist_id = $contributingArtist->id;
         $album = Album::get(Artist::getVarious(), $albumName, true);
     }
     $this->album_id = $album->id;
     $this->lyrics = $lyrics;
     $this->track = $track;
     $this->save();
     // Get the updated record, with album and all.
     $updatedSong = self::with('album', 'album.artist', 'contributingArtist')->find($this->id);
     // Make sure lyrics is included in the returned JSON.
     $updatedSong->makeVisible('lyrics');
     return $updatedSong;
 }
Example #26
0
 /**
  * Get extra information about an album via Last.fm.
  *
  * @param Album $album
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function getInfo(Album $album)
 {
     return response()->json($album->getInfo());
 }
Example #27
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     if ($this->auth->check()) {
         $status = "logined";
     } else {
         $status = "unlogin";
     }
     $albums = Album::with('Photos')->find($id);
     return view('layouts.photos', ['loginStauts' => $status], ['album' => $albums]);
 }
Example #28
0
 /**
  * Sync the song with all available media info against the database.
  *
  * @param array $tags  The (selective) tags to sync (if the song exists)
  * @param bool  $force Whether to force syncing, even if the file is unchaged
  *
  * @return bool|Song A Song object on success,
  *                   true if file exists but is unmodified,
  *                   or false on an error.
  */
 public function sync($tags, $force = false)
 {
     // If the file is not new or changed and we're not forcing update, don't do anything.
     if (!$this->isNewOrChanged() && !$force) {
         return true;
     }
     // If the file is invalid, don't do anything.
     if (!($info = $this->getInfo())) {
         return false;
     }
     if ($this->isChanged() || $force) {
         // This is a changed file, or the user is forcing updates.
         // We cater for the tags by removing those not specified.
         $info = array_intersect_key($info, array_flip($tags));
         $artist = isset($info['artist']) ? Artist::get($info['artist']) : $this->song->album->artist;
         $album = isset($info['album']) ? Album::get($artist, $info['album']) : $this->song->album;
     } else {
         $album = Album::get(Artist::get($info['artist']), $info['album']);
     }
     if (!empty($info['cover']) && !$album->has_cover) {
         try {
             $album->generateCover($info['cover']);
         } catch (Exception $e) {
             Log::error($e);
         }
     }
     $info['album_id'] = $album->id;
     // Remove these values from the info array, so that we can just use the array as model's input data.
     array_forget($info, ['artist', 'album', 'cover']);
     $song = Song::updateOrCreate(['id' => $this->hash], $info);
     $song->save();
     return $song;
 }
Example #29
0
File: File.php Project: phanan/koel
 /**
  * Sync the song with all available media info against the database.
  *
  * @param array $tags  The (selective) tags to sync (if the song exists)
  * @param bool  $force Whether to force syncing, even if the file is unchanged
  *
  * @return bool|Song A Song object on success,
  *                   true if file exists but is unmodified,
  *                   or false on an error.
  */
 public function sync($tags, $force = false)
 {
     // If the file is not new or changed and we're not forcing update, don't do anything.
     if (!$this->isNewOrChanged() && !$force) {
         return true;
     }
     // If the file is invalid, don't do anything.
     if (!($info = $this->getInfo())) {
         return false;
     }
     // Fixes #366. If the file is new, we use all tags by simply setting $force to false.
     if ($this->isNew()) {
         $force = false;
     }
     $artist = null;
     if ($this->isChanged() || $force) {
         // This is a changed file, or the user is forcing updates.
         // In such a case, the user must have specified a list of tags to sync.
         // A sample command could be: ./artisan koel:sync --force --tags=artist,album,lyrics
         // We cater for these tags by removing those not specified.
         // There's a special case with 'album' though.
         // If 'compilation' tag is specified, 'album' must be counted in as well.
         // But if 'album' isn't specified, we don't want to update normal albums.
         // This variable is to keep track of this state.
         $changeCompilationAlbumOnly = false;
         if (in_array('compilation', $tags, true) && !in_array('album', $tags, true)) {
             $tags[] = 'album';
             $changeCompilationAlbumOnly = true;
         }
         $info = array_intersect_key($info, array_flip($tags));
         // If the "artist" tag is specified, use it.
         // Otherwise, re-use the existing model value.
         $artist = isset($info['artist']) ? Artist::get($info['artist']) : $this->song->album->artist;
         $isCompilation = (bool) array_get($info, 'compilation');
         // If the "album" tag is specified, use it.
         // Otherwise, re-use the existing model value.
         if (isset($info['album'])) {
             $album = $changeCompilationAlbumOnly ? $this->song->album : Album::get($artist, $info['album'], $isCompilation);
         } else {
             $album = $this->song->album;
         }
     } else {
         // The file is newly added.
         $isCompilation = (bool) array_get($info, 'compilation');
         $artist = Artist::get($info['artist']);
         $album = Album::get($artist, $info['album'], $isCompilation);
     }
     if (!$album->has_cover) {
         // If the album has no cover, we try to get the cover image from existing tag data
         if (!empty($info['cover'])) {
             try {
                 $album->generateCover($info['cover']);
             } catch (Exception $e) {
                 Log::error($e);
             }
         } elseif ($cover = $this->getCoverFileUnderSameDirectory()) {
             $album->copyCoverFile($cover);
         }
     }
     $info['album_id'] = $album->id;
     // If the song is part of a compilation, make sure we properly set its
     // artist and contributing artist attributes.
     if ($isCompilation) {
         $info['contributing_artist_id'] = $artist->id;
     }
     // Remove these values from the info array, so that we can just use the array as model's input data.
     array_forget($info, ['artist', 'albumartist', 'album', 'cover', 'compilation']);
     return Song::updateOrCreate(['id' => $this->hash], $info);
 }
 public function actionDeletefileAjax()
 {
     $model = Uploads::findOne(Yii::$app->request->post('key'));
     if ($model !== NULL) {
         $filename = Album::getUploadPath() . $model->ref . '/' . $model->realfilename;
         $thumbnail = Album::getUploadPath() . $model->ref . '/thumbnail/' . $model->realfilename;
         if ($model->delete()) {
             @unlink($filename);
             @unlink($thumbnail);
             echo json_encode(['success' => true]);
         } else {
             echo json_encode(['success' => false]);
         }
     } else {
         echo json_encode(['success' => false]);
     }
 }