Esempio n. 1
0
 public function homepage()
 {
     $album_latsed = Album::where('published_at', '<', date("Y-m-d h:i:s"))->where('display_id', 0)->orderBy('id', 'desc')->take(8)->get();
     $Video_latsed = Video::where('published_at', '<', date("Y-m-d h:i:s"))->orderBy('id', 'desc')->take(8)->get();
     $banner = Album::where('display_id', 2)->get();
     return view('welcome', ['album_latsed' => $album_latsed, 'video_latsed' => $Video_latsed, 'banners' => $banner]);
 }
Esempio n. 2
0
 public function download($filename)
 {
     $public_path = public_path();
     $entry = Video::where('original_filename', '=', $filename)->firstOrFail();
     $file = $public_path . '/uploads/' . $filename;
     return response()->download($file);
 }
 /**
  * Handle the event.
  *
  * @param  UserWasDeleted  $event
  * @return void
  */
 public function handle(UserWasDeleted $event)
 {
     // Delete everything the user created
     Article::where('user_id', $event->user_id)->delete();
     Photo::where('user_id', $event->user_id)->delete();
     PhotoAlbum::where('user_id', $event->user_id)->delete();
     Video::where('user_id', $event->user_id)->delete();
     VideoAlbum::where('user_id', $event->user_id)->delete();
 }
 /**
  * Fetch videos of a particular category from the database based on user's category selection. If an invalid
  *  category is specified in the route an erro message is returned
  * @param  $category
  */
 public function videoCategories($category)
 {
     $category = ucwords(strtolower(str_replace('_', ' ', $category)));
     $videoCategories = VideoCategories::getCategories();
     $videos = Video::where('category', '=', $category)->paginate(12);
     if (in_array($category, $videoCategories)) {
         return view('landing', ['videos' => $videos]);
     } else {
         return view('errors.error_page', ['error' => '"' . $category . '" is not a valid video category. Please select a valid category from the "Explore" menu above.']);
     }
 }
 /**
  * View a video.
  *
  * @param $slug
  * @return mixed
  */
 public function video($slug)
 {
     $slug = explode('-', $slug);
     $id = $slug[0];
     $video = $this->video->with(['watchedVideo'])->where('id', $id);
     if ($video->count() > 0) {
         $next = $this->video->where('id', '>', $id);
         return view('Main.Videos.View')->withVideo($video->first())->withNext($next);
     }
     abort(404);
 }
Esempio n. 6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(CommentRequest $request)
 {
     $input = $request->all();
     if (Auth::guest()) {
         \Session::flash('flash_message', 'You need to be logged in to comment!');
     } else {
         $input['user_id'] = Auth::id();
         Comment::create($input);
     }
     $video = Video::findOrFail($input['video_id']);
     $test = Video::where('id', $input['video_id'])->increment('numComments');
     return view('videos/show', compact('video', 'test'));
 }
Esempio n. 7
0
 public function renderVideoByCategory($id)
 {
     $videos = \App\Video::where('is_publish', '1')->orderBy('id', 'desc');
     $ids = array();
     $categories = \DB::select('select * from video_categories where categories_id = ?', array($id));
     foreach ($categories as $value) {
         $ids[] = $value->video_id;
     }
     $videos = $videos->whereIn('id', $ids)->get()->toArray();
     // Render View With Parameters
     return \View::make('video.bycategory')->with('videos', $videos);
     // print "<pre>";
     // var_dump(  );
     // exit;
 }
 public function search(Request $request)
 {
     $search = (string) $request->input('search');
     $arr = explode(" ", $search);
     $squery = '%' . $search . '%';
     $squeryWithoutSpaces = preg_replace('/\\s+/', '', $squery);
     $videos = Video::where(function ($query) use($arr) {
         foreach ($arr as $item) {
             $query->where(function ($query) use($item) {
                 $query->where('class', 'like', '%' . $item . '%')->orWhere('instructor', 'like', '%' . $item . '%')->orWhere('tags', 'like', '%' . $item . '%')->orWhere('title', 'like', '%' . $item . '%');
             });
         }
     })->paginate(15);
     return view('videos.search', compact('videos'))->with('search', $search);
 }
Esempio n. 9
0
 public static function downloadVideo()
 {
     $videos = Video::where('state', '=', 'detected')->take(1)->get();
     if ($videos->count() == 0) {
         return;
     }
     $video = $videos[0];
     $sys = php_uname('s');
     if ($sys == 'Windows NT') {
         TumblrDownloader::downloadVideoInWindowsNT($video);
     } else {
         if ($sys == 'Linux') {
             TumblrDownloader::downloadVideoInLinux($video);
         }
     }
 }
Esempio n. 10
0
 public static function zipOneDay(Carbon $date)
 {
     $begin = $date->copy()->setTime(0, 0, 0);
     $end = $date->copy()->setTime(23, 59, 59);
     $deleteLocs = [];
     $videoLocs = [];
     $videos = Video::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($videos as $video) {
         $deleteLocs[] = $video->location;
         $videoLocs[] = storage_path('app/' . $video->location);
         $video->state = 'zipped';
         $video->save();
     }
     $imageLocs = [];
     $images = Image::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get();
     foreach ($images as $image) {
         $deleteLocs[] = $image->location;
         $imageLocs[] = storage_path('app/' . $image->location);
         $image->state = 'zipped';
         $image->save();
     }
     $locs = array_merge($videoLocs, $imageLocs);
     if (count($locs) == 0) {
         Log::info('TumblrZip : no file to be ziped.');
         return;
     }
     $zipName = $begin->toDateString() . '.zip';
     $zipLocs = 'zips/' . $zipName;
     $zippy = Zippy::load();
     $zippy->create(storage_path('app/' . $zipLocs), $locs);
     $zip = new Zip();
     $zip->state = 'ziped';
     $zip->error = '';
     $zip->name = $zipName;
     $zip->date = $begin->toDateString();
     $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB';
     $zip->imageSize = count($imageLocs);
     $zip->videoSize = count($videoLocs);
     $zip->location = $zipLocs;
     $zip->save();
     Storage::delete($deleteLocs);
 }
Esempio n. 11
0
 /**
  * 得到页面上所有的视频地址,已经存过的视频地址不会被重新储存。
  * @param int $page 第几页
  * @return array 视频地址
  */
 protected function fetchVideosrcs($page)
 {
     // 准备DOM
     $html = $this->getHtml($page);
     $dom = new Dom();
     $dom->load($html);
     $videoSrcs = [];
     // 遍历全部iframe
     foreach ($dom->find('iframe') as $videoFrame) {
         // 获得iframe的地址
         $videoFrameSrc = $videoFrame->getAttribute('src');
         // 如果iframe的地址不存在,或者不含有特定字符串(用来判别是否是视频),废弃
         if (empty($videoFrameSrc)) {
             continue;
         }
         if (!strstr($videoFrameSrc, 'https://www.tumblr.com/video/')) {
             continue;
         }
         // 如果已经检测了此视频,返回
         $parentId = $videoFrame->getParent()->getAttribute('id');
         $name = explode('_', $parentId)[3] . '.mp4';
         if (Video::where('name', '=', $name)->count() != 0) {
             continue;
         }
         // 准备video的DOM
         $videoHtml = $this->requestHtml($videoFrameSrc);
         $videoDom = new Dom();
         $videoDom->load($videoHtml);
         // 获取对应节点
         $videoElem = $videoDom->find('video')[0];
         $videoSource = $videoElem->find('source')[0];
         // 开始读取数据
         $video = new Video();
         $video->state = 'detected';
         $video->error = '';
         $video->name = $name;
         $video->source = $videoSource->getAttribute('src');
         $video->save();
     }
 }
