public static function markFlag($id) { // Create the flag FlagList::create(['url' => $id, 'time' => Carbon::now()]); // Remove from queue/history queue $items = MusicQueue::where('url', $id)->get(); // Shouldn't be in the queue more than once, but who knows foreach ($items as $item) { // Remove any copies of this video that might be in the queue $item->delete(); } // Get all items with the same url in music_history $items = MusicHistory::where('url', $id)->get(); // Remove all copies from music_history foreach ($items as $item) { $item->delete(); } }
public function save() { // Get the input $input = Request::all(); $matches = []; // Verify the URL if (!preg_match("/(?:http(?:s?):\\/\\/|)(?:www\\.)?youtu(?:be\\.com\\/watch\\?v=|\\.be\\/)([\\w\\-\\_]*)(&(amp;)?[\\w\\?=]*)?/i", $input['video_url'], $matches)) { Session::flash('error', 'Not a valid YouTube URL'); } else { // Regular expression to check if the video is categorized as music if (preg_match('/href="\\/channel\\/UC-9-kyTW8ZkZNDHQJ6FgpwQ"/i', file_get_contents($input['video_url']))) { // Make sure that the regular expression did not mess up if (!empty($matches)) { // Make sure the song isn't already in the queue $try = MusicQueue::where('url', '=', $matches[1])->first(); if (is_null($try)) { // Make sure the video isn't blacklisted $blacklisted_items = BlackList::where('url', '=', $matches[1])->get()->toArray(); if (sizeof($blacklisted_items) == 0) { // Video meets all requirements and is not blacklisted // Save to the queue $song = MusicQueue::create(['url' => $matches[1], 'time_in' => Carbon::now(), 'user_in' => Session::getId()]); Session::flash('success', 'Video successfully enqueued.'); } else { // Video is blacklisted, do not allow it to enter the queue Session::flash('error', 'That video is blacklisted and cannot be put into the queue.'); } } else { // Song is already in the queue Session::flash('info', 'That song is already in the queue.'); } } else { // Shouldn't happen, but it might. Just in case Session::flash('error', 'Something went wrong... Please try again.'); } } else { // Video is not categorized as "Music" on youtube. Session::flash('error', 'Video not categorized as Music'); } } // Return to the control page return redirect('control'); }