mirror of
				https://github.com/searxng/searxng.git
				synced 2025-11-04 03:27:06 -05:00 
			
		
		
		
	[fix] flickr.com mods
This commit is contained in:
		
							parent
							
								
									8d40445ab8
								
							
						
					
					
						commit
						3386e21cdf
					
				@ -1,48 +1,54 @@
 | 
				
			|||||||
#!/usr/bin/env python
 | 
					#!/usr/bin/env python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from urllib import urlencode
 | 
					from urllib import urlencode
 | 
				
			||||||
from json import loads
 | 
					#from json import loads
 | 
				
			||||||
#from urlparse import urljoin
 | 
					from urlparse import urljoin
 | 
				
			||||||
 | 
					from lxml import html
 | 
				
			||||||
 | 
					from time import time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
categories = ['images']
 | 
					categories = ['images']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# url = 'https://secure.flickr.com/'
 | 
					url = 'https://secure.flickr.com/'
 | 
				
			||||||
# search_url = url+'search/?{query}&page={page}'
 | 
					search_url = url+'search/?{query}&page={page}'
 | 
				
			||||||
# results_xpath = '//div[@id="thumbnails"]//a[@class="rapidnofollow photo-click" and @data-track="photo-click"]'  # noqa
 | 
					results_xpath = '//div[@class="view display-item-tile"]/figure/div'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
paging = True
 | 
					paging = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# text=[query]
 | 
					 | 
				
			||||||
# TODO clean "extras"
 | 
					 | 
				
			||||||
search_url = 'https://api.flickr.com/services/rest?extras=can_addmeta%2Ccan_comment%2Ccan_download%2Ccan_share%2Ccontact%2Ccount_comments%2Ccount_faves%2Ccount_notes%2Cdate_taken%2Cdate_upload%2Cdescription%2Cicon_urls_deep%2Cisfavorite%2Cispro%2Clicense%2Cmedia%2Cneeds_interstitial%2Cowner_name%2Cowner_datecreate%2Cpath_alias%2Crealname%2Csafety_level%2Csecret_k%2Csecret_h%2Curl_c%2Curl_h%2Curl_k%2Curl_l%2Curl_m%2Curl_n%2Curl_o%2Curl_q%2Curl_s%2Curl_sq%2Curl_t%2Curl_z%2Cvisibility&per_page=50&page={page}&{query}&sort=relevance&method=flickr.photos.search&api_key=ad11b34c341305471e3c410a02e671d0&format=json'  # noqa
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def request(query, params):
 | 
					def request(query, params):
 | 
				
			||||||
    params['url'] = search_url.format(query=urlencode({'text': query}),
 | 
					    params['url'] = search_url.format(query=urlencode({'text': query}),
 | 
				
			||||||
                                      page=params['pageno'])
 | 
					                                      page=params['pageno'])
 | 
				
			||||||
    #params['url'] = search_url.format(query=urlencode({'q': query}),
 | 
					    time_string = str(int(time())-3)
 | 
				
			||||||
    #                                  page=params['pageno'])
 | 
					    params['cookies']['BX'] = '3oqjr6d9nmpgl&b=3&s=dh'
 | 
				
			||||||
 | 
					    params['cookies']['xb'] = '421409'
 | 
				
			||||||
 | 
					    params['cookies']['localization'] = 'en-us'
 | 
				
			||||||
 | 
					    params['cookies']['flrbp'] = time_string +\
 | 
				
			||||||
 | 
					        '-3a8cdb85a427a33efda421fbda347b2eaf765a54'
 | 
				
			||||||
 | 
					    params['cookies']['flrbs'] = time_string +\
 | 
				
			||||||
 | 
					        '-ed142ae8765ee62c9ec92a9513665e0ee1ba6776'
 | 
				
			||||||
 | 
					    params['cookies']['flrb'] = '9'
 | 
				
			||||||
    return params
 | 
					    return params
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def response(resp):
 | 
					def response(resp):
 | 
				
			||||||
    results = []
 | 
					    results = []
 | 
				
			||||||
    images = loads(resp.text[14:-1])["photos"]["photo"]
 | 
					    dom = html.fromstring(resp.text)
 | 
				
			||||||
    for i in images:
 | 
					    for result in dom.xpath(results_xpath):
 | 
				
			||||||
        results.append({'url': i['url_s'],
 | 
					        img = result.xpath('.//img')
 | 
				
			||||||
                        'title': i['title'],
 | 
					
 | 
				
			||||||
                        'img_src': i['url_s'],
 | 
					        if not img:
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        img = img[0]
 | 
				
			||||||
 | 
					        img_src = 'https:'+img.attrib.get('src')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if not img_src:
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        href = urljoin(url, result.xpath('.//a')[0].attrib.get('href'))
 | 
				
			||||||
 | 
					        title = img.attrib.get('alt', '')
 | 
				
			||||||
 | 
					        results.append({'url': href,
 | 
				
			||||||
 | 
					                        'title': title,
 | 
				
			||||||
 | 
					                        'img_src': img_src,
 | 
				
			||||||
                        'template': 'images.html'})
 | 
					                        'template': 'images.html'})
 | 
				
			||||||
    #dom = html.fromstring(resp.text)
 | 
					 | 
				
			||||||
    #for result in dom.xpath(results_xpath):
 | 
					 | 
				
			||||||
    #    href = urljoin(url, result.attrib.get('href'))
 | 
					 | 
				
			||||||
    #    img = result.xpath('.//img')[0]
 | 
					 | 
				
			||||||
    #    title = img.attrib.get('alt', '')
 | 
					 | 
				
			||||||
    #    img_src = img.attrib.get('data-defer-src')
 | 
					 | 
				
			||||||
    #    if not img_src:
 | 
					 | 
				
			||||||
    #        continue
 | 
					 | 
				
			||||||
    #    results.append({'url': href,
 | 
					 | 
				
			||||||
    #                    'title': title,
 | 
					 | 
				
			||||||
    #                    'img_src': img_src,
 | 
					 | 
				
			||||||
    #                    'template': 'images.html'})
 | 
					 | 
				
			||||||
    return results
 | 
					    return results
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user