Skip to content

Commit 319f6d2

Browse files
committed
Initialize the package
1 parent b352f4c commit 319f6d2

File tree

6 files changed

+805
-22
lines changed

6 files changed

+805
-22
lines changed

.gitignore

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
1-
vendor/
2-
node_modules/
3-
npm-debug.log
4-
5-
# Laravel 4 specific
6-
bootstrap/compiled.php
7-
app/storage/
8-
9-
# Laravel 5 & Lumen specific
10-
public/storage
11-
public/hot
12-
storage/*.key
13-
.env.*.php
14-
.env.php
15-
.env
16-
Homestead.yaml
17-
Homestead.json
18-
19-
# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
20-
.rocketeer/
1+
.idea

README.md

Lines changed: 150 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,150 @@
1-
# youtube-uploader-laravel
2-
The package will help you to upload videos to youtube with privacy parameter
1+
# Youtube Uploader for Laravel
2+
laravel youtube uploader is a php package written by [Arman Khachatryan](https://github.com/arm092) with laravel to handle many youtube sdk functionality by making it's api more easy.
3+
4+
## Features
5+
- Uploading videos to user channel
6+
- Creating playlists
7+
- Insert video to existing playlist
8+
- Set thumbnail to existing video or at uploading video
9+
- Deleting video
10+
11+
# Installation Guide
12+
At laravel project install package using composer
13+
```
14+
composer require arm092/youtube-uploader-laravel
15+
```
16+
The package is compatible with Laravel 6.x so you don't need to set providers or aliases for the package, we're using laravel auto discovery
17+
18+
## Get Your Credentials From Google
19+
- Go to [Google Developers Console](https://console.developers.google.com/) Press Credentials from the sidebar then create project from OAuth consent screen then Click Credentials => Create credentials => OAuth client id, choose it web application and set you Authorized redirect URIs, also you can edit or add new urls later
20+
- You will get Client Id and Client Secret
21+
- Go to your .env file and paste your credentials to be like this
22+
23+
```
24+
GOOGLE_CLIENT_ID=YOUR_CLIENT_ID
25+
GOOGLE_CLIENT_SECRET=YOUR_SECRET
26+
```
27+
28+
You are now ready to use the package
29+
30+
There is two steps to do any thing for the package, get authenticated url and do the youtube api action
31+
32+
### To get the auth url, just go to routes/web.php and do this route or the path you want to use
33+
```
34+
Route::get('youtube/auth', 'YoutubeUploaderController@auth');
35+
```
36+
At the controller, you will get the url and you can show it in view file or redirect user to it directly
37+
```
38+
use Youtube;
39+
public function auth() {
40+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback'; // Upload video path
41+
42+
return redirect(Youtube::setRedirectUrl($redirect_url)->AuthUrl());
43+
}
44+
```
45+
This code will authenticate user then redirect user to another url to do your logic on it, and to do any logic code, you need to add route url to routes/web.php
46+
```
47+
Route::get('youtube/callback', 'YoutubeUploaderController@callback');
48+
```
49+
50+
Don't forget to save full path of callback url at google console developer at credential for project
51+
52+
The we will now show our logic of the package
53+
54+
## Upload video
55+
```
56+
public function callback(Request $request) {
57+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback';
58+
$video = public_path('VIDEO_FILE');
59+
$image = public_path('IMAGE_FILE');
60+
$youtube = Youtube::setRedirectUrl($redirect_url)->upload($video,
61+
[
62+
'title' => 'TITLE',
63+
'description' => 'DESCRIPTION',
64+
'tags' => ['tag 1', 'tag 2'],
65+
'category_id' => '22',
66+
'privacy' => 'public' // or 'private' and 'unlisted'
67+
]
68+
);
69+
70+
// Get uploaded video id
71+
$video_id = $youtube->uploadedVideoId();
72+
}
73+
```
74+
75+
## Set thumbnail to existing video
76+
Remember that you need to set auth url at routes for each callback url
77+
```
78+
public function another_callback(Request $request) {
79+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
80+
$video_id = 'VIDEO_ID';
81+
$image = public_path('THUMBNAIL_PATH');
82+
$youtube = Youtube::setRedirectUrl($redirect_url)->updateThumbnail($video_id, $image);
83+
}
84+
```
85+
86+
## Set thumbnail at uploading
87+
Remember that you need to set auth url at routes for each callback url
88+
```
89+
public function another_callback(Request $request) {
90+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
91+
$video = public_path('VIDEO_PATH');
92+
$image = public_path('THUMBNAIL_PATH');
93+
$youtube = Youtube::setRedirectUrl($redirect_url)->upload($video,
94+
[
95+
'title' => 'TITLE',
96+
'description' => 'Description1',
97+
'tags' => ['tag 1', 'tag2'],
98+
'category_id' => '22',
99+
'privacy' => 'public' // or 'private' and 'unlisted'
100+
]
101+
)->withThumbnail($image);
102+
103+
$video_id = $youtube->uploadedVideoId();
104+
}
105+
```
106+
107+
## Set tags for existing video
108+
Remember that you need to set auth url at routes for each callback url
109+
```
110+
public function another_callback(Request $request) {
111+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
112+
$video_id = 'YOUR_VIDEO_ID';
113+
$youtube = Youtube::setRedirectUrl($redirect_url)->updateTags($video_id, ['tag 1', 'tag2', 'Tag3', 'Tag 4']);
114+
}
115+
```
116+
117+
## Create Playlist
118+
Remember that you need to set auth url at routes for each callback url
119+
120+
```
121+
public function another_callback(Request $request) {
122+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
123+
$youtube = Youtube::setRedirectUrl($redirect_url)
124+
->createPlaylist('TITLE', 'DESCRIPTION');
125+
126+
// Get playlist id
127+
$playlist_id = $youtube->createdPlaylistId();
128+
}
129+
```
130+
131+
## Insert Video to playlist
132+
Remember that you need to set auth url at routes for each callback url
133+
```
134+
public function another_callback(Request $request) {
135+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
136+
$youtube = Youtube::setRedirectUrl($redirect_url)
137+
->VideoToPlaylist('VIDEO_ID', 'PLAYLIST_ID');
138+
}
139+
```
140+
141+
## Delete video by the given id
142+
Remember that you need to set auth url at routes for each callback url
143+
```
144+
public function another_callback(Request $request) {
145+
$redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
146+
$video_id = 'VIDEO_ID';
147+
$youtube = Youtube::setRedirectUrl($redirect_url)->deleteVideo($video_id);
148+
}
149+
```
150+

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "arm092/laravel-youtube-uploader",
3+
"description": "The package will help you to upload videos to youtube with privacy parameter and making youtube api much easier",
4+
"type": "library",
5+
"require": {
6+
"google/apiclient": "^2.0@dev"
7+
},
8+
"license": "MIT",
9+
"authors": [
10+
{
11+
"name": "Arman Khachatryan",
12+
"email": "[email protected]"
13+
}
14+
],
15+
"minimum-stability": "dev",
16+
"autoload": {
17+
"psr-4": {
18+
"Arm092\\YoutubeUploader\\": "src/"
19+
}
20+
},
21+
"extra": {
22+
"laravel": {
23+
"providers": [
24+
"Arm092\\YoutubeUploader\\YoutubeUploaderServiceProvider"
25+
],
26+
"aliases": {
27+
"Youtube": "Arm092\\YoutubeUploader\\Facades\\Youtube"
28+
}
29+
}
30+
}
31+
}

src/Facades/Youtube.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Arm092\YoutubeUploader\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class Youtube extends Facade {
8+
/**
9+
* Get the registered name of the component.
10+
*
11+
* @return string
12+
*/
13+
protected static function getFacadeAccessor() {
14+
return 'youtube';
15+
}
16+
}

0 commit comments

Comments
 (0)