Esempio n. 12
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $type, $id)
 {
     if ($type == 'event' || $type == 'page') {
         try {
             $event = Event::where('slug', $id)->where('type', $type)->firstOrFail();
         } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return view('errors.pageNotFound');
         }
         if ($type == 'event') {
             $this->validate($request, ['title' => 'required|max:50', 'content' => 'required|max:10000', 'start_date' => 'required|date|before:end_date', 'end_date' => 'required|date|after:start_date', 'start_time' => 'date_format:H:i|before:end_time', 'end_time' => 'date_format:H:i|after:start_time', 'number' => 'max:12', 'street' => 'max:40', 'suburb' => 'max:40', 'area' => 'max:40', 'country' => 'max:30', 'image[]' => 'image']);
             if ($request->status == 0 || $request->status == 1) {
                 $event->status = $request->status;
             } elseif ($request->status == 2) {
                 foreach ($event->images as $image) {
                     $original = 'img/site/original/';
                     $sliderPath = 'img/site/slider/';
                     $galleryThumbPath = 'img/site/gallery/thumbnail/';
                     $galleryPrevPath = 'img/site/gallery/preview/';
                     $thumbnail = 'img/site/thumbnail/';
                     $imagedb = Image::where('id', $image->id)->first();
                     \File::delete([$sliderPath . $imagedb->image, $galleryPrevPath . $imagedb->image, $galleryThumbPath . $imagedb->image, $thumbnail . $imagedb->image, $original . $imagedb->image]);
                     EventImage::where('event_id', $event->id)->where('image_id', $image->id)->delete();
                     $imagedb->delete();
                 }
                 $event->delete();
                 return redirect('/admin/' . $type . '/');
             }
             $event->title = $request->title;
             $event->content = $request->content;
             $event->start_date = str_replace('-', '/', $request->start_date);
             $event->end_date = str_replace('-', '/', $request->end_date);
             $event->start_time = $request->start_time;
             $event->end_time = $request->end_time;
             $event->save();
             $event->locations->number = $request->number;
             $event->locations->street = $request->street;
             $event->locations->suburb = $request->suburb;
             $event->locations->area = $request->area;
             $event->locations->country = $request->country;
             $event->locations->location_map = $request->number . '+' . $request->street . ',+' . $request->suburb . ',+' . $request->area . ',+' . $request->country;
             $event->locations->location_map = str_replace(' ', '+', $event->locations->location_map);
             $event->locations->save();
             $original = 'img/site/original/';
             $sliderPath = 'img/site/slider/';
             $galleryThumbPath = 'img/site/gallery/thumbnail/';
             $galleryPrevPath = 'img/site/gallery/preview/';
             $thumbnail = 'img/site/thumbnail/';
             if ($request->hasFile('image')) {
                 $counter = 0;
                 foreach ($request->file('image') as $image) {
                     $fileName = uniqid() . '.' . $request->file('image')[$counter]->getClientOriginalName();
                     $imageSource = \Image::make($request->file('image')[$counter]);
                     $imageSource->save($original . $fileName);
                     \Image::make($request->file('image')[$counter])->resize(1000, null, function ($constraint) {
                         $constraint->aspectRatio();
                     })->save($galleryPrevPath . $fileName, 80);
                     \Image::make($request->file('image')[$counter])->resize(1000, null, function ($constraint) {
                         $constraint->aspectRatio();
                     })->crop(1000, 400, 0, 0)->save($sliderPath . $fileName, 80);
                     \Image::make($request->file('image')[$counter])->fit(100, 100)->save($galleryThumbPath . $fileName, 80);
                     \Image::make($request->file('image')[$counter])->fit(250, 150)->save($thumbnail . $fileName, 80);
                     $imagedb = new Image();
                     $eventImage = new EventImage();
                     $imagedb->image = $fileName;
                     $imagedb->save();
                     $eventImage->image_id = $imagedb->id;
                     $eventImage->event_id = $event->id;
                     $eventImage->save();
                     $counter++;
                 }
             }
             if (count($request->currentImage) > 0) {
                 foreach ($request->currentImage as $checked) {
                     $imagedb = Image::where('id', $checked)->first();
                     \File::delete([$sliderPath . $imagedb->image, $galleryPrevPath . $imagedb->image, $galleryThumbPath . $imagedb->image, $thumbnail . $imagedb->image, $original . $imagedb->image]);
                     EventImage::where('event_id', $event->id)->where('image_id', $checked)->delete();
                     $imagedb->delete();
                 }
             }
         } elseif ($type == 'page') {
             $event->content = $request->content;
             $event->save();
         }
     } elseif ($type == 'staff') {
         try {
             $event = Staff::where('slug', $id)->firstOrFail();
         } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return view('errors.pageNotFound');
         }
         $event->title = $request->title;
         $event->name = $request->name;
         $event->slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $event->name)));
         $original = 'img/site/original/';
         $staff = 'img/site/staff/';
         if ($request->hasFile('photo')) {
             if ($event->image != 'default.png') {
                 \File::delete([$original . $event->image, $staff . $event->image]);
             }
             $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalName();
             $imageSource = \Image::make($request->file('photo'));
             $imageSource->save($original . $fileName);
             \Image::make($request->file('photo'))->fit(190, 190)->save($staff . $fileName, 80);
             $event->image = $fileName;
         }
         $event->save();
         return redirect('/admin/' . $type . '/');
     } elseif ($type == 'video') {
         try {
             $event = Video::where('slug', $id)->firstOrFail();
         } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
             return view('errors.pageNotFound');
         }
         $event->title = $request->title;
         $event->description = $request->description;
         $event->player = $request->player;
         if ($request->player == 'youtube') {
             $event->video = substr($request->video, -11);
         } elseif ($request->player == 'vimeo') {
             $event->video = substr($request->video, -9);
         }
         $event->slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $event->title)));
         $event->save();
         return redirect('/admin/' . $type . '/');
     } else {
         return view('errors.404');
     }
     if (isset($request->preview)) {
         return redirect('/' . $type . '/' . $event->slug);
     } else {
         return redirect('/admin/' . $type . '/' . $event->slug . '/edit');
     }
 }
 public function getFreeVideos()
 {
     return Video::where('plan_id', '3')->get();
 }
Esempio n. 14
0
 /**
  * Reorder items
  *
  * @param items list
  * @return items from @param
  */
 public function getReorder(ReorderRequest $request)
 {
     $list = $request->list;
     $items = explode(",", $list);
     $order = 1;
     foreach ($items as $value) {
         if ($value != '') {
             Video::where('id', '=', $value)->update(array('position' => $order));
             $order++;
         }
     }
     return $list;
 }
Esempio n. 15
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $dadosForm = $request->except('_token');
     Video::where('id', $id)->update($dadosForm);
     $vid_categoria = VidCategoria::lists('name');
     return redirect("home");
 }
 public function categories($id)
 {
     $videos = Video::where('category_id', '=', $id);
     $categories = Category::all();
     //return redirect('/')->with('videos', );
 }
Esempio n. 17
0
 public function item($id)
 {
     $video_album = VideoAlbum::find($id);
     $videos = Video::where('video_album_id', $id)->get();
     return view('site.video.view_album', compact('videos', 'video_album'));
 }
 /**
  * Get the curent logged in user's videos
  */
 public static function getLoggedInUserVideos()
 {
     $videos = Video::where('user_id', Auth::user()->id)->orderBy('created_at', 'desc')->paginate(12);
     return $videos;
 }
 /**
  * Accepts an SNS message to containing the video duration
  *
  * @param Request $request
  *
  * @return mixed Json containing the success of the SNS values being stored
  */
 public function anyCompletedtranscode(Request $request)
 {
     $decodedRequestContent = json_decode(json_decode($request->getContent(), true)['Message'], true);
     $video_duration = $decodedRequestContent['outputs'][0]['duration'];
     $thumnail_count = floor($video_duration / env('THUMBS_MADE_FRAMERATE'));
     $video_timecode = substr($decodedRequestContent['outputs'][0]['key'], 0, -5);
     $video = App\Video::where('timecode', $video_timecode)->first();
     $video->thumbnail_count = (int) $thumnail_count;
     $video->duration_seconds = (int) $video_duration;
     $success = $video->save();
     return Response::json(['success' => $success], 200);
 }
