コード例 #1
0
 public function doCreateAlbum(Guard $guard, Request $request)
 {
     if ($guard->guest()) {
         throw new AppException(AppException::NEED_SIGN_IN);
     }
     $musics = $request->get('musics');
     $coverImageId = $request->get('cover_image_id');
     $title = $request->get('title');
     $artist = $request->get('artist');
     $year = $request->get('year');
     $genre = $request->get('genre');
     $album = new Album();
     $album->title = $title;
     $album->artist = $artist;
     $album->year = $year;
     $album->genre = $genre;
     $album->coverImage()->associate($coverImageId);
     $album->user()->associate($guard->id());
     $album->save();
     foreach ($musics as $musicId) {
         /** @var Music $music */
         $music = Music::where('id', $musicId)->first();
         if (!$music) {
             continue;
         }
         $album->musics()->attach($musicId);
         if (!$music->coverImage) {
             $music->coverImage()->associate($album->coverImage);
             $music->save();
         }
     }
     return $this->buildResponse(trans('api.album.create.success'), Tools::toArray($album));
 }
コード例 #2
0
 public function destroy($id)
 {
     $music = Music::findOrFail($id);
     $input = Request::all();
     $music->delete($input);
     return redirect()->route('music.index');
 }
コード例 #3
0
 public function getAmaotoFlow()
 {
     $flow = new Collection();
     Music::orderByRaw('RAND()')->take(10)->get()->each(function ($item) use(&$flow) {
         /** @var Music $item */
         $flow->push(['type' => 'music', 'data' => $item->toArray()]);
     });
     Album::orderByRaw('RAND()')->take(10)->get()->each(function ($item) use(&$flow) {
         /** @var Album $item */
         $flow->push(['type' => 'album', 'data' => $item->toArray()]);
     });
     $result = $flow->shuffle();
     return $this->buildResponse(trans('api.system.get-amaoto-flow.success'), Tools::toArray($result));
 }
コード例 #4
0
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $music = Music::orderBy('music_id', 'desc')->first();
     $love = ['song_collection_id' => $music->music_id, 'love_source' => 1];
     $loves = Love::where($love)->count();
     $is_love = false;
     if (Auth::user()) {
         $love['love_user'] = Auth::user()->id;
         $row = Love::where($love)->first();
         if ($row) {
             $is_love = true;
         }
     }
     $previous = Music::where('music_id', '<', $music->music_id)->max('music_id');
     $next = Music::where('music_id', '>', $music->music_id)->min('music_id');
     return view('music/show', compact('music', 'loves', 'is_love', 'previous', 'next'));
 }
コード例 #5
0
ファイル: test001Controller.php プロジェクト: WangWeigao/m1
 /**
  * 给已经添加的midi文件添加播放时长(duration字段)
  */
 public function getTrackCount()
 {
     $midis = range(199, 245);
     foreach ($midis as $v) {
         $file = public_path() . DIRECTORY_SEPARATOR . 'midis' . DIRECTORY_SEPARATOR . $v . '.mid';
         if (file_exists($file)) {
             $music = Music::find($v);
             if (!is_null($music)) {
                 $midi = new MidiDuration();
                 $midi->importMid($file);
                 $music->getNoteList[] = $midi->getNoteList();
                 echo $music->id . '-' . count($music->getNoteList);
                 // echo $music->id . '-' . $music->track;
                 echo "\n";
                 // $music->save();
             }
         }
     }
 }
コード例 #6
0
 public function store(MusicRequest $music)
 {
     //        $rsvp = new Rsvp;
     //
     //        $rsvp->setImagePath($request->getImagePath());
     //
     //        $rsvp->imagePath = $request->imagePath;
     Music::create($music->all());
     //        $file = null;
     //        if ($request->hasFile('imageName')) {
     //            $file = $request->file('imageName');
     //            $ext = strtolower($file->getClientOriginalExtension());
     //            $request["imagePath"] = $ext;
     //        }
     //        $request->file('imageName')->move(base_path() . '/public/images/catalog/', $file);
     //
     //        $request['imagePath'] = base_path().'/public/images/catalog/'.$file;
     //
     //
     return view('pages.music', compact('music'));
     //        return view('pages.thanks', compact('rsvp'));
 }
コード例 #7
0
ファイル: FileManager.php プロジェクト: lialosiu/amaoto-core
 public static function UploadMusic($oriFilePath, $fileName, User $user, $diskName = null)
 {
     $fs = Storage::disk($diskName);
     $fileContent = $fs->get($oriFilePath);
     $mimeType = $fs->mimeType($oriFilePath);
     if (!str_is('audio/*', $mimeType) && !str_is('video/*', $mimeType)) {
         $fs->delete($oriFilePath);
         throw new RequestValidationException(RequestValidationException::FileIsNotMusic);
     }
     $fileModel = self::saveFileByFileContent($fileContent, $fileName, $mimeType, $user, $diskName);
     $fs->delete($oriFilePath);
     $getId3Result = self::analyzeFileByGetId3($fileModel);
     // 标签数据
     if ($getId3Result && isset($getId3Result['tags'])) {
         $types = ['quicktime', 'ape', 'id3v2', 'id3v1'];
         foreach ($types as $type) {
             if (!isset($getId3Result['tags'][$type])) {
                 continue;
             }
             $tag = $getId3Result['tags'][$type];
             $tag_title = implode(';', isset($tag['title']) ? $tag['title'] : []);
             $tag_artist = implode(';', isset($tag['artist']) ? $tag['artist'] : []);
             $tag_album = implode(';', isset($tag['album']) ? $tag['album'] : []);
             $tag_year = implode(';', isset($tag['creation_date']) ? $tag['creation_date'] : (isset($tag['year']) ? $tag['year'] : []));
             $tag_track = implode(';', isset($tag['track_number']) ? $tag['track_number'] : (isset($tag['track']) ? $tag['track'] : []));
             $tag_genre = implode(';', isset($tag['genre']) ? $tag['genre'] : []);
             //                $tag_comment      = implode(';', isset($tag['comment']) ? $tag['comment'] : []);
             $tag_album_artist = implode(';', isset($tag['album_artist']) ? $tag['album_artist'] : []);
             $tag_composer = implode(';', isset($tag['composer']) ? $tag['composer'] : []);
             //                $tag_disc_number  = implode(';', isset($tag['disc_number']) ? $tag['disc_number'] : []);
             break;
         }
     }
     // 封面图
     if ($getId3Result && isset($getId3Result['comments']) && isset($getId3Result['comments']['picture']) && isset($getId3Result['comments']['picture']['0']) && isset($getId3Result['comments']['picture']['0']['data'])) {
         $coverData = $getId3Result['comments']['picture']['0']['data'];
         $coverTempFile = FileManager::saveTempFileByFileContent($coverData, $user);
         //            $coverFileGetId3Result = self::analyzeFileByGetId3($coverTempFile);
         $coverFileName = sprintf('%s-cover-file', isset($tag_title) && $tag_title ? $tag_title : $fileName);
         $coverImage = self::UploadImage($coverTempFile->baseFile->path, $coverFileName, $user);
     }
     $music = new Music();
     $music->title = isset($tag_title) && $tag_title ? $tag_title : $fileModel->name;
     if (isset($tag_artist) && $tag_artist) {
         $music->artist = $tag_artist;
     } else {
         if (isset($tag_composer) && $tag_composer) {
             $music->artist = $tag_composer;
         } else {
             if (isset($tag_album_artist) && $tag_album_artist) {
                 $music->artist = $tag_album_artist;
             } else {
                 $music->artist = null;
             }
         }
     }
     $music->year = isset($tag_year) && $tag_year ? $tag_year : null;
     if (isset($tag_track) && $tag_track) {
         $tmp = explode('/', $tag_track);
         $trackNum = is_array($tmp) && sizeof($tmp) > 0 ? $tmp[0] : $tag_track;
         $music->track = $trackNum;
     }
     $music->genre = isset($tag_genre) && $tag_genre ? $tag_genre : null;
     $music->playtime = isset($getId3Result['playtime_seconds']) ? $getId3Result['playtime_seconds'] : null;
     $music->bitrate = isset($getId3Result['bitrate']) ? $getId3Result['bitrate'] : null;
     $music->album_title = isset($tag_album) && $tag_album ? $tag_album : null;
     $music->album_artist = isset($tag_album_artist) && $tag_album_artist ? $tag_album_artist : null;
     $music->tags = $getId3Result && isset($getId3Result['tags']) ? json_encode($getId3Result['tags']) : null;
     $music->file()->associate($fileModel);
     if (isset($coverImage) && $coverImage) {
         $music->coverImage()->associate($coverImage);
     }
     $music->save();
     return $music;
 }
