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

How to download youtube playlist info using youtube-dl in a python program? #21505

Closed
abhiank opened this issue Jun 23, 2019 · 5 comments
Closed

How to download youtube playlist info using youtube-dl in a python program? #21505

abhiank opened this issue Jun 23, 2019 · 5 comments
Labels

Comments

@abhiank
Copy link

@abhiank abhiank commented Jun 23, 2019

Checklist

  • [x ] I'm asking a question
  • [x ] I've looked through the README and FAQ for similar questions
  • [x ] I've searched the bugtracker for similar questions including closed ones

Question

I'm trying to download info about all items in a youtube playlist. I've figured out the command to execute on the terminal but I'm unable to figure out its equivalent code when embedded in a python program.

Here's the terminal command I use :
youtube-dl --dump-single-json --flat-playlist PLFftu4DSZBSwrGiOlZXKHRSoKArsKSuz9 > /Users/abhimanyu/Desktop/list.json

Here's how far I got in embedded python :

import youtube_dl

ydl = youtube_dl.YoutubeDL({'dump_single_json': 'True',
                            'extract_flat' : 'True'})

with ydl:
    result = ydl.download([
        'https://www.youtube.com/playlist?list=PLFftu4DSZBSwrGiOlZXKHRSoKArsKSuz9'])

print(len(result))

I also tried ydl.extract_info but that starts fetching info about each video individually which I don't need.

@abhiank abhiank added the question label Jun 23, 2019
@abhiank abhiank changed the title How to download youtube playlist using youtube-dl in a python program? How to download youtube playlist info using youtube-dl in a python program? Jun 23, 2019
@dstftw
Copy link
Collaborator

@dstftw dstftw commented Jun 23, 2019

Arguments are bools not strings.

@dstftw dstftw closed this Jun 23, 2019
@abhiank
Copy link
Author

@abhiank abhiank commented Jun 24, 2019

Oh thank you @dstftw. That was a really silly mistake 😅. I'm still kinda new to Python so the syntax confuses me sometimes.

Ps. It worked!

@abhiank
Copy link
Author

@abhiank abhiank commented Jun 24, 2019

Hey @dstftw, I'm stuck again. I'm unable to capture the json output into a variable. In the current code, result only has a value of 0 and not the json which I was expecting. How do I do that?

@silverbacknet
Copy link

@silverbacknet silverbacknet commented Jun 24, 2019

When downloading, 0 means success. Anything else means an error. (Classic C behavior.)

You were on the right track, result = ydl.extract_info(url, False) should give what you want. Default is to download everything, which you don't want, thus download=False.

@abhiank
Copy link
Author

@abhiank abhiank commented Jun 27, 2019

Thank you @silverbacknet

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
3 participants
You can’t perform that action at this time.