Skip to content

Class: Videos

Saqib Razzaq edited this page Apr 20, 2019 · 9 revisions

Videos class is responsible for all major video related operations. This includes uploading, inserting, updating, deleting among many others. This page lists all available methods of Videos class along with examples.

initialize

Thus method creates required variables and makes things ready for all other parameters. This is a required method when creating new Videos() object.

Parameters
[object] $database [optional]

You can pass already initialized Database object or functional will automatically try to use global object.

Examples
$videos = new Videos();
$videos->intialize();

column

This method determines if given value is video id (int) or vkey (string)

Parameters
[mixed] $identifier

Any videoid or vkey

Returns

Returns 'id' or 'vkey' depending on value provided.

Examples
$videos->column(1412); // outputs id
$videos->column('7v0cw_tPRm'); // outputs vkey

owns

Check if a video is owned by certain user.

Parameters
[string] $username

Username to check ownership against.

[mixed] $video

Videoid or vkey for video to be checked for ownership.

Returns

This returns boolean value. Please note that all Admin (user with level 1) own all videos and this will return true if user is Admin even if uploader is different.

Examples
$videos->owns('stark', 1412);
$videos->owns('jon', '7v0cw_tPRm');

exists

Check if a value exists against given columns

Parameters
[string] $fields

Single field or set of field => value to match

[mixed] $value [optional]

Value to match against when $fields is string

[string] $fetch [optional]

Fields to return if match is found

Returns

Returns boolean or array of fields requested in $fetch parameter

Examples
// check if a filename exists
$this->exists('filename', 'GLXiXBPxyxhkelD');
// check if a vkey exists
$this->exists('vkey', '5CGun_cSKF');
// check if vkey, filename and uploader exist for same video and also return fields
$match = array(
    'vkey' => '5CGun_cSKF',
    'filename' => 'GLXiXBPxyxhkelD',
    'uploader_name' => 'ivar_the_boneless'
);

$fields = array('id', 'title', 'duration', 'views');
$this->exists($match, false, $fields);

idExists

Check if given id exists

Parameters
[integer] $id

ID to check for

Returns

Boolean depending case of value found

Examples
$videos->idExists(123);

keyExists

Check if given vkey exists

Parameters
[string] $vkey

vkey to check for

Returns

Boolean depending case of value found

Examples
$videos->keyExists('143DKSA_DSDA');

filenameExists

Check if given filename exists

Parameters
[string] $filename

Filename to check for

Returns

Boolean depending case of value found

Examples
$videos->filenameExists('GLXiXBPxyxhkelD');

get

Get all fields for a single video

Parameters
[mixed] $identifier

Value of field to search against

[string] $type [optional]

Name of field to search against, by default it tries to determine between ID and vkey

Returns

An array of data consisting of all available columns against matching video.

Examples
// get a video by vkey (vkey and id are automatically detected)
$videos->get('5CGun_cSKF');
// get a video by filename
$videos->get('GLXiXBPxyxhkelD', 'filename');

getField

Get a single field for a single video

Parameters
[mixed] $identifier

ID or vkey to search for

[string] $field

Name of field to fetch

Returns

An array of data for matching video

Examples
// get video scope
$videos->getField('5CGun_cSKF', 'scope')
get video views
$videos->getField('5CGun_cSKF', 'views')
// get video description
$videos->getField(25125, 'description')

getFields

Get a multiple fields for a single video

Parameters
[mixed] $identifier

ID or vkey to search for

[array] $fields

A list of fields to fetch

Returns

An array of data consisting of fields requested only.

Examples
// get filename and publish date
$videos->getFields('5CGun_cSKF', array('filename','date'));

setField

Update a single field of single video

Parameters
[string] $field

Field to be updated

[mixed] $value

New value to set

[mixed] $identiferValue

Value to search video by

[string] $identifier [optional]

Column to search against. If false then function will consider it vkey.

Returns

Boolean depending on how update query went.

Examples
// update video title using vkey 
$videos->setField('title', 'The Great Army', '5CGun_cSKF', 'vkey');

setFieldBulk

Update a single field of multiple videos

Parameters
[string] $field

Field to be updated

[mixed] $value

New value to set

[array] $identifierValueArray

Value list to search video by

[string] $identifier [optional]

Column to search against. If false then function will consider it vkey.

Returns

Boolean depending on how update query went.