コード例 #8
0
 public function musicrequests()
 {
     $songs = Music::all();
     return view('pages.musicrequests', compact('songs'));
 }
コード例 #9
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     Music::create($request->all());
     return back();
 }
コード例 #10
0
ファイル: MusicController.php プロジェクト: poudigne/or
 private function GetUploadSongData($title, $band)
 {
     $song = Music::where('title', 'like', '%' . $title . '%')->where('band', 'like', '%' . $band . '%')->first();
     return $song;
 }
コード例 #11
0
ファイル: MusicController.php プロジェクト: WangWeigao/m1
 /**
  * 按乐器种类返回统计结果
  * @method musicStatisticsByInstrument
  * @param  Request                     $request [description]
  * @return [json]                               [description]
  */
 public function musicStatisticsByInstrument(Request $request)
 {
     $instrumentValue = $request->get('instrumentValue');
     if ($instrumentValue == 0) {
         $data['allCount'] = Music::count();
         $data['onshelfCount'] = Music::where('onshelf', 2)->count();
         $data['waitForCheck'] = Music::where('onshelf', 1)->count();
         $data['deleteCount'] = Music::onlyTrashed()->count();
         // 业余考级乐曲统计
         $data['amateur_allCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->count();
         $data['amateur_onshelfCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->where('onshelf', 2)->count();
         $data['amateur_waitForCheck'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->where('onshelf', 1)->count();
         $data['amateur_deleteCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->onlyTrashed()->count();
         // 专业考级乐曲统计
         $data['pro_allCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->count();
         $data['pro_onshelfCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->where('onshelf', 2)->count();
         $data['pro_waitForCheck'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->where('onshelf', 1)->count();
         $data['pro_deleteCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->onlyTrashed()->count();
         // 热门曲目统计
         $data['hot_allCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->count();
         $data['hot_onshelfCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->where('onshelf', 2)->count();
         $data['hot_waitForCheck'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->where('onshelf', 1)->count();
         $data['hot_deleteCount'] = Music::whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->onlyTrashed()->count();
     } else {
         $data['allCount'] = Music::where('instrument_id', $instrumentValue)->count();
         $data['onshelfCount'] = Music::where('instrument_id', $instrumentValue)->where('onshelf', 2)->count();
         $data['waitForCheck'] = Music::where('instrument_id', $instrumentValue)->where('onshelf', 1)->count();
         $data['deleteCount'] = Music::where('instrument_id', $instrumentValue)->onlyTrashed()->count();
         // 业余考级乐曲统计
         $data['amateur_allCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->count();
         $data['amateur_onshelfCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->where('onshelf', 2)->count();
         $data['amateur_waitForCheck'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->where('onshelf', 1)->count();
         $data['amateur_deleteCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '业余考级');
         })->onlyTrashed()->count();
         // 专业考级乐曲统计
         $data['pro_allCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->count();
         $data['pro_onshelfCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->where('onshelf', 2)->count();
         $data['pro_waitForCheck'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->where('onshelf', 1)->count();
         $data['pro_deleteCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '专业考级');
         })->onlyTrashed()->count();
         // 热门曲目统计
         $data['hot_allCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->count();
         $data['hot_onshelfCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->where('onshelf', 2)->count();
         $data['hot_waitForCheck'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->where('onshelf', 1)->count();
         $data['hot_deleteCount'] = Music::where('instrument_id', $instrumentValue)->whereHas('tags', function ($query) {
             $query->where('name', '热门曲目');
         })->onlyTrashed()->count();
     }
     return $data;
 }
コード例 #12
0
 public function getMusicsWithPaginate(Request $request)
 {
     $perPage = $request->get('num');
     if (!is_numeric($perPage) || $perPage < 1 || $perPage > 30) {
         $perPage = 15;
     }
     $musics = MusicModel::orderBy('id', 'desc')->paginate($perPage);
     return $this->buildResponse(trans('api.music.paginate.success'), Tools::toArray($musics));
 }
コード例 #13
0
 public function destroy($id)
 {
     $music = Music::find($id);
     $music->delete();
     return redirect('admin/music');
 }