-
Notifications
You must be signed in to change notification settings - Fork 18
Class: Videos
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
- column
- owns
- exists
- idExists
- keyExists
- filenameExists
- get
- getField
- getFields
- setField
- setFieldBulk
- setFields
- setFieldsBulk
- getById
- getByKey
- getByFilename
- getId
- getKey
- getFilename
- getUploaderId
- getUploaderName
- getDate
- getTitle
- getDescription
- getScope
- getFeatured
- getStatus
- getQualities
- getDuration
- getThumbnailsCount
- getViews
- getComments
- getState
- list
- listTrending
- listFresh
- listByState
- listActive
- listInactive
- listByStatus
- listSuccessful
- listPending
- listFailed
- listByScope
- listPublic
- listPrivate
- listUnlist
- listByUploader
- count
- countActive
- parameters
- countInactive
- countSuccessful
- countPending
- countFailed
- validateUpload
- validateUpdate
- validateInsert
- validatePermissions
- activate
- bulkActivate
- deactivate
- bulkDeactivate
- feature
- unfeature
- delete
- bulkDelete
- createKey
- createFilename
- upload
- insert
- update
- setViews
- setComments
Thus method creates required variables and makes things ready for all other parameters. This is a required method when creating new Videos() object.
You can pass already initialized Database object or functional will automatically try to use global object.
$videos = new Videos();
$videos->intialize();
This method determines if given value is video id (int) or vkey (string)
Any videoid or vkey
Returns 'id' or 'vkey' depending on value provided.
$videos->column(1412); // outputs id
$videos->column('7v0cw_tPRm'); // outputs vkey
Check if a video is owned by certain user.
Username to check ownership against.
Videoid or vkey for video to be checked for ownership.
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.
$videos->owns('stark', 1412);
$videos->owns('jon', '7v0cw_tPRm');
Check if a value exists against given columns
Single field or set of field => value to match
Value to match against when $fields is string
Fields to return if match is found
Returns boolean or array of fields requested in $fetch parameter
// 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);
Check if given id exists
ID to check for
Boolean depending case of value found
$videos->idExists(123);
Check if given vkey exists
vkey to check for
Boolean depending case of value found
$videos->keyExists('143DKSA_DSDA');
Check if given filename exists
Filename to check for
Boolean depending case of value found
$videos->filenameExists('GLXiXBPxyxhkelD');
Get all fields for a single video
Value of field to search against
Name of field to search against, by default it tries to determine between ID and vkey
An array of data consisting of all available columns against matching video.
// get a video by vkey (vkey and id are automatically detected)
$videos->get('5CGun_cSKF');
// get a video by filename
$videos->get('GLXiXBPxyxhkelD', 'filename');
Get a single field for a single video
ID or vkey to search for
Name of field to fetch
An array of data for matching video
// get video scope
$videos->getField('5CGun_cSKF', 'scope')
get video views
$videos->getField('5CGun_cSKF', 'views')
// get video description
$videos->getField(25125, 'description')
Get a multiple fields for a single video
ID or vkey to search for
A list of fields to fetch
An array of data consisting of fields requested only.
// get filename and publish date
$videos->getFields('5CGun_cSKF', array('filename','date'));
Update a single field of single video
Field to be updated
New value to set
Value to search video by
Column to search against. If false then function will consider it vkey.
Boolean depending on how update query went.
// update video title using vkey
$videos->setField('title', 'The Great Army', '5CGun_cSKF', 'vkey');
Update a single field of multiple videos
Field to be updated
New value to set
Value list to search video by
Column to search against. If false then function will consider it vkey.
Boolean depending on how update query went.
// activate multiple videos
$list= array('AHo41_PX78', 'KcKI1_H84T', 'Ij3Sx_vGjX');
$videos->setFieldBulk('state', 'active', $list, 'vkey');
update multiple fields of single video
An assoc. array of field => value to update
Value to search video by
Column to search values against. If false then function will consider it vkey.
Boolean depending on status of update.
// update title, duration and views
$details = array(
'title' => 'All Hail Ragnar',
'duration' => 153,
'views' => 145212
);
$videos->setFields($details, 'Ij3Sx_vGjX', 'vkey');
update multiple columns of multiple videos
An assoc. array of field => value to update
List of values to search videos by
Column to search values against. If false then function will consider it vkey.
Boolean depending on status of update.
// 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);
Get all fields of video by id
ID to search video by
An array consisting of all columns for matching video.
$videos->getById(124521);
Get all fields of video by key
vkey to search video by
An array consisting of all columns for matching video.
$videos->getByKey('5CGun_cSKF');
Get all fields of video by filename
Filename to search video by
An array consisting of all columns for matching video.
$videos->getByFilename('GLXiXBPxyxhkelD');
Get ID of video
vkey of video to fetch
ID for matching video
$videos->getId('5CGun_cSKF');
Get key of video
ID of video to fetch
vkey for matching video
$videos->getKey(15123);
Get Filename of video
ID or vkey of video to fetch
Filename for matching video
$videos->getFilename('5CGun_cSKF');
Get video uploader's ID
ID or vkey of video to fetch
Video uploader's ID for matching video
$videos->getUploaderId('5CGun_cSKF');
Get video uploader's name
ID or vkey of video to fetch
Video uploader's name for matching video
$videos->getUploaderName('5CGun_cSKF');
Get publish date of video
ID or vkey of video to fetch
The publish date for matching video
$videos->getDate('5CGun_cSKF');
Get title of video
ID or vkey of video to fetch
The title for matching video
$videos->getTitle('5CGun_cSKF');
Get description of video
ID or vkey of video to fetch
Description for matching video
$videos->description ('5CGun_cSKF');
Get scope of video
ID or vkey of video to fetch
Scope for matching video
$videos->getScope('5CGun_cSKF');
Get featured status of video
ID or vkey of video to fetch
Featured status for matching video
$videos->getFeatured('5CGun_cSKF');
Get processing status of video
ID or vkey of video to fetch
Processing status for matching video
$videos->getStatus('5CGun_cSKF');
Get qualities of video
ID or vkey of video to fetch
List of available qualities for matching video
$videos->getQualities('5CGun_cSKF');
Get duration of video
ID or vkey of video to fetch
Duration for matching video
$videos->getDuration('5CGun_cSKF');
Get thumbnails count of video
ID or vkey of video to fetch
Total thumbnails count for matching video
$videos->getThumbnailsCount('5CGun_cSKF');
Get total views of video
ID or vkey of video to fetch
Total views count for matching video
$videos->getViews('5CGun_cSKF');
Get total comments of video
ID or vkey of video to fetch
Total comments count for matching video
$videos->getComments('5CGun_cSKF');
Get state of video
ID or vkey of video to fetch
State for matching video
$videos->getState('5CGun_cSKF');
List videos matching several dynamic parameters
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.
An array consisting of videos that matched pattern after $limit was applied.
// 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);
List most viewed videos since start
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
// 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);
List most recent videos
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
// 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);
List most videos by specific state
State of video to fetch. Options for this are active, inactive or disabled
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
// get 10 active videos
$videos->listByState('active', 10);
// get 10 inactive videos
$videos->listByState('inactive', 10);
List videos by active state
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
// get 10 active videos
$videos->listActive(10);
// get 10 active videos by specific uploader
$parameters = array(
'uploader_name' => 'tommy_shelby'
);
$videos->listActive(10, $parameters);
List videos by inactive state
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listInactive(10);
List videos by processing status
Conversion status of video to fetch. Options for this are pending, successful or failed.
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listByStatus('failed', 10);
List successfully processed videos
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listSuccessful(10);
List videos that are pending processing
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listPending(10);
List most videos that failed during processing
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listFailed(10);
List by a specific scope
Conversion status of video to fetch. Options for this are pending, successful or failed.
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listByScope('public', 10);
List public videos
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listPublic(10);
List private videos
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listPrivate(10);
List unlisted videos
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listUnlist(10);
List videos by specific uploader
Uploader's name or user ID
Number or MySQL style limit
Additional parameters to apply
An array of videos matching parameters.
$videos->listByUploader('ralph', 10);
Count total videos matching parameters
An array of parameters to match and count videos against
The number of videos found
// count all videos
$videos->count();
// count videos with 100+ comments
$parameters['comments'] = array(100, '>');
$videos->count($parameters);
Count total active videos
An array of parameters to match and count videos against
The number of videos found
$videos->countActive();
Count total inactive videos
An array of parameters to match and count videos against
The number of videos found
$videos->countInactive();
Count total successful videos
An array of parameters to match and count videos against
The number of videos found
$videos->countSuccessful();
Count total pending videos
An array of parameters to match and count videos against
The number of videos found
$videos->countPending();
Count total failed videos
An array of parameters to match and count videos against
The number of videos found
$videos->countFailed();
Validate video upload data before moving into processing queue
The raw $_FILES object
True if upload is valid and false if it isn't
$upload = $_FILES['video'];
if ($videos->validateUpload($upload)) {
// video is valid for upload
}
Validate fields before updating video
The fields array to be updated
True if update is valid and false if it isn't
$fields = array('title' => 'hello world', 'duration' => '100');
if ($videos->validateUpdate($fields)) {
// video is valid for update
}
Validate form before inserting video
The fields array to be updated
True if update is valid and false if it isn't
$fields = array(
'title' => 'hello world',
'uploader_name' => 'snow',
'uploader_id', 212
);
if ($videos->validateInsert($fields)) {
// video is valid for insertion
}
Validate permissions of logged in user requesting changes to video
ID or vkey of video to check
Boolean
// let a user activate a video if has permissions
if ($videos->validatePermissions(2144)) {
$videos->activate(2144); // note that activate function performs that check itself
}
Set video state to active
ID or vkey of video to activate
Boolean depending on how request went
$videos->activate(142412);
Set video state to active for multiple videos
A list of videos to be activated
Column to match list against. If nothing is specified then it is considered 'vkey'.
Boolean depending on how request went
$list = array(141532, 12411, 14245);
$videos->bulkActivate($list, 'id');
Set video state to inactive
ID or vkey of video to deactivate
Boolean depending on how request went
$videos->deactivate(214124);
Set video state to inactive for multiple videos
A list of videos to be deactivated
Column to match list against. If nothing is specified then it is considered 'vkey'.
Boolean depending on how request went
$list = array(141532, 12411, 14245);
$videos->bulkDeactivate($list, 'id');
Set video to featured
ID or vkey of video to be featured
Boolean depending on how request went
$videos->feature(9242);
Remove video from featured
ID or vkey of video to be unfeatured
Boolean depending on how request went
$videos->unfeature(9242);
Delete a video and all media files belonging to it
ID or vkey of video to delete
Boolean depending on how request went
$videos->delete(124214);
Delete multiple videos and their media files
A list of vkeys to be deleted
Boolean depending on how request went
$list = array('214_ASd', 'dJWDI_31K', 'AGA_142245');
$videos->bulkDelete($list);
Create unique public key to be used for new video
Unique video key that doesn't exist in database
$videos->createKey();
Create unique filename to be used for new video
Unique video filename that doesn't exist in database
$videos->createFilename();
Upload a new video file
The raw $_FILES object
filename, path and directory of uploaded video
$fileData = $_FILES['fileData'];
$videos->upload($fileData);
Insert a video into database
Raw form fields
ID of inserted video
$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 a video's fields
ID or public key
Array with fields and values to be updated
Boolean depending on how update went
$fields = array('state' => 'active', 'duration' => 100, 'views' => 4219);
$videos->update(72421, $fields);
Increment video views
ID or public key
Number of views to increment
Boolean
$videos->setViews(187321); // increment 1 view
Increment video comments
ID or public key
Number of comments to increment
Boolean
$videos->setComments(187321); // increment 1 comment