Esempio n. 20
0
 public function rf(Request $request)
 {
     $user = Auth::user();
     $username = $user->username;
     $device = "1";
     $video_id = $request->video_id;
     $action_type = 6;
     $explicit_rf = $request->score;
     //check if $request->score==-1 or 0 or 1
     $record_exists = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_type)->first();
     if (empty($record_exists)) {
         $user_action = new UserAction(['username' => $username, 'device_id' => '1', 'video_id' => $video_id, 'explicit_rf' => $explicit_rf, 'action' => $action_type]);
         $user_action->save();
         $get_importance = Action::where('id', $action_type)->first();
         $importance = $get_importance->importance;
         $user_action->update(array('weight' => $explicit_rf, 'importance' => $importance));
         //			return $record_exists;
     } else {
         $record_exists->update(array('explicit_rf' => $explicit_rf, 'weight' => $explicit_rf));
     }
     //store in the dcgs table - only used for the online experiments
     $mecanex_user = MecanexUser::where('username', $username)->first();
     $dcg_record = Dcg::where('mecanex_user_id', $mecanex_user->id)->where('video_id', $video_id);
     $dcg_record->update(array('explicit_rf' => $explicit_rf));
     //////////////calculate ku///////////////////////
     $k_nominator = UserAction::where('username', $username)->where('video_id', $video_id)->groupBy('username')->get(['username', DB::raw('SUM(importance*weight) as total_score')])->first();
     //prepei edw na to diairw k me to plithos twn sunolikwn enrichments k ads
     $query = "SELECT SUM(t1.importance ) AS total FROM (SELECT DISTINCT action, importance FROM user_actions WHERE username=:username AND video_id=:videoid) AS t1 ";
     $k_denominator = DB::select(DB::raw($query), array('username' => $username, 'videoid' => $video_id));
     //returns array
     $k = $k_nominator->total_score / $k_denominator[0]->total;
     //to [0] gia na prospelasei to 1o stoixeio tou array pou einai to object
     /////////////////////////////update weights and update profile//////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////Retrieve Terms/////////////////////////////
     //////////////retrieve terms for given video//////////////
     $video = Video::where('video_id', $video_id)->first();
     $threshold = 0.1;
     //need to appropriate set
     $results = $video->term()->where('video_score', '>', $threshold)->distinct()->get(array('term_id'));
     //$results = $results->unique();
     //return $results;
     $video_term_list = [];
     foreach ($results as $result) {
         //retrieve the terms that will be updated
         array_push($video_term_list, $result->term_id);
     }
     sort($video_term_list);
     //return $video_term_list;
     ///////////retrieve terms for the clicked enrichments//////////////
     $get_actionid = Action::where('action', 'click enrichment')->first();
     $action_id = $get_actionid->id;
     $enrichment_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id'));
     $enrichment_term_list = [];
     //		foreach ($enrichment_ids as $enrichment_id)
     //		{
     //
     //			//call the api and get some terms
     //			//or emulate enrichment_terms
     //			//$results=Enrichment::where('id',$enrichment_id)->get(array('term_id'))
     //			foreach($results as $result)
     //			{
     //				array_push($enrichment_term_list,$result->term_id);
     //			}
     //
     //		}
     //$enrichment_terms=array_unique($enrichment_term_list);
     //		$enrichment_terms = [3, 4, 7];
     //retrieve terms for the clicked ads
     //		$ads_terms = [4, 8, 10];
     ///Final term_list -  no need since I will update in three steps
     //		$term_list=array_merge($video_term_list,$enrichment_terms,$ads_terms);
     //		$terms=array_unique($term_list);
     ////////////////update weights of profile//////////////////////////
     $term_scores = [];
     //save all scores to get the max
     $user = MecanexUser::where('username', $username)->get()->first();
     $video = Video::where('video_id', $video_id)->get()->first();
     $link_user = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->get()->first();
     //return $link_user;
     //update based on video_terms
     foreach ($video_term_list as $video_term_id) {
         $temp_user = $user->term->find($video_term_id);
         $user_term_score = $temp_user->pivot->user_score;
         //get score of user
         $temp_video = $video->term->find($video_term_id);
         $video_term_score = $temp_video->pivot->video_score;
         //get score of video
         //update score
         $new_score = $user_term_score + $k * (0.8 * $video_term_score);
         //ok
         $new_score = max($new_score, 0);
         // don't let negative values
         array_push($term_scores, $new_score);
         //				//store score
         $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false);
     }
     // update matrix
     $number_video_terms = count($video_term_list);
     $link_term_scores = [];
     //save all scores to get the max
     for ($i = 0; $i <= $number_video_terms - 1; $i++) {
         for ($j = $i + 1; $j < $number_video_terms; $j++) {
             $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first();
             //return $temp_user_matrix;
             $temp_video = $video->term->find($video_term_list[$i]);
             $video_term_score1 = $temp_video->pivot->video_score;
             $temp_video = $video->term->find($video_term_list[$j]);
             $video_term_score2 = $temp_video->pivot->video_score;
             //return $temp_user_matrix;
             $new_score = $temp_user_matrix->link_score + $k * (0.8 * ($video_term_score1 * $video_term_score2));
             $new_score = max($new_score, 0);
             // don't let negative values
             array_push($link_term_scores, $new_score);
             $temp_user_matrix->link_score = $new_score;
             $temp_user_matrix->save();
         }
     }
     //same should be done for enrichments and ads
     //find max value and divide term values
     $max_term_value = max(max($term_scores), 1);
     if ($link_term_scores != []) {
         $max_link_term_value = max(max($link_term_scores), 1);
     }
     foreach ($video_term_list as $video_term_id) {
         $temp_user = $user->term->find($video_term_id);
         $user_term_score = $temp_user->pivot->user_score;
         //get score of user
         $temp_video = $video->term->find($video_term_id);
         $video_term_score = $temp_video->pivot->video_score;
         //get score of video
         //update score
         $new_score = $user_term_score / $max_term_value;
         //ok
         //				//store score
         $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false);
     }
     for ($i = 0; $i <= $number_video_terms - 1; $i++) {
         for ($j = $i + 1; $j < $number_video_terms; $j++) {
             $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first();
             $old_score = $temp_user_matrix->link_score;
             $new_score = $old_score / $max_link_term_value;
             $temp_user_matrix->link_score = $new_score;
             $temp_user_matrix->save();
         }
     }
     //calculate profile
     $terms = Term::all()->count();
     for ($j = 1; $j <= $terms; $j++) {
         $profile_score = 0;
         for ($i = 1; $i <= $terms; $i++) {
             $temp_user = $user->term->find($i);
             $user_term_score = $temp_user->pivot->user_score;
             //get score of user
             if ($i == $j) {
                 $link_score = 0;
             } elseif ($i > $j) {
                 $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $j)->where('term_neighbor_id', $i)->get()->first();
                 $link_score = $temp_user_matrix->link_score;
             } else {
                 $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $i)->where('term_neighbor_id', $j)->get()->first();
                 $link_score = $temp_user_matrix->link_score;
             }
             $profile_score = $profile_score + $user_term_score * $link_score;
         }
         $user->profilescore()->sync([$j => ['profile_score' => $profile_score]], false);
     }
     DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->delete();
     return Redirect::route('home')->with('message', 'Thank you for watching the video');
 }
 public function getOfflineVideos($id)
 {
     $videos = $id ? User::findOrFail($id)->videos : Video::where('offline', 1)->get();
     return $videos;
 }
