added support for updating yt-dlp binary;moved version info display to admin section
This commit is contained in:
@@ -22,13 +22,13 @@ class Application extends App implements IBootstrap
|
||||
}
|
||||
public function register(IRegistrationContext $context): void
|
||||
{
|
||||
$context->registerService('httpClient', function () {
|
||||
$context->registerService(Client::class, function () {
|
||||
$options = [
|
||||
'ipv4' => true,
|
||||
];
|
||||
return Client::create($options);
|
||||
});
|
||||
$context->registerService('crawler', function () {
|
||||
$context->registerService(Crawler::class, function () {
|
||||
return new Crawler();
|
||||
});
|
||||
$sites = Helper::getSearchSites();
|
||||
@@ -36,8 +36,8 @@ class Application extends App implements IBootstrap
|
||||
//fully qualified class name
|
||||
$className = $site['class'];
|
||||
$context->registerService($className, function (ContainerInterface $container) use ($className) {
|
||||
$crawler = $container->get('crawler');
|
||||
$client = $container->get('httpClient');
|
||||
$crawler = $container->get(Crawler::class);
|
||||
$client = $container->get(Client::class);
|
||||
return $className::create($crawler, $client);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,5 +30,8 @@ return [
|
||||
//api routes
|
||||
['name' => 'Api#download', 'url' => '/api/v1/download', 'verb' => 'POST'],
|
||||
['name' => 'Api#search', 'url' => '/api/v1/search', 'verb' => 'POST'],
|
||||
//binary updates
|
||||
['name' => 'Main#ytdlCheck', 'url' => '/ytdl/release/check', 'verb' => 'GET'],
|
||||
['name' => 'Main#ytdlUpdate', 'url' => '/ytdl/release/update', 'verb' => 'GET'],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -412,8 +412,14 @@ class Aria2
|
||||
{
|
||||
return $this->bin;
|
||||
}
|
||||
public function version(){
|
||||
public function version()
|
||||
{
|
||||
$resp = $this->getVersion();
|
||||
return $resp['result']['version'] ?? null;
|
||||
}
|
||||
public function install()
|
||||
{
|
||||
$url = "https://github.com/shiningw/ncdownloader-bin/raw/master/aria2c";
|
||||
Helper::Download($url, $this->bin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,4 +226,14 @@ class MainController extends Controller
|
||||
$counter = $this->counters->getCounters();
|
||||
return new JSONResponse(['counter' => $counter]);
|
||||
}
|
||||
|
||||
public function ytdlCheck()
|
||||
{
|
||||
$resp = $this->ytdl->check();
|
||||
return new JSONResponse($resp);
|
||||
}
|
||||
public function ytdlUPdate(){
|
||||
$resp = $this->ytdl->update();
|
||||
return new JSONResponse($resp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\NCDownloader\http;
|
||||
namespace OCA\NCDownloader\Http;
|
||||
|
||||
//require __DIR__ . "/../../vendor/autoload.php";
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
@@ -8,12 +8,12 @@ use Symfony\Component\HttpClient\HttpClient;
|
||||
final class Client
|
||||
{
|
||||
private $client;
|
||||
public function __construct(?array $options = null)
|
||||
public function __construct(?array $options = [])
|
||||
{
|
||||
$this->client = HttpClient::create($this->configure($options));
|
||||
}
|
||||
|
||||
public static function create(?array $options = null)
|
||||
public static function create(?array $options =[])
|
||||
{
|
||||
return new self($options);
|
||||
}
|
||||
@@ -26,8 +26,7 @@ final class Client
|
||||
private function defaultOptions(): array
|
||||
{
|
||||
$settings = [
|
||||
'headers' => [
|
||||
],
|
||||
'headers' => [],
|
||||
'extra' => ['curl' => null],
|
||||
];
|
||||
return $settings;
|
||||
|
||||
@@ -39,7 +39,8 @@ class Admin implements ISettings
|
||||
$settings = Helper::getAllAdminSettings();
|
||||
$settings += [
|
||||
"path" => "/apps/ncdownloader/admin/save",
|
||||
|
||||
"aria2_version" => Helper::getAria2Version(),
|
||||
"ytdl_version" => Helper::getYtdlVersion(),
|
||||
];
|
||||
$parameters = [
|
||||
'settings' => $settings,
|
||||
|
||||
@@ -50,8 +50,6 @@ class Personal implements ISettings
|
||||
"path" => $path,
|
||||
"disallow_aria2_settings" => Helper::getAdminSettings("disallow_aria2_settings"),
|
||||
"is_admin" => \OC_User::isAdminUser($this->uid),
|
||||
"aria2_version" => Helper::getAria2Version(),
|
||||
"ytdl_version" => Helper::getYtdlVersion(),
|
||||
],
|
||||
"options" => [
|
||||
[
|
||||
|
||||
@@ -12,6 +12,9 @@ use OC_Util;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCA\NCDownloader\Aria2\Aria2;
|
||||
use OCA\NCDownloader\Ytdl\Ytdl;
|
||||
use OCA\NCDownloader\Http\Client;
|
||||
|
||||
require __DIR__ . "/../../vendor/autoload.php";
|
||||
|
||||
class Helper
|
||||
{
|
||||
@@ -592,4 +595,52 @@ class Helper
|
||||
];
|
||||
return $options;
|
||||
}
|
||||
public static function getLatestRelease($owner, $repo)
|
||||
{
|
||||
$client = Client::create();
|
||||
$response = $client->request('GET', "https://api.github.com/repos/$owner/$repo/releases/latest", [
|
||||
'headers' => [
|
||||
'User-Agent' => 'PHP'
|
||||
]
|
||||
]);
|
||||
$data = json_decode($response->getContent(), true);
|
||||
if (isset($data['tag_name'])) {
|
||||
return $data['tag_name'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function downloadLatestRelease($owner, $repo, $file)
|
||||
{
|
||||
$client = Client::create(['max_redirects' => 10]);
|
||||
$response = $client->request('GET', "https://api.github.com/repos/$owner/$repo/releases/latest", [
|
||||
'headers' => [
|
||||
'User-Agent' => 'PHP'
|
||||
]
|
||||
]);
|
||||
$data = json_decode($response->getContent(), true);
|
||||
$downloadUrl = null;
|
||||
foreach ($data['assets'] as $asset) {
|
||||
if ($asset['name'] == $repo) {
|
||||
$downloadUrl = $asset['browser_download_url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($downloadUrl) {
|
||||
if (!is_writable(dirname($file))) {
|
||||
throw new \Exception(dirname($file) . " is not writable");
|
||||
}
|
||||
$response = $client->request('GET', $downloadUrl);
|
||||
if ($byte = file_put_contents($file, $response->getContent())) {
|
||||
return $byte;
|
||||
}else {
|
||||
throw new \Exception("Failed to download $downloadUrl");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static function removeLetters($str)
|
||||
{
|
||||
return preg_replace('/[^0-9.]+/', '', $str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,8 +271,31 @@ class Ytdl
|
||||
$process = new Process([$this->bin, '--version']);
|
||||
$process->run();
|
||||
if ($process->isSuccessful()) {
|
||||
return $process->getOutput();
|
||||
//remove any new line
|
||||
return trim($process->getOutput());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function check()
|
||||
{
|
||||
if ($tagName = Helper::getLatestRelease('yt-dlp', 'yt-dlp')) {
|
||||
$tagName = Helper::removeLetters($tagName);
|
||||
$version = $this->version();
|
||||
if ($version && version_compare($version, $tagName, '<')) {
|
||||
return ['status' => true, 'message' => $tagName];
|
||||
}
|
||||
}
|
||||
return ['status' => false, 'message' => 'No update available'];
|
||||
}
|
||||
public function update()
|
||||
{
|
||||
$file = __DIR__ . "/../../bin/yt-dlp";
|
||||
try {
|
||||
Helper::downloadLatestRelease('yt-dlp', 'yt-dlp', $file);
|
||||
chmod($file, 0744);
|
||||
} catch (\Exception $e) {
|
||||
return ['status' => false,'message' => $e->getMessage()];
|
||||
}
|
||||
return ['status' => true, 'message' => 'Updated to latest version','data' => $this->version()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
path="/apps/ncdownloader/admin/aria2/save" :validOptions="validOptions">
|
||||
<template #save>Save Settings</template>
|
||||
</customOptions>
|
||||
<systemInfo :aria2Version="aria2Version" :ytdVersion="ytdVersion" />
|
||||
</template>
|
||||
<script>
|
||||
import customOptions from "./components/customOptions";
|
||||
@@ -19,6 +20,7 @@ import helper from "./utils/helper";
|
||||
import aria2Options from "./utils/aria2Options";
|
||||
import settingsRow from "./components/settingsRow";
|
||||
import toggleButton from "./components/toggleButton";
|
||||
import systemInfo from "./components/systemInfo";
|
||||
|
||||
export default {
|
||||
name: "adminSettings",
|
||||
@@ -28,12 +30,15 @@ export default {
|
||||
validOptions: aria2Options,
|
||||
settings: [],
|
||||
pStatus: false,
|
||||
aria2Version: "",
|
||||
ytdVersion: "",
|
||||
};
|
||||
},
|
||||
components: {
|
||||
customOptions,
|
||||
settingsRow,
|
||||
toggleButton,
|
||||
systemInfo,
|
||||
},
|
||||
methods: {
|
||||
toggle(name, value) {
|
||||
@@ -83,10 +88,13 @@ export default {
|
||||
options = JSON.parse(options);
|
||||
this.settings = data;
|
||||
this.pStatus = helper.str2Boolean(data["disallow_aria2_settings"]);
|
||||
this.aria2Version = data["aria2_version"];
|
||||
this.ytdVersion = data["ytdl_version"];
|
||||
this.options = options;
|
||||
} catch (e) {
|
||||
helper.error(e);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -199,18 +199,16 @@ export default {
|
||||
.checkboxes {
|
||||
border-radius: 0%;
|
||||
}
|
||||
.download-button,
|
||||
.search-button {
|
||||
height: $column-height;
|
||||
.btn-primary {
|
||||
.download-button.btn-primary,
|
||||
.search-button.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #2d3f59;
|
||||
border-color: #1e324f;
|
||||
border-radius: 0%;
|
||||
}
|
||||
.btn-primary:hover {
|
||||
}
|
||||
.download-button.btn-primary:hover,
|
||||
.search-button.btn-primary:hover {
|
||||
background-color: #191a16;
|
||||
}
|
||||
}
|
||||
|
||||
.magnet-link,
|
||||
|
||||
144
src/components/systemInfo.vue
Normal file
144
src/components/systemInfo.vue
Normal file
@@ -0,0 +1,144 @@
|
||||
<template>
|
||||
<div class="system-info-wrapper section">
|
||||
<h2 class="section-title">System Info</h2>
|
||||
<div class="system-info">
|
||||
<div class="system-info-item">
|
||||
<div class="system-info-item-label">Aria2 Version: </div>
|
||||
<div class="system-info-item-value"><span class="version">{{ aria2Ver }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="system-info-item">
|
||||
<div class="system-info-item-label">Yt-dlp Version: </div>
|
||||
<div class="system-info-item-value"><span class="version">{{ ytdVer }}</span>
|
||||
<actionButton action="check" btnType="ytd" @clicked="checkUpdate" enableLoading="true"
|
||||
className="check-button">
|
||||
{{
|
||||
ytdBtn
|
||||
}}</actionButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import helper from "../utils/helper";
|
||||
import actionButton from "./actionButton";
|
||||
const ARIA2_CHECK_URL = "/apps/ncdownloader/aria2/release/check";
|
||||
const ARIA2_UPDATE_URL = "/apps/ncdownloader/aria2/release/update";
|
||||
const YTD_CHECK_URL = "/apps/ncdownloader/ytdl/release/check";
|
||||
const YTD_UPDATE_URL = "/apps/ncdownloader/ytdl/release/update";
|
||||
|
||||
export default {
|
||||
name: "systemInfo",
|
||||
data() {
|
||||
return {
|
||||
aria2Btn: "Check for Update",
|
||||
ytdBtn: "Check for Update",
|
||||
};
|
||||
},
|
||||
components: {
|
||||
actionButton
|
||||
},
|
||||
computed: {
|
||||
aria2Ver: {
|
||||
get() {
|
||||
return this.$props.aria2Version
|
||||
},
|
||||
set(value) {
|
||||
this.$props.aria2Version = value
|
||||
//this.$emit("update:aria2Version", value)
|
||||
}
|
||||
},
|
||||
ytdVer: {
|
||||
get() {
|
||||
return this.$props.ytdVersion
|
||||
},
|
||||
set(value) {
|
||||
this.$props.ytdVersion = value
|
||||
//this.$emit("update:ytdVersion", value)
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
checkUpdate(event, $vm) {
|
||||
const { btnType, action } = $vm.$props;
|
||||
const path = action === "check" ? (btnType === "aria2" ? ARIA2_CHECK_URL : YTD_CHECK_URL) : (btnType === "aria2" ? ARIA2_UPDATE_URL : YTD_UPDATE_URL);
|
||||
helper
|
||||
.httpClient(helper.generateUrl(path))
|
||||
.setMethod("GET")
|
||||
.setHandler((data) => {
|
||||
$vm.loading = false;
|
||||
if (data.status) {
|
||||
helper.info(data.message)
|
||||
//update button text
|
||||
if (action == "check") {
|
||||
if (btnType == "ytd") {
|
||||
this.ytdBtn = "Update"
|
||||
} else {
|
||||
this.aria2Btn = "Update"
|
||||
}
|
||||
$vm.$props.action = "update"
|
||||
} else {
|
||||
if (btnType == "ytd") {
|
||||
this.ytdBtn = "Check for Update"
|
||||
} else {
|
||||
this.aria2Btn = "Check for Update"
|
||||
}
|
||||
$vm.$props.action = "check"
|
||||
if (data.data) {
|
||||
if (btnType == "ytd") {
|
||||
this.ytdVer = data.data
|
||||
} else if (btnType == "aria2") {
|
||||
this.aria2Ver = data.data
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
helper.info(data.message)
|
||||
}
|
||||
})
|
||||
.send();
|
||||
},
|
||||
|
||||
},
|
||||
props: {
|
||||
aria2Version: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
ytdVersion: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.system-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: 10px;
|
||||
|
||||
|
||||
.system-info-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.system-info-item-label {
|
||||
font-weight: bold;
|
||||
margin-right: 10px;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.system-info-item-value {
|
||||
font-weight: normal;
|
||||
|
||||
.check-button {
|
||||
border-radius: 0.25em;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
1
src/css/bootstrap.scss
vendored
1
src/css/bootstrap.scss
vendored
@@ -1,3 +1,4 @@
|
||||
@import "../../node_modules/bootstrap/scss/functions";
|
||||
@import "../../node_modules/bootstrap/scss/variables";
|
||||
@import "../../node_modules/bootstrap/scss/mixins";
|
||||
@import "../../node_modules/bootstrap/scss/root";
|
||||
|
||||
1
src/css/btn.scss
Normal file
1
src/css/btn.scss
Normal file
@@ -0,0 +1 @@
|
||||
@import "../../node_modules/bootstrap/scss/buttons";
|
||||
@@ -12,19 +12,6 @@
|
||||
path="/apps/ncdownloader/personal/ytdl/save" :validOptions="ytdlOptions">
|
||||
<template #save>Save Youtube-dl Settings</template>
|
||||
</customOptions>
|
||||
<div class="system-info-wrapper section">
|
||||
<h2 class="section-title">System Info</h2>
|
||||
<div class="system-info">
|
||||
<div class="system-info-item">
|
||||
<div class="system-info-item-label">Aria2 Version: </div>
|
||||
<div class="system-info-item-value">{{ aria2Version }}</div>
|
||||
</div>
|
||||
<div class="system-info-item">
|
||||
<div class="system-info-item-label">yt-dlp Version: </div>
|
||||
<div class="system-info-item-value">{{ ytdVersion }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import customOptions from "./components/customOptions";
|
||||
@@ -42,9 +29,6 @@ export default {
|
||||
ytdlOptions: ytdlOptions,
|
||||
disallowAria2Settings: false,
|
||||
isAdmin: false,
|
||||
aria2Version: "",
|
||||
ytdVersion: "",
|
||||
|
||||
};
|
||||
},
|
||||
components: {
|
||||
@@ -102,8 +86,6 @@ export default {
|
||||
options = JSON.parse(options);
|
||||
this.disallowAria2Settings = helper.str2Boolean(data["disallow_aria2_settings"]);
|
||||
this.isAdmin = data["is_admin"];
|
||||
this.aria2Version = data["aria2_version"];
|
||||
this.ytdVersion = data["ytdl_version"];
|
||||
this.options = options
|
||||
} catch (e) {
|
||||
helper.error(e);
|
||||
@@ -111,25 +93,3 @@ export default {
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.system-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.system-info-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.system-info-item-label {
|
||||
font-weight: bold;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.system-info-item-value {
|
||||
font-weight: normal;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user