Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSTask problem with --audio-format #9742

Closed
WiS3 opened this issue Jun 10, 2016 · 2 comments
Closed

NSTask problem with --audio-format #9742

WiS3 opened this issue Jun 10, 2016 · 2 comments

Comments

@WiS3
Copy link

@WiS3 WiS3 commented Jun 10, 2016

I'm using Objective-C NSTask to start youtube-dl.

Here is the code i'm currently using:

    NSString *URL = [NSString stringWithFormat:@"'%@'", _URLInput.stringValue]; // _URLInput = NSTextField with a YouTube URL
    NSArray *args = [NSArray arrayWithObjects: @"--extract-audio", @"-f 22", @"--audio-format m4a", @"-o '~/Downloads/%(extractor_key)s/%(title)s.%(ext)s'", URL, nil];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperationWithBlock:^(void) {
        NSString* youtube_dl_Path = @"/usr/local/bin/youtube-dl";

        NSTask *task = [[NSTask alloc] init];
        NSPipe *standardOutputPipe = [NSPipe pipe];
        NSPipe *standardErrorPipe = [NSPipe pipe];
                NSString* stringOutput; 
        [[standardOutputPipe fileHandleForReading]setReadabilityHandler:^(NSFileHandle *file) {
            NSData *data = [file availableData]; // this will read to EOF, so call only once
            NSLog(@"Task output! %@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]);
        }];

        NSFileHandle * readError = [standardErrorPipe fileHandleForReading];

        [task setLaunchPath: youtube_dl_Path];
        [task setArguments: args];
        [task setStandardError: standardErrorPipe];

        [task launch];
        [task waitUntilExit];
        NSData* errorData = [readError readDataToEndOfFile];
        NSString* stringError = [[NSString alloc] initWithData:errorData encoding:NSASCIIStringEncoding];

        if(stringError.length > 0){
            NSLog(@"ERROR: %@",stringError);
        }else{
            NSLog(@"DONE");
        }
    }];

And i get this error:

ERROR: Usage: youtube-dl [OPTIONS] URL [URL...]
youtube-dl: error: no such option: --audio-format m4a

If i remove --audio-format m4a from the args array, it is working.
If i run directly in the terminal with the same arguments, it is working.
Only with NSTask i get this issue.
I have latest youtube-dl.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Jun 10, 2016

I guess you need: @"--audio-format", @"m4a"

@WiS3
Copy link
Author

@WiS3 WiS3 commented Jun 10, 2016

Thank you! It is working now!

@WiS3 WiS3 closed this Jun 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.