Esempio n. 22
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $slug, $event_id)
 {
     if (strpos($request->link, 'youtu') == false) {
         Flash::error('Votre musique n\'a pas pu être ajoutée. Veuillez vérifier les champs renseignés.');
         return redirect('events/' . $slug . '-' . $event_id . '#songs');
     }
     $validation = Validator::make($request->all(), ['link' => 'url|required', 'artist' => 'required', 'title' => 'required']);
     $author = Auth::guest() ? '0' : Auth::user()->id;
     if ($validation->fails()) {
         Flash::error('Votre musique n\'a pas pu être ajoutée. Veuillez vérifier les champs renseignés.');
         return redirect('events/' . $slug . '-' . $id . '#songs');
     }
     if (Video::where('link', $request->link)->count() > 0) {
         $video = Video::where('link', $request->link)->first();
         $video_id = $video->id;
         $video_title = $video->title;
         $video_artist = $video->artist;
         if (VideosOnEvent::where('event_id', $event_id)->where('video_id', $video_id)->count() > 0) {
             Flash::error('Cette musique a déjà été ajoutée.');
             return redirect('events/' . $slug . '-' . $id . '#songs');
         } else {
             VideoOnEvent::create(['user_id' => $author, 'event_id' => $event_id, 'video_id' => $video_id, 'title' => $video_name, 'artist' => $video_artist]);
         }
     } elseif (Video::where('title', $request->title)->where('artist', $request->artist)->count() > 0) {
         $video = Video::where('title', $request->title)->where('artist', $request->artist)->first();
         $video_id = $video->id;
         $video_title = $video->title;
         $video_artist = $video->artist;
         if (VideosOnEvent::where('event_id', $event_id)->where('video_id', $video_id)->count() > 0) {
             Flash::error('Cette musique a déjà été ajoutée.');
             return redirect('events/' . $slug . '-' . $event_id . '#songs');
         } else {
             VideosOnEvent::create(['user_id' => $author, 'event_id' => $event_id, 'video_id' => $video_id, 'title' => $video_title, 'artist' => $video_artist]);
         }
     } else {
         // MISE EN FORME DE L'URL STOCKEE
         $link = $request->link;
         $link = str_replace('http://', '', $link);
         $link = str_replace('https://', '', $link);
         if (strpos($link, 'youtu.be') == false) {
             $link = str_replace('www.', '', $link);
             $link = str_replace('youtube.com/watch?v=', '', $link);
             if (strpos($link, '&')) {
                 $link = explode($link, '&')[0];
             }
         }
         // STOCKAGE DES DONNEES
         $link = str_replace('youtu.be/', '', $link);
         Video::create(['title' => $request->title, 'artist' => $request->artist, 'link' => $link]);
         $video = Video::where('link', $link)->first();
         $video_id = $video->id;
         $video_title = $video->title;
         $video_artist = $video->artist;
         VideosOnEvent::create(['user_id' => $author, 'event_id' => $event_id, 'video_id' => $video_id, 'title' => $video_title, 'artist' => $video_artist]);
     }
     Flash::success('Votre musique a bien été ajoutée à l\'événement.');
     return redirect('events/' . $slug . '-' . $event_id . '#songs');
 }
