mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Tool to import a channel
This commit is contained in:
parent
469b1dfbca
commit
b125c72ec4
3 changed files with 144 additions and 4 deletions
127
install/importChannel.php
Normal file
127
install/importChannel.php
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
<?php
|
||||||
|
//streamer config
|
||||||
|
require_once '../videos/configuration.php';
|
||||||
|
|
||||||
|
if (!isCommandLineInterface()) {
|
||||||
|
return die('Command Line only');
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_end_flush();
|
||||||
|
|
||||||
|
function download($url, $filename, $path, $forceDownload=false){
|
||||||
|
$parts = explode("/{$filename}/", $url);
|
||||||
|
$parts2 = explode('?', $parts[1]);
|
||||||
|
$file = $parts2[0];
|
||||||
|
$destination = $path.$file;
|
||||||
|
if($forceDownload || !file_exists($destination)){
|
||||||
|
_error_log("importChannel::download $url [$destination]");
|
||||||
|
return wget($url, $destination, true);
|
||||||
|
}else{
|
||||||
|
_error_log("importChannel::download skipped $url [$destination]");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_time_limit(1800);
|
||||||
|
ini_set('max_execution_time', 1800);
|
||||||
|
|
||||||
|
$global['rowCount'] = $global['limitForUnlimitedVideos'] = 999999;
|
||||||
|
|
||||||
|
$channelURL = trim(@$argv[1]);
|
||||||
|
|
||||||
|
if(empty($channelURL) || !isValidURL($channelURL)){
|
||||||
|
echo 'Enter a valid URL';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$channelURL = 'https://vod.lifestream.tv/channel/Fcccbmt';
|
||||||
|
|
||||||
|
$parts = explode('/channel/', $channelURL);
|
||||||
|
|
||||||
|
$siteURL = addLastSlash($parts[0]);
|
||||||
|
$channelName = urlencode($parts[1]);
|
||||||
|
$rowCount = 10;
|
||||||
|
$current = 1;
|
||||||
|
|
||||||
|
if(empty($channelName)){
|
||||||
|
echo 'Enter a valid channel URL';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasNewContent = true;
|
||||||
|
|
||||||
|
_error_log("importChannel: start {$siteURL} {$channelName}");
|
||||||
|
|
||||||
|
while($hasNewContent){
|
||||||
|
|
||||||
|
$APIURL = "{$siteURL}plugin/API/get.json.php?APIName=video&channelName=$channelName&rowCount={$current}";
|
||||||
|
|
||||||
|
$content = url_get_contents($APIURL, "", 30);
|
||||||
|
|
||||||
|
$hasNewContent = false;
|
||||||
|
$current++;
|
||||||
|
|
||||||
|
if(!empty($content)){
|
||||||
|
_error_log("importChannel: SUCCESS {$APIURL}");
|
||||||
|
$json = _json_decode($content);
|
||||||
|
if(!empty($json) && !empty($json->response) && !empty($json->response->totalRows)){
|
||||||
|
_error_log("importChannel: JSON SUCCESS totalRows={$json->response->totalRows}");
|
||||||
|
$hasNewContent = true;
|
||||||
|
foreach ($json->response->rows as $value) {
|
||||||
|
|
||||||
|
$videos_id = 0;
|
||||||
|
|
||||||
|
$row = Video::getVideoFromFileNameLight($value->filename);
|
||||||
|
if(!empty($row)){
|
||||||
|
_error_log("importChannel: Video found");
|
||||||
|
$videos_id = $row['id'];
|
||||||
|
}else{
|
||||||
|
_error_log("importChannel: Video NOT found");
|
||||||
|
}
|
||||||
|
_error_log("importChannel: Video {$videos_id} {$value->title} {$value->fileName}");
|
||||||
|
|
||||||
|
$video = new Video($value->title, $value->filename, $videos_id);
|
||||||
|
|
||||||
|
$video->setCreated("'$value->created'");
|
||||||
|
$video->setDuration($value->duration);
|
||||||
|
$video->setType($value->type);
|
||||||
|
$video->setVideoDownloadedLink($value->videoDownloadedLink);
|
||||||
|
$video->setDuration_in_seconds($value->duration_in_seconds);
|
||||||
|
$video->setDescription($value->description);
|
||||||
|
$video->setUsers_id(1);
|
||||||
|
$video->setStatus(Video::$statusTranfering);
|
||||||
|
|
||||||
|
_error_log("importChannel: Saving video");
|
||||||
|
$id = $video->save(false, true);
|
||||||
|
if($id){
|
||||||
|
_error_log("importChannel: Video saved {$id}");
|
||||||
|
$path = getVideosDir().$value->filename.DIRECTORY_SEPARATOR;
|
||||||
|
make_path($path);
|
||||||
|
|
||||||
|
// download images
|
||||||
|
download($value->images->poster, $value->filename, $path);
|
||||||
|
download($value->images->thumbsGif, $value->filename, $path);
|
||||||
|
|
||||||
|
foreach ($value->videos->mp4 as $value2) {
|
||||||
|
download($value2, $value->filename, $path);
|
||||||
|
}
|
||||||
|
$video->setStatus(Video::$statusActive);
|
||||||
|
}else{
|
||||||
|
_error_log("importChannel: ERROR Video NOT saved");
|
||||||
|
$video->setStatus(Video::$statusBrokenMissingFiles);
|
||||||
|
}
|
||||||
|
$video->save(false, true);
|
||||||
|
exit;
|
||||||
|
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
_error_log("importChannel: JSON ERROR {$content} ");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
_error_log("importChannel: ERROR {$APIURL} content is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
die();
|
|
@ -5026,9 +5026,9 @@ function wget($url, $filename, $debug = false) {
|
||||||
if (empty($url) || $url == "php://input" || !preg_match("/^http/", $url)) {
|
if (empty($url) || $url == "php://input" || !preg_match("/^http/", $url)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (wgetIsLocked($url)) {
|
if ($lockfilename = wgetIsLocked($url)) {
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
_error_log("wget: ERROR the url is already downloading $url, $filename");
|
_error_log("wget: ERROR the url is already downloading {$lockfilename} $url, $filename");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5201,7 +5201,7 @@ function wgetIsLocked($url) {
|
||||||
unlink($filename);
|
unlink($filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// due the some OS gives a fake is_writable response
|
// due the some OS gives a fake is_writable response
|
||||||
|
|
|
@ -62,6 +62,7 @@ if (!class_exists('Video')) {
|
||||||
private $likes;
|
private $likes;
|
||||||
private $dislikes;
|
private $dislikes;
|
||||||
private $users_id_company;
|
private $users_id_company;
|
||||||
|
private $created;
|
||||||
public static $statusDesc = [
|
public static $statusDesc = [
|
||||||
'a' => 'Active',
|
'a' => 'Active',
|
||||||
'k' => 'Active and Encoding',
|
'k' => 'Active and Encoding',
|
||||||
|
@ -120,7 +121,15 @@ if (!class_exists('Video')) {
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCreated() {
|
||||||
|
return $this->created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreated($created): void {
|
||||||
|
$this->created = $created;
|
||||||
|
}
|
||||||
|
|
||||||
function getUsers_id_company(): int {
|
function getUsers_id_company(): int {
|
||||||
return intval($this->users_id_company);
|
return intval($this->users_id_company);
|
||||||
}
|
}
|
||||||
|
@ -408,10 +417,14 @@ if (!class_exists('Video')) {
|
||||||
$insert_row = $this->id;
|
$insert_row = $this->id;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(empty($this->created)){
|
||||||
|
$this->created = 'now()';
|
||||||
|
}
|
||||||
$sql = "INSERT INTO videos "
|
$sql = "INSERT INTO videos "
|
||||||
. "(duration_in_seconds, title,clean_title, filename, users_id, categories_id, status, description, duration,type,videoDownloadedLink, next_videos_id, created, modified, videoLink, can_download, can_share, only_for_paid, rrating, externalOptions, sites_id, serie_playlists_id,live_transmitions_history_id, video_password, encoderURL, filepath , filesize, users_id_company) values "
|
. "(duration_in_seconds, title,clean_title, filename, users_id, categories_id, status, description, duration,type,videoDownloadedLink, next_videos_id, created, modified, videoLink, can_download, can_share, only_for_paid, rrating, externalOptions, sites_id, serie_playlists_id,live_transmitions_history_id, video_password, encoderURL, filepath , filesize, users_id_company) values "
|
||||||
. "('{$this->duration_in_seconds}','{$this->title}','{$this->clean_title}', '{$this->filename}', {$this->users_id},{$this->categories_id}, '{$this->status}', '{$this->description}', '{$this->duration}', '{$this->type}', '{$this->videoDownloadedLink}', {$this->next_videos_id},now(), now(), '{$this->videoLink}', '{$this->can_download}', '{$this->can_share}','{$this->only_for_paid}', '{$this->rrating}', '$this->externalOptions', {$this->sites_id}, {$this->serie_playlists_id},{$this->live_transmitions_history_id}, '{$this->video_password}', '{$this->encoderURL}', '{$this->filepath}', '{$this->filesize}', ".(empty($this->users_id_company)?'NULL':intval($this->users_id_company)).")";
|
. "('{$this->duration_in_seconds}','{$this->title}','{$this->clean_title}', '{$this->filename}', {$this->users_id},{$this->categories_id}, '{$this->status}', '{$this->description}', '{$this->duration}', '{$this->type}', '{$this->videoDownloadedLink}', {$this->next_videos_id},{$this->created}, now(), '{$this->videoLink}', '{$this->can_download}', '{$this->can_share}','{$this->only_for_paid}', '{$this->rrating}', '$this->externalOptions', {$this->sites_id}, {$this->serie_playlists_id},{$this->live_transmitions_history_id}, '{$this->video_password}', '{$this->encoderURL}', '{$this->filepath}', '{$this->filesize}', ".(empty($this->users_id_company)?'NULL':intval($this->users_id_company)).")";
|
||||||
|
|
||||||
|
//_error_log("Video::save ".$sql);
|
||||||
$insert_row = sqlDAL::writeSql($sql);
|
$insert_row = sqlDAL::writeSql($sql);
|
||||||
}
|
}
|
||||||
if ($insert_row) {
|
if ($insert_row) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue