示例#1
0
 public function index()
 {
     $songConfig = config('song');
     $argWhere = $argGet = [];
     $keyword = Input::get('keyword');
     if ($keyword) {
         $argGet['keyword'] = $keyword;
         $songs = Song::where('song_name', 'like', "%{$keyword}%")->orderBy('song_id', 'desc')->paginate(15);
     } else {
         $language = Input::get('language');
         if ($language) {
             $argWhere['song_language'] = $argGet['language'] = $language;
         }
         $mood = Input::get('mood');
         if ($mood) {
             $argWhere['song_moods'] = $argGet['mood'] = $mood;
         }
         $style = Input::get('style');
         if ($style) {
             $argWhere['song_style'] = $argGet['style'] = $style;
         }
         $songs = Song::where($argWhere)->orderBy('song_id', 'desc')->paginate(15);
     }
     return view('song/home', compact('songs', 'songConfig', 'argGet'));
 }
 public function search(Request $request)
 {
     // keyword to search
     $keyword = $request->input('keyword');
     // filter songs by keyword
     $songs = Song::where('songname', 'LIKE', "%{$keyword}%")->get();
     return $songs;
 }
 /**
  * @param $slug
  * @return string
  */
 public function update($slug)
 {
     /*dd(Song::where('slug', $slug)->first()->toArray());*/
     /*$song = Song::where('slug', $slug)->first();
       $song->title = Input::get('title');
       $song->lyrics = Input::get('lyrics');
       $song->save();*/
     Song::where('slug', $slug)->first()->fill(['title' => Input::get('title'), 'lyrics' => Input::get('lyrics')])->save();
     return redirect('songs');
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     //$router->model('article', 'App\Article');//
     $router->bind('article', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     //$router->model('tags', 'App\Tag');
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     $router->bind('songs', function ($slug) {
         //return App\Song::whereSlug($slug)->first();//App\Song::where('slug', $slug)->first()
         return \App\Song::where('slug', $slug)->firstOrFail();
     });
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     if (!empty($data) && isset($data['id'])) {
         $videoId = $data['id'];
         $song = new Song();
         $row = $song->where('video_id', $videoId)->first();
         if (is_null($row)) {
             $submission = new Submission();
             $user = \Auth::user();
             $latestSong = new Song();
             $latestSong = $latestSong->orderby('updated_at', 'desc')->first();
             // Add song
             $song->video_id = $videoId;
             $song->video_name = $data['name'];
             $song->video_duration = $data['duration'];
             $song->created_at = Carbon::now()->addHours(2);
             if (is_null($latestSong)) {
                 $song->updated_at = $song->created_at;
             } else {
                 // We want to set the updated_at coorsponding to latest added
                 // song duration, for a consistent playlist.
                 $latestSongUpdateDate = Carbon::parse($latestSong->updated_at)->timestamp;
                 $latestSongDuration = $latestSong->video_duration;
                 $nextUpdateAtStop = $latestSongUpdateDate + $latestSongDuration;
                 $song->updated_at = Carbon::createFromTimestamp($nextUpdateAtStop)->toDateTimeString();
             }
             $song->save();
             $submission->facebook_id = $user->facebook_id;
             $submission->playlist_id = $song->video_id;
             $submission->save();
             // Publish song added
             $this->pusher->trigger('playlist-channel', 'song-added', []);
             return new Response(json_encode($song), Response::HTTP_CREATED);
         } else {
             // Song record already exists
             return new Response('Conflict', Response::HTTP_CONFLICT);
         }
     }
     // Request data not supported
     return new Response('Unprocessable Entity', Response::HTTP_UNPROCESSABLE_ENTITY);
 }
示例#6
0
 public function playlist($id)
 {
     $url = "http://music.163.com/api/playlist/detail?id={$id}";
     $refer = "http://music.163.com/";
     $header[] = "Cookie: appver=2.0.2;";
     $response = json_decode(http_get($url), true);
     if ($response["code"] == 200 && $response["result"]) {
         //处理音乐信息
         $result = $response["result"]["tracks"];
         $collect = [];
         foreach ($result as $k => $value) {
             $mp3_url = str_replace("http://m", "http://p", $value["mp3Url"]);
             $song_cover = '';
             $artists = [];
             foreach ($value["artists"] as $artist) {
                 $artists[] = $artist["name"];
             }
             if ($value['album']['picUrl']) {
                 $song_cover = $value['album']['picUrl'];
             }
             $artists = implode(",", $artists);
             $song = ["song_name" => $value["name"], "song_path" => $mp3_url, "song_authors" => $artists, "song_image" => $song_cover, "song_source" => 2, "song_language" => 1, "song_style" => 1, "song_moods" => 1];
             $row = Song::where('song_path', $mp3_url)->first();
             if (empty($row)) {
                 $row = Song::create($song);
             }
             $collect[] = $row;
         }
         return $collect;
     }
 }
 public function postEdit(SongRequest $r, $id = null)
 {
     $r['user_id'] = Auth::user()->id;
     Song::where('id', $id)->where('user_id', Auth::user()->id)->update($r->except('_token'));
     //return redirect('cabinet');
 }
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('auth/login', 'Auth\\AuthController@getLogin');
Route::post('auth/login', 'Auth\\AuthController@postLogin');
Route::get('auth/logout', 'Auth\\AuthController@getLogout');
/**
 * Handle facebook authentication
 */
Route::get('auth/fbauth', 'Auth\\AuthController@redirectToProvider');
Route::get('callback', 'Auth\\AuthController@handleProviderCallback');
/**
 *
 *
 */
Route::resource('listeners', 'ListenerController');
Route::resource('albums', 'AlbumController');
Route::resource('songs', 'SongController');
Route::resource('artists', 'ArtistController');
/**
 * used for ajax call to retrieve the songs based on album id
 *
 *
 */
Route::get('/ajax-call', function () {
    $id = Input::get('album_id');
    $songs = \App\Song::where('album_id', '=', $id)->get();
    return Response::json($songs);
});
示例#9
0
 /**
  * Serve song file
  */
 public function serveMP3($userSlug, $fileName)
 {
     $song = Song::where('file_name', $fileName)->first();
     Log::info('ServeMP3 called', ['user' => Auth::user(), 'song' => $song]);
     return Response::download(storage_path('app/' . $song->file_location . $song->file_name));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function getIndex()
 {
     $picture = \App\Song::where('showhide', 'show')->orderBy('id', 'DESC')->paginate(20);
     return view('templates.gallery')->with('picture', $picture);
 }