├── CODE_OF_CONDUCT.md ├── FakeLiveDemo.php ├── Ingest_google_drive.php ├── LICENSE ├── README.md ├── bulk_update.php ├── create_csv.php ├── import_from_ftp.php └── update_metadata.php /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | education, socio-economic status, nationality, personal appearance, race, 10 | religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Be friendly and welcoming 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | - Interpret the arguments of others in good faith, do not seek to disagree. 21 | - When we do disagree, try to understand why. 22 | * Focusing on what is best for the community 23 | * Showing empathy towards other community members 24 | * Be patient 25 | - Remember that people have varying communication styles and that not everyone is using their native language. (Meaning and tone can be lost in translation.) 26 | * Be thoughtful 27 | - Productive communication requires effort. Think about how your words will be interpreted. 28 | - Remember that sometimes it is best to refrain entirely from commenting. 29 | * Avoid destructive behavior: 30 | - Derailing: stay on topic; if you want to talk about something else, start a new conversation. 31 | - Unconstructive criticism: don't merely decry the current state of affairs; offer—or at least solicit—suggestions as to how things may be improved. 32 | - Snarking (pithy, unproductive, sniping comments) 33 | - Discussing potentially offensive or sensitive issues; this all too often leads to unnecessary conflict. 34 | - Microaggressions: brief and commonplace verbal, behavioral and environmental indignities that communicate hostile, derogatory or negative slights and insults to a person or group. 35 | 36 | 37 | Examples of unacceptable behavior by participants include: 38 | 39 | * The use of sexualized language or imagery and unwelcome sexual attention or 40 | advances 41 | * Trolling, insulting/derogatory comments, and personal or political attacks 42 | * Public or private harassment 43 | * Publishing others' private information, such as a physical or electronic 44 | address, without explicit permission 45 | * Other conduct which could reasonably be considered inappropriate in a 46 | professional setting 47 | 48 | People are complicated. You should expect to be misunderstood and to misunderstand others; when this inevitably occurs, resist the urge to be defensive or assign blame. Try not to take offense where no offense was intended. Give people the benefit of the doubt. Even if the intent was to provoke, do not rise to it. It is the responsibility of all parties to de-escalate conflict when it arises. 49 | 50 | ## Our Responsibilities 51 | 52 | Project maintainers are responsible for clarifying the standards of acceptable 53 | behavior and are expected to take appropriate and fair corrective action in 54 | response to any instances of unacceptable behavior. 55 | 56 | Project maintainers have the right and responsibility to remove, edit, or 57 | reject comments, commits, code, wiki edits, issues, and other contributions 58 | that are not aligned to this Code of Conduct, or to ban temporarily or 59 | permanently any contributor for other behaviors that they deem inappropriate, 60 | threatening, offensive, or harmful. 61 | 62 | ## Scope 63 | 64 | This Code of Conduct applies both within project spaces and in public spaces 65 | when an individual is representing the project or its community. Examples of 66 | representing a project or community include using an official project e-mail 67 | address, posting via an official social media account, or acting as an appointed 68 | representative at an online or offline event. Representation of a project may be 69 | further defined and clarified by project maintainers. 70 | 71 | ## Enforcement 72 | 73 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 74 | reported to the community leaders responsible for enforcement at 75 | help@api.video. 76 | All complaints will be reviewed and investigated promptly and fairly. 77 | 78 | All community leaders are obligated to respect the privacy and security of the 79 | reporter of any incident. 80 | 81 | ## Enforcement Guidelines 82 | 83 | Community leaders will follow these Community Impact Guidelines in determining 84 | the consequences for any action they deem in violation of this Code of Conduct: 85 | 86 | ### 1. Correction 87 | 88 | **Community Impact**: Use of inappropriate language or other behavior deemed 89 | unprofessional or unwelcome in the community. 90 | 91 | **Consequence**: A private, written warning from community leaders, providing 92 | clarity around the nature of the violation and an explanation of why the 93 | behavior was inappropriate. A public apology may be requested. 94 | 95 | ### 2. Warning 96 | 97 | **Community Impact**: A violation through a single incident or series of 98 | actions. 99 | 100 | **Consequence**: A warning with consequences for continued behavior. No 101 | interaction with the people involved, including unsolicited interaction with 102 | those enforcing the Code of Conduct, for a specified period of time. This 103 | includes avoiding interactions in community spaces as well as external channels 104 | like social media. Violating these terms may lead to a temporary or permanent 105 | ban. 106 | 107 | ### 3. Temporary Ban 108 | 109 | **Community Impact**: A serious violation of community standards, including 110 | sustained inappropriate behavior. 111 | 112 | **Consequence**: A temporary ban from any sort of interaction or public 113 | communication with the community for a specified period of time. No public or 114 | private interaction with the people involved, including unsolicited interaction 115 | with those enforcing the Code of Conduct, is allowed during this period. 116 | Violating these terms may lead to a permanent ban. 117 | 118 | ### 4. Permanent Ban 119 | 120 | **Community Impact**: Demonstrating a pattern of violation of community 121 | standards, including sustained inappropriate behavior, harassment of an 122 | individual, or aggression toward or disparagement of classes of individuals. 123 | 124 | **Consequence**: A permanent ban from any sort of public interaction within the 125 | community. 126 | 127 | ### Reporting an incident 128 | 129 | Incidents that violate the Code of Conduct are extremely damaging to api.video, and they will not be tolerated. The silver lining is that, in many cases, these incidents present a chance for the offenders, and the teams at large, to grow, learn, and become better. 130 | 131 | > The following should be handled by a line manager who has been informed of the incident 132 | 133 | Try to get as much of the incident in written form. The important information to gather include the following: 134 | 135 | - Name of the participant doing the harassing 136 | - The location in which the incident occurred 137 | - The behavior that was in violation 138 | - The approximate time of the behavior 139 | - The circumstances surrounding the incident 140 | - Other people involved in the incident 141 | 142 | The line manager who is handling the reported offence should find out the following: 143 | 144 | - What happened? 145 | - Are we doing anything about it? 146 | - Who is doing those things? 147 | - When are they doing them? 148 | 149 | After the above has been identified and discussed, have an appropriate line manager communicate with the alleged harasser. Make sure to inform them of what has been reported about them. 150 | 151 | Allow the alleged harasser to give their side of the story. After this point, if the report stands, let the alleged harasser know what actions will be taken against them. 152 | 153 | Some things for the staff to consider when dealing with Code of Conduct offenders: 154 | 155 | - Warning the harasser to cease their behaviour and that any further reports will result in sanctions 156 | - Requiring that the harasser avoid any interaction with, and physical proximity to, their victim until a resolution or course of action has been decided upon 157 | - Requiring that the harasser not volunteer for future events your organisation runs (either indefinitely or for a certain time period) 158 | - Depending on the severity/details of the incident, removing a harasser from membership of api.video organisation 159 | 160 | Give accused staff members a place to appeal to if there is one, but in the meantime the report stands. Keep in mind that it is not a good idea to encourage an apology from the harasser. 161 | 162 | It is very important how we deal with the incident publicly. Our policy is to make sure that everyone aware of the initial incident is also made aware that it is not according to policy and that official action has been taken - while still respecting the privacy of individual staff members. When speaking to individuals (those who are aware of the incident, but were not involved with the incident) about the incident it is a good idea to keep the details out. 163 | 164 | Depending on the incident, the head of responsible department, or designate, may decide to make one or more public announcements. If necessary, this will be done with a short announcement either during the plenary and/or through other channels. No one other than the head of responsible department or someone delegated authority from them should make any announcements. No personal information about either party will be disclosed as part of this process. 165 | 166 | 167 | ## Attribution 168 | 169 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 170 | version 2.1, available at 171 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 172 | 173 | Community Impact Guidelines were inspired by 174 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 175 | 176 | From both [Golang](https://golang.org/conduct) and the [Golang UK Conference](http://golanguk.com/conduct/). 177 | 178 | For answers to common questions about this code of conduct, see the FAQ at 179 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 180 | [https://www.contributor-covenant.org/translations][translations]. 181 | 182 | [homepage]: https://www.contributor-covenant.org 183 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 184 | [Mozilla CoC]: https://github.com/mozilla/diversity 185 | [FAQ]: https://www.contributor-covenant.org/faq 186 | [translations]: https://www.contributor-covenant.org/translations 187 | -------------------------------------------------------------------------------- /FakeLiveDemo.php: -------------------------------------------------------------------------------- 1 | videos->search( 24 | array( 25 | 'currentPage' => 1, 26 | 'pageSize' => 25, 27 | 'sortBy' => 'publishedAt', 28 | 'sortOrder' => 'desc', 29 | 'tags' => $_POST['tags'] 30 | ) 31 | ); 32 | } 33 | else{ 34 | $videos = $client->videos->search( 35 | array( 36 | 'sortBy' => 'publishedAt', 37 | 'sortOrder' => 'desc', 38 | 'currentPage' => 1, 39 | 'pageSize' => 25 40 | ) 41 | ); 42 | } 43 | 44 | //We check if content is playable before adding it in the array of videos to play 45 | foreach ($videos as $video){ 46 | try { 47 | if($client->videos->getStatus($video->videoId)->encoding->playable) $videoIds[] = $video->videoId; 48 | } catch (Exception $e) { 49 | } 50 | } 51 | 52 | // We'll get total duration of all videos to know where to begin the reading 53 | $totalDuration =0; 54 | 55 | foreach ($videoIds as $videoId){ 56 | $status = $client->videos->getStatus($videoId); 57 | $duration = $status->encoding->metadata['duration'] ; 58 | $startTime = $totalDuration; 59 | $stopTime = $startTime + $duration; 60 | if($timeInSeconds > $startTime && $timeInSeconds < $stopTime){ 61 | $seekTime = $timeInSeconds - $startTime; 62 | $videoToRead = $videoId; 63 | } 64 | $totalDuration += $duration; 65 | } 66 | 67 | 68 | // We reorganize the array to put first video to be read at the beginning of the array 69 | $keys = array_keys($videoIds); 70 | $key = array_search($videoToRead, $videoIds); 71 | $index = array_search($key, $keys); 72 | 73 | $newVideoIds = array_merge(array_slice($videoIds, $index), array_slice($videoIds, 0, $index)); 74 | 75 | 76 | ?> 77 | 78 | 79 | 80 | 81 | api.video : How to create a fake live with my videos that starts related to a defined hour in the past 82 | 83 | 84 | 85 | --> Fake Live has began at : and this video is running since : seconds 86 | 87 | 88 | 89 | 90 |
91 | 92 | 142 | -------------------------------------------------------------------------------- /Ingest_google_drive.php: -------------------------------------------------------------------------------- 1 | players->search(array('currentPage' => 1, 'pageSize' => 50)); 42 | 43 | // Ask for player id 44 | if(count($players) !=0){ 45 | echo "Do you want to apply an existing playerId on imported videos ? (y /n ) : "."\n"; 46 | $handlePlayer = fopen ("php://stdin","r"); 47 | $linePlayer = fgets($handlePlayer); 48 | fclose($handlePlayer); 49 | if(trim($linePlayer) == 'y'){ 50 | echo "Choose a player Id in the following list:\n"; 51 | foreach($players as $player){ 52 | echo $player->playerId."\n"; 53 | } 54 | echo "\n"; 55 | echo "PlayerId : "; 56 | $handlePlayerId = fopen ("php://stdin","r"); 57 | $linePlayerId = fgets($handlePlayerId); 58 | if(trim($linePlayerId != '')) $playerId = trim($linePlayerId); 59 | } 60 | echo "\n"; 61 | } 62 | 63 | 64 | // Ask for Google drive credentials 65 | echo "A file credentials.json corresponding to your Google Drive api credentials must be placed at the same level of this script"."\n"; 66 | echo "If you have the script type 'yes' else type 'no'"."\n"; 67 | $handleGD = fopen ("php://stdin","r"); 68 | $lineGD = fgets($handleGD); 69 | if(trim($lineGD) != 'yes'){ 70 | echo "ABORTING!\n"; 71 | echo "You must provide credentials.json : Go to https://developers.google.com/drive/api/v3/quickstart/php "."\n"; 72 | echo "Use the 'Enable Api drive' button and get your credentials.json"."\n"; 73 | echo "Then launch the script again"."\n"; 74 | exit; 75 | } 76 | fclose($handleGD); 77 | echo "\n"; 78 | echo "Thank you, connecting to Google Drive, you now may be prompted to get a valid token ..."."\n"; 79 | 80 | 81 | /** 82 | * Returns an authorized API client. 83 | * @return Google_Client the authorized client object 84 | */ 85 | function getClient() 86 | { 87 | $client = new Google_Client(); 88 | $client->setApplicationName('Google Drive API PHP Quickstart'); 89 | $client->setScopes(Google_Service_Drive::DRIVE_READONLY); 90 | $client->setAuthConfig('credentials.json'); 91 | $client->setAccessType('offline'); 92 | $client->setPrompt('select_account consent'); 93 | 94 | // Load previously authorized token from a file, if it exists. 95 | // The file token.json stores the user's access and refresh tokens, and is 96 | // created automatically when the authorization flow completes for the first 97 | // time. 98 | $tokenPath = 'token.json'; 99 | if (file_exists($tokenPath)) { 100 | $accessToken = json_decode(file_get_contents($tokenPath), true); 101 | $client->setAccessToken($accessToken); 102 | } 103 | 104 | // If there is no previous token or it's expired. 105 | if ($client->isAccessTokenExpired()) { 106 | // Refresh the token if possible, else fetch a new one. 107 | if ($client->getRefreshToken()) { 108 | $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); 109 | } else { 110 | // Request authorization from the user. 111 | $authUrl = $client->createAuthUrl(); 112 | printf("Open the following link in your browser:\n%s\n", $authUrl); 113 | print 'Enter verification code: '; 114 | $authCode = trim(fgets(STDIN)); 115 | 116 | // Exchange authorization code for an access token. 117 | $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); 118 | $client->setAccessToken($accessToken); 119 | 120 | // Check to see if there was an error. 121 | if (array_key_exists('error', $accessToken)) { 122 | throw new Exception(join(', ', $accessToken)); 123 | } 124 | } 125 | // Save the token to a file. 126 | if (!file_exists(dirname($tokenPath))) { 127 | mkdir(dirname($tokenPath), 0700, true); 128 | } 129 | file_put_contents($tokenPath, json_encode($client->getAccessToken())); 130 | } 131 | return $client; 132 | } 133 | 134 | 135 | // Get the API client and construct the service object. 136 | $client = getClient(); 137 | $service = new Google_Service_Drive($client); 138 | 139 | // Ask for Google Drive folder to explore 140 | echo "Please provide a Google Drive folder name to import your videos :"."\n"; 141 | $handleFolder = fopen ("php://stdin","r"); 142 | $lineFolder = fgets($handleFolder); 143 | if(trim($lineFolder) == ''){ 144 | echo "You must provide a folder name !\n"; 145 | exit; 146 | } 147 | fclose($handleFolder); 148 | echo "\n"; 149 | echo "Thank you, continuing...\n"; 150 | 151 | $folderName = trim($lineFolder); 152 | $optFolder = 153 | array( 154 | 'pageSize' => 10, 155 | 'fields' => "nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents)", 156 | 'q' => "name = '".$folderName."' and mimeType = 'application/vnd.google-apps.folder'" 157 | ); 158 | $folders = $service->files->listFiles($optFolder); 159 | $folderId = $folders[0]->getId(); 160 | 161 | $optParams = array( 162 | 'pageSize' => 10, 163 | 'fields' => "nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents)", 164 | 'q' => "'".$folderId."' in parents" 165 | ); 166 | 167 | // Retrieving data from folder 168 | $results = $service->files->listFiles($optParams); 169 | 170 | if (count($results->getFiles()) == 0) { 171 | print "No files found.\n"; 172 | } else { 173 | print "Files:\n"; 174 | foreach ($results->getFiles() as $file) { 175 | if(strpos($file->getmimeType(), 'video/') !== false) { 176 | $content = $service->files->get($file->getId(), array("alt" => "media")); 177 | printf("%s (%s)\n", $file->getName(), $file->getId()); 178 | //create temp file 179 | $outHandle = fopen("tmpgd.mp4", "w+"); 180 | while (!$content->getBody()->eof()) { 181 | fwrite($outHandle, $content->getBody()->read(1024)); 182 | } 183 | fclose($outHandle); 184 | // Upload a video resource from local drive 185 | $newVideo = $apiVideoClient->videos->upload( 186 | 'tmpgd.mp4', 187 | array('title' => $file->getName()) 188 | ); 189 | 190 | if(null === $newVideo){ 191 | echo "An issue has been detected for file ".$file->getName()."\n"; 192 | var_dump($apiVideoClient->videos->getLastError()); 193 | } 194 | else{ 195 | // set player theme if provided 196 | if(isset($playerId)){ 197 | 198 | $videoId = $newVideo->videoId; 199 | 200 | echo "Attach player Theme: ".$playerId."\n"; 201 | echo "check projection "; 202 | while (!$newVideo = $apiVideoClient->videos->get($videoId)) { 203 | usleep(500); 204 | echo "."; 205 | } 206 | echo 'OK'."\n"; 207 | 208 | $apiVideoClient->videos->update( 209 | $videoId, 210 | array('playerId' => $playerId) 211 | ); 212 | echo 'Player Id '.$playerId.' attached to videoId ' . $videoId . "\n"; 213 | } 214 | } 215 | 216 | // delete temp file 217 | @unlink('tmpgd.mp4'); 218 | } 219 | } 220 | echo "All Done"; 221 | } 222 | 223 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![badge](https://img.shields.io/twitter/follow/api_video?style=social)](https://twitter.com/intent/follow?screen_name=api_video) 2 | 3 | [![badge](https://img.shields.io/github/stars/apivideo/helpful-scripts?style=social)](https://github.com/apivideo/helpful-scripts) 4 | 5 | [![badge](https://img.shields.io/discourse/topics?server=https%3A%2F%2Fcommunity.api.video)](https://community.api.video) 6 | 7 | ![](https://github.com/apivideo/.github/blob/main/assets/apivideo_banner.png) 8 | 9 | [api.video](https://api.video) is an API that encodes on the go to facilitate immediate playback, enhancing viewer streaming experiences across multiple devices and platforms. You can stream live or on-demand online videos within minutes. 10 | 11 | # helpful-scripts 12 | This repository contains useful scripts for PHP users who want to move videos into api.video more easily, or extract data details from your api.video account into a csv file. It includes: 13 | * Google Drive to api.video - Move all your videos from a folder on your Google Drive into api.video 14 | * FTP Server to api.video - Move all your videos from a folder on your FTP server into api.video 15 | * Export Video Details to .csv File - Gather data about all your videos on api.video and export it in a .csv file. 16 | 17 | # Google Drive to api.video 18 | 19 | Quickly ingest video from Google Drive to api.video with this script. 20 | 21 | ## Prerequisites 22 | 23 | * PHP 5.4 or greater with the command-line interface (CLI) and JSON extension installed 24 | * The Composer dependency management tool 25 | * A Google account with Google Drive enabled 26 | * An api.video account 27 | 28 | ## Installation 29 | 30 | ```shell 31 | composer require api-video/php-sdk 32 | composer require google/apiclient:^2.0 33 | ``` 34 | ## Walkthrough 35 | If you want help setting up the Google Drive to api.video script, we have a complete walkthrough available: 36 | [Helpful PHP Scripts Pt 1 - Upload Videos from Google Drive to API Video](https://api.video/blog/tutorials/helpful-php-scripts-upload-videos-from-google-drive-to-api-video) 37 | 38 | ## Quick Start 39 | 40 | ```shell 41 | php Ingest_google_drive.php 42 | ``` 43 | 44 | # Ingest from ftp server to api.video 45 | 46 | Easily ingest files from a selected ftp.server to your api.video account. 47 | 48 | ## Prerequisites 49 | 50 | * PHP 5.4 or greater with the command-line interface (CLI) 51 | * The Composer dependency management tool 52 | * An Ftp server account 53 | * An api.video account 54 | 55 | ## Installation 56 | 57 | ```shell 58 | composer require api-video/php-sdk 59 | ``` 60 | 61 | ## Walkthrough 62 | If you want help setting up the Google Drive to api.video script, we have a complete walkthrough available: 63 | [Helpful PHP Scripts Pt 2 - Upload Videos from an FTP Server](https://api.video/blog/tutorials/helpful-php-scripts-pt-2-upload-videos-from-an-ftp-server) 64 | 65 | ### Quick start 66 | 67 | ```shell 68 | php import_from_ftp.php 69 | ``` 70 | 71 | # php-export-csv 72 | 73 | Allow to easily export data details from tour api.video account into a csv file. 74 | 75 | ## Prerequisites 76 | 77 | * PHP 5.4 or greater with the command-line interface (CLI) 78 | * The Composer dependency management tool 79 | * An api.video account 80 | 81 | ## Installation 82 | 83 | ```composer require api-video/php-sdk 84 | ``` 85 | ## Walkthrough 86 | If you want help setting up the Export Video Details to a .csv File script, we have a complete walkthrough available: 87 | [Helpful PHP Scripts Pt 3 - Export All Your Video Details to a .csv File](https://api.video/blog/tutorials/helpful-php-scripts-pt-3-export-all-your-video-details-to-a-csv/) 88 | 89 | ## Quick Start 90 | 91 | ```shell 92 | php create_csv.php 93 | ``` 94 | -------------------------------------------------------------------------------- /bulk_update.php: -------------------------------------------------------------------------------- 1 | videos->getBrowser()->getClient()->setTimeout(60); 36 | $videos = $apiVideoClient->videos->search(); 37 | 38 | 39 | // Operation choice 40 | echo "Choose what operation to apply on all videos :" . ".\n\n"; 41 | echo "- 'private' choice will update all videos to private mode :" . ".\n"; 42 | echo "- 'public' choice will update all videos to public mode :" . ".\n"; 43 | echo "- 'mp4on' choice will update all videos with download available :" . ".\n"; 44 | echo "- 'mp4off' choice will update all videos with download disabled :" . ".\n"; 45 | 46 | 47 | $handleFunc = fopen("php://stdin", "r"); 48 | $lineFunc = fgets($handleFunc); 49 | if (trim($lineFunc) == 'private') { 50 | echo "All videos will be updated to private mode\n"; 51 | } elseif (trim($lineFunc) == 'public') { 52 | echo "All videos will be updated to public mode\n"; 53 | } elseif (trim($lineFunc) == 'mp4on') { 54 | echo "All videos will be updated with mp4Support on\n"; 55 | } elseif (trim($lineFunc) == 'mp4off') { 56 | echo "All videos will be updated with mp4Support off\n"; 57 | } else { 58 | echo "Choice not recognized : ABORTING!\n"; 59 | exit; 60 | } 61 | fclose($handleFunc); 62 | echo "\n"; 63 | 64 | 65 | foreach ($videos as $video) { 66 | switch (trim($lineFunc)) { 67 | case "private": 68 | $apiVideoClient->videos->setPrivate($video->videoId); 69 | if (!empty($apiVideoClient->videos->getLastError())) { 70 | echo $video->videoId . ':Error on video update :' . "\n"; 71 | var_dump($apiVideoClient->videos->getLastError()); 72 | } 73 | echo $video->videoId . " is now private \n"; 74 | break; 75 | case "public": 76 | $apiVideoClient->videos->setPublic($video->videoId); 77 | if (!empty($apiVideoClient->videos->getLastError())) { 78 | echo $video->videoId . ': Error on video update :' . "\n"; 79 | var_dump($apiVideoClient->videos->getLastError()); 80 | } 81 | echo $video->videoId . " is now public \n"; 82 | break; 83 | case "mp4on": 84 | if ($video->mp4Support == false) { 85 | $apiVideoClient->videos->update( 86 | $video->videoId, 87 | array('mp4Support' => true) 88 | ); 89 | if (!empty($apiVideoClient->videos->getLastError())) { 90 | echo $video->videoId . ': Error on mp4Support update' . "\n"; 91 | var_dump($apiVideoClient->videos->getLastError()); 92 | } 93 | echo $video->videoId . " is now downloadable \n"; 94 | } 95 | break; 96 | case "mp4off": 97 | if ($video->mp4Support == true) { 98 | $apiVideoClient->videos->update( 99 | $video->videoId, 100 | array('mp4Support' => false) 101 | ); 102 | if (!empty($apiVideoClient->videos->getLastError())) { 103 | echo $video->videoId . ': Error on mp4Support update' . "\n"; 104 | var_dump($apiVideoClient->videos->getLastError()); 105 | } 106 | echo $video->videoId . " is now NOT downloadable \n"; 107 | } 108 | break; 109 | } 110 | } 111 | echo "script finished\n"; 112 | -------------------------------------------------------------------------------- /create_csv.php: -------------------------------------------------------------------------------- 1 | videos->getBrowser()->getClient()->setTimeout(60); 40 | $videos = $apiVideoClient->videos->search(); 41 | 42 | $csv = fopen('./project_details.csv', 'a'); 43 | 44 | $names= array( 45 | 'id', 46 | 'title', 47 | 'createdAt', 48 | 'iframe', 49 | 'hls', 50 | 'thumbnail', 51 | 'misc' 52 | ); 53 | 54 | fputcsv($csv, $names, $delimiter = ',', $enclosure = '"'); 55 | 56 | echo "Building CSV :".".\n"; 57 | foreach($videos as $video) 58 | { 59 | $values = array( 60 | $video->videoId, 61 | $video->title, 62 | ($video->publishedAt)->format('Y-m-d H:i:sP'), 63 | $video->assets['iframe'], 64 | $video->assets['hls'], 65 | $video->assets['thumbnail'], 66 | ); 67 | 68 | if($video->mp4Support && $video->assets['mp4']){ 69 | $values[]= 'mp4: '.$video->assets['mp4']; 70 | } 71 | else{} 72 | 73 | if($video->metadata) { 74 | foreach ($video->metadata as $metadata) { 75 | $values[] = $metadata['key'] . ': ' . $metadata['value']; 76 | } 77 | } 78 | fputcsv($csv, $values, $delimiter = ',', $enclosure = '"'); 79 | } 80 | 81 | echo "Done - created file : project_details.csv.\n"; 82 | -------------------------------------------------------------------------------- /import_from_ftp.php: -------------------------------------------------------------------------------- 1 | players->search(array('currentPage' => 1, 'pageSize' => 50)); 42 | 43 | // Ask for player id 44 | if(count($players) !=0){ 45 | echo "Do you want to apply an existing playerId on imported videos ? (y /n ) : "."\n"; 46 | $handlePlayer = fopen ("php://stdin","r"); 47 | $linePlayer = fgets($handlePlayer); 48 | fclose($handlePlayer); 49 | if(trim($linePlayer) == 'y'){ 50 | echo "Choose a player Id in the following list:\n"; 51 | foreach($players as $player){ 52 | echo $player->playerId."\n"; 53 | } 54 | echo "\n"; 55 | echo "PlayerId : "; 56 | $handlePlayerId = fopen ("php://stdin","r"); 57 | $linePlayerId = fgets($handlePlayerId); 58 | if(trim($linePlayerId != '')) $playerId = trim($linePlayerId); 59 | } 60 | echo "\n"; 61 | } 62 | 63 | // Ask for ftp credentials 64 | echo "Please provide ... \n"; 65 | echo "ftp address (ftp.mydomain.com) : "; 66 | $handleFtpServer = fopen ("php://stdin","r"); 67 | $lineFtpServer = fgets($handleFtpServer); 68 | if(trim($lineFtpServer) == ''){ 69 | echo "You must provide an ftp server : ABORTING!\n"; 70 | exit; 71 | } 72 | fclose($handleFtpServer); 73 | 74 | echo "ftp username : "; 75 | $handleFtpUserName = fopen ("php://stdin","r"); 76 | $lineFtpUserName = fgets($handleFtpUserName); 77 | if(trim($lineFtpUserName) == ''){ 78 | echo "You must provide a username : ABORTING!\n"; 79 | exit; 80 | } 81 | fclose($handleFtpUserName); 82 | 83 | echo "ftp password : "; 84 | $handleFtpUserPass = fopen ("php://stdin","r"); 85 | $lineFtpUserPass = fgets($handleFtpUserPass); 86 | if(trim($lineFtpUserPass) == ''){ 87 | echo "You must provide a password : ABORTING!\n"; 88 | exit; 89 | } 90 | fclose($handleFtpUserPass); 91 | 92 | echo "Path to folder to analyze (e.g. : 'www/video') : "; 93 | $handleFtpFolderPath = fopen ("php://stdin","r"); 94 | $lineFtpFolderPath = fgets($handleFtpFolderPath); 95 | if(trim($lineFtpFolderPath) == ''){ 96 | echo "You must provide a folder path : ABORTING!\n"; 97 | exit; 98 | } 99 | fclose($handleFtpFolderPath); 100 | 101 | echo "\n"; 102 | 103 | $ftp_server = trim($lineFtpServer); 104 | $ftp_user_name = trim($lineFtpUserName); 105 | $ftp_user_pass = trim($lineFtpUserPass); 106 | $conn_id = ftp_connect($ftp_server); 107 | 108 | $folder = trim($lineFtpFolderPath); 109 | 110 | 111 | // Ftp Ident with credentials 112 | $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 113 | 114 | // test video mime type 115 | function isVideo($file) { 116 | return is_file($file) && (0 === strpos(mime_content_type($file), 'video/')); 117 | } 118 | 119 | // List directory content 120 | $contents = ftp_mlsd($conn_id, $folder); 121 | 122 | $local_file = 'tmp_ftp.mp4'; 123 | 124 | // Check content is file and type video 125 | foreach($contents as $content) { 126 | if($content['name'] != '.' && $content['name'] != '..'){ 127 | $server_file = $content['name']; 128 | if (ftp_get($conn_id, $local_file, $folder.'/'.$server_file, FTP_BINARY)) { 129 | echo "File ".$local_file." has been written"." \n"; 130 | } else { 131 | echo "There was an issue writing ".$server_file."\n"; 132 | } 133 | 134 | if(isVideo($local_file)){ 135 | // Create and upload a video resource from local drive 136 | $video = $client->videos->upload( 137 | $local_file, 138 | array('title' => $server_file) 139 | ); 140 | 141 | if(null === $video){ 142 | var_dump($client->videos->getLastError()); 143 | } 144 | else{ 145 | @unlink($local_file); 146 | } 147 | // set player theme if provided 148 | if(isset($playerId)){ 149 | 150 | $videoId = $video->videoId; 151 | 152 | echo "Attach player Theme: ".$playerId."\n"; 153 | echo "check projection "; 154 | while (!$video = $client->videos->get($videoId)) { 155 | usleep(500); 156 | echo "."; 157 | } 158 | echo 'OK'."\n"; 159 | 160 | $client->videos->update( 161 | $videoId, 162 | array('playerId' => $playerId) 163 | ); 164 | echo 'Player Id '.$playerId.' attached to videoId ' . $videoId . "\n"; 165 | } 166 | } 167 | 168 | else{ 169 | echo "File ".$server_file." is not a video"."\n"; 170 | @unlink($local_file); 171 | } 172 | } 173 | } 174 | // Close ftp connection 175 | ftp_close($conn_id); 176 | 177 | -------------------------------------------------------------------------------- /update_metadata.php: -------------------------------------------------------------------------------- 1 | videos->getBrowser()->getClient()->setTimeout(60); 53 | 54 | $csvVideoMetas = file('./'.trim($lineFileName)); 55 | 56 | //HANDLE FILE INTEGRITY 57 | echo "Before making changes, your file will be checked to detect errors"."\n"; 58 | echo "E.g.: separator must be a tab"."\n"; 59 | echo "First row: \n"; 60 | echo "id metanameX metanameY metanameZ "."\n"; 61 | echo "Following rows: \n"; 62 | echo "23-24charsvideoId metavalueX metavalueY metavalueZ"."\n\n"; 63 | echo "We are going to check that the first column name is 'id', and then that all id fields are set and correspond to api.video standards"."\n"; 64 | echo "READY ?(y/n)"."\n"; 65 | 66 | $handleQuest = fopen ("php://stdin","r"); 67 | $lineQuest = fgets($handleQuest); 68 | if(trim($lineQuest) == 'y'){ 69 | echo "Ok let's check\n"; 70 | $firstRowTabs = explode("\t", $csvVideoMetas[0]); 71 | if($firstRowTabs[0] != 'id') { 72 | echo 'first column must be called id : ABORTING!'."\n"; 73 | exit; 74 | } 75 | 76 | $z=1; 77 | foreach ($csvVideoMetas as $otherRow){ 78 | if($otherRow != $csvVideoMetas[0]){ 79 | $z++; 80 | $otherRowTabs = explode("\t", $otherRow); 81 | if(preg_match('/^vi[a-zA-Z0-9]{21,22}$/', $otherRowTabs[0]) ) { 82 | continue; 83 | } 84 | elseif (preg_match('/^video_[a-zA-Z0-9]{22}$/', $otherRowTabs[0]) ){ 85 | continue; 86 | } 87 | echo 'Please fix the problem detected on the id located line '.$z.': id must be 23/24 chars long and alphanumeric beginning by vi or 28 chars long beginning by video_ : ABORTING!'."\n"; 88 | exit; 89 | } 90 | } 91 | echo "File seems ok, proceeding ..."."\n"; 92 | } 93 | else{ 94 | echo "Sorry we need to check your file before anything happens : ABORTING!\n"; 95 | exit; 96 | } 97 | fclose($handleQuest); 98 | echo "\n"; 99 | 100 | 101 | //creating an array with meta keys 102 | $cleanedMetaKeys = trim($csvVideoMetas[0]); 103 | $cleanedMetaKeysArray = explode("\t", $cleanedMetaKeys); 104 | foreach ($cleanedMetaKeysArray as $cleanedMetaKey){ 105 | // line with id and metadatas keys(names) 106 | if($cleanedMetaKey != $cleanedMetaKeysArray[0]){ 107 | $metaKeysArray[] = trim($cleanedMetaKey); 108 | } 109 | } 110 | 111 | foreach ($csvVideoMetas as $linedata) { 112 | //initialize var to fit the correct metadata key 113 | $i=0; 114 | 115 | // lines with video ids and metadatas values 116 | if($linedata != $csvVideoMetas[0]){ 117 | // get the video object from video Id 118 | $cleanedline = trim($linedata); 119 | $lineTabs = explode("\t", $cleanedline); 120 | $videoId = $lineTabs[0]; 121 | $videoObject = $apiVideoClient->videos->get($videoId); 122 | 123 | 124 | // clean metadataArray if isset 125 | if(isset($metaArray)) unset($metaArray); 126 | 127 | // check for existing metadatas on object 128 | if($videoObject->metadata) { 129 | foreach ($videoObject->metadata as $metadata) { 130 | $metaArray[] = array('key' => $metadata['key'], 'value' => $metadata['value']); 131 | } 132 | } 133 | 134 | // read new metadatas from file to add 135 | foreach ($lineTabs as $linemeta){ 136 | if($linemeta != $lineTabs[0]){ 137 | if($linemeta !=''){ 138 | $metaValue = trim($linemeta); 139 | // add new meta to existing array 140 | $metaArray[] = array('key' => $metaKeysArray[$i], 'value' => $metaValue); 141 | } 142 | $i++; 143 | } 144 | } 145 | 146 | //update metadata 147 | if($metaArray) { 148 | //$cleanarray = array_unique($metaArray); 149 | echo "Adding metadata to ". $videoId; 150 | $apiVideoClient->videos->update( 151 | $videoId, 152 | array( 153 | 'metadata' => $metaArray, 154 | ) 155 | ); 156 | if (!empty($apiVideoClient->videos->getLastError())) { 157 | echo ' -> Error on metadata update :' . "\n"; 158 | var_dump($apiVideoClient->videos->getLastError()); 159 | } 160 | else echo " : Ok"."\n"; 161 | } 162 | } 163 | } 164 | 165 | echo "Script applied!"."\n"; 166 | --------------------------------------------------------------------------------