Package: unlimited-youtube-search
Unlimited YouTube SearchUnlimited YouTube Search (UYTS) is a quick and easy way to search YouTube from your Python program without the need for the YouTube Data API. It's a Python port ofyoutube-scrapebyHerman Fassettand has the majority of its features.How do I install it?Simply runpip install unlimited-youtube-searchin the command prompt to install it from the Python Package Index. Alternatively, clone the repo to your PC, navigate to its folder, and runpython setup.py install. Both of these methods will install UYTS and its dependencies.How do I use it?You'll need to importuytsat the start of your project in order to use Unlimited YouTube Search. From then on, you can search YouTube usingsearch = uyts.Search('search query'). This returns a search object which has the attributeresultsstoring a list of Video, Playlist and Channel objects. For example, you could runprint(search.results[0].title)to see its title. For more information, read on.Simple Example ProgramHere's a simple program to show how easy it is to search YouTube with UYTS.importuytsquery=input("Search query: ")search=uyts.Search(query)forresultinsearch.results:print(result)What if I want to host a server with it?That's already built in! To host a server, simply run the following code:fromuytsimportServerapp=Server()app.run()This will host a Flask server on port 80. More information on how to customise this is in the documentation below.DocumentationSearch classUsage:uyts.Search(query,minResults=0)Parameters:query: the string to search forlanguage(optional): the language to return search results in, defaults to "en", accepts ISO codes (e.g. "en", "en-gb", "fr-fr"). For best results, use with thecountryparametercountry(optional): the region to make the request from, defaults to "GB", accepts ISO codes (e.g. "GB", "US", "FR"). For best results, use with thelanguageparameterminResults(optional): the minimum number of results to return. UYTS will continue making requests until it reaches this number or runs out of results. The default value of 0 will make one search request.timeout(optional): the number of seconds to wait before giving up on the request, defaults to 5Attributes:results: list of search resultsresultsJSON: JSON object of search resultsquery: the original search queryresultsCount: the number of search results returnedmaxResultsCount: YouTube's estimation of total possible search resultssuggestedSearches: list of suggested searches related to your queryThe following three classes are returned in the search results, and while they can be created yourself, there's pretty much no reason you would want to do that so I haven't included how to do so here. It's self explanatory in the code however.Video classAttributes:id: the ID of the YouTube videotitle: the title of the YouTube videothumbnail_src: the URL of the thumbnailviews: the number of viewsauthor: the name of the uploaderduration: the duration of the videoresultType: the type of result (in this case,video)accountType: the type of the author's account, either "verified", "music" or "regular"ToJSON(): returns the video as a JSON objectToXML(): returns the video as an XML stringPlaylist classAttributes:id: the ID of the playlisttitle: the title of the playlistthumbnail_src: the URL of the thumbnaillength: the number of videos in the playlistauthor: the name of the creatorresultType: the type of result (in this case,playlist)ToJSON(): returns the playlist as a JSON objectToXML(): returns the playlist as an XML stringChannel classAttributes:id: the ID of the channeltitle: the name of the channelsubsorsubscriber_count: the number of subscribers the channel hasresultType: the type of result (in this case,channel)accountType: the type of the author's account, either "verified", "music" or "regular"ToJSON(): returns the channel as a JSON objectToXML(): returns the channel as an XML stringServer classThe server must be initialised before you can callrun().Parameters:serverName(optional): the name for the Flask server, defaults touyts-apiserverMessage(optional): the message that appears on the server homepage, defaults toServer onlinerawHTML(optional): ifTrue, treatsserverMessageas raw HTML rather than a string, defaults toFalseMethods:run(host="0.0.0.0",port=80): runs a Flask server on your local IP on port 80, unless specified otherwiseAttributes:app: this is a Flask object for the server. For most use-cases you won't need to directly interact with it. However, if you wanted to deploy this to Heroku you would need to do something likeserver = uyts.Server().appand then use Gunicorn to run it withweb: gunicorn main:serverfor the Procfile as you can't run something from inside a class (e.g.web: gunicorn main:server.appwould be invalid).Server routes:/: main page, should show "Server online" if the server is online/api: API page, either GET/api/<query>or/api/<query>/<minResults>depending on whether you want to specify the minimum results. The response should look like this (but with more results):[{"id":"dQw4w9WgXcQ","title":"Rick Astley - Never Gonna Give You Up (Video)","thumbnail_src":"http://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg","views":"746,623,786 views","author":"Official Rick Astley","duration":"3:32","resultType":"video","accountType":"music"},{"id":"UC-lHJZR3Gqxm24_Vd_AJ5Yw","title":"PewDiePie","subscriber_count":"106M subscribers","resultType":"channel","accountType":"verified"}]