kewlbear / YoutubeDL

An iOS app using youtube-dl Python module with PythonKit Swift package
MIT License
210 stars 36 forks source link

How to cancel ongoing download #18

Open kicortez opened 8 months ago

kicortez commented 8 months ago

Can you guide me on how to cancel an ongoing download? Calling download again while another is downloading causes a crash. Thanks~

kicortez commented 8 months ago

Adding crash info:

Screenshot 2023-12-23 at 10 46 41 PM Screenshot 2023-12-23 at 10 48 03 PM
hileo commented 8 months ago

I have the same problem, how to cancel it manually?😭

kicortez commented 8 months ago

Hey @hileo . Got more time to work on this, and here's what I came up with.

  1. Add package YoutubeDL-iOS locally. Had to do some changes on the package so I had to add it locally.
  2. Look for the yt_dlp function, 'public func yt_dlp(argv: ...', and make the progress parameter a throwing closure.
  3. Throw an error from the download call. 'try await yt_dlp(argv: argv) { ... '

1  throwing yt_dlp 2  throwing makeProgressHook

3  throw canceled error

I think throwing is the right approach, as the original function already throws. Though I haven't checked deeper on how it affects the process, etc. Let us know what you think. @kewlbear