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

Add the option to return only the info_dict #296

Closed
cochiseruhulessin opened this issue Feb 27, 2012 · 5 comments
Closed

Add the option to return only the info_dict #296

cochiseruhulessin opened this issue Feb 27, 2012 · 5 comments
Assignees

Comments

@cochiseruhulessin
Copy link

When _real_extract() is called, it immediately sends the parsed info to it's FileDownloader.

To expand the usability of youtube_dl, it would be great if the caller could only retrieve the parsed video info and do whatever he pleases with it.

A quick look at the code shows that this could be done by adding a, for example, "data_only" argument to InfoExtractor.extract(),
which is a bool indicating if we should download, or only parse the info. This is then passed to _real_extract().

See this example for init.py, line 1450-1467. It assumes _real_extract() got the "data only" argument.

            try:
                # Process video information
                data = {
                    'id':       video_id.decode('utf-8'),
                    'url':      video_real_url.decode('utf-8'),
                    'uploader': video_uploader.decode('utf-8'),
                    'upload_date':  upload_date,
                    'title':    video_title,
                    'stitle':   simple_title,
                    'ext':      video_extension.decode('utf-8'),
                    'format':   (format_param is None and u'NA' or format_param.decode('utf-8')),
                    'thumbnail':    video_thumbnail.decode('utf-8'),
                    'description':  video_description,
                    'player_url':   player_url,
                }
                if data_only:
                    return data
                self._downloader.process_info(data)
            except UnavailableVideoError, err:
                self._downloader.trouble(u'\nERROR: unable to download video')
@FiloSottile
Copy link
Collaborator

It might be clearer to separate the info extracting and the passing to the downloader. So for example real_extract returns the info dict and extract passes it to the downloader.

@eadmaster
Copy link

after studying the code a bit i came to the same conclusion!

@FiloSottile
Copy link
Collaborator

Actually the docstring for extract() suggest that behavior:
"""Extracts URL information and returns it in list of dicts."""
The download should be done by FileDownloader.process_info()

@FiloSottile
Copy link
Collaborator

Hmm, the current implementation is insane, particularly for the randomly positioned increment_downloads. We should definitively put all that stuff in FileDownloader.download().
It also helps the API-fication.

FiloSottile referenced this issue in FiloSottile/youtube-dl Mar 30, 2012
…oad (#296) (follows current doclines); a small step towards importability #217
@ghost ghost assigned jaimeMF Apr 29, 2013
@jaimeMF
Copy link
Collaborator

jaimeMF commented May 15, 2013

All the InfoExtractors now returns an info_dict.

@jaimeMF jaimeMF closed this as completed May 15, 2013
joedborg referenced this issue in joedborg/youtube-dl Nov 17, 2020
[pull] master from ytdl-org:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants