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
kuwapa opened this issue Jun 23, 2019 · 5 comments
Closed
Labels

Comments

@kuwapa
Copy link

kuwapa 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.

@kuwapa kuwapa 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 commented Jun 23, 2019

Arguments are bools not strings.

@dstftw dstftw closed this as completed Jun 23, 2019
@kuwapa
Copy link
Author

kuwapa 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!

@kuwapa
Copy link
Author

kuwapa 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

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.

@kuwapa
Copy link
Author

kuwapa 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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants