kewlbear / YoutubeDL

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

Downloading m3u8 file issue - only works from Xcode and json.decoder.JSONDecodeError #15

Closed majedoh closed 1 year ago

majedoh commented 1 year ago

Hello,

I am encountering two issues with the argv for downloading an m3u8 file.

let argv: [String] = (
    url.pathExtension == "mp4"
    ? ["-o", url.lastPathComponent,]
    : [
        "-f", "hls-2176",
        "-S","ext:mp4:m4a",
    ]
)
+ [
    "--no-check-certificates",
    url.absoluteString,
]

1st Issue: App functioning only when running from Xcode

The download only works when the app is run from Xcode. If I close Xcode and reopen it, the download no longer functions. Here are the steps to reproduce the issue:

  1. Clone the repository.
  2. Run the app from Xcode.
  3. Close the app.
  4. Open the app manually - not by running the project from Xcode.
  5. Attempt to download the sample URL using the provided argv.

I've included a screenshot of the issue:

IMG_2782

2nd Issue: json.decoder.JSONDecodeError

While the app is running via Xcode and the download is complete, I encounter the following error:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
startDownload(url:) Error Domain=App Code=1 "ERROR: Expecting value: line 1 column 1 (char 0)" UserInfo={NSLocalizedDescription=ERROR: Expecting value: line 1 column 1 (char 0)}

Steps to reproduce the issue:

  1. Run the app from Xcode.
  2. Attempt to download the sample URL using the provided argv.

Here are the screenshots of the second issue:

Screenshot 2023-07-24 at 11 10 25 AM Screenshot 2023-07-24 at 11 10 08 AM

I would appreciate any help or guidance with these issues.

majedoh commented 1 year ago

Easier steps to reproduce the first issue: 1- Edit Scheme 2- Run Tap 3- Change Launch configuration to " wait for executable to be launched" 4- Run the app, 5-Attempt to download the sample URL using the provided argv.

Screenshot 2023-07-24 at 3 45 42 PM
let argv: [String] = (
    url.pathExtension == "mp4"
    ? ["-o", url.lastPathComponent,]
    : [
        "-f", "hls-2176",
        "-S","ext:mp4:m4a",
    ]
)
+ [
    "--no-check-certificates",
    url.absoluteString,
]
majedoh commented 1 year ago

@kewlbear Any tips on how can I address it?

kewlbear commented 1 year ago

For the second issue, you can see which field missing in the debugger and change it to optional. First issue may require adding some logging and watching it from console app.

majedoh commented 1 year ago

Solution: The problem is occurring in the following line of var: lazy var popenHandler = PythonFunction { args in Specifically, the issue is with this line: result[0] = read(pipe: outPipe) To resolve this, simply set the value of the result[0] manually.