-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.py
22 lines (19 loc) · 899 Bytes
/
youtube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gdata.youtube
import gdata.youtube.service
def get_video_results(query, maxReturn = 10):
startIndex = 1
uri = 'https://gdata.youtube.com/feeds/api/videos?q={0}&orderby=relevance&start-index={1}&max-results={2}&v=2'.format(query, startIndex, maxReturn)
videoInfo = []
yt_service = gdata.youtube.service.YouTubeService()
feed = yt_service.GetYouTubeVideoFeed(uri)
for entry in feed.entry:
videoInfo.append({'vid_url': entry.media.player.url, 'thumbnail_url': entry.media.thumbnail[0].url, "title": entry.media.title.text, "vid_time": convertToMinutesAndSeconds(entry.media.duration.seconds)})
return videoInfo
def convertToMinutesAndSeconds(timeString):
minutes = int(timeString)/60
seconds = int(timeString) % 60
if seconds < 10:
separator = ":0"
else:
separator = ":"
return str(minutes) + separator + str(seconds)