GithubHelp home page GithubHelp logo

classicvalues / python-youtube-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rhayun/python-youtube-api

0.0 1.0 0.0 24 KB

A basic Python wrapper for the Youtube Data API v3

License: GNU General Public License v3.0

Python 100.00%

python-youtube-api's Introduction

python-youtube-api

********************* ย  THIS REPO IS NO LONGER MAINTAINED ****************************************************

BASED ON php-youtube-api from: https://github.com/madcoda/php-youtube-api

A basic Python wrapper for the Youtube Data API v3 ( Non-OAuth ). Designed to let devs easily fetch public data (Video, Channel, Playlists info) from Youtube. No 3rd party dependancy. (except PHPUnit) The reason of returning the decoded JSON response directly is that you only need to read the Google API doc to use this library, instead of learning my set of API again (Keep it simple).

youtube = YoutubeAPI('key': '/* Your API key here */')

// Return a dict 
video = youtube.get_video_info('rie-hPVJ7Sw')

// Search playlists, channels and videos
results = youtube.search('Android')

// Search only Videos
video_list = youtube.search_videos('Android')

// Search only Videos in a given channel
video_list = youtube.search_channel_videos('keyword', 'UCk1SpWNzOs4MYmr0uICEntg', 50)

results = youtube.search_advanced({/* params */ })

channel = youtube.get_channel_by_name('xdadevelopers')

channel = youtube.get_channel_by_id('UCk1SpWNzOs4MYmr0uICEntg')

playlist = youtube.get_playlist_by_id('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs')

playlists = youtube->get_playlists_by_channel_id('UCk1SpWNzOs4MYmr0uICEntg')

playlist_items = youtube.get_playlist_items_by_playlist_id('PL590L5WQmH8fJ54F369BLDSqIwcs-TCfs')

activities = youtube.get_activities_by_channel_id('UCk1SpWNzOs4MYmr0uICEntg')

video_id = youtube.parse_vid_from_url('https://www.youtube.com/watch?v=moSFlvxnbgk')
// result: moSFlvxnbgk

Basic Search Pagination

youtube = YoutubeAPI('key': '/* Your API key here */')

// Set Default Parameters
params = {
    'q': 'Android',
    'type': 'video',
    'part': 'id, snippet',
    'maxResults': 50
}

// Make Intial Call. With second argument to reveal page info such as page tokens.
search = youtube.search_advanced(params, True)

// check if we have a pageToken
if 'nextPageToken' in search['info']:
    params['pageToken'] = search['info']['nextPageToken']


// Make Another Call and Repeat
search = youtube.search_advanced(params, True)          

// add results key with info parameter set
print search['results'] 

/* Alternative approach with new built in paginateResults function */
 
// Same Params as before
params = {
    'q': 'Android',
    'type': 'video',
    'part': 'id, snippet',
    'maxResults': 50
}

// an array to store page tokens so we can go back and forth
page_tokens = {}

// make inital search
search = youtube.paginate_results(params, None)

// store token
page_tokens.append(search['info']['nextPageToken'])

// go to next page in result
search = youtube.paginate_results(params, page_tokens[0])

// store token
pageTokens.append(search['info']['nextPageToken'])

// go to next page in result
search = youtube.paginate_results(params, page_tokens[1])

// store token
pageTokens.append(search['info']['nextPageToken'])

// go back a page
search = youtube.paginate_results(params, page_tokens[0])

// add results key with info parameter set
print search['results']

The pagination above is quite basic. Depending on what you are trying to achieve; you may want to create a recurssive function that traverses the results.

Youtube Data API v3

Contact

For bugs, complain and suggestions please file an Issue here or send email to [email protected] :)

python-youtube-api's People

Contributors

classicvalues avatar mend-bolt-for-github[bot] avatar rhayun avatar williamroot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.