Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Youtube API v3 #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions settings_local.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ FLOWPLAYER_SWF = 'http://releases.flowplayer.org/swf/flowplayer-3.2.8.swf'

# Enables google analytics
GOOGLE_ANALYTICS_ID = None

# Youtube API KEY https://console.developers.google.com/start
YOUTUBE_API_KEY = ''
13 changes: 5 additions & 8 deletions traveler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def process(self):
conn.close()

# it exists! (302 is a redirect for sharing links i.e. youtu.be)
if r1.status == 200 or r1.status == 302:
if r1.status == 200 or r1.status == 302 or r1.status == 301:
self.content_provider = url_data.hostname.lstrip('www.')
query = cgi.parse_qs(url_data.query)

Expand All @@ -463,16 +463,13 @@ def process(self):
self.content_provider = 'youtube.com'
self.url = 'http://www.youtube.com/watch?v=' + self.video_id

data_url = 'http://gdata.youtube.com/feeds/api/videos/' + self.video_id + '?v=2&alt=json'
data_url = 'https://www.googleapis.com/youtube/v3/videos?id='+ self.video_id+'&key='+ settings.YOUTUBE_API_KEY +'&part=snippet'
youtube_data = simplejson.load(urllib.urlopen(data_url))
item = iter(youtube_data['items']).next()

thumbs = youtube_data['entry']['media$group']['media$thumbnail']
if len(thumbs) > 1:
self.screenshot = thumbs[1]['url']
elif len(thumbs):
self.screenshot = thumbs[0]['url']
self.screenshot = item['snippet']['thumbnails']['standard']['url']
self.caption = item['snippet']['title']

self.caption = youtube_data['entry']['title']['$t']

# vimeo
elif self.content_provider == 'vimeo.com':
Expand Down