JiPaix / xdccJS

xdccJS is a Node.js library and client to download files from XDCC bots on IRC
MIT License
28 stars 7 forks source link

Resumption of stopped downloads not working #494

Closed ishiharas closed 2 years ago

ishiharas commented 2 years ago

Hello again, sorry for writing directly 2 tickets in a row.

Maybe I'm doing something wrong or just don't understand it right. Right now I wanted to test the resume functionality of an aborted or failed download.

I tried the following usecases through code-flow and through cli-flow. Both failed on me.

Step 1: npx xdccJS --host irc.rizon.net --bot "CR-HOLLAND|NEW" --nickname climan --channel #subsplease --download 2679 --path __dirname

Step 2: Abort download after 2-3 seconds. (On unix - terminals you can abort the running command with command+c) In code-flow I just wrote setTimeout(() => { job.cancel() }, 3000)

Step 3: Now I'm just restarting the download from step 1 again.

Result:

connected to : irc.rizon.net joined: [ #subsplease ] sending command: /MSG CR-HOLLAND|NEW xdcc send 2679 [X] couldn't connect to 89.149.202.221:12345 [X] couldn't connect to 89.149.202.221:12345 [i] retrying: 1/1 [X] couldn't connect to 89.149.202.221:12345 [X] couldn't connect to 89.149.202.221:12345 [X] skipped pack: 2679 [X] couldn't download pack: 2679 from cr-holland|new

The only solution right now is to delete the file from the folder specified in the path-variable from step 1 completely. Only then the download will restart again.

Any ideas how this can be fixed?

JiPaix commented 2 years ago

On unix - terminals you can abort the running command with command+c

Exiting the client like this doesn't send the cancel command to the bot so when you reconnect multiple contradictory things happen:

Now I'm just restarting the download from step 1 again.

It's pretty hard to tell why without seeing the bot response as the issue could come from xdccjs and/or the bot. here's a setup file so you can display the bot messages:


const xdccJS = new XDCC({ // new XDCC.default if you used require
  host: 'irc.rizon.net',
  chan: ['#subsplease'],
  verbose: true,
  path: __dirname
});

const bot = "CR-HOLLAND|NEW"

xdccJS.on('ready', async () => {
  const job = await xdccJS.download(bot, 2679)
  job.once('downloading', () => {
    setTimeout(() => {
      job.cancel()
    }, 3000)
  })
})

// display CR-HOLLAND|NEW's messages
xdccJS.irc.on('message', (message) => {
  if(message.nick === bot) {
    console.log(message.message);
  }
})
// display CR-HOLLAND|NEW's messages
xdccJS.irc.on('notice', (message) => {
  if(message.nick === bot) {
    console.log(message.message);
  }
})
ishiharas commented 2 years ago

Okay, thanks for the info's, missing the cancel command when exiting the terminal makes sense. I tried your suggestion and also tried to resume the download after a few seconds. The logged answers from the irc client were the following:

** You have a DCC pending, Set your client to receive the transfer. Type "/MSG CR-HOLLAND|NEW XDCC CANCEL" to abort the transfer. (150 seconds remaining until timeout)

Do you have an idea?

I'm attaching the total logs and the couple lines of codes, which are almost the same as yours:

LOGS

``` > connected to : irc.rizon.net > joined: [ #subsplease ] CONNECTING > sending command: /MSG CR-HOLLAND|NEW xdcc send 2679 [i] downloading : Anime - 106 [480p].mkv / [========== ] ETA: 4s @ 13.82 MB/s - 50% CANCEL > done. DOWNLOAD DONE ** Closing Connection: Unable to transfer data (Connection reset by peer) ** Closing Connection: Unable to transfer data (Connection reset by peer) > sending command: /MSG CR-HOLLAND|NEW xdcc send 2679 ** You have a DCC pending, Set your client to receive the transfer. Type "/MSG CR-HOLLAND|NEW XDCC CANCEL" to abort the transfer. (150 seconds remaining until timeout) ** You have a DCC pending, Set your client to receive the transfer. Type "/MSG CR-HOLLAND|NEW XDCC CANCEL" to abort the transfer. (150 seconds remaining until timeout) CALLED ERR: Error: couldn't connect to %yellow%89.149.202.221:12348 at Downloader.routine (~/node_modules/xdccjs/dist/timeouthandler.js:59:23) at Timeout._onTimeout (~/node_modules/xdccjs/dist/timeouthandler.js:44:18) at listOnTimeout (internal/timers.js:557:17) at processTimers (internal/timers.js:500:7) CALLED ERR INFO: undefined [X] couldn't connect to 89.149.202.221:12348 [i] retrying: 1/1 ```

CODE

``` async function startXDCCDownloader(bot: string, pack: string) { const xdccJS = new XDCC({ host: 'irc.rizon.net', port: 6667, chan: ['#subsplease'], verbose: true, path: path.resolve(__dirname), }) xdccJS.on('ready', async () => { console.log('CONNECTING') let job: Job = await xdccJS.download(bot, pack) job.once('downloading', (_fileInfo: FileInfo, received: number, percentage: number) => { setTimeout(() => { console.log(' CANCEL') job.cancel() xdccJS.irc.say(bot, 'XDCC CANCEL') }, 3 * 1000) }) setTimeout(async () => { let jobRestart: Job = await xdccJS.download(bot, pack) jobRestart.once('downloading', (_fileInfo: FileInfo, received: number, percentage: number) => { }) }, 20 * 1000) }) xdccJS.irc.on('message', (message) => { if (message.nick === bot) { console.log(message.message) } }) // display CR-HOLLAND|NEW's messages xdccJS.irc.on('notice', (message) => { if (message.nick === bot) { console.log(message.message) } }) xdccJS.on('done', async () => { console.log('DOWNLOAD DONE') // xdccJS.quit() }) xdccJS.on('error', async (error: Error, fileInfo: FileInfo) => { console.log('CALLED ERR: ', error) console.log('CALLED ERR INFO: ', fileInfo) // xdccJS.quit() }) } ```

JiPaix commented 2 years ago

fixed and published.

npm binaries

There's still another issue I can't fix because that's a limitation from the bot owners.

When you cancel a download and request it again the bot denies the request with this message

** You already requested that pack

You'd have to wait a certain amount of time before requesting that same pack again. Reconnecting to the server with another nickname could fool the bot.. (or maybe just changing nick without reconnect).. Idk...