Esempio n. 23
0
 public function explicitrf_function(SignalsRequest $request)
 {
     $username = $request->username;
     $device = $request->device_id;
     $video_id = $request->video_id;
     $action_type = $request->action;
     $explicit_rf = $request->value;
     //check if $request->score==-1 or 0 or 1
     $record_exists = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_type)->first();
     if (empty($record_exists)) {
         $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'explicit_rf' => $explicit_rf, 'action' => $action_type]);
         $user_action->save();
         $get_importance = Action::where('id', $request->action)->first();
         $importance = $get_importance->importance;
         $user_action->update(array('weight' => $explicit_rf, 'importance' => $importance));
     } else {
         $record_exists->update(array('explicit_rf' => $explicit_rf, 'weight' => $explicit_rf));
     }
     //store in the dcgs table - only used for the online experiments
     $mecanex_user = MecanexUser::where('username', $username)->first();
     $dcg_record = Dcg::where('mecanex_user_id', $mecanex_user->id)->where('video_id', $video_id);
     $dcg_record->update(array('explicit_rf' => $explicit_rf));
     //////////////calculate ku///////////////////////
     // number of all enrichments
     $video = Video::where('video_id', $video_id)->first();
     $num_all_enrichments = DB::select(DB::raw('SELECT COUNT(*) as num FROM enrichments_videos_time WHERE video_id=?'), [$video->id]);
     $num_all_enrichments = $num_all_enrichments[0]->num;
     // create list with clicked enrichments
     $get_action_id = Action::where('action', 'click enrichment')->first();
     $action_id = $get_action_id->id;
     $enrichment_click_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id'));
     $num_clicked_enrichments = count($enrichment_click_ids);
     // replace all database entries with one with the appropriate weight (so that the calculation can be easily done).
     // The information for what enrichments where clicked is now in the $enrichment_click_ids variable
     if ($num_clicked_enrichments != 0) {
         DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->delete();
         $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'action' => $action_id, 'content_id' => '1']);
         $user_action->save();
         $get_importance = Action::where('id', $action_id)->first();
         $importance = $get_importance->importance;
         $user_action->update(array('weight' => $num_clicked_enrichments / $num_all_enrichments, 'importance' => $importance));
     }
     // create list with shared enrichments
     $get_action_id = Action::where('action', 'share')->first();
     $action_id = $get_action_id->id;
     $enrichment_share_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id'));
     $num_shared_enrichments = count($enrichment_share_ids);
     // replace all database entries with one with the appropriate weight (so that the calculation can be easily done).
     // The information for what enrichments where clicked is now in the $enrichment_shared_ids variable
     if ($num_shared_enrichments != 0) {
         DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->delete();
         $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'action' => $action_id, 'content_id' => '1']);
         $user_action->save();
         $get_importance = Action::where('id', $action_id)->first();
         $importance = $get_importance->importance;
         $user_action->update(array('weight' => $num_shared_enrichments / $num_all_enrichments, 'importance' => $importance));
     }
     $k_nominator = UserAction::where('username', $username)->where('video_id', $video_id)->groupBy('username')->get(['username', DB::raw('SUM(importance*weight) as total_score')])->first();
     $query = "SELECT SUM(t1.importance ) AS total FROM (SELECT DISTINCT action, importance FROM user_actions WHERE username=:username AND video_id=:videoid) AS t1 ";
     $k_denominator = DB::select(DB::raw($query), array('username' => $username, 'videoid' => $video_id));
     //returns array
     $k = $k_nominator->total_score / $k_denominator[0]->total;
     //to [0] gia na prospelasei to 1o stoixeio tou array pou einai to object
     /////////////////////////////update weights and update profile//////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////Retrieve Terms/////////////////////////////
     //////////////retrieve terms for given video//////////////
     $video = Video::where('video_id', $request->video_id)->first();
     $threshold = 0;
     //need to appropriate set
     $results = $video->term()->where('video_score', '>', $threshold)->get(array('term_id'));
     $video_term_list = [];
     foreach ($results as $result) {
         //retrieve the terms that will be updated
         array_push($video_term_list, $result->term_id);
     }
     sort($video_term_list);
     ///////////retrieve terms for the clicked enrichments//////////////
     //		$get_actionid = Action::where('action', 'click enrichment')->first();
     //		$action_id = $get_actionid->id;
     //		$enrichment_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id'));
     $enrichment_term_list = [];
     //		foreach ($enrichment_ids as $enrichment_id)
     //		{
     //
     //			//call the api and get some terms
     //			//or emulate enrichment_terms
     //			//$results=Enrichment::where('id',$enrichment_id)->get(array('term_id'))
     //			foreach($results as $result)
     //			{
     //				array_push($enrichment_term_list,$result->term_id);
     //			}
     //
     //		}
     //$enrichment_terms=array_unique($enrichment_term_list);
     $enrichment_terms = [3, 4, 7];
     //retrieve terms for the clicked ads
     $ads_terms = [4, 8, 10];
     ///Final term_list -  no need since I will update in three steps
     //		$term_list=array_merge($video_term_list,$enrichment_terms,$ads_terms);
     //		$terms=array_unique($term_list);
     ////////////////update weights of profile//////////////////////////
     $term_scores = [];
     //save all scores to get the max
     $user = MecanexUser::where('username', $username)->get()->first();
     $video = Video::where('video_id', $video_id)->get()->first();
     $link_user = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->get()->first();
     //return $video;
     //return $link_user;
     //update based on video_terms
     //return $video_term_list;
     foreach ($video_term_list as $video_term_id) {
         $temp_user = $user->term->find($video_term_id);
         $user_term_score = $temp_user->pivot->user_score;
         //get score of user
         $temp_video = $video->term->find($video_term_id);
         $video_term_score = $temp_video->pivot->video_score;
         //get score of video
         $final_score = $k * (0.8 * $video_term_score);
         foreach ($enrichment_click_ids as $enrichment_click_id) {
             $id = $enrichment_click_id->content_id;
             $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
             $temp_enrichment = $enrichment->term->find($video_term_id);
             $enrichment_term_score = $temp_enrichment->pivot->enrichment_score;
             $final_score = $final_score + $k * (0.1 / $num_clicked_enrichments * $enrichment_term_score);
         }
         foreach ($enrichment_share_ids as $enrichment_share_id) {
             $id = $enrichment_share_id->content_id;
             $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
             $temp_enrichment = $enrichment->term->find($video_term_id);
             $enrichment_term_score = $temp_enrichment->pivot->enrichment_score;
             $final_score = $final_score + $k * (0.1 / $num_shared_enrichments * $enrichment_term_score);
         }
         //update score
         $new_score = $user_term_score + $final_score;
         //ok
         $new_score = max($new_score, 0);
         // don't let negative values
         array_push($term_scores, $new_score);
         //				//store score
         $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false);
     }
     //return $term_scores;
     // update matrix
     $number_video_terms = count($video_term_list);
     $link_term_scores = [];
     //save all scores to get the max
     for ($i = 0; $i <= $number_video_terms - 1; $i++) {
         for ($j = $i + 1; $j < $number_video_terms; $j++) {
             $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first();
             //return $temp_user_matrix;
             $temp_video = $video->term->find($video_term_list[$i]);
             $video_term_score1 = $temp_video->pivot->video_score;
             $temp_video = $video->term->find($video_term_list[$j]);
             $video_term_score2 = $temp_video->pivot->video_score;
             $final_score = $k * (0.8 * $video_term_score1 * $video_term_score2);
             foreach ($enrichment_click_ids as $enrichment_click_id) {
                 $id = $enrichment_click_id->content_id;
                 $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
                 $temp_enrichment = $enrichment->term->find($video_term_list[$i]);
                 $enrichment_term_score1 = $temp_enrichment->pivot->enrichment_score;
                 $temp_enrichment = $enrichment->term->find($video_term_list[$j]);
                 $enrichment_term_score2 = $temp_enrichment->pivot->enrichment_score;
                 $final_score = $final_score + $k * (0.1 / $num_clicked_enrichments * $enrichment_term_score1 * $enrichment_term_score2);
             }
             foreach ($enrichment_share_ids as $enrichment_share_id) {
                 $id = $enrichment_share_id->content_id;
                 $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
                 $temp_enrichment = $enrichment->term->find($video_term_list[$i]);
                 $enrichment_term_score1 = $temp_enrichment->pivot->enrichment_score;
                 $temp_enrichment = $enrichment->term->find($video_term_list[$j]);
                 $enrichment_term_score2 = $temp_enrichment->pivot->enrichment_score;
                 $final_score = $final_score + $k * (0.1 / $num_shared_enrichments * $enrichment_term_score1 * $enrichment_term_score2);
             }
             $new_score = $temp_user_matrix->link_score + $final_score;
             $new_score = max($new_score, 0);
             // don't let negative values
             array_push($link_term_scores, $new_score);
             $temp_user_matrix->link_score = $new_score;
             $temp_user_matrix->save();
         }
     }
     //same should be done for enrichments and ads
     //find max value and divide term values
     $max_term_value = max(max($term_scores), 1);
     if ($link_term_scores != []) {
         $max_link_term_value = max(max($link_term_scores), 1);
     }
     foreach ($video_term_list as $video_term_id) {
         $temp_user = $user->term->find($video_term_id);
         $user_term_score = $temp_user->pivot->user_score;
         //get score of user
         $temp_video = $video->term->find($video_term_id);
         $video_term_score = $temp_video->pivot->video_score;
         //get score of video
         //update score
         $new_score = $user_term_score / $max_term_value;
         //ok
         //store score
         $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false);
     }
     for ($i = 0; $i <= $number_video_terms - 1; $i++) {
         for ($j = $i + 1; $j < $number_video_terms; $j++) {
             $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first();
             $old_score = $temp_user_matrix->link_score;
             $new_score = $old_score / $max_link_term_value;
             $temp_user_matrix->link_score = $new_score;
             $temp_user_matrix->save();
         }
     }
     //calculate profile
     $terms = Term::all()->count();
     for ($j = 1; $j <= $terms; $j++) {
         $profile_score = 0;
         for ($i = 1; $i <= $terms; $i++) {
             $temp_user = $user->term->find($i);
             $user_term_score = $temp_user->pivot->user_score;
             //get score of user
             if ($i == $j) {
                 $link_score = 0;
             } elseif ($i > $j) {
                 $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $j)->where('term_neighbor_id', $i)->get()->first();
                 $link_score = $temp_user_matrix->link_score;
             } else {
                 $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $i)->where('term_neighbor_id', $j)->get()->first();
                 $link_score = $temp_user_matrix->link_score;
             }
             $profile_score = $profile_score + $user_term_score * $link_score;
         }
         $user->profilescore()->sync([$j => ['profile_score' => $profile_score]], false);
     }
     DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->delete();
     $response = ["message" => 'RF Saved'];
     $statusCode = 200;
     return response($response, $statusCode)->header('Content-Type', 'application/json');
 }
 public function search(Request $request)
 {
     return Video::where('title', 'like', $request->input('q') . '%')->get();
 }
Esempio n. 25
0
 public function addMusic(Request $request)
 {
     $artist = $request->artist;
     $name = $request->name;
     $playlist_id = $request->playlist_id;
     $link = $request->link;
     $playlistVideo = false;
     $video_id = Youtube::parseVidFromUrl($link);
     // Si l'utilisateur est connecté, sinon on utilise l'utilisateur null null id=1
     $user_id = Auth::check() ? Auth::user()->id : 1;
     $vid = Video::where('url', $video_id)->first();
     $vid2 = Video::where('artist', 'LIKE', $artist)->where('name', 'LIKE', $name)->first();
     $check = !empty($vid) || !empty($vid2);
     if ($check) {
         if (!empty($vid)) {
             $pv = PlaylistVideo::where('video_id', $vid->id)->first();
         }
         if (empty($pv)) {
             if (!empty($vid)) {
                 $playlistVideo = PlaylistVideo::create(['video_id' => $vid->id, 'playlist_id' => $playlist_id, 'user_id' => $user_id]);
             } elseif (!empty($vid2)) {
                 $playlistVideo = PlaylistVideo::create(['video_id' => $vid2->id, 'playlist_id' => $playlist_id, 'user_id' => $user_id]);
             }
         }
     } else {
         $video = Video::create(['url' => $video_id, 'name' => $name, 'artist' => $artist, 'tags' => strtolower($name) . ' ' . strtolower($artist)]);
         $playlistVideo = PlaylistVideo::create(['video_id' => $video->id, 'playlist_id' => $playlist_id, 'user_id' => $user_id]);
     }
     if ($playlistVideo != false) {
         $playlistVideo->load('video');
     }
     return response()->json($playlistVideo);
 }
Esempio n. 26
0
 public function recommend($username)
 {
     //this assumes that the input is of type videos=EUS_025A722EA4B240D8B6F6330A8783143C,EUS_00A5E7F2D522422BB3BF3BF611CAB22F
     //however according to the input decided proper adjustments have to be made bearing in mind that where in expects string, e.g. 'a',b'
     $limit = 10;
     $user = MecanexUser::where('username', $username)->get()->first();
     $videos = Video::all();
     $num_of_videos = count($videos);
     if (empty($user)) {
         $response = ["error" => "User doesn`t exist"];
         $statusCode = 404;
     } else {
         $user_id = $user->id;
         //parameter for the experiment
         $neighs = '0';
         $list_neighs = [];
         $video_ids = [];
         //content_based recommendation
         $results_content = $this->content_similarity($user_id, $video_ids);
         //collaborative recommendation
         //			//multiplies vector of user i with every one of its neighbors and sorts them in descending order
         $results_neighs = $this->similar_neighbors($user_id, $neighs);
         foreach ($results_neighs as $neigh) {
             //            array_push($list_neighs, $neigh->neighbor);
             array_push($list_neighs, $neigh);
         }
         $num_of_neighbors = count($list_neighs);
         if ($num_of_neighbors < 3) {
             $results_recommendation = $results_content;
         } else {
             $results_collaborative = array_fill(1, $num_of_videos, 0);
             foreach ($list_neighs as $neigh) {
                 $neighbor_results_content = $this->content_similarity($neigh["neighbor"], $video_ids);
                 foreach ($neighbor_results_content as $id => $result) {
                     $results_collaborative[$id] = $results_collaborative[$id] + $result / $num_of_neighbors;
                 }
             }
             foreach ($results_content as $id => $result) {
                 $results_recommendation[$id] = 0.8 * $results_content[$id] + 0.2 * $results_collaborative[$id];
             }
         }
         arsort($results_recommendation);
         $results_recommendation = array_slice($results_recommendation, 0, $limit, true);
         $final_results = [];
         foreach ($results_recommendation as $id => $result) {
             $video = Video::where('id', $id)->get()->first();
             array_push($final_results, $video["video_id"]);
         }
         $response = ["Video Ids" => $final_results];
         $statusCode = 200;
     }
     return response($response, $statusCode)->header('Content-Type', 'application/json');
 }
Esempio n. 27
0
 public function serve($video)
 {
     $video = Video::where('slug', $video)->firstOrFail();
     return view('pages.video.single', ['video' => $video]);
 }