|
@@ -1,42 +1,69 @@
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
1
|
11
|
from json import loads
|
2
|
12
|
from urllib import urlencode
|
3
|
13
|
from dateutil import parser
|
4
|
14
|
|
|
15
|
+
|
5
|
16
|
categories = ['videos']
|
6
|
|
-
|
7
|
|
-search_url = ('https://gdata.youtube.com/feeds/api/videos'
|
8
|
|
- '?alt=json&{query}&start-index={index}&max-results=25')
|
9
|
|
-
|
10
|
17
|
paging = True
|
|
18
|
+language_support = True
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+base_url = 'https://gdata.youtube.com/feeds/api/videos'
|
|
22
|
+search_url = base_url + '?alt=json&{query}&start-index={index}&max-results=5'
|
11
|
23
|
|
12
|
24
|
|
|
25
|
+
|
13
|
26
|
def request(query, params):
|
14
|
|
- index = (params['pageno'] - 1) * 25 + 1
|
|
27
|
+ index = (params['pageno'] - 1) * 5 + 1
|
|
28
|
+
|
15
|
29
|
params['url'] = search_url.format(query=urlencode({'q': query}),
|
16
|
30
|
index=index)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+ if params['language'] != 'all':
|
|
34
|
+ params['url'] += '&lr=' + params['language'].split('_')[0]
|
|
35
|
+
|
17
|
36
|
return params
|
18
|
37
|
|
19
|
38
|
|
|
39
|
+
|
20
|
40
|
def response(resp):
|
21
|
41
|
results = []
|
|
42
|
+
|
22
|
43
|
search_results = loads(resp.text)
|
|
44
|
+
|
|
45
|
+
|
23
|
46
|
if not 'feed' in search_results:
|
24
|
|
- return results
|
|
47
|
+ return []
|
|
48
|
+
|
25
|
49
|
feed = search_results['feed']
|
26
|
50
|
|
|
51
|
+
|
27
|
52
|
for result in feed['entry']:
|
28
|
53
|
url = [x['href'] for x in result['link'] if x['type'] == 'text/html']
|
|
54
|
+
|
29
|
55
|
if not url:
|
30
|
56
|
return
|
|
57
|
+
|
31
|
58
|
|
32
|
59
|
url = url[0].replace('feature=youtube_gdata', '')
|
33
|
60
|
if url.endswith('&'):
|
34
|
61
|
url = url[:-1]
|
|
62
|
+
|
35
|
63
|
title = result['title']['$t']
|
36
|
64
|
content = ''
|
37
|
65
|
thumbnail = ''
|
38
|
66
|
|
39
|
|
-
|
40
|
67
|
pubdate = result['published']['$t']
|
41
|
68
|
publishedDate = parser.parse(pubdate)
|
42
|
69
|
|
|
@@ -49,6 +76,7 @@ def response(resp):
|
49
|
76
|
else:
|
50
|
77
|
content = result['content']['$t']
|
51
|
78
|
|
|
79
|
+
|
52
|
80
|
results.append({'url': url,
|
53
|
81
|
'title': title,
|
54
|
82
|
'content': content,
|
|
@@ -56,4 +84,5 @@ def response(resp):
|
56
|
84
|
'publishedDate': publishedDate,
|
57
|
85
|
'thumbnail': thumbnail})
|
58
|
86
|
|
|
87
|
+
|
59
|
88
|
return results
|