Skip to content

Commit

Permalink
Create deleteAllVideos.php
Browse files Browse the repository at this point in the history
  • Loading branch information
herve-api-video authored Jan 24, 2022
1 parent ff02595 commit 05ff9c5
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions examples/deleteAllVideos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
require_once '../vendor/autoload.php';

use Symfony\Component\HttpClient\Psr18Client;
use ApiVideo\Client\Client;
use ApiVideo\Client\Model\VideoCreationPayload;

// Environment choice
echo "WARNING ! APPLYING THIS SCRIPT WILL DELETE PERMANENTLY ALL YOUR VIDEOS"."\n";
echo "Choose now your environment ('p' for prod or 's' for sandbox) :".".\n";
$handleEnv = fopen ("php://stdin","r");
$lineEnv = trim(fgets($handleEnv));
if($lineEnv == 'p'){
echo "Prod chosen\n";
$apiVideoEndpoint = 'https://ws.api.video';
}
elseif($lineEnv == 's'){
echo "Sandbox chosen\n";
$apiVideoEndpoint = 'https://sandbox.api.video';
}
else{
echo "Choice not recognized : ABORTING!\n";
exit;
}
fclose($handleEnv);
echo "\n";

// Ask for api.video credentials
echo "Please provide your api.video key :"."\n";
$handleApiKey = fopen ("php://stdin","r");
$lineApiVideoKey = trim(fgets($handleApiKey));
if($lineApiVideoKey == ''){
echo "ABORTING!\n";
exit;
}
fclose($handleApiKey);
echo "\n";

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$client = new ApiVideo\Client\Client(
$apiVideoEndpoint,
$lineApiVideoKey,
$httpClient
);

$videos = $client->videos()->list();

foreach($videos->getData() as $video) {
echo 'deleting '.$video->getTitle().' - '.$video->getVideoId()."\n";
$client->videos()->delete($video->getVideoId());
}
echo "all videos are now deleted"."\n";

0 comments on commit 05ff9c5

Please sign in to comment.