Skip to content

Instantly share code, notes, and snippets.

@dmsysop
Created January 7, 2021 12:29
Show Gist options
  • Save dmsysop/1dfd696553a948a338bdbb441c36ef4d to your computer and use it in GitHub Desktop.
Save dmsysop/1dfd696553a948a338bdbb441c36ef4d to your computer and use it in GitHub Desktop.
GoogleYoutubeService.php
<?php
namespace App\Services;
use Illuminate\Http\Request;
use App\Models\{Professor, Video};
use Youtube;
class GoogleYoutubeService
{
protected $video;
protected $professor;
protected $tags;
protected $categoryId;
protected $privacy;
public function __construct(Request $request)
{
$this->professor = Professor::findOrFail($request->professor_id)->firstname;
$otherTags = array('XXXXXX', 'YYYYYYY', 'ZZZZZZ', $this->professor, $request->name);
$systemTags = explode(',', $request->tags);
$this->tags = !empty($request->tags) ? array_merge($otherTags, $systemTags) : $otherTags;
$this->video = $request;
$this->categoryId = 22;
$this->privacy = 'unlisted';
}
public function insert()
{
$video = Youtube::upload($this->video->file('youtubeVideo')->getPathName(), [
'title' => $this->video->name,
'description' => strip_tags($this->video->description),
'tags' => [$this->tags],
]);
return $video->getVideoId();
}
public function update()
{
$videoId = Video::where('youtube_video_id', $this->video)->first()->youtube_video_id;
dd($videoId);
$video = Youtube::update($videoId, [
'title' => $this->video->name,
'description' => strip_tags($this->video->description),
'tags' => [$this->tags],
'category_id' => $this->categoryId
], $this->privacy);
return $video->getVideoId();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment