2015-03-04 21:00:36 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2014-02-26 19:48:50 +00:00
# This file is part of Mylar.
#
# Mylar is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mylar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mylar. If not, see <http://www.gnu.org/licenses/>.
import mylar
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
from mylar import db , mb , importer , search , process , versioncheck , logger , webserve , helpers
2016-09-07 04:04:42 +00:00
import simplejson as simplejson
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
import json
2015-03-04 21:00:36 +00:00
import cherrypy
2017-12-31 02:10:22 +00:00
import random
2015-03-04 21:00:36 +00:00
import os
import urllib2
import cache
import imghdr
2015-05-14 23:12:48 +00:00
from operator import itemgetter
2015-05-15 21:57:23 +00:00
from cherrypy . lib . static import serve_file , serve_download
2017-01-12 20:24:39 +00:00
import datetime
2014-02-26 19:48:50 +00:00
2016-12-20 07:54:06 +00:00
cmd_list = [ ' getIndex ' , ' getComic ' , ' getUpcoming ' , ' getWanted ' , ' getHistory ' ,
' getLogs ' , ' clearLogs ' , ' findComic ' , ' addComic ' , ' delComic ' ,
' pauseComic ' , ' resumeComic ' , ' refreshComic ' , ' addIssue ' ,
' queueIssue ' , ' unqueueIssue ' , ' forceSearch ' , ' forceProcess ' ,
' getVersion ' , ' checkGithub ' , ' shutdown ' , ' restart ' , ' update ' ,
' getComicInfo ' , ' getIssueInfo ' , ' getArt ' , ' downloadIssue ' ,
2017-12-31 02:19:03 +00:00
' downloadNZB ' , ' getReadList ' , ' getStoryArc ' , ' addStoryArc ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
class Api ( object ) :
def __init__ ( self ) :
self . apikey = None
self . cmd = None
self . id = None
2015-03-04 21:00:36 +00:00
self . img = None
2015-05-15 21:57:23 +00:00
self . file = None
self . filename = None
2014-02-26 19:48:50 +00:00
self . kwargs = None
self . data = None
self . callback = None
2015-06-12 06:37:27 +00:00
self . apitype = None
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
self . comicrn = False
2014-02-26 19:48:50 +00:00
2015-05-22 08:32:51 +00:00
def checkParams ( self , * args , * * kwargs ) :
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
if ' apikey ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing api key ' )
2014-02-26 19:48:50 +00:00
return
2015-03-04 21:00:36 +00:00
2015-06-07 01:44:46 +00:00
if ' cmd ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: cmd ' )
2015-06-07 01:44:46 +00:00
return
2017-10-25 18:33:56 +00:00
if not mylar . CONFIG . API_ENABLED :
2015-06-07 01:44:46 +00:00
if kwargs [ ' apikey ' ] != mylar . DOWNLOAD_APIKEY :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' API not enabled ' )
2015-06-07 01:44:46 +00:00
return
2017-10-25 18:33:56 +00:00
if kwargs [ ' apikey ' ] != mylar . CONFIG . API_KEY and all ( [ kwargs [ ' apikey ' ] != mylar . DOWNLOAD_APIKEY , mylar . DOWNLOAD_APIKEY != None ] ) :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Incorrect API key ' )
2014-02-26 19:48:50 +00:00
return
else :
2017-10-25 18:33:56 +00:00
if kwargs [ ' apikey ' ] == mylar . CONFIG . API_KEY :
2015-06-12 06:37:27 +00:00
self . apitype = ' normal '
elif kwargs [ ' apikey ' ] == mylar . DOWNLOAD_APIKEY :
self . apitype = ' download '
logger . fdebug ( ' Matched to key. Api set to : ' + self . apitype + ' mode. ' )
2014-02-26 19:48:50 +00:00
self . apikey = kwargs . pop ( ' apikey ' )
2015-03-04 21:00:36 +00:00
2017-10-25 18:33:56 +00:00
if not ( [ mylar . CONFIG . API_KEY , mylar . DOWNLOAD_APIKEY ] ) :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' API key not generated ' )
2015-06-07 01:44:46 +00:00
return
2015-06-12 06:37:27 +00:00
if self . apitype :
2017-10-25 18:33:56 +00:00
if self . apitype == ' normal ' and len ( mylar . CONFIG . API_KEY ) != 32 :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' API key not generated correctly ' )
2015-06-12 06:37:27 +00:00
return
if self . apitype == ' download ' and len ( mylar . DOWNLOAD_APIKEY ) != 32 :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Download API key not generated correctly ' )
2015-06-12 06:37:27 +00:00
return
else :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' API key not generated correctly ' )
2014-02-26 19:48:50 +00:00
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
if kwargs [ ' cmd ' ] not in cmd_list :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Unknown command: %s ' % kwargs [ ' cmd ' ] )
2014-02-26 19:48:50 +00:00
return
else :
self . cmd = kwargs . pop ( ' cmd ' )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
self . kwargs = kwargs
self . data = ' OK '
def fetchData ( self ) :
2015-03-04 21:00:36 +00:00
if self . data == ' OK ' :
2018-02-23 18:32:01 +00:00
logger . fdebug ( ' Received API command: ' + self . cmd )
2014-02-26 19:48:50 +00:00
methodToCall = getattr ( self , " _ " + self . cmd )
result = methodToCall ( * * self . kwargs )
if ' callback ' not in self . kwargs :
2015-03-04 21:00:36 +00:00
if self . img :
return serve_file ( path = self . img , content_type = ' image/jpeg ' )
2015-05-15 21:57:23 +00:00
if self . file and self . filename :
return serve_download ( path = self . file , name = self . filename )
if isinstance ( self . data , basestring ) :
2014-02-26 19:48:50 +00:00
return self . data
else :
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
if self . comicrn is True :
return self . data
else :
cherrypy . response . headers [ ' Content-Type ' ] = " application/json "
return simplejson . dumps ( self . data )
2014-02-26 19:48:50 +00:00
else :
self . callback = self . kwargs [ ' callback ' ]
self . data = simplejson . dumps ( self . data )
self . data = self . callback + ' ( ' + self . data + ' ); '
2015-03-04 21:00:36 +00:00
cherrypy . response . headers [ ' Content-Type ' ] = " application/javascript "
2014-02-26 19:48:50 +00:00
return self . data
else :
return self . data
2015-03-04 21:00:36 +00:00
2015-05-14 23:12:48 +00:00
def _dic_from_query ( self , query ) :
2014-02-26 19:48:50 +00:00
myDB = db . DBConnection ( )
rows = myDB . select ( query )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
rows_as_dic = [ ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
for row in rows :
row_as_dic = dict ( zip ( row . keys ( ) , row ) )
rows_as_dic . append ( row_as_dic )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
return rows_as_dic
2015-03-04 21:00:36 +00:00
2016-11-06 14:54:39 +00:00
def _error_with_message ( self , message ) :
error = { ' error ' : { ' message ' : message } }
cherrypy . response . headers [ ' Content-Type ' ] = " application/json "
return simplejson . dumps ( error )
2014-02-26 19:48:50 +00:00
def _getIndex ( self , * * kwargs ) :
self . data = self . _dic_from_query ( ' SELECT * from comics order by ComicSortName COLLATE NOCASE ' )
2015-03-04 21:00:36 +00:00
return
2016-12-20 07:54:06 +00:00
def _getReadList ( self , * * kwargs ) :
self . data = self . _dic_from_query ( ' SELECT * from readlist order by IssueDate ASC ' )
return
2014-02-26 19:48:50 +00:00
def _getComic ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
comic = self . _dic_from_query ( ' SELECT * from comics WHERE ComicID= " ' + self . id + ' " ' )
issues = self . _dic_from_query ( ' SELECT * from issues WHERE ComicID= " ' + self . id + ' " order by Int_IssueNumber DESC ' )
2017-10-25 18:33:56 +00:00
if mylar . CONFIG . ANNUALS_ON :
2014-02-26 19:48:50 +00:00
annuals = self . _dic_from_query ( ' SELECT * FROM annuals WHERE ComicID= " ' + self . id + ' " ' )
2015-05-15 21:57:23 +00:00
else :
2018-05-02 14:24:54 +00:00
annuals = [ ]
2015-03-04 21:00:36 +00:00
2015-05-14 23:12:48 +00:00
self . data = { ' comic ' : comic , ' issues ' : issues , ' annuals ' : annuals }
2014-02-26 19:48:50 +00:00
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getHistory ( self , * * kwargs ) :
self . data = self . _dic_from_query ( ' SELECT * from snatched order by DateAdded DESC ' )
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getUpcoming ( self , * * kwargs ) :
2016-09-21 04:34:06 +00:00
if ' include_downloaded_issues ' in kwargs and kwargs [ ' include_downloaded_issues ' ] . upper ( ) == ' Y ' :
2017-01-29 04:49:51 +00:00
select_status_clause = " w.STATUS IN ( ' Wanted ' , ' Snatched ' , ' Downloaded ' ) "
2016-09-21 04:34:06 +00:00
else :
select_status_clause = " w.STATUS = ' Wanted ' "
2017-01-29 04:49:51 +00:00
# Days in a new year that precede the first Sunday will look to the previous Sunday for week and year.
2017-01-12 20:24:39 +00:00
today = datetime . date . today ( )
2017-01-29 04:49:51 +00:00
if today . strftime ( ' % U ' ) == ' 00 ' :
weekday = 0 if today . isoweekday ( ) == 7 else today . isoweekday ( )
sunday = today - datetime . timedelta ( days = weekday )
week = sunday . strftime ( ' % U ' )
year = sunday . strftime ( ' % Y ' )
2017-01-12 20:24:39 +00:00
else :
2017-01-29 04:49:51 +00:00
week = today . strftime ( ' % U ' )
2017-01-12 20:24:39 +00:00
year = today . strftime ( ' % Y ' )
2016-09-21 04:34:06 +00:00
self . data = self . _dic_from_query (
" SELECT w.COMIC AS ComicName, w.ISSUE AS IssueNumber, w.ComicID, w.IssueID, w.SHIPDATE AS IssueDate, w.STATUS AS Status, c.ComicName AS DisplayComicName \
FROM weekly w JOIN comics c ON w . ComicID = c . ComicID WHERE w . COMIC IS NOT NULL AND w . ISSUE IS NOT NULL AND \
2017-01-12 20:24:39 +00:00
SUBSTR ( ' 0 ' | | w . weeknumber , - 2 ) = ' " + week + " ' AND w . year = ' " + year + " ' AND " + select_status_clause + " ORDER BY c . ComicSortName " )
2014-02-26 19:48:50 +00:00
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getWanted ( self , * * kwargs ) :
self . data = self . _dic_from_query ( " SELECT * from issues WHERE Status= ' Wanted ' " )
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getLogs ( self , * * kwargs ) :
2015-07-01 06:41:29 +00:00
self . data = mylar . LOG_LIST
return
2015-07-01 22:39:49 +00:00
def _clearLogs ( self , * * kwargs ) :
2015-07-01 06:41:29 +00:00
mylar . LOG_LIST = [ ]
self . data = ' Cleared log '
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _delComic ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
myDB = db . DBConnection ( )
myDB . action ( ' DELETE from comics WHERE ComicID= " ' + self . id + ' " ' )
myDB . action ( ' DELETE from issues WHERE ComicID= " ' + self . id + ' " ' )
myDB . action ( ' DELETE from upcoming WHERE ComicID= " ' + self . id + ' " ' )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _pauseComic ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
myDB = db . DBConnection ( )
controlValueDict = { ' ComicID ' : self . id }
newValueDict = { ' Status ' : ' Paused ' }
myDB . upsert ( " comics " , newValueDict , controlValueDict )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _resumeComic ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
myDB = db . DBConnection ( )
controlValueDict = { ' ComicID ' : self . id }
newValueDict = { ' Status ' : ' Active ' }
myDB . upsert ( " comics " , newValueDict , controlValueDict )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _refreshComic ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
try :
importer . addComictoDB ( self . id )
except Exception , e :
self . data = e
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _addComic ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
try :
2015-05-14 23:12:48 +00:00
importer . addComictoDB ( self . id )
2014-02-26 19:48:50 +00:00
except Exception , e :
self . data = e
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _queueIssue ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
myDB = db . DBConnection ( )
controlValueDict = { ' IssueID ' : self . id }
newValueDict = { ' Status ' : ' Wanted ' }
myDB . upsert ( " issues " , newValueDict , controlValueDict )
2015-03-04 21:00:36 +00:00
search . searchforissue ( self . id )
2014-02-26 19:48:50 +00:00
def _unqueueIssue ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
myDB = db . DBConnection ( )
controlValueDict = { ' IssueID ' : self . id }
newValueDict = { ' Status ' : ' Skipped ' }
myDB . upsert ( " issues " , newValueDict , controlValueDict )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _forceSearch ( self , * * kwargs ) :
search . searchforissue ( )
2015-03-04 21:00:36 +00:00
2018-02-23 18:32:01 +00:00
def _issueProcess ( self , * * kwargs ) :
if ' comicid ' not in kwargs :
self . data = self . _error_with_message ( ' Missing parameter: comicid ' )
return
else :
self . comicid = kwargs [ ' comicid ' ]
if ' issueid ' not in kwargs :
self . issueid = None
else :
self . issueid = kwargs [ ' issueid ' ]
if ' folder ' not in kwargs :
self . data = self . _error_with_message ( ' Missing parameter: folder ' )
return
else :
self . folder = kwargs [ ' folder ' ]
fp = process . Process ( self . comicid , self . folder , self . issueid )
self . data = fp . post_process ( )
return
2014-02-26 19:48:50 +00:00
def _forceProcess ( self , * * kwargs ) :
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
2014-05-08 04:35:13 +00:00
if ' nzb_name ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: nzb_name ' )
2014-05-08 04:35:13 +00:00
return
else :
self . nzb_name = kwargs [ ' nzb_name ' ]
if ' nzb_folder ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: nzb_folder ' )
2014-05-08 04:35:13 +00:00
return
else :
self . nzb_folder = kwargs [ ' nzb_folder ' ]
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
if ' failed ' not in kwargs :
failed = False
else :
failed = kwargs [ ' failed ' ]
2018-03-12 19:37:38 +00:00
if ' issueid ' not in kwargs :
issueid = None
else :
issueid = kwargs [ ' issueid ' ]
if ' comicid ' not in kwargs :
comicid = None
else :
comicid = kwargs [ ' comicid ' ]
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
2019-01-16 22:09:51 +00:00
if ' ddl ' not in kwargs :
ddl = False
else :
ddl = True
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
if ' apc_version ' not in kwargs :
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
logger . info ( ' Received API Request for PostProcessing %s [ %s ]. Queueing... ' % ( self . nzb_name , self . nzb_folder ) )
mylar . PP_QUEUE . put ( { ' nzb_name ' : self . nzb_name ,
' nzb_folder ' : self . nzb_folder ,
' issueid ' : issueid ,
' failed ' : failed ,
' comicid ' : comicid ,
2019-01-16 22:09:51 +00:00
' apicall ' : True ,
' ddl ' : ddl } )
FIX:(#1905) Unicode errors when logging and system language is not a subset of english, IMP: Added post-processing queue (currently just for forceProcess api, but will be used by default for all post-processing actions soon), IMP: Multiple Torznab support added, IMP: Logging values for number of files and size/file added to config, IMP: Pushover notifications can be sent to specific device now, IMP: Added nzbget, newznab, nzb.su and dognzb test options, IMP: Added graphical checkmark/x when performing various tests (providers, downloaders, notifiers) within configuration, IMP: Removed some more unnecessary logging lines from searches
2018-04-06 17:46:39 +00:00
self . data = ' Successfully submitted request for post-processing for %s ' % self . nzb_name
#fp = process.Process(self.nzb_name, self.nzb_folder, issueid=issueid, failed=failed, comicid=comicid, apicall=True)
#self.data = fp.post_process()
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
else :
logger . info ( ' [API] Api Call from ComicRN detected - initiating script post-processing. ' )
fp = webserve . WebInterface ( )
self . data = fp . post_process ( self . nzb_name , self . nzb_folder , failed = failed , apc_version = kwargs [ ' apc_version ' ] , comicrn_version = kwargs [ ' comicrn_version ' ] )
self . comicrn = True
return
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getVersion ( self , * * kwargs ) :
2015-03-04 21:00:36 +00:00
self . data = {
2017-10-25 18:33:56 +00:00
' git_path ' : mylar . CONFIG . GIT_PATH ,
2015-05-14 23:12:48 +00:00
' install_type ' : mylar . INSTALL_TYPE ,
' current_version ' : mylar . CURRENT_VERSION ,
' latest_version ' : mylar . LATEST_VERSION ,
' commits_behind ' : mylar . COMMITS_BEHIND ,
2014-02-26 19:48:50 +00:00
}
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _checkGithub ( self , * * kwargs ) :
versioncheck . checkGithub ( )
self . _getVersion ( )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _shutdown ( self , * * kwargs ) :
mylar . SIGNAL = ' shutdown '
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _restart ( self , * * kwargs ) :
mylar . SIGNAL = ' restart '
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _update ( self , * * kwargs ) :
mylar . SIGNAL = ' update '
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getArtistArt ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
self . data = cache . getArtwork ( ComicID = self . id )
def _getIssueArt ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
self . data = cache . getArtwork ( IssueID = self . id )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getComicInfo ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
self . data = cache . getInfo ( ComicID = self . id )
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
def _getIssueInfo ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2014-02-26 19:48:50 +00:00
return
else :
self . id = kwargs [ ' id ' ]
2015-03-04 21:00:36 +00:00
2014-02-26 19:48:50 +00:00
self . data = cache . getInfo ( IssueID = self . id )
2015-03-04 21:00:36 +00:00
def _getArt ( self , * * kwargs ) :
if ' id ' not in kwargs :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing parameter: id ' )
2015-03-04 21:00:36 +00:00
return
else :
self . id = kwargs [ ' id ' ]
img = None
2017-10-25 18:33:56 +00:00
image_path = os . path . join ( mylar . CONFIG . CACHE_DIR , str ( self . id ) + ' .jpg ' )
2015-03-04 21:00:36 +00:00
# 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 :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Failed return a image ' )
2015-03-04 21:00:36 +00:00
else :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Failed to return a image ' )
2015-05-14 23:12:48 +00:00
def _findComic ( self , name , issue = None , type_ = None , mode = None , explisit = None , serinfo = None ) :
# set defaults
if type_ is None :
type_ = ' comic '
if mode is None :
mode = ' series '
# Dont do shit if name is missing
if len ( name ) == 0 :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Missing a Comic name ' )
2015-05-14 23:12:48 +00:00
return
if type_ == ' comic ' and mode == ' series ' :
searchresults , explisit = mb . findComic ( name , mode , issue = issue )
elif type_ == ' comic ' and mode == ' pullseries ' :
pass
elif type_ == ' comic ' and mode == ' want ' :
searchresults , explisit = mb . findComic ( name , mode , issue )
elif type_ == ' story_arc ' :
searchresults , explisit = mb . findComic ( name , mode , issue = None , explisit = ' explisit ' , type = ' story_arc ' )
searchresults = sorted ( searchresults , key = itemgetter ( ' comicyear ' , ' issues ' ) , reverse = True )
self . data = searchresults
2015-05-15 21:57:23 +00:00
def _downloadIssue ( self , id ) :
if not id :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' You need to provide a issueid ' )
2015-05-15 21:57:23 +00:00
return
self . id = id
# Fetch a list of dicts from issues table
i = self . _dic_from_query ( ' SELECT * from issues WHERE issueID= " ' + self . id + ' " ' )
2015-05-14 23:12:48 +00:00
2015-05-15 21:57:23 +00:00
if not len ( i ) :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' Couldnt find a issue with issueID %s ' % self . id )
2015-05-15 21:57:23 +00:00
return
# issueid is unique so it should one dict in the list
issue = i [ 0 ]
issuelocation = issue . get ( ' Location ' , None )
# Check the issue is downloaded
if issuelocation is not None :
# Find the comic location
comic = self . _dic_from_query ( ' SELECT * from comics WHERE comicID= " ' + issue [ ' ComicID ' ] + ' " ' ) [ 0 ]
comiclocation = comic . get ( ' ComicLocation ' )
f = os . path . join ( comiclocation , issuelocation )
if not os . path . isfile ( f ) :
2017-10-25 18:33:56 +00:00
if mylar . CONFIG . MULTIPLE_DEST_DIRS is not None and mylar . CONFIG . MULTIPLE_DEST_DIRS != ' None ' :
pathdir = os . path . join ( mylar . CONFIG . MULTIPLE_DEST_DIRS , os . path . basename ( comiclocation ) )
2015-05-15 21:57:23 +00:00
f = os . path . join ( pathdir , issuelocation )
self . file = f
self . filename = issuelocation
else :
self . file = f
self . filename = issuelocation
else :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' You need to download that issue first ' )
2015-05-15 21:57:23 +00:00
return
2015-06-07 01:44:46 +00:00
def _downloadNZB ( self , nzbname ) :
if not nzbname :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' You need to provide a nzbname ' )
2015-06-07 01:44:46 +00:00
return
self . nzbname = nzbname
2017-10-25 18:33:56 +00:00
f = os . path . join ( mylar . CONFIG . CACHE_DIR , nzbname )
2015-06-07 01:44:46 +00:00
if os . path . isfile ( f ) :
self . file = f
self . filename = nzbname
else :
2016-11-06 14:54:39 +00:00
self . data = self . _error_with_message ( ' NZBname does not exist within the cache directory. Unable to retrieve. ' )
2015-06-07 01:44:46 +00:00
return
2017-12-31 02:10:22 +00:00
def _getStoryArc ( self , * * kwargs ) :
if not ' id ' in kwargs :
if ' customOnly ' in kwargs and kwargs [ ' customOnly ' ] :
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
self . data = self . _dic_from_query ( ' SELECT StoryArcID, StoryArc, MAX(ReadingOrder) AS HighestOrder from storyarcs WHERE StoryArcID LIKE " C % " GROUP BY StoryArcID ORDER BY StoryArc ' )
2017-12-31 02:10:22 +00:00
else :
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
self . data = self . _dic_from_query ( ' SELECT StoryArcID, StoryArc, MAX(ReadingOrder) AS HighestOrder from storyarcs GROUP BY StoryArcID ORDER BY StoryArc ' )
2017-12-31 02:10:22 +00:00
else :
self . id = kwargs [ ' id ' ]
self . data = self . _dic_from_query ( ' SELECT StoryArc, ReadingOrder, ComicID, ComicName, IssueNumber, IssueID, \
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
IssueDate , IssueName , IssuePublisher from storyarcs WHERE StoryArcID = " ' + self.id + ' " ORDER BY ReadingOrder ' )
2017-12-31 02:10:22 +00:00
return
def _addStoryArc ( self , * * kwargs ) :
issuecount = 0
if not ' id ' in kwargs :
self . id = ' C %04d ' % random . randint ( 1 , 9999 )
if not ' storyarcname ' in kwargs :
self . data = self . _error_with_message ( ' You need to provide either id or storyarcname ' )
return
else :
storyarcname = kwargs . pop ( ' storyarcname ' )
else :
self . id = kwargs . pop ( ' id ' )
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
arc = self . _dic_from_query ( ' SELECT * from storyarcs WHERE StoryArcID= " ' + self . id + ' " ORDER by ReadingOrder ' )
2017-12-31 02:10:22 +00:00
storyarcname = arc [ 0 ] [ ' StoryArc ' ]
issuecount = len ( arc )
if not ' issues ' in kwargs and not ' arclist ' in kwargs :
self . data = self . _error_with_message ( ' No issues specified ' )
return
else :
arclist = " "
if ' issues ' in kwargs :
issuelist = kwargs . pop ( ' issues ' ) . split ( " , " )
index = 0
for issue in issuelist :
arclist + = " %s , %s " % ( issue , issuecount + 1 )
index + = 1
issuecount + = 1
if index < len ( issuelist ) :
arclist + = " | "
if ' arclist ' in kwargs :
cvlist = kwargs . pop ( ' arclist ' )
2017-12-31 02:26:04 +00:00
issuelist = cvlist . split ( " | " )
2017-12-31 02:10:22 +00:00
index = 0
for issue in issuelist :
arclist + = " %s , %s " % ( issue . split ( " , " ) [ 0 ] , issuecount + 1 )
index + = 1
issuecount + = 1
if index < len ( issuelist ) :
arclist + = " | "
wi = webserve . WebInterface ( )
logger . info ( " arclist: %s - arcid: %s - storyarcname: %s - storyarcissues: %s " % ( arclist , self . id , storyarcname , issuecount ) )
wi . addStoryArc_thread ( arcid = self . id , storyarcname = storyarcname , storyarcissues = issuecount , arclist = arclist , * * kwargs )
IMP: Added Choose specific Download option to manually select from result list on Upcoming/Details/Weekly tabs, IMP: Added Wanted storyarcs to the overall Wanted section so now will search as per global options (storyarc issues can be displayed optionally on Wanted tab), IMP: Added custom url option for image banners/posters for storyarcs, IMP: updated Cherrypy, FIX: Fixed ComicRN not working when forms authentication used - in conjunction updated autoProcessComics to 2.0 which now uses apikey instead of user/pass, IMP: Alternate Series Covers option for alternating existing series image to the most current issue image, IMP: Added overall series total to series page for reference, IMP: Search workflow completely changed to accomodate more than one indexer - now will simultaneously sumbit initial request to each provider, wait 30s submit additional as required at 30s intervals, FIX: Removed TPSE as an option and relabelled to just Public Torrents, IMP: Added direct backlog search to WWT option (pack support will follow), FIX: Removed line about configparser being required for ComicTagger usage, IMP: Test code in place for newzab testing, FIX: Fixed layout problem with torrents that are in auto-snatch status on weekly tab, IMP: backend code improvements to allow for better alias usage and annual linking directly from WS, IMP: Updated systemd init-scripts with read.me, IMP: When post-processing, will now check for available destination free space before actually moving files, IMP: Will copy during metatagging to cache folder instead of move being an option so cleanup is cleaner if something fails, FIX: Changed readinglist table to storyarcs for clarity, IMP: When post-processing issues, will now only update the one issue status and adjust totals accordingly (instead of doing a complete rescan of the series), FIX: Clear out empty ID's from the Failed DB on startup, IMP: Initial code-run at REST API interface, FIX: Fixed some matching problems with 32p due to case, IMP: removed apikeys from log entries that were accidentally logging, IMP: When searching 32p, if items get packed up - will now delete the cached reference so new items of the same can be located, IMP: ForceSearch option switched to scheduler so simultaneous runs should not occur, FIX: Fixed manual metatagging error that would occur if multiple destination directories existed
2018-02-16 19:57:01 +00:00
return
class REST ( object ) :
def __init__ ( self ) :
pass
class verify_api ( object ) :
def __init__ ( self ) :
pass
def validate ( self ) :
logger . info ( ' attempting to validate... ' )
req = cherrypy . request . headers
logger . info ( ' thekey: %s ' % req )
logger . info ( ' url: %s ' % cherrypy . url ( ) )
logger . info ( ' mylar.apikey: %s [ %s ] ' % ( mylar . CONFIG . API_KEY , type ( mylar . CONFIG . API_KEY ) ) )
logger . info ( ' submitted.apikey: %s [ %s ] ' % ( req [ ' Api-Key ' ] , type ( req [ ' Api-Key ' ] ) ) )
if ' Api-Key ' not in req or req [ ' Api-Key ' ] != str ( mylar . CONFIG . API_KEY ) : #str(mylar.API_KEY) or mylar.API_KEY not in cherrypy.url():
logger . info ( ' wrong APIKEY ' )
return ' api-key provided was either not present in auth header, or was incorrect. '
else :
return True
class Watchlist ( object ) :
exposed = True
def __init__ ( self ) :
pass
def GET ( self ) :
va = REST . verify_api ( )
vchk = va . validate ( )
if vchk is not True :
return ( ' api-key provided was either not present in auth header, or was incorrect. ' )
#rows_as_dic = []
#for row in rows:
# row_as_dic = dict(zip(row.keys(), row))
# rows_as_dic.append(row_as_dic)
#return rows_as_dic
some = helpers . havetotals ( )
return simplejson . dumps ( some )
class Comics ( object ) :
exposed = True
def __init__ ( self ) :
pass
def _dic_from_query ( self , query ) :
myDB = db . DBConnection ( )
rows = myDB . select ( query )
rows_as_dic = [ ]
for row in rows :
row_as_dic = dict ( zip ( row . keys ( ) , row ) )
rows_as_dic . append ( row_as_dic )
return rows_as_dic
def GET ( self ) :
va = REST . verify_api ( )
vchk = va . validate ( )
if vchk is not True :
return ( ' api-key provided was either not present in auth header, or was incorrect. ' )
#req = cherrypy.request.headers
#logger.info('thekey: %s' % req)
#if 'api-key' not in req or req['api-key'] != 'hello':
# logger.info('wrong APIKEY')
# return('api-key provided was either not present in auth header, or was incorrect.')
self . comics = self . _dic_from_query ( ' SELECT * from comics order by ComicSortName COLLATE NOCASE ' )
return ( ' Here are all the comics we have: %s ' % self . comics )
@cherrypy.popargs ( ' comic_id ' , ' issuemode ' , ' issue_id ' )
class Comic ( object ) :
exposed = True
def __init__ ( self ) :
pass
def _dic_from_query ( self , query ) :
myDB = db . DBConnection ( )
rows = myDB . select ( query )
rows_as_dic = [ ]
for row in rows :
row_as_dic = dict ( zip ( row . keys ( ) , row ) )
rows_as_dic . append ( row_as_dic )
return rows_as_dic
def GET ( self , comic_id = None , issuemode = None , issue_id = None ) :
va = REST . verify_api ( )
vchk = va . validate ( )
if vchk is not True :
return ( ' api-key provided was either not present in auth header, or was incorrect. ' )
#req = cherrypy.request.headers
#logger.info('thekey: %s' % req)
#if 'api-key' not in req or req['api-key'] != 'hello':
# logger.info('wrong APIKEY')
# return('api-key provided was either not present in auth header, or was incorrect.')
self . comics = self . _dic_from_query ( ' SELECT * from comics order by ComicSortName COLLATE NOCASE ' )
if comic_id is None :
return ( ' No valid ComicID entered ' )
else :
if issuemode is None :
match = [ c for c in self . comics if comic_id == c [ ' ComicID ' ] ]
if match :
return json . dumps ( match , ensure_ascii = False )
else :
return ( ' No Comic with the ID %s :-( ' % comic_id )
elif issuemode == ' issues ' :
self . issues = self . _dic_from_query ( ' SELECT * from issues where comicid= " ' + comic_id + ' " ' )
return json . dumps ( self . issues , ensure_ascii = False )
elif issuemode == ' issue ' and issue_id is not None :
self . issues = self . _dic_from_query ( ' SELECT * from issues where comicid= " ' + comic_id + ' " and issueid= " ' + issue_id + ' " ' )
return json . dumps ( self . issues , ensure_ascii = False )
else :
return ( ' Nothing to do. ' )