Skip to content

Commit

Permalink
Add support for restarting failed or canceled downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
m4heshd committed Oct 28, 2023
1 parent 763c16b commit 0bdba15
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ That's it. Now you're ready to go.

- [x] Migrate to Vite (dev)
- [x] Support for concurrent multi-fragment download
- [ ] Ability to restart failed downloads
- [x] Ability to restart failed/canceled downloads
- [ ] Support for more architectures, including ARM-based systems
- [ ] Mobile-responsive Web UI
- [ ] Make completed files downloadable right from the UFC Ripper Web UI (hosted)
Expand Down
33 changes: 19 additions & 14 deletions server-modules/bin-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function validateBins(cb) {
}
}

function openDLSession(VOD, cb) {
function openDLSession(VOD, isRestart, cb) {
const {qID, title, hls, vodURL} = VOD;
const {
vidQuality,
Expand All @@ -62,7 +62,7 @@ function openDLSession(VOD, cb) {
} = getConfig();

// Download configuration
const fullTitle = `${numberFiles ? `${curNumber}. ` : ''}${title}`;
const fullTitle = isRestart ? title : `${numberFiles ? `${curNumber}. ` : ''}${title}`;
const progressTemplate = JSON.stringify({
status: '%(progress.status)s',
progress: '%(progress._percent_str)s',
Expand Down Expand Up @@ -93,20 +93,25 @@ function openDLSession(VOD, cb) {
};

// Begin download process
console.log(clr.yellowBright.bgBlack.bold.underline(`Downloading "${fullTitle}"`));
console.log(clr.yellowBright.bgBlack.bold.underline(`${isRestart ? 'Restarting' : 'Downloading'} "${fullTitle}"`));
console.log(clr.dim(`${vodURL}\n`));

incFileNumber();
sendVODDownload({
...VOD,
title: fullTitle,
task: 'prepare',
status: 'downloading',
progress: 0,
size: 'N/A',
speed: 'N/A',
eta: 'N/A'
}, cb);
if (!isRestart) incFileNumber();

sendVODDownload(
{
...VOD,
title: fullTitle,
task: 'prepare',
status: 'downloading',
progress: 0,
size: 'N/A',
speed: 'N/A',
eta: 'N/A'
},
isRestart,
cb
);

// Launch and handle yt-dlp process
const dlArgsAll = [
Expand Down
18 changes: 11 additions & 7 deletions server-modules/io-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ async function verifyVOD(url, cb) {
}
}

async function downloadVOD(VOD, cb) {
async function downloadVOD(VOD, isRestart, cb) {
try {
require('./bin-util').openDLSession({
...VOD,
hls: await getVODStream(VOD.id)
}, cb);
require('./bin-util').openDLSession(
{
...VOD,
hls: await getVODStream(VOD.id)
},
isRestart,
cb
);
} catch (error) {
sendError(error, cb);
}
Expand Down Expand Up @@ -145,10 +149,10 @@ function sendVODMeta(VOD, cb) {
});
}

function sendVODDownload(VOD, cb) {
function sendVODDownload(VOD, isRestart, cb) {
DLQ[VOD.qID] = {
...VOD,
idx: Object.values(DLQ).length + 1
idx: isRestart ? VOD.idx : Object.values(DLQ).length + 1
};

cb(VOD);
Expand Down
27 changes: 23 additions & 4 deletions src/components/VODCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@
</button>
<span>{{ `${vVODData.progress}%` }}</span>
</div>
<i v-else>{{ statusIcons[vVODData.status] }}</i>
<div
v-else
class="center-content vod-card__details__status__post-action"
>
<button
v-if="isFailed"
class="square round fill small"
title="Retry download"
@click="$emit('retryDL',vVODData)"
>
<i>refresh</i>
</button>
<i>{{ statusIcons[vVODData.status] }}</i>
</div>
</div>
</div>
</div>
Expand All @@ -75,7 +88,8 @@ const props = defineProps({
});
defineEmits([
'cancelDL'
'cancelDL',
'retryDL'
]);
// Status and progress
Expand Down Expand Up @@ -177,8 +191,13 @@ const taskDescs = {
}
}
& > i {
cursor: default;
&__post-action {
flex-direction: column;
gap: 12px;
& > i {
cursor: default;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/ws-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export function useWSUtil() {
return emitPromise('verify-url', url);
}

function downloadVOD(VOD) {
return emitPromise('download', VOD);
function downloadVOD(VOD, isRestart) {
return emitPromise('download', VOD, isRestart);
}

function cancelDownload(VOD) {
Expand Down
11 changes: 10 additions & 1 deletion src/pages/Landing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
:vShowThumb="store.config.showThumb"
:vShowDesc="store.config.showDesc"
@cancelDL="onDownloadCancel"
@retryDL="onDownloadRetry"
></VODCard>
</div>
</article>
Expand Down Expand Up @@ -154,6 +155,14 @@ function onDownloadCancel(VOD) {
.catch(store.popError);
}
function onDownloadRetry(VOD) {
store.setDownloadRestart(VOD);
store.popInfo('Download restarted');
downloadVOD(VOD, true)
.catch(store.popError);
}
// Lifecycle hooks
onMounted(() => nextTick(() => {
window.ui();
Expand All @@ -163,7 +172,7 @@ onMounted(() => nextTick(() => {
function download(VOD) {
switchBusyState();
downloadVOD(VOD)
downloadVOD(VOD, false)
.then((res) => {
store.addDownload(res);
store.popInfo('Download started');
Expand Down
11 changes: 11 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ export const useAppStore = defineStore('app', {
idx: this.downloadQueue.length + 1
};
},
setDownloadRestart(VOD) {
this.downloads[VOD.qID] = {
...VOD,
task: 'prepare',
status: 'downloading',
progress: 0,
size: 'N/A',
speed: 'N/A',
eta: 'N/A'
};
},
setDownloadCancelled(qID) {
this.downloads[qID].status = 'cancelled';
}
Expand Down

0 comments on commit 0bdba15

Please sign in to comment.