Examples
// activate multiple videos
$list= array('AHo41_PX78', 'KcKI1_H84T', 'Ij3Sx_vGjX');
$videos->setFieldBulk('state', 'active', $list, 'vkey');

setFields

update multiple fields of single video

Parameters
[array] $fieldValueArray

An assoc. array of field => value to update

[mixed] $identiferValue

Value to search video by

[string] $identifier [optional]

Column to search values against. If false then function will consider it vkey.

Returns

Boolean depending on status of update.

Examples
// update title, duration and views
$details = array(
    'title' => 'All Hail Ragnar',
    'duration' => 153,
    'views' => 145212
);

$videos->setFields($details, 'Ij3Sx_vGjX', 'vkey');

setFieldsBulk

update multiple columns of multiple videos

Parameters
[array] $fieldValueArray

An assoc. array of field => value to update

[mixed] $identiferValueArray

List of values to search videos by

[string] $identifier [optional]

Column to search values against. If false then function will consider it vkey.

Returns

Boolean depending on status of update.

Examples
// activate multiple videos, make them private and change their uploader
$fields = array(
    'state' => 'active',
    'scope' => 'private',
    'uploader_name' => 'luca'
);
$list = array('AHo41_PX78', 'KcKI1_H84T', 'Ij3Sx_vGjX');
$videos->setFieldsBulk($fields, $list);

getById

Get all fields of video by id

Parameters
[integer] $id

ID to search video by

Returns

An array consisting of all columns for matching video.

Examples
$videos->getById(124521);

getByKey

Get all fields of video by key

Parameters
[integer] $vkey

vkey to search video by

Returns

An array consisting of all columns for matching video.

Examples
$videos->getByKey('5CGun_cSKF');

getByFilename

Get all fields of video by filename

Parameters
[integer] $filename

Filename to search video by

Returns

An array consisting of all columns for matching video.

Examples
$videos->getByFilename('GLXiXBPxyxhkelD');

getId

Get ID of video

Parameters
[string] $identifier

vkey of video to fetch

Returns

ID for matching video

Examples
$videos->getId('5CGun_cSKF');

getKey

Get key of video

Parameters
[string] $identifier

ID of video to fetch

Returns

vkey for matching video

Examples
$videos->getKey(15123);

getFilename

Get Filename of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Filename for matching video

Examples
$videos->getFilename('5CGun_cSKF');

getUploaderId

Get video uploader's ID

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Video uploader's ID for matching video

Examples
$videos->getUploaderId('5CGun_cSKF');

getUploaderName

Get video uploader's name

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Video uploader's name for matching video

Examples
$videos->getUploaderName('5CGun_cSKF');

getDate

Get publish date of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

The publish date for matching video

Examples
$videos->getDate('5CGun_cSKF');

getTitle

Get title of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

The title for matching video

Examples
$videos->getTitle('5CGun_cSKF');

getDescription

Get description of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Description for matching video

Examples
$videos->description ('5CGun_cSKF');

getScope

Get scope of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Scope for matching video

Examples
$videos->getScope('5CGun_cSKF');

getFeatured

Get featured status of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Featured status for matching video

Examples
$videos->getFeatured('5CGun_cSKF');

getStatus

Get processing status of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Processing status for matching video

Examples
$videos->getStatus('5CGun_cSKF');

getQualities

Get qualities of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

List of available qualities for matching video

Examples
$videos->getQualities('5CGun_cSKF');

getDuration

Get duration of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Duration for matching video

Examples
$videos->getDuration('5CGun_cSKF');

getThumbnailsCount

Get thumbnails count of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Total thumbnails count for matching video

Examples
$videos->getThumbnailsCount('5CGun_cSKF');

getViews

Get total views of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Total views count for matching video

Examples
$videos->getViews('5CGun_cSKF');

getComments

Get total comments of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

Total comments count for matching video

Examples
$videos->getComments('5CGun_cSKF');

getState

Get state of video

Parameters
[string] $identifier

ID or vkey of video to fetch

Returns

State for matching video

Examples
$videos->getState('5CGun_cSKF');

list

List videos matching several dynamic parameters

Parameters
[array] $parameters [optional]

An array of parameters to match videos against. This array can contain any of columns from 'videos' table. You can select values using =, >, >=, < or <= to have more control.

Returns

An array consisting of videos that matched pattern after $limit was applied.

