Commit a8d6acc1 authored by prx's avatar prx

no more allocnie

parent 4092b87f
......@@ -137,5 +137,5 @@ Add `-f` to sign the package.
Thanks
------
- Thanks to allocine, btdigg, torrentproject and other search engines for results.
- Thanks to imdb, piratebay, btdigg, torrentproject and other search engines for results.
- Thanks to Douglas Adams for inspiration
......@@ -98,7 +98,7 @@ def search2html(keywords, extrawords=' ', searchengine='torrentproject', page=0,
return html
def allocinesch2html(keywords, serie=False):
def sch2html(keywords, serie=False):
"""
......@@ -107,16 +107,16 @@ def allocinesch2html(keywords, serie=False):
serie:
Return:
Return a research on allocine in html code
Return a research on omdb in html code
"""
results = allocine_sch(keywords, serie=serie)
results = omdb_sch(keywords, serie=serie)
if len(results) == 0:
return ''
else:
html = '<ul class="ca-menu">'
for r in results:
isserie = 1 if serie else 0
html += '<li><a href="/whatsthat/{1}/{2}/{3}/{1}"><img src="{0}"><p>{1} <br> {2}</p></a></li>'.format(
html += '<li><a href="/whatsthat/{1}/{2}/{3}"><img src="{0}"><p>{1} <br> {2}</p></a></li>'.format(
r['poster'], r['title'], r['year'], isserie)
html += '</ul>'
......@@ -184,6 +184,8 @@ def omdb2template(keywords, year, isserie=0):
writer = r['Writer']
actors = r['Actors']
poster = r['Poster']
if poster == 'N/A':
poster = "/static/unknown.png"
plot = r['Plot']
rating = r['imdbRating']
else:
......@@ -449,9 +451,9 @@ class DontPanic:
if nocatalog != "1":
logger.info('Searching {}... '.format("in series"))
seriessch = allocinesch2html(keywords, serie=True)
seriessch = sch2html(keywords, serie=True)
logger.info('Searching {}... '.format("in movies"))
moviessch = allocinesch2html(keywords, serie=False)
moviessch = sch2html(keywords, serie=False)
tplvars = {'sch_res': htmlresults,
'the_search': '{} {}'.format(keywords, extrawords).strip(),
......@@ -487,18 +489,14 @@ class DontPanic:
return template('results', tplvars)
@self.app.route('/whatsthat/<title>/<year>/<isserie>/')
@self.app.route('/whatsthat/<title>/<year>/<isserie>/<oldposter:path>')
def whatsthat(title, year, isserie, oldposter=""):
@self.app.route('/whatsthat/<title>/<year>/<isserie>')
def whatsthat(title, year, isserie):
title_simplify = simplifyname(title)
title, runtime, director, writer, actors, poster, plot, rating, html = omdb2template(
title_simplify, year, isserie)
if poster == "N/A" and oldposter != "":
poster = oldposter
if len(poster) > 0:
whoami = request.get_cookie("username", secret=self.secret)
self._add_to_recent_search(whoami, title, year, poster, isserie)
whoami = request.get_cookie("username", secret=self.secret)
self._add_to_recent_search(whoami, title, year, poster, isserie)
tplvars = {
'title': title,
......@@ -806,15 +804,9 @@ class DontPanic:
database.remove_in_recent(whoami, title)
redirect(link)
@self.app.route('/_bestvideos/<i:int>/<j:int>')
def best_videos(i, j):
@self.app.route('/_bestvideos/<i:int>')
def best_videos(i):
# Set source from IMDB
if j == 1:
best = BestIMDB()
# Set source from Allocine
else:
best = BestAllocine()
## FIXME : parse allocine best results
best = BestIMDB()
# See the best series
......
......@@ -5,7 +5,6 @@ Bugs:
Suggestion:
-----------
- ne plus utiliser allocine comme moteur
- résultats apparaissent petit à petit
- Lorsque utilisateur choisit une vidéo: le titre de la vidéo est celui de sa recherche, plus logique d'afficher le nom de la vidéo
- Lorsque la vidéo est stocké dans la base de donnée, actuellement on stocke la recherche comme nom, plus logique de stocker le titre de la vidéo -> oui et non. On garde comme ça en mémoire aussi les différentes sources de vidéo qui peuvent être différentes d'une fois sur l'autre"
......
......@@ -29,9 +29,9 @@
<div class="text-center">
<p>
<a href="/_bestvideos/0/0">{{tpl_best_dvd}}</a>
<a href="/_bestvideos/0">{{tpl_best_dvd}}</a>
-
<a href="/_bestvideos/1/0">{{tpl_popular_series}}</a>
<a href="/_bestvideos/1">{{tpl_popular_series}}</a>
</p>
</div>
......
......@@ -60,10 +60,14 @@ class OMDBbAPI:
keys = {'i': id, 'r': 'json', 'plot': plot}
return do_req_get(cls.URL, "json", keys)
@classmethod
def search_any(cls, sch):
keys = {'s': sch, 'r': 'json'}
return do_req_get(cls.URL, "json", keys)
def allocine_sch(sch, serie=False):
def omdb_sch(sch, serie = False):
"""
Search on allocine for a movie or a serie. Default search is movie
Search on omdb for a movie or a serie. Default search is movie
Args:
sch (str): The title of the search
......@@ -73,61 +77,33 @@ def allocine_sch(sch, serie=False):
List of results:
result = {'poster' : posterurl, 'title' : title, 'year' : year }
"""
if serie:
url = 'http://www.allocine.fr/recherche/6/'
else:
url = 'http://www.allocine.fr/recherche/1/'
keys = {'q': sch}
s = do_req_get(url, "text", keys)
soup = bs4.BeautifulSoup(s, "html.parser")
resultslist = []
poster, title, year = '', '', ''
for i in soup.find_all('td', style=" vertical-align:top;"):
# information
desc = i.get_text().strip().splitlines()
while '' in desc:
desc.remove('')
# now desc looks like this
# ['FlashForward', '2009', 'avec Joseph Fiennes, John Cho']
# or
#  ['Flash', '(The Flash)', '1990', 'avec John Wesley Shipp, Amanda Pays']
if len(desc) > 0:
if len(desc) >= 3:
# original title
if desc[1].startswith('(') and desc[1].endswith(')'):
title = desc[1][1:-1] # remove ()
year = desc[2]
else:
title = desc[0]
year = desc[1]
results = []
title, year, posterurl = "", "", ""
search_omdb = OMDBbAPI.search_any(sch)
if search_omdb['Response']:
for res in search_omdb['Search'] :
if serie :
if res['Type'] == "series":
title = res['Title']
year = res['Year']
posterurl = res['Poster']
if posterurl == 'N/A':
posterurl = "/static/unknown.png"
results.append({'poster' : posterurl, 'title' : title, 'year' : year })
else:
title = desc[0]
if len(desc) == 2:
year = desc[1]
else:
# image of the show
img = i.find('img')
if img:
poster = img['src'].replace('r_75_106', 'c_160_214') # get bigger image
if poster != '' and title != '' and year != '':
if sys.version_info < (3, 0):
poster = poster.encode("utf-8")
title = title.encode("utf-8")
year = year.encode("utf-8")
resultslist.append({'poster': poster, 'title': title, 'year': year})
poster, title, year = '', '', ''
return resultslist
if res['Type'] == "movie":
title = res['Title']
year = res['Year']
posterurl = res['Poster']
if posterurl == 'N/A':
posterurl = "/static/unknown.png"
results.append({'poster' : posterurl, 'title' : title, 'year' : year })
return results
def get_episode_list(title, year):
"""
Args:
title:
year:
......@@ -255,86 +231,6 @@ class BestIMDB:
return cls.URL_TVSHOWS
class BestAllocine:
URL_TVSHOWS = "http://www.allocine.fr/series/top/"
URL_DVD = "http://www.allocine.fr/dvd/du-mois/meilleures-notes-spectateurs/"
def __init__(self):
pass
@classmethod
def get_best_dvd(cls):
s = do_req_get(cls.URL_DVD, "text")
soup = bs4.BeautifulSoup(s, "html.parser")
results = soup.find_all("div", class_="datablock vpadding10t")
elements = []
for result in results:
title = result.find("div", class_="titlebar").h2.a.string
title = title.replace("\n", "")
year = result.find("div", class_="titlebar").p.string
year = year[year.find(":") + 1:] # Don't take '..Date de sortie..'
year = year.replace("\n", "")
img = result.find("div", class_="picturezone").a.img['src']
poster = img.replace('r_75_106', 'c_160_214') # get bigger image
if sys.version_info < (3, 0):
title = title.encode('utf-8')
year = year.encode('utf-8')
poster = poster.encode('utf-8')
elements.append({"title": title, "year": year, "img": poster})
return elements
@classmethod
def get_best_tvshows(cls):
s = do_req_get(cls.URL_TVSHOWS, "text")
soup = bs4.BeautifulSoup(s, "html.parser")
results = soup.find_all("div", class_="data_box")
elements = []
for result in results:
title = result.find("div", class_="titlebar_02").h2.a.string
title = title.replace("\n", "")
year = result.find("div", class_="oflow_a").string
year = year.replace("\n", "")
if sys.version_info >= (3, 0):
search_string = "Aujourd'hui"
else:
search_string = u"Aujourd'hui"
if year.endswith(search_string):
year = year[:year.find(search_string) - 1] + _("Today")
img = result.find("div", class_="poster").span.img['src']
poster = img.replace('r_75_106', 'c_160_214') # get bigger image
if sys.version_info < (3, 0):
title = title.encode('utf-8')
year = year.encode('utf-8')
poster = poster.encode('utf-8')
elements.append({"title": title, "year": year, "img": poster})
return elements
@classmethod
def url_best_dvd(cls):
return cls.URL_DVD
@classmethod
def url_best_tvshows(cls):
return cls.URL_TVSHOWS
class TorrentSearch:
def __init__(self, searchengine):
......@@ -584,12 +480,6 @@ class TorrentSearch:
if __name__ == '__main__':
import time
t1 = time.time()
searchengine = "*"
with TorrentSearch(searchengine) as ts:
s = ts.search("test")
print(s)
print(time.time() - t1)
omdb_sch("flash")
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment