added the option for restarting stalled downloads

This commit is contained in:
huangjx
2021-10-06 15:21:14 +08:00
parent 118ff8ec31
commit 74a905e37f
7 changed files with 33 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ return [
['name' => 'Youtube#Index', 'url' => '/youtube/get', 'verb' => 'POST'], ['name' => 'Youtube#Index', 'url' => '/youtube/get', 'verb' => 'POST'],
['name' => 'Youtube#Download', 'url' => '/youtube/new', 'verb' => 'POST'], ['name' => 'Youtube#Download', 'url' => '/youtube/new', 'verb' => 'POST'],
['name' => 'Youtube#Delete', 'url' => '/youtube/delete', 'verb' => 'POST'], ['name' => 'Youtube#Delete', 'url' => '/youtube/delete', 'verb' => 'POST'],
['name' => 'Youtube#Redownload', 'url' => '/youtube/redownload', 'verb' => 'POST'],
['name' => 'Search#Execute', 'url' => '/search', 'verb' => 'POST'], ['name' => 'Search#Execute', 'url' => '/search', 'verb' => 'POST'],
// AdminSettings // AdminSettings
['name' => 'Settings#Admin', 'url' => '/admin/save', 'verb' => 'POST'], ['name' => 'Settings#Admin', 'url' => '/admin/save', 'verb' => 'POST'],

View File

@@ -65,6 +65,9 @@ div .number {
.icon-unpause { .icon-unpause {
background-image: url('../img/play.svg'); background-image: url('../img/play.svg');
} }
.icon-refresh {
background-image: url('../img/refresh.svg');
}
#ncdownloader-action-links-container { #ncdownloader-action-links-container {
position: relative; position: relative;

View File

@@ -59,7 +59,8 @@ class YoutubeController extends Controller
$path = $this->urlGenerator->linkToRoute('ncdownloader.Youtube.Delete'); $path = $this->urlGenerator->linkToRoute('ncdownloader.Youtube.Delete');
$tmp['actions'][] = ['name' => 'delete', 'path' => $path]; $tmp['actions'][] = ['name' => 'delete', 'path' => $path];
} else { } else {
$tmp['actions'][] = ['name' => 'disabled', 'path' => '#']; $path = $this->urlGenerator->linkToRoute('ncdownloader.Youtube.Redownload');
$tmp['actions'][] = ['name' => 'refresh', 'path' => $path];
} }
$tmp['data_gid'] = $value['gid'] ?? 0; $tmp['data_gid'] = $value['gid'] ?? 0;
array_push($resp['row'], $tmp); array_push($resp['row'], $tmp);
@@ -69,7 +70,7 @@ class YoutubeController extends Controller
$resp['counter'] = ['youtube-dl' => count($data)]; $resp['counter'] = ['youtube-dl' => count($data)];
return new JSONResponse($resp); return new JSONResponse($resp);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
*/ */
@@ -99,7 +100,7 @@ class YoutubeController extends Controller
return ['error' => $this->l10n->t("failed to get any url!")]; return ['error' => $this->l10n->t("failed to get any url!")];
} }
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
*/ */
@@ -115,6 +116,25 @@ class YoutubeController extends Controller
} }
} }
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function Redownload()
{
$gid = $this->request->getParam('gid');
if (!$gid) {
return new JSONResponse(['error' => "no gid value is received!"]);
}
$row = $this->dbconn->getByGid($gid);
$data = unserialize($row['data']);
if (!empty($data['link'])) {
$resp = $this->youtube->forceIPV4()->download($data['link']);
folderScan::sync();
return new JSONResponse($resp);
}
return new JSONResponse(['error' => "no link"]);
}
private function _download($url, $filename = null) private function _download($url, $filename = null)
{ {

View File

@@ -14,7 +14,7 @@ class Youtube
private $format = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'; private $format = 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best';
private $options = []; private $options = [];
private $downloadDir; private $downloadDir;
private $timeout = 60 * 60 * 3; //3 hours private $timeout = 60 * 60 * 10; //10 hours
private $outTpl = "/%(id)s-%(title)s.%(ext)s"; private $outTpl = "/%(id)s-%(title)s.%(ext)s";
private $defaultDir = "/tmp/downloads"; private $defaultDir = "/tmp/downloads";
private $env = []; private $env = [];

View File

@@ -47,7 +47,7 @@ const helper = {
return magnetURI.test(url.trim()); return magnetURI.test(url.trim());
}, },
message: function (message,duration = 5000) { message: function (message,duration = 3000) {
Toastify({ Toastify({
text: message, text: message,
duration:duration, duration:duration,

View File

@@ -72,7 +72,6 @@ const inputHandler = (event) => {
let inputData = helper.getData('form-input-wrapper'); let inputData = helper.getData('form-input-wrapper');
let inputValue = inputData.form_input_text; let inputValue = inputData.form_input_text;
if (inputData.type !== 'search' && !helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) { if (inputData.type !== 'search' && !helper.isURL(inputValue) && !helper.isMagnetURI(inputValue)) {
helper.message(t("ncdownloader", "Invalid url")); helper.message(t("ncdownloader", "Invalid url"));
return; return;

View File

@@ -92,7 +92,8 @@ class ncTable {
if (!value.name) { if (!value.name) {
return; return;
} }
container.appendChild(this.createActionButton(value.name, value.path)); let data = value.data || '';
container.appendChild(this.createActionButton(value.name, value.path,data));
}) })
rowItem.appendChild(container); rowItem.appendChild(container);
row.appendChild(rowItem); row.appendChild(rowItem);
@@ -126,10 +127,11 @@ class ncTable {
} }
createActionButton(name, path) { createActionButton(name, path, data) {
let button = document.createElement("button"); let button = document.createElement("button");
button.classList.add("icon-" + name); button.classList.add("icon-" + name);
button.setAttribute("path", path); button.setAttribute("path", path);
button.setAttribute("data", data);
return button; return button;
} }