Examples
// list videos by specific uploader
$parameters['uploader_name'] = 'limbs';
$videos->list($parameters);
// list videos longer than 60 seconds
$parameters['duration'] = array('60', '>');
$videos->list($parameters);
// most recent videos by limit
$params['limit'] = 10;
$response = $videos->list($params);
// most viewed videos
$params = array('sort' => 'views');
$response = $videos->list($params);
// get videos longer than 60 seconds by jon_snow with more than 100 views
$params = array(
  'uploader_name' => 'jon_snow',
  'duration' => array('60', '<')
  'views' => array('200', '>')
);
$response = $videos->list($params);

listTrending

List most viewed videos since start

Parameters
[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
// get 10 most viewed videos
$videos->listTrending(10);
// get 10 most viewed videos by specific uploader
$parameters = array(
    'uploader_name' => 'tommy_shelby'
);
$videos->listTrending(10, $parameters);
// get 10 most viewed videos by specific uploader with duration less than 30 seconds
$parameters = array(
    'uploader_name' => 'tommy_shelby', 
    'duration' => array('30', '<')
);
$videos->listTrending(10, $parameters);

listFresh

List most recent videos

Parameters
[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
// get 10 most recent videos
$videos->listFresh(10);
// get 10 most recent videos by specific uploader
$parameters = array(
    'uploader_name' => 'tommy_shelby'
);
$videos->listFresh(10, $parameters);
// get 10 most recent videos by specific uploader with duration less than 30 seconds
$parameters = array(
    'uploader_name' => 'tommy_shelby', 
    'duration' => array('30', '<')
);
$videos->listFresh(10, $parameters);

listByState

List most videos by specific state

Parameters
[string] $state

State of video to fetch. Options for this are active, inactive or disabled

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
// get 10 active videos
$videos->listByState('active', 10);
// get 10 inactive videos
$videos->listByState('inactive', 10);

listActive

List videos by active state

Parameters
[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
// get 10 active videos
$videos->listActive(10);
// get 10 active videos by specific uploader
$parameters = array(
    'uploader_name' => 'tommy_shelby'
);
$videos->listActive(10, $parameters);

listInactive

List videos by inactive state

Parameters
[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listInactive(10);

listByStatus

List videos by processing status

Parameters
[string] $status

Conversion status of video to fetch. Options for this are pending, successful or failed.

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listByStatus('failed', 10);

listSuccessful

List successfully processed videos

Parameters
[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listSuccessful(10);

listPending

List videos that are pending processing

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listPending(10);

listFailed

List most videos that failed during processing

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listFailed(10);

listByScope

List by a specific scope

Parameters
[string] $status

Conversion status of video to fetch. Options for this are pending, successful or failed.

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listByScope('public', 10);

listPublic

List public videos

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listPublic(10);

listPrivate

List private videos

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listPrivate(10);

listUnlist

List unlisted videos

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listUnlist(10);

listByUploader

List videos by specific uploader

[string] $uploader

Uploader's name or user ID

[mixed] $limit

Number or MySQL style limit

[array] $parameters [optional]

Additional parameters to apply

Returns

An array of videos matching parameters.

Examples
$videos->listByUploader('ralph', 10);

count

Count total videos matching parameters

Parameters
[array] $parameters [optional]

An array of parameters to match and count videos against

Returns

The number of videos found

Examples
// count all videos
$videos->count();
// count videos with 100+ comments
$parameters['comments'] = array(100, '>');
$videos->count($parameters);

countActive

Count total active videos

Parameters
[array] $parameters [optional]

An array of parameters to match and count videos against

Returns

The number of videos found

Examples
$videos->countActive();

countInactive

Count total inactive videos

Parameters
[array] $parameters [optional]

An array of parameters to match and count videos against

Returns

The number of videos found

Examples
$videos->countInactive();

countSuccessful

Count total successful videos

Parameters
[array] $parameters [optional]

An array of parameters to match and count videos against

Returns

The number of videos found

Examples
$videos->countSuccessful();

countPending

Count total pending videos

Parameters
[array] $parameters [optional]

An array of parameters to match and count videos against

Returns

The number of videos found

Examples
$videos->countPending();

countFailed

Count total failed videos

Parameters
[array] $parameters [optional]

An array of parameters to match and count videos against

Returns

The number of videos found

Examples
$videos->countFailed();

validateUpload

Validate video upload data before moving into processing queue

Parameters
[object] $fileData

The raw $_FILES object

Returns

True if upload is valid and false if it isn't

Examples
$upload = $_FILES['video'];
if ($videos->validateUpload($upload)) {
    // video is valid for upload
}

validateUpdate

Validate fields before updating video

Parameters
[array] $fields

The fields array to be updated

Returns

True if update is valid and false if it isn't

Examples
$fields = array('title' => 'hello world', 'duration' => '100');
if ($videos->validateUpdate($fields)) {
    // video is valid for update
}

validateInsert

Validate form before inserting video

Parameters
[array] $fields

The fields array to be updated

Returns

True if update is valid and false if it isn't

Examples
$fields = array(
    'title' => 'hello world', 
    'uploader_name' => 'snow', 
    'uploader_id', 212
);
if ($videos->validateInsert($fields)) {
    // video is valid for insertion
}

validatePermissions

Validate permissions of logged in user requesting changes to video

Parameters
[mixed] $video

ID or vkey of video to check

Returns

Boolean

Examples
// let a user activate a video if has permissions
if ($videos->validatePermissions(2144)) {
    $videos->activate(2144); // note that activate function performs that check itself
}

activate

Set video state to active

Parameters
[mixed] $video

ID or vkey of video to activate

Returns

Boolean depending on how request went

Examples
$videos->activate(142412);

bulkActivate

Set video state to active for multiple videos

Parameters
[array] $videosArray

A list of videos to be activated

[string] $identifier [optional]

Column to match list against. If nothing is specified then it is considered 'vkey'.

Returns

Boolean depending on how request went

Examples
$list = array(141532, 12411, 14245);
$videos->bulkActivate($list, 'id');

deactivate

Set video state to inactive

Parameters
[mixed] $video

ID or vkey of video to deactivate

Returns

Boolean depending on how request went

Examples
$videos->deactivate(214124);

bulkDeactivate

Set video state to inactive for multiple videos

Parameters
[array] $videosArray

A list of videos to be deactivated

[string] $identifier [optional]

Column to match list against. If nothing is specified then it is considered 'vkey'.

Returns

Boolean depending on how request went

Examples
$list = array(141532, 12411, 14245);
$videos->bulkDeactivate($list, 'id');

feature

Set video to featured

Parameters
[mixed] $video

ID or vkey of video to be featured

Returns

Boolean depending on how request went

Examples
$videos->feature(9242);

unfeature

Remove video from featured

Parameters
[mixed] $video

ID or vkey of video to be unfeatured

Returns

Boolean depending on how request went

Examples
$videos->unfeature(9242);

delete

Delete a video and all media files belonging to it

Parameters
[mixed] $video

ID or vkey of video to delete

Returns

Boolean depending on how request went

Examples
$videos->delete(124214);

bulkDelete

Delete multiple videos and their media files

Parameters
[array] $videosArray

A list of vkeys to be deleted

Returns

Boolean depending on how request went

Examples
$list = array('214_ASd', 'dJWDI_31K', 'AGA_142245');
$videos->bulkDelete($list);

createKey

Create unique public key to be used for new video

Returns

Unique video key that doesn't exist in database

Examples
$videos->createKey();

createFilename

Create unique filename to be used for new video

Returns

Unique video filename that doesn't exist in database

Examples
$videos->createFilename();

upload

Upload a new video file

Parameters
[object] $fileData

The raw $_FILES object

Returns

filename, path and directory of uploaded video

Examples
$fileData = $_FILES['fileData'];
$videos->upload($fileData);

insert

Insert a video into database

Parameters
[array] $form

Raw form fields

Returns

ID of inserted video

Examples
$form = array(
    'title' => 'King Ragnar is dead',
    'description' => 'Well, he is dead. What else?',
    'filename' => $videos->createFilename(), // usually this is created and returned when calling upload() 
    'uploader_id' => $users->userId(), // logged in userid
    'uploader_name' => $users->username() // logged in username 
);
$videos->insert($form);

update

Update a video's fields

Parameters
[mixed] $identifier

ID or public key

[array] $details

Array with fields and values to be updated

Returns

Boolean depending on how update went

Examples
$fields = array('state' => 'active', 'duration' => 100, 'views' => 4219);
$videos->update(72421, $fields);

setViews

Increment video views

Parameters
[mixed] $video

ID or public key

[integer] $views

Number of views to increment

Returns

Boolean

Examples
$videos->setViews(187321); // increment 1 view

setComments

Increment video comments

Parameters
[mixed] $video

ID or public key

[integer] $comments

Number of comments to increment

Returns

Boolean

Examples
$videos->setComments(187321); // increment 1 comment
Clone this wiki locally