Skip to content

Commit 1c35a19

Browse files
committed
Extract ytd binary to config, other minor changes
1 parent 11dd6c8 commit 1c35a19

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

Diff for: aria2.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function fetchFormats($force_pull = false)
134134
$this->formats = unserialize(file_get_contents($this->availableFormatsPath));
135135
} else {
136136
$creds = $this->getCreds();
137-
$out = shell_exec('youtube-dl "' . $this->url . '" --dump-json' . $creds);
137+
$out = shell_exec($GLOBALS['config']['ytd_binary'] . ' "' . $this->url . '" --dump-json' . $creds);
138138
$json_formats = json_decode($out, 1);
139139
if (isset($json_formats)) {
140140
foreach ($json_formats['formats'] as $format) {
@@ -341,7 +341,7 @@ private function dispatchToAria2c()
341341
{
342342
$this->incrementAttempts();
343343
$creds = $this->getCreds();
344-
$url = shell_exec('youtube-dl -f "' . $this->selectedFormat . '" "' . $this->url . '" -g ' . (($this->useCookiesForAria2c == 0) ? '' : '--cookies ' . $this->cookiesPath) . $creds);
344+
$url = shell_exec($GLOBALS['config']['ytd_binary'] . ' -f "' . $this->selectedFormat . '" "' . $this->url . '" -g ' . (($this->useCookiesForAria2c == 0) ? '' : '--cookies ' . $this->cookiesPath) . $creds);
345345
if ($url === "" || is_null($url)) {
346346
return null;
347347
}
@@ -612,12 +612,12 @@ public function pListInternalQueue($type, $offset = 0, $limit = 100)
612612
break;
613613
}
614614
$stmt = $this->connection->prepare("select count(id) as count from downloads where dispatched = :type_code");
615-
$stmt->bindValue(':type_code', $type_code);
615+
$stmt->bindValue(':type_code', $type_code);
616616
$stmt->execute();
617617
$count = $stmt->fetch(PDO::FETCH_ASSOC);
618618
$pages = ceil($count['count'] / $limit);
619619
$stmt = $this->connection->prepare("select id, url, formatOption, download_url, opt, priority, attempts, addedTime, dispatched from downloads where dispatched = :type_code order by " . ($type_code === 0 ? "priority desc, " : "") . " id " . ($type_code === 0 ? "asc" : "desc") . " limit :limit offset :offset");
620-
$stmt->bindValue(':limit', $limit);
620+
$stmt->bindValue(':limit', $limit);
621621
$stmt->bindValue(':offset', $offset);
622622
$stmt->bindValue(':type_code', $type_code);
623623
$stmt->execute();

Diff for: config.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

33
# db_location => set path to directory where db will be saved
4-
$config = ["db_location" => "/opt/php_aria2", "delay_after_ytd_url_generation" => 0, "use_cookies_by_default" => false, "add_to_internal_queue_by_default" => true, "max_download_attempts" => 10];
4+
$config = ["ytd_binary" => "youtube-dl", "db_location" => "/opt/php_aria2", "delay_after_ytd_url_generation" => 0, "use_cookies_by_default" => false, "add_to_internal_queue_by_default" => true, "max_download_attempts" => 10];
55
$custom_locations = [
66
// "LABEL" => "LOCATION",
77
// eg.
88
// "Downloads" => "/home/ubuntu/Downloads",
99
// "HDD" => "/data/hdd/",
1010
];
11-
$default_name_value = "";
11+
$default_name_value = "";

Diff for: index.php

+26-20
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ function unlockFile($fp)
152152
redirectToSelf(("?status=" . urlencode($status)));
153153
}
154154

155+
function populateEditForm($data)
156+
{
157+
foreach ($data as $key => $field) {
158+
if ($key === "opt") {
159+
$downloadOptions = unserialize($field);
160+
$_POST['out_name'] = $downloadOptions['out'];
161+
$_POST['dir_name'] = $downloadOptions['dir'];
162+
} else {
163+
$_POST[$key] = $field;
164+
}
165+
}
166+
$_POST['addToInternalQueue'] = "true";
167+
$_POST['skipCookies'] = "true";
168+
return true;
169+
}
170+
171+
if (isset($_POST['editDownloadByID'])) {
172+
$data = php2Aria2c::getDownloadByID(intval($_POST['editDownloadByID']));
173+
$edit_form = populateEditForm($data);
174+
}
175+
155176
if (isset($_POST['url'])) {
156177
$url = $_POST['url'];
157178
if (!empty($url)) {
@@ -163,30 +184,15 @@ function unlockFile($fp)
163184
$available_credentials = $php2Aria2c->getListOfCredentials();
164185
if (!(isset($_POST['id']) && !empty($_POST['id']))) {
165186
$alreadyAdded = $php2Aria2c->findByURL();
187+
if (isset($alreadyAdded) && count($alreadyAdded) > 0){
188+
$data = end($alreadyAdded);
189+
unset($data['formatOption']);
190+
$edit_form = populateEditForm($data);
191+
}
166192
}
167193
}
168194
}
169195

170-
if (isset($_POST['editDownloadByID']) || (isset($alreadyAdded) && count($alreadyAdded) > 0)) {
171-
if (isset($alreadyAdded) && count($alreadyAdded) > 0){
172-
$data = end($alreadyAdded);
173-
} else {
174-
$data = php2Aria2c::getDownloadByID(intval($_POST['editDownloadByID']));
175-
}
176-
foreach ($data as $key => $field) {
177-
if ($key === "opt") {
178-
$downloadOptions = unserialize($field);
179-
$_POST['out_name'] = $downloadOptions['out'];
180-
$_POST['dir_name'] = $downloadOptions['dir'];
181-
} else {
182-
$_POST[$key] = $field;
183-
}
184-
}
185-
$_POST['addToInternalQueue'] = "true";
186-
$_POST['skipCookies'] = "true";
187-
$edit_form = true;
188-
}
189-
190196
if (isset($php2Aria2c) && isset($_POST['formatOption']) && in_array($_POST['formatOption'], $available_formats) && !$edit_form) {
191197
$php2Aria2c->setSelectedFormat($_POST['formatOption']);
192198
$php2Aria2c->priority = $_POST['priority'];

0 commit comments

Comments
 (0)