mirror of
https://github.com/evilhero/mylar
synced 2025-01-03 05:24:43 +00:00
remove auth for /cache, added getArt
Set correct headers, add imageurls to do, added getArt.
This commit is contained in:
parent
dea9ee73a2
commit
052e6ecb0b
5 changed files with 248 additions and 171 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,6 +1,12 @@
|
|||
mylar.db
|
||||
config.ini
|
||||
*.pyc
|
||||
*.py[co]
|
||||
.idea
|
||||
logs
|
||||
.AppleDouble
|
||||
cache/
|
||||
custom_exceptions.csv
|
||||
Thumbs.db
|
||||
*.torrent
|
||||
ehtumbs.db
|
||||
Thumbs.db
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of Mylar.
|
||||
#
|
||||
# Mylar is free software: you can redistribute it and/or modify
|
||||
|
@ -1410,7 +1413,7 @@ def dbcheck():
|
|||
c_error = 'sqlite3.OperationalError'
|
||||
c=conn.cursor()
|
||||
|
||||
c.execute('CREATE TABLE IF NOT EXISTS comics (ComicID TEXT UNIQUE, ComicName TEXT, ComicSortName TEXT, ComicYear TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER, Have INTEGER, Total INTEGER, ComicImage TEXT, ComicPublisher TEXT, ComicLocation TEXT, ComicPublished TEXT, LatestIssue TEXT, LatestDate TEXT, Description TEXT, QUALalt_vers TEXT, QUALtype TEXT, QUALscanner TEXT, QUALquality TEXT, LastUpdated TEXT, AlternateSearch TEXT, UseFuzzy TEXT, ComicVersion TEXT, SortOrder INTEGER, DetailURL TEXT, ForceContinuing INTEGER, ComicName_Filesafe TEXT, AlternateFileName TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS comics (ComicID TEXT UNIQUE, ComicName TEXT, ComicSortName TEXT, ComicYear TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER, Have INTEGER, Total INTEGER, ComicImage TEXT, ComicPublisher TEXT, ComicLocation TEXT, ComicPublished TEXT, LatestIssue TEXT, LatestDate TEXT, Description TEXT, QUALalt_vers TEXT, QUALtype TEXT, QUALscanner TEXT, QUALquality TEXT, LastUpdated TEXT, AlternateSearch TEXT, UseFuzzy TEXT, ComicVersion TEXT, SortOrder INTEGER, DetailURL TEXT, ForceContinuing INTEGER, ComicName_Filesafe TEXT, AlternateFileName TEXT, ComicImageURL TEXT, ComicImageALTURL TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS issues (IssueID TEXT, ComicName TEXT, IssueName TEXT, Issue_Number TEXT, DateAdded TEXT, Status TEXT, Type TEXT, ComicID TEXT, ArtworkURL Text, ReleaseDate TEXT, Location TEXT, IssueDate TEXT, Int_IssueNumber INT, ComicSize TEXT, AltIssueNumber TEXT, IssueDate_Edit TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS snatched (IssueID TEXT, ComicName TEXT, Issue_Number TEXT, Size INTEGER, DateAdded TEXT, Status TEXT, FolderName TEXT, ComicID TEXT, Provider TEXT)')
|
||||
c.execute('CREATE TABLE IF NOT EXISTS upcoming (ComicName TEXT, IssueNumber TEXT, ComicID TEXT, IssueID TEXT, IssueDate TEXT, Status TEXT, DisplayComicName TEXT)')
|
||||
|
@ -1497,6 +1500,16 @@ def dbcheck():
|
|||
except sqlite3.OperationalError:
|
||||
c.execute('ALTER TABLE comics ADD COLUMN AlternateFileName TEXT')
|
||||
|
||||
try:
|
||||
c.execute('SELECT ComicImageURL from comics')
|
||||
except sqlite3.OperationalError:
|
||||
c.execute('ALTER TABLE comics ADD COLUMN ComicImageURL TEXT')
|
||||
|
||||
try:
|
||||
c.execute('SELECT ComicImageALTURL from comics')
|
||||
except sqlite3.OperationalError:
|
||||
c.execute('ALTER TABLE comics ADD COLUMN ComicImageALTURL TEXT')
|
||||
|
||||
# -- Issues Table --
|
||||
|
||||
try:
|
||||
|
|
70
mylar/api.py
70
mylar/api.py
|
@ -1,3 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of Mylar.
|
||||
#
|
||||
# Mylar is free software: you can redistribute it and/or modify
|
||||
|
@ -14,30 +17,30 @@
|
|||
# along with Mylar. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import mylar
|
||||
|
||||
from mylar import db, mb, importer, search, PostProcessor, versioncheck, logger
|
||||
|
||||
from mylar import db, importer, search, PostProcessor, versioncheck, logger
|
||||
import lib.simplejson as simplejson
|
||||
from xml.dom.minidom import Document
|
||||
import copy
|
||||
import cherrypy
|
||||
import os
|
||||
import urllib2
|
||||
import cache
|
||||
import imghdr
|
||||
from cherrypy.lib.static import serve_file
|
||||
|
||||
cmd_list = [ 'getIndex', 'getComic', 'getComic', 'getUpcoming', 'getWanted', 'getHistory', 'getLogs',
|
||||
cmd_list = ['getIndex', 'getComic', 'getUpcoming', 'getWanted', 'getHistory', 'getLogs',
|
||||
'findComic', 'findIssue', 'addComic', 'delComic', 'pauseComic', 'resumeComic', 'refreshComic',
|
||||
'addIssue', 'queueIssue', 'unqueueIssue', 'forceSearch', 'forceProcess', 'getVersion', 'checkGithub',
|
||||
'shutdown', 'restart', 'update', 'getComicInfo', 'getIssueInfo']
|
||||
'shutdown', 'restart', 'update', 'getComicInfo', 'getIssueInfo', 'getArt']
|
||||
|
||||
|
||||
class Api(object):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.apikey = None
|
||||
self.cmd = None
|
||||
self.id = None
|
||||
|
||||
self.img = None
|
||||
self.kwargs = None
|
||||
|
||||
self.data = None
|
||||
|
||||
self.callback = None
|
||||
|
||||
|
||||
|
@ -83,14 +86,18 @@ class Api(object):
|
|||
methodToCall = getattr(self, "_" + self.cmd)
|
||||
result = methodToCall(**self.kwargs)
|
||||
if 'callback' not in self.kwargs:
|
||||
if self.img:
|
||||
return serve_file(path=self.img, content_type='image/jpeg')
|
||||
if type(self.data) == type(''):
|
||||
return self.data
|
||||
else:
|
||||
cherrypy.response.headers['Content-Type'] = "application/json"
|
||||
return simplejson.dumps(self.data)
|
||||
else:
|
||||
self.callback = self.kwargs['callback']
|
||||
self.data = simplejson.dumps(self.data)
|
||||
self.data = self.callback + '(' + self.data + ');'
|
||||
cherrypy.response.headers['Content-Type'] = "application/javascript"
|
||||
return self.data
|
||||
else:
|
||||
return self.data
|
||||
|
@ -317,3 +324,44 @@ class Api(object):
|
|||
|
||||
self.data = cache.getInfo(IssueID=self.id)
|
||||
|
||||
def _getArt(self, **kwargs):
|
||||
|
||||
if 'id' not in kwargs:
|
||||
self.data = 'Missing parameter: id'
|
||||
return
|
||||
else:
|
||||
self.id = kwargs['id']
|
||||
|
||||
img = None
|
||||
image_path = os.path.join(mylar.CACHE_DIR, str(self.id) + '.jpg')
|
||||
|
||||
# Checks if its a valid path and file
|
||||
if os.path.isfile(image_path):
|
||||
# check if its a valid img
|
||||
if imghdr.what(image_path):
|
||||
self.img = image_path
|
||||
return
|
||||
else:
|
||||
# If we cant find the image, lets check the db for a url.
|
||||
comic = self._dic_from_query('SELECT * from comics WHERE ComicID="' + self.id + '"')
|
||||
|
||||
# Try every img url in the db
|
||||
try:
|
||||
img = urllib2.urlopen(comic[0]['ComicImageURL']).read()
|
||||
except:
|
||||
try:
|
||||
img = urllib2.urlopen(comic[0]['ComicImageALTURL']).read()
|
||||
except:
|
||||
pass
|
||||
|
||||
if img:
|
||||
# verify the img stream
|
||||
if imghdr.what(None, img):
|
||||
with open(image_path, 'wb') as f:
|
||||
f.write(img)
|
||||
self.img = image_path
|
||||
return
|
||||
else:
|
||||
self.data = 'Failed return a image'
|
||||
else:
|
||||
self.data = 'Failed to return a image'
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of Mylar.
|
||||
#
|
||||
# Mylar is free software: you can redistribute it and/or modify
|
||||
|
@ -90,6 +93,7 @@ def addComictoDB(comicid,mismatch=None,pullupd=None,imported=None,ogcname=None,c
|
|||
|
||||
# we need to lookup the info for the requested ComicID in full now
|
||||
comic = cv.getComic(comicid,'comic')
|
||||
logger.fdebug(comic)
|
||||
|
||||
if not comic:
|
||||
logger.warn('Error fetching comic. ID for : ' + comicid)
|
||||
|
@ -469,6 +473,8 @@ def addComictoDB(comicid,mismatch=None,pullupd=None,imported=None,ogcname=None,c
|
|||
"ComicName_Filesafe": comicname_filesafe,
|
||||
"ComicYear": SeriesYear,
|
||||
"ComicImage": ComicImage,
|
||||
"ComicImageURL": comic.get("ComicImage", ""),
|
||||
"ComicImageALTURL": comic.get("ComicImageALT", ""),
|
||||
"Total": comicIssues,
|
||||
"ComicVersion": comicVol,
|
||||
"ComicLocation": comlocation,
|
||||
|
@ -810,6 +816,8 @@ def GCDimport(gcomicid, pullupd=None,imported=None,ogcname=None):
|
|||
"ComicLocation": comlocation,
|
||||
#"ComicVersion": comicVol,
|
||||
"ComicImage": ComicImage,
|
||||
"ComicImageURL": comic.get('ComicImage', ''),
|
||||
"ComicImageALTURL": comic.get('ComicImageALT', ''),
|
||||
#"ComicPublisher": comic['ComicPublisher'],
|
||||
#"ComicPublished": comicPublished,
|
||||
"DateAdded": helpers.today(),
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of Headphones.
|
||||
#
|
||||
# Headphones is free software: you can redistribute it and/or modify
|
||||
|
@ -100,7 +103,8 @@ def initialize(options):
|
|||
},
|
||||
'/cache':{
|
||||
'tools.staticdir.on': True,
|
||||
'tools.staticdir.dir': mylar.CACHE_DIR
|
||||
'tools.staticdir.dir': mylar.CACHE_DIR,
|
||||
'tools.auth_basic.on': False
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,5 +130,3 @@ def initialize(options):
|
|||
sys.exit(0)
|
||||
|
||||
cherrypy.server.wait()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue