API Guide — youtube-data-api 0.0.17 documentation

文章推薦指數: 80 %
投票人數:10人

The YouTube Data API has a single class YouTubeDataAPI , which authenticates your API key and provides functions to interact with the API. youtube-data-api latest UserGuide/Tutorial: Installation Quickstart APIReference: APIGuide youtube_api.youtube_apimodule youtube_api.parsersmodule youtube_api.youtube_api_utilsmodule youtube-data-api Docs» APIGuide EditonGitHub APIGuide¶ TheYouTubeDataAPIhasasingleclassYouTubeDataAPI,whichauthenticatesyourAPIkeyandprovidesfunctionstointeractwiththeAPI. youtube_api.youtube_apimodule¶ ThisistheclientclasstoaccesstheYouTubeAPI. classyoutube_api.youtube_api.YouTubeDataAPI(key,api_version='3',verify_api_key=True,verbose=False,timeout=20)[source]¶ Bases:object TheYoutubeDataAPIhandlesthekeysandmethodstoaccessdatafromtheYouTubeDataAPI paramkey:YouTubeDataAPIkey.GetaYouTubeDataAPIkeyhere:https://console.cloud.google.com/apis/dashboard verify_key()[source]¶ ChecksittheAPIkeyisvalid. Returns:TrueiftheAPIkeyisvalid,Falseifthekeyisnotvalid. Returntype:bool get_channel_id_from_user(username,**kwargs)[source]¶ Getachannel_idfromaYouTubeusername.ThesearetheuniqueidentifiersforallYouTube“uers”.IE.“Munchies”->“UCaLfMkkHhSA_LaCta0BzyhQ”. Readthedocs:https://developers.google.com/youtube/v3/docs/channels/list Parameters:username(str)–theusernameforaYouTubechannel Returns:YouTubeChannelIDforagivenusername Returntype:str get_channel_metadata_gen(channel_id,parser=,part=['id','snippet','contentDetails','statistics','topicDetails','brandingSettings'],**kwargs)[source]¶ Getsadictionaryofchannelmetadatagivenachannel_id,oralistofchannel_ids. Parameters: channel_id(strorlist)–channelid(s) parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument. part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:yieldstheYouTubechannelmetadata Returntype:dict get_channel_metadata(channel_id,parser=,part=['id','snippet','contentDetails','statistics','topicDetails','brandingSettings'],**kwargs)[source]¶ Getsadictionaryofchannelmetadatagivenachannel_id,oralistofchannel_ids. Readthedocs:https://developers.google.com/youtube/v3/docs/channels/list Parameters: channel_id(strorlist)–thechannelid(s) parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument. part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:theYouTubechannelmetadata Returntype:dict get_video_metadata_gen(video_id,parser=,part=['statistics','snippet'],**kwargs)[source]¶ Givenavideo_idreturnsmetrics(views,likes,comments)andmetadata(description,category)asadictionary. Readthedocs:https://developers.google.com/youtube/v3/docs/videos/list Parameters: video_id(strorlistofstr)–TheIDofavideoIE:“kNbhUWLH_yY”,thiscanbefoundattheendofYouTubeurlsandbyparsinglinksusingyoutube_api.youtube_api_utils.strip_youtube_id(). parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:returnsmetadatafromtheinputted``video_id``s. Returntype:dict get_video_metadata(video_id,parser=,part=['statistics','snippet'],**kwargs)[source]¶ Givenasingleorlistofvideo_idreturnsmetrics(views,likes,comments)andmetadata(description,category)asadictionary. Readthedocs:https://developers.google.com/youtube/v3/docs/videos/list Parameters: video_id(strorlistofstr)–theIDofavideoIE:[‘kNbhUWLH_yY’],thiscanbefoundattheendofYouTubeurlsandbyparsinglinksusingyoutube_api.youtube_api_utils.strip_youtube_id(). parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:yieldsavideometadata. Returntype:dict get_playlists(channel_id,next_page_token=False,parser=,part=['id','snippet','contentDetails'],**kwargs)[source]¶ ReturnsalistofplaylistIDsthatchannel_idcreated. Notethatplaylistscancontainsvideosfromanyusers. Readthedocs:https://developers.google.com/youtube/v3/docs/playlists/list Parameters: channel_id(str)–achannel_idIE:“UCn8zNIfYAQNdrFRrr8oibKw” next_page_token(str)–atokentocontinuefromapreciouslystoppedqueryIE:“CDIQAA” parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:playlistinfothatchannel_idissubscribedto. Returntype:listofdict get_videos_from_playlist_id(playlist_id,next_page_token=None,parser=,part=['snippet'],max_results=200000,**kwargs)[source]¶ Givenaplaylist_id,returnsvideo_idsassociatedwiththatplaylist. Notethatuseruploadsforanygivenchannelarefromaplaylistnamed“uploadplaylistid”.Youcangetthisvalueusingyoutube_api.youtube_api.get_channel_metadata()oryoutube_api.youtube_api_utils.get_upload_playlist_id().TheplaylistIDforuploadsisalwaysthechannel_idwith“UU”subbedfor“UC”. Readthedocs:https://developers.google.com/youtube/v3/docs/playlistItems Parameters: playlist_id–theplaylist_idIE:“UUaLfMkkHhSA_LaCta0BzyhQ” next_page_token(str)–atokentocontinuefromapreciouslystoppedqueryIE:“CDIQAA” parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. max_results–HowmanyvideoIDsshouldreturned?Contrarytothename,thisisactuallytheminimumnumberofresultstobereturned. Returns:videoidsassociatedwithplaylist_id. Returntype:listofdict get_subscriptions(channel_id,next_page_token=False,parser=,part=['id','snippet'],**kwargs)[source]¶ ReturnsalistofchannelIDsthatchannel_idissubscribedto. Readthedocs:https://developers.google.com/youtube/v3/docs/subscriptions Parameters: channel_id(str)–achannel_idIE:“UCn8zNIfYAQNdrFRrr8oibKw” next_page_token(str)–atokentocontinuefromapreciouslystoppedqueryIE:“CDIQAA” stop_after_n_iteration(int)–stopstheAPIcallsafterNAPIcalls parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:channelIDsthatchannel_idissubscribedto. Returntype:list get_featured_channels_gen(channel_id,parser=,part=['id','brandingSettings'],**kwargs)[source]¶ Givenachannel_idreturnsadictionary{channel_id:[list,of,channel_ids]} offeaturedchannels. Optionally,cantakealistofchannelIDS,andreturnsalistofdictionaries. Readthedocs:https://developers.google.com/youtube/v3/docs/channels/list Parameters: channel_id(stroflistofstr)–channel_idsIE:[‘UCn8zNIfYAQNdrFRrr8oibKw’] parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:yieldsmetadataforfeaturedchannels Returntype:dict get_featured_channels(channel_id,parser=,**kwargs)[source]¶ Givenachannel_idreturnsadictionary{channel_id:[list,of,channel_ids]} offeaturedchannels. Optionally,cantakealistofchannelIDs,andreturnsalistofdictionaries. Readthedocs:https://developers.google.com/youtube/v3/docs/channels/list Parameters: channel_id(strorlistofstr)–channel_idsIE:[‘UCn8zNIfYAQNdrFRrr8oibKw’] parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:metadataforfeaturedchannelsfromchannel_id. Returntype:listofdict get_video_comments(video_id,get_replies=True,max_results=None,next_page_token=False,parser=,part=['snippet'],**kwargs)[source]¶ Returnscommentsandrepliestocommentsforagivenvideo. Readthedocs:https://developers.google.com/youtube/v3/docs/commentThreads/list Parameters: video_id(str)–avideo_idIE:“eqwPlwHSL_M” get_replies(bool)–whetherornottogetrepliestocomments parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. Returns:commentsandresponsestocommentsofthegivenvideo_id. Returntype:listofdict search(q=None,channel_id=None,max_results=5,order_by='relevance',next_page_token=None,published_after=946684800.0,published_before=32503680000.0,location=None,location_radius='1km',region_code=None,safe_search=None,relevance_language=None,event_type=None,topic_id=None,video_duration=None,search_type='video',parser=,part=['snippet'],**kwargs)[source]¶ SearchYouTubeforeithervideos,channelsforkeywords.Onlyreturnsupto500videospersearch.Foranexhaustivesearch,takeadvantageofthepublished_afterandpublished_beforeparams.Notethedocstringneedstobeupdatedtoaccountforalltheargumentsthisfunctiontakes. Readthedocs:https://developers.google.com/youtube/v3/docs/search/list Parameters: q(listorstr)–regexpatterntosearchusing|foror,&&forand,and-fornot.IEboat|fishingisboatorfishing max_results(int)–maxnumberofvideosreturnedbyasearchquery. parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument part(list)–Thepartparameterspecifiesacomma-separatedlistofoneormoreresourcepropertiesthattheAPIresponsewillinclude.DifferentparameterscostdifferentquotacostsfromtheAPI. order_by(str)–Returnsearchresultsorderedbyeitherrelevance,date,rating,title,videoCount,viewCount. next_page_token(str)–AtokentocontinuefromapreciouslystoppedqueryIE:CDIQAA published_after(datetime)–Onlyshowvideosuploadedafterdatetime published_before(datetime)–Onlyshowvideosuploadedbeforedatetime location(tuple)–Coodinatesofvideouploadedinlocation. location_radius(str)–Theradiusfromthelocationparamtoincludeinthesearch. region_code(str)–searchresultsforvideosthatcanbeviewedinthespecifiedcountry.TheparametervalueisanISO3166-1alpha-2countrycode. safe_search(strorNone)–whetherornottoincluderestrictedcontent,optionsare“moderate”,“strict”,None. relevance_language(str)–InstructstheAPItoreturnsearchresultsthataremostrelevanttothespecifiedlanguage. event_type(str)–whetherthevideois“live”,“completed”,or“upcoming”. topic_id(str)–onlycontainresourcesassociatedwiththespecifiedtopic.ThevalueidentifiesaFreebasetopicID. video_duration(str)–filteronvideodurations“any”,“long”,“medium”,“short”. search_type–returnresultsona“video”,“channel”,or“playlist”search. Returns:incompletevideometadataofvideosreturnedbysearchquery. Returntype:listofdict get_recommended_videos(video_id,max_results=5,parser=,**kwargs)[source]¶ GetrecommendedvideosgivenavideoID.ThisextendsthesearchAPI. Notethatsearchhistorydoesnotinfluenceresults. Readthedocs:https://developers.google.com/youtube/v3/docs/search/list Parameters: video_id–(str)avideo_idIE:“eqwPlwHSL_M” max_results–(int)maxnumberofrecommendedvids parser(youtube_api.parsersmodule)–thefunctiontoparsethejsondocument Returns:incompletevideometadatafromrecommendedvideosofvideo_id. Returntype:listofdict classyoutube_api.youtube_api.YoutubeDataApi(key,**kwargs)[source]¶ Bases:youtube_api.youtube_api.YouTubeDataAPI VariantcaseofthemainYouTubeDataAPIclass.Thisclasswilldedepricatedbyversion0.0.21 youtube_api.parsersmodule¶ Everyfunctionfromtheyoutube_api.youtube_apiclasshasanargumentforparser.parsercanbeanyfunctionthattakesadictionaryasinput.Herearethedefaultparserfucntionsforeachfunction.Usetheseastemplatestobuildyourowncustomparsers,orusetheyoutube_api.parsers.raw_json()orNoneastheparserargumentfortherawAPIresponse. youtube_api.parsers.raw_json(item)[source]¶ ReturnstherawjsonoutputfromtheAPI. youtube_api.parsers.parse_video_metadata(item)[source]¶ Parsesandprocessesrawoutputandreturnsvideo_id,channel_title,channel_id,video_publish_date,video_title,video_description,video_category,video_view_count,video_comment_count,video_like_count,video_dislike_count,video_thumbnail,video_tags,collection_date. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_video_url(item)[source]¶ Parsesandprocessesrawoutputandreturnspublish_date,video_id,channel_id,collection_date Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_channel_metadata(item)[source]¶ Parsesandprocessesrawoutputandreturnschannel_id,title,account_creatation_date,keywords,description,view_count,video_count,subscription_count,playlist_id_likes,playlist_id_uploads,topic_ids,country,collection_date. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_subscription_descriptive(item)[source]¶ Parsesandprocessesrawoutputandreturnssubscription_title,subscription_channel_id,subscription_kind,subscription_publish_date,collection_date. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_featured_channels(item)[source]¶ Parsesandprocessesrawoutputandreturnsadictionarywherethekeyisthechannel_idandthekeyisalistofchannelURLs. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_playlist_metadata(item)[source]¶ Parsesandprocessesrawoutputandreturnsplaylist_name,playlist_id,playlist_publish_date,playlist_n_videos,channel_id,channel_name,collection_date. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_comment_metadata(item)[source]¶ Parsesandprocessesrawoutputandreturnsvideo_id,commenter_channel_url,commenter_channel_display_name,comment_id,comment_like_count,comment_publish_date,text,commenter_rating,comment_parent_id,collection_date. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_rec_video_metadata(item)[source]¶ Parsesandprocessesrawoutputandreturnsvideo_id,channel_title,channel_id,video_publish_date,video_title,video_description,video_category,video_thumbnail,collection_date. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.parsers.parse_caption_track(item)[source]¶ Returnsthevideo_id,captionsandcollection_date. Paramsitem:jsondocument Returns:parseddictionary Returntype:dict youtube_api.youtube_api_utilsmodule¶ Theseareutilsusedbytheclientclass,withsomeadditionalfunctionsforanalysis. youtube_api.youtube_api_utils.parse_yt_datetime(date_str)[source]¶ ParsesadatestringreturnedfromYouTube’sAPIintoaPythondatetime. youtube_api.youtube_api_utils.get_upload_playlist_id(channel_id)[source]¶ Givenachannel_id,returnstheuseruploadedplaylistid. youtube_api.youtube_api_utils.get_liked_playlist_id(channel_id)[source]¶ Givenachannel_id,returnstheuserlikedplaylistid. ReadtheDocs v:latest Versions latest Downloads pdf OnReadtheDocs ProjectHome Builds FreedocumenthostingprovidedbyReadtheDocs.



請為這篇文章評分?