celiao / tmdbsimple

A wrapper for The Movie Database API v3.
GNU General Public License v3.0
579 stars 122 forks source link

How can I get only Youtube ID? #51

Closed albertoivo closed 6 years ago

albertoivo commented 6 years ago

Hi,

I have the following code:

kwargs = {'append_to_response': 'trailers'}
movie = tmdb.Movies(603).info(**kwargs)
print(movie.get('trailers'))

and the output:

{u'quicktime': [], u'youtube': [{u'source': u'm8e-FF8MsqU', u'type': u'Trailer', u'name': u'Matrix Trailer HD (1999)', u'size': u'HD'}]}

How can I get only the value of the source attribute: m8e-FF8MsqU ?

Thanks in advance!

celiao commented 6 years ago

This ought to do the trick.

This code:

import tmdbsimple as tmdb
tmdb.API_KEY = 'YOUR_API_KEY_HERE'

kwargs = {'append_to_response': 'trailers'}
movie = tmdb.Movies(603).info(**kwargs)
result = movie.get('trailers')
print(movie.get('trailers')['youtube'][0]['source'])

outputs:

m8e-FF8MsqU