I'd like to know how can I simply get the title or other information about a video using Youtube API, in case the only thing I know is the url of the video (so basically the video ID).
What other info can I get about a video? eg: Length, Category, Uploader name, Country of origin, ... ???
Can somebody provide me a usable code snippet and the library to use for this data collecting?
Thanks for the help in advance.
There are plenty of examples and documentation about what you can get using the YouTube API's Python bindings.
Here are Python code samples as provided by YouTube:
https://developers.google.com/youtube/v3/code_samples/python#create_and_manage_youtube_video_caption_tracks
And the code samples can also be downloaded from their GitHub repository:
https://github.com/youtube/api-samples/tree/master/python
Try below code:
payload = {'id': search_result["id"]["videoId"], 'part': 'contentDetails,statistics,snippet', 'key': DEVELOPER_KEY}
l = requests.Session().get('https://www.googleapis.com/youtube/v3/videos', params=payload)
resp_dict = json.loads(l.content)
print "Title: ",resp_dict['items'][0]['snippet']['title']
Try using this API: https://pypi.org/project/python-youtube/
To grab the title, you can do something like this:
from pyyoutube import Api
playlistVideoItems = api.get_playlist_items(playlist_id='PLOU2XLYxmsIKpaV8h0AGE05so0fAwwfTw').items
print(playlistVideoItems[0].snippet.title)
Note that the above is somewhat untested code. I copied the relevant bits and pieces from what I currently have, but I did not test this exact set lines of code. And of course, I'm not actually using that playlist ID for my purposes.
In regards to what other types of information can be gathered, I would recommend reading the documentation or running in a debugger. As of this writing, I am trying to figure out how to obtain the video uploader name, but I don't really need this data although it would be nice to have. I will update this answer if I figure it out.
Related
I'm trying to gather metadata from a youtube channel using python via youtube data api-v3.
I've managed to get data in json format but the texts like titles, descriptions, comments etc are in Korean language and they are shown as
ex : "title": "\ud55c \uc5ec\ub984\ubc24\uc758 \uafc8",
Is there a way to set encoding for specific feature/keys?
https://developers.google.com/youtube/v3/docs/i18nLanguages/list
The above seems to be the way to solve the problem, but I am new to api and I do not know how to apply it... can anyone give me an example or a link? so I can try myself?
or is there a way to decode back to original language? from the broken language output?
Thank you very much for your time.
So, I am trying to print out gifs by using Tenor API.
I want it to only print one gif link but it prints out everything any Idea how to fix this?
Thank you.
https://i.stack.imgur.com/xf084.png
Sadly, I can not tell you the exact problem you are having, I replicated your code and used the official API Docs here
From what I can tell, this is one GIF just in a lot of different formats.
You can filter them like so:
print(top_8gifs['weburl'])
or
print(top_8gifs['results'][0])
EDIT: Looking at your .png (please embed it as code in the future) this should work for you, if you want the url:
print(top_8gifs[0]['url'])
A Python dict you can select using the key (like gifs['weburl'])
A Python list you have to select by index so gifs[0]
Using these techniques you can gather the data you need from that output.
I am working on Python3.4.4
I tried to use a Merriam-Webster API, and here is an example link:
http://www.dictionaryapi.com/api/v1/references/collegiate/xml/purple?key=bf534d02-bf4e-49bc-b43f-37f68a0bf4fd
There is a file under the tag, you will see after you open the url.
And I am wondering that how can I retrieve that wav file......
Because it is kind of just a string to me......
Thank you very much!
Okay, I just sort it out.
Usually you need to look at the instructions for the API, I look it up on the official website and it tells you that how you are going to retrieve that. In this case you are going to another url, and then wala
I'm using python amazon product api and I can't seem to get the url for the image of the product.
Here is my code so far
for book in amz_api.item_search('Books', Keywords='cookies', ResponseGroup='Large', limit=10):
print book.ItemAttributes.Large
But I get this reply
AttributeError: no such child: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}Large
Any help would be apprecicated
To access the image URLs, you can try to change your code to use one of the following:
print book.SmallImage.URL
print book.MediumImage.URL
print book.LargeImage.URL
The error is because there is no "Large" attribute in ItemAttributes. The image URLs are available in a different part of the response.
The Large Response Group (ResponseGroup='Large') returns a lot of data. According to the docs it's for demonstration purposes and not intended for production applications. To make your code production ready, you might need a different approach, such as the Images Response Group (ResponseGroup='Images').
Also, the python type for the book variable in the above code is:
<type 'lxml.objectify.ObjectifiedElement'>
While debugging, you can look at all the data available in book using something like this:
from lxml import objectify
print(objectify.dump(book))
I would like to retrieve captions from a number of YouTube clips and figured I could do this using the YouTube Data API. I would also like to specify the language (e.g. English, German). I believe this would have been possible with v2 but after some research it doesn't seem to be possible with v3. Could someone please advise? After retrieval of the text files I plan to analyse the texts using Python. Many thanks!
you would want to use pafy api
http://np1.github.io/pafy/
the code will be like
import pafy
url = "https://www.youtube.com/watch?v=bMt47wvK6u0"
video = pafy.new(url)
print video.title