Skip to content

Commit

Permalink
huge refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
0DUDDU committed Jun 1, 2023
1 parent 24cb272 commit a387d8b
Show file tree
Hide file tree
Showing 15 changed files with 736 additions and 1,244 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/vendor
/composer.lock

### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down
2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
preset: psr2
preset: psr12
46 changes: 0 additions & 46 deletions CODE_OF_CONDUCT.md

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ We accept contributions via Pull Requests on [Github](https://github.com/alchemy

## Pull Requests

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``.
- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``.

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

Expand Down
4 changes: 2 additions & 2 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Not obligatory, but suggest an idea for implementing addition or change.

Include as many relevant details about the environment you experienced the bug in and how to reproduce it.

* Version used (e.g. PHP 5.6, HHVM 3):
* Operating system and version (e.g. Ubuntu 16.04, Windows 7):
* Version used (e.g. PHP 8.0, HHVM 4):
* Operating system and version (e.g. Ubuntu 22.04, Windows 10):
* Link to your project:
* ...
* ...
80 changes: 41 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ $authUrl = $authObject->getLoginUrl('email','identifier');
Now once the user authorizes by visiting the url, the authcode will be redirected to the redirect_url specified in .env with params as code( this will be auth code) and state (this will be identifier we added during making the loginUrl)

```php
$code = Input::get('code');
$identifier = Input::get('state');
$code = $request->get('code');
$identifier = $request->get('state');

```

- **Auth-Token and Details For Channel**

```php
$authObject = new AuthenticateService;
$authResponse = $authObject->authChannelWithCode($code);
$authResponse = $authObject->authChannelWithCode($code, true);
```

- **This will return an array**:
Expand All @@ -90,6 +90,21 @@ $authResponse['channel_details']
$authResponse['live_streaming_status'] (enabled or disabled)
```

- **Auth-Token only**

```php
$authObject = new AuthenticateService;
$authResponse = $authObject->authChannelWithCode($code, false);
```

- **This will return an array**:
```
$authResponse['token'] (Channel Token)
```

- **Refresh Token**
If your token expires, it will be refreshed using the refresh token, and the new token will be available by calling `getNewToken()` on any object. It will return null if no new token has been fetched.

### Full Live Streaming API

- **Add Code to call the api class**
Expand All @@ -106,26 +121,23 @@ use ZeroDUDDU\YoutubeLaravelApi\LiveStreamService;
```php
# data format creating live event
$data = array(
"title" => "",
"description" => "",
"thumbnail_path" => "", // Optional
"event_start_date_time" => "",
"event_end_date_time" => "", // Optional
"time_zone" => "",
'privacy_status' => "", // default: "public" OR "private"
'privacy_status' => "", // default: "private"
"language_name" => "", // default: "English"
"tag_array" => "" // Optional and should not be more than 500 characters
);

$ytEventObj = new LiveStreamService();
$ytEventObj = new LiveStreamService($authToken);
/**
* The broadcast function returns array of details from YouTube.
* Store this information & will be required to supply to youtube
* for live streaming using encoder of your choice.
*/
$response = $ytEventObj->broadcast($authToken, $data);
$response = $ytEventObj->broadcast($title, $description, $data);
if ( !empty($response) ) {

$youtubeEventId = $response['broadcast_response']['id'];
$serverUrl = $response['stream_response']['cdn']->ingestionInfo->ingestionAddress;
$serverKey = $response['stream_response']['cdn']->ingestionInfo->streamName;
Expand All @@ -136,12 +148,12 @@ if ( !empty($response) ) {
- **Updating a Youtube Event**

```php
$ytEventObj = new LiveStreamService();
$ytEventObj = new LiveStreamService($authToken);
/**
* The updateBroadcast response give details of the youtube_event_id,server_url and server_key.
* The server_url & server_key gets updated in the process. (save the updated server_key and server_url).
*/
$response = $ytEventObj->updateBroadcast($authToken, $data, $youtubeEventId);
$response = $ytEventObj->updateBroadcast($data, $youtubeEventId);

// $youtubeEventId = $response['broadcast_response']['id'];
// $serverUrl = $response['stream_response']['cdn']->ingestionInfo->ingestionAddress;
Expand All @@ -151,16 +163,16 @@ $response = $ytEventObj->updateBroadcast($authToken, $data, $youtubeEventId);
- **Deleting a Youtube Event**

```php
$ytEventObj = new LiveStreamService();
$ytEventObj = new LiveStreamService($authToken);

# Deleting the event requires authentication token for the channel in which the event is created and the youtube_event_id
$ytEventObj->deleteEvent($authToken, $youtubeEventId);
$ytEventObj->deleteEvent($youtubeEventId);
```

- Starting a Youtube Event Stream:

```php
$ytEventObj = new LiveStreamService();
$ytEventObj = new LiveStreamService($authToken);
/**
* $broadcastStatus - ["testing", "live"]
* Starting the event takes place in 3 steps
Expand All @@ -169,18 +181,18 @@ $ytEventObj = new LiveStreamService();
* 3. If transitioEvent() returns successfull for testing broadcast status, then start live streaming your video by passing $broadcastStatus="live"
* & in response it will return us the stream status.
*/
$streamStatus = $ytEventObj->transitionEvent($authToken, $youtubeEventId, $broadcastStatus);
$streamStatus = $ytEventObj->transitionEvent($youtubeEventId, $broadcastStatus);
```

- **Stopping a Youtube Event Stream**

```php
$ytEventObj = new LiveStreamService();
$ytEventObj = new LiveStreamService($authToken);
/**
* $broadcastStatus - ["complete"]
* Once live streaming gets started succesfully. We can stop the streaming the video by passing broadcastStatus="complete" and in response it will give us the stream status.
*/
$ytEventObj->transitionEvent($authToken, $youtubeEventId, $broadcastStatus); // $broadcastStatus = ["complete"]
$ytEventObj->transitionEvent($youtubeEventId, $broadcastStatus); // $broadcastStatus = ["complete"]
```


Expand All @@ -197,7 +209,6 @@ use ZeroDUDDU\YoutubeLaravelApi\ChannelService;

- **Channel details By Channel Id**
If you want channel details for multiple channels add channel id saperated by commas(,) in param
`NOTE: This doesn't require authorization token`

```php
/**
Expand All @@ -208,7 +219,7 @@ use ZeroDUDDU\YoutubeLaravelApi\ChannelService;

$part = 'id,snippet';
$params = array('id'=> 'channel_1_id,channel_2_id');
$channelServiceObject = new ChannelService;
$channelServiceObject = new ChannelService($authToken);
$channelDetails = $channelServiceObject->channelsListById($part, $params);

```
Expand All @@ -232,7 +243,7 @@ $channelDetails = $channelServiceObject->getChannelDetails($authToken);
* totalResults = the amount of results you want
* maxResults = max of results PER PAGE. We don't need this parameter here since it will loop until it gets all the results you want.
*/
$channelServiceObject = new ChannelService;
$channelServiceObject = new ChannelService($authToken);
$channelDetails = $channelServiceObject->subscriptionByChannelId($params);
```

Expand Down Expand Up @@ -272,8 +283,8 @@ $response = $channelServiceObject->removeSubscription( $token, $subscriptionId);
* 'brandingSettings.channel.unsubscribedTrailer' => '')
*/

$channelServiceObject = new ChannelService;
$response = $channelServiceObject->updateChannelBrandingSettings($googleToken, $properties);
$channelServiceObject = new ChannelService($authToken);
$response = $channelServiceObject->updateChannelBrandingSettings($properties);
```

### Full Youtube Video API
Expand All @@ -291,31 +302,22 @@ use ZeroDUDDU\YoutubeLaravelApi\VideoService;

```php
$part ='snippet,contentDetails,id,statistics';
$params =array('id'=>'xyzgh');
$videoServiceObject = new VideoService;
$params =['id'=>'xyzgh'];
$videoServiceObject = new VideoService($authToken);
$response = $videoServiceObject->videosListById($part, $params);
```

- **Upload Video To Your Channel**
```php

/*
* $videoPath path to the video
* $data array('title'=>"",
* 'description'=>"",
* 'tags'=>"",
* 'category_id'=>"",
* 'video_status'=>"")
*/

$videoServiceObject = new VideoService;
$response = $videoServiceObject->uploadVideo($googleToken, $videoPath, $data);
$videoServiceObject = new VideoService($authToken);
$response = $videoServiceObject->uploadVideo($videoPath, $title, $description, $categoryId, $privacyStatus, $tags, $data);
```

- **Delete Video To Your Channel**
```php
$videoServiceObject = new VideoService;
$response = $videoServiceObject->deleteVideo($googleToken, $videoId);
$videoServiceObject = new VideoService($authToken);
$response = $videoServiceObject->deleteVideo($videoId);
```


Expand All @@ -324,8 +326,8 @@ $response = $videoServiceObject->deleteVideo($googleToken, $videoId);

```php
# rating 'like' or 'dislike' or 'none'
$videoServiceObject = new VideoService;
$response = $videoServiceObject->videosRate($googleToken, $videoId, $rating);
$videoServiceObject = new VideoService($authToken);
$response = $videoServiceObject->videosRate( $videoId, $rating);

```

Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
}
],
"require": {
"google/apiclient": "^2.0"
"php": "^8.0",
"google/apiclient": "^2.0",
"laravel/framework": "^9.0|^10.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.3"
"squizlabs/php_codesniffer": "^3.7"
},
"autoload": {
"psr-4": {
Expand All @@ -29,9 +31,9 @@
},
"scripts": {
"check-style":
"phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"phpcs -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src",
"fix-style":
"phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
"phpcbf -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src"
},
"extra": {
"branch-alias": {
Expand Down
Loading

0 comments on commit a387d8b

Please sign in to comment.