diff --git a/install/importChannel.php b/install/importChannel.php new file mode 100644 index 0000000000..c54650f063 --- /dev/null +++ b/install/importChannel.php @@ -0,0 +1,127 @@ +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(); diff --git a/objects/functions.php b/objects/functions.php index e8216aeb01..63c8f94550 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -5026,9 +5026,9 @@ function wget($url, $filename, $debug = false) { if (empty($url) || $url == "php://input" || !preg_match("/^http/", $url)) { return false; } - if (wgetIsLocked($url)) { + if ($lockfilename = wgetIsLocked($url)) { 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; } @@ -5201,7 +5201,7 @@ function wgetIsLocked($url) { unlink($filename); return false; } - return true; + return $filename; } // due the some OS gives a fake is_writable response diff --git a/objects/video.php b/objects/video.php index 21fe85a5d5..59cb61e0e3 100644 --- a/objects/video.php +++ b/objects/video.php @@ -62,6 +62,7 @@ if (!class_exists('Video')) { private $likes; private $dislikes; private $users_id_company; + private $created; public static $statusDesc = [ 'a' => 'Active', 'k' => 'Active and Encoding', @@ -120,7 +121,15 @@ if (!class_exists('Video')) { $this->filename = $filename; } } + + public function getCreated() { + return $this->created; + } + public function setCreated($created): void { + $this->created = $created; + } + function getUsers_id_company(): int { return intval($this->users_id_company); } @@ -408,10 +417,14 @@ if (!class_exists('Video')) { $insert_row = $this->id; } } else { + if(empty($this->created)){ + $this->created = 'now()'; + } $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 " - . "('{$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); } if ($insert_row) {