2
# -*- coding: iso-8859-15 -*-
5
__date__ ='$26-dic-2011'
9
# Copyright (C) 2011 Lorenzo Carbonell
10
# lorenzo.carbonell.cerezo@gmail.com
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License as published by
14
# the Free Software Foundation, either version 3 of the License, or
15
# (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
29
import gdata.youtube.service
36
self.client = gdata.youtube.service.YouTubeService()
38
def search(self,search = None, page = 1, categories = [], orderby = 'viewCount', time = 'all_time', rating = 0):
39
query = gdata.youtube.service.YouTubeVideoQuery()
41
query.vq = search # the term(s) that you are searching for
42
query.orderby = orderby # how to display the results
45
query.max_results = RECORDS_PER_PAGE # number of results to retrieve
46
query.start_index = 1 + (page - 1) * RECORDS_PER_PAGE
47
query.racy = 'include'
48
if len(categories) > 0:
49
for category in categories:
50
query.categories.append(category)
52
feed = self.client.YouTubeQuery(query)
54
feed = self.client.GetMostViewedVideoFeed()
56
feed = self.client.GetMostViewedVideoFeed()
59
for entry in feed.entry:
61
if entry.title and entry.title.text:
62
result['title'] = entry.title.text
65
if entry.media and entry.media.thumbnail and len(entry.media.thumbnail)>0 and entry.media.thumbnail[0]:
66
result['icon'] = entry.media.thumbnail[0].url
69
if entry.link and len(entry.link)>0 and entry.link[0].href:
70
result['href'] = entry.link[0].href
73
if entry.summary and entry.summary.text:
74
result['summary'] = entry.summary.text
76
result['summary'] = ''
77
if entry.rating and entry.rating.average and entry.rating.average:
78
result['rating'] = int(float(entry.rating.average))
79
result['summary'] = 'Rating: %s'% result['rating']
82
if result['rating']>=rating:
83
results.append(result)
85
if contador >= RECORDS_PER_PAGE:
90
if __name__ == '__main__':
93
categories.append('Animals')
94
results = yt.search(search = 'Prueba', categories = categories, rating = 4)
95
for result in results:
96
print '########################################################'
100
print result['summary']
101
print result['rating']
103
client = gdata.youtube.service.YouTubeService()
104
#gdata.alt.appengine.run_on_appengine(client)
105
query = gdata.youtube.service.YouTubeVideoQuery()
107
#query.vq = 'nasa' # the term(s) that you are searching for
108
query.orderby = 'viewCount' # how to display the results
109
query.max_results = '25' # number of results to retrieve
110
#query.category = 'Tech'#'Science & Technology'
111
#query.categories.append('Travel')
114
feed = client.YouTubeQuery(query)
115
for entry in feed.entry:
116
print '#######################################################'
117
print entry.link[0].href
118
print entry.title.text
119
print entry.published.text
122
print entry.rating.average
123
print entry.rating.num_raters
124
print entry.media.category[0]
125
print entry.media.thumbnail[0].url
127
print entry.recorded.text
129
print entry.rights.text
131
print entry.source.text
133
print entry.statistics.text
135
print entry.summary.text
137
print entry.text.text
139
print entry.title.text
141
print entry.updated.text