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

Support for user-defineable params? #31

Closed
ping opened this issue May 8, 2015 · 3 comments
Closed

Support for user-defineable params? #31

ping opened this issue May 8, 2015 · 3 comments

Comments

@ping
Copy link

ping commented May 8, 2015

I've noticed a problem with using the /api/info endpoint for channels, such as https://www.youtube.com/user/Youtube/videos.
The endpoint will attempt to lookup all of the videos in the channel which can take a very long time and likely timeout eventually.

This can be mitigated by defining the playlistend param, but there is no way to do this currently.
I patched my local copy of app.py to support a small set of user-defined params, but I'm not sure if this a good/pythonic way of doing it.

def info():
    url = request.args['url']
    # list of user defined params
    supported_params = {'playliststart': 'int', 'playlistend': 'int', 'playlist_items': 'int', 'matchtitle': 'str', 'rejecttitle': 'str'}
    params = {}
    for p in supported_params:
        if p in request.args:
            if supported_params[p] == 'int':
                params[p] = int(request.args[p])
            else:
                params[p] = request.args[p]
    errors = (youtube_dl.utils.DownloadError, youtube_dl.utils.ExtractorError)
    try:
        result = get_videos(url, params)    # modified
        key = 'info'

    # ... <snip>


def get_videos(url, params=None):
    '''
    Get a list with a dict for every video founded
    '''
    ydl_params = {
        'format': 'best',
        'cachedir': False,
        'logger': app.logger.getChild('youtube-dl'),
    }
    # merge user params if provided
    if params:
        ydl_params.update(params)
    ydl = SimpleYDL(ydl_params)
    res = ydl.extract_info(url, download=False)
    return res
@jaimeMF
Copy link
Owner

jaimeMF commented May 8, 2015

I have implemented it (same idea but with some small difference in the implementation), thanks!

I haven't added matchtitle and rejectitle because they only work when the video is going to be downloaded and therefore wouldn't work here.

@ping
Copy link
Author

ping commented May 8, 2015

@jaimeMF Awesome!

But can you take a look again at matchtitle and rejecttitle?

I've tested it with https://www.youtube.com/user/GoogleWebmasterHelp/videos.
When defined, matchtitle=English will return only videos with titles containing the word "English"
and rejecttitle=German will exclude videos titles containing "German".

Another param for possible whitelisting is playlistreverse (bool).

@jaimeMF
Copy link
Owner

jaimeMF commented May 8, 2015

Added in 978e6be and 7136e1b, I only checked with playlists, it works on users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants