diff --git a/couchpotato/__init__.py b/couchpotato/__init__.py index 8386ed9f1695af8c8bb63cfac8d20187c689ad0e..8482160e6b438223cbbba1b51191bae30ad16fda 100644 --- a/couchpotato/__init__.py +++ b/couchpotato/__init__.py @@ -15,6 +15,7 @@ from sqlalchemy.orm import scoped_session from sqlalchemy.orm.session import sessionmaker from werkzeug.utils import redirect import os +import time log = CPLog(__name__) @@ -73,5 +74,10 @@ def getApiKey(): def page_not_found(error): index_url = url_for('web.index') url = getattr(request, 'path')[len(index_url):] - return redirect(index_url + '#' + url) + + if url[:3] != 'api': + return redirect(index_url + '#' + url) + else: + time.sleep(2) + return 'Wrong API key used', 404 diff --git a/couchpotato/api.py b/couchpotato/api.py index 71cf9b87337db5d58fc6bb0accce4523b3deddf5..934fa94aab2c47aefd4018809e6801db828c374a 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -1,6 +1,5 @@ from flask.blueprints import Blueprint from flask.helpers import url_for -from flask.templating import render_template from werkzeug.utils import redirect api = Blueprint('api', __name__) diff --git a/couchpotato/core/_base/_core/main.py b/couchpotato/core/_base/_core/main.py index 81ed944942ec2818334667cf67cb75cf9cdd4c5a..81ccac24daa6835a35aadf526cec755dba70983f 100644 --- a/couchpotato/core/_base/_core/main.py +++ b/couchpotato/core/_base/_core/main.py @@ -165,7 +165,7 @@ class Core(Plugin): return '%s:%d%s' % (cleanHost(host).rstrip('/'), int(port), '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else '') def createApiUrl(self): - return '%s/%s' % (self.createBaseUrl(), Env.setting('api_key')) + return '%s/api/%s' % (self.createBaseUrl(), Env.setting('api_key')) def version(self): ver = fireEvent('updater.info', single = True) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 035ccab1b065de838d77580290aa9082c57b60bb..d91fc6c71b80b25e676708dc39a838545bc284bc 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -55,7 +55,7 @@ class Plugin(object): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', self.__class__.__name__) class_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() - path = '%s/static/%s/' % (Env.setting('api_key'), class_name) + path = 'api/%s/static/%s/' % (Env.setting('api_key'), class_name) addView(path + '<path:filename>', self.showStatic, static = True) if add_to_head: diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index e18d000db8558dabe12ce2747f75cd01ab946fc1..62dfac2aa8286e55520640a56231c22ad07761d5 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -79,6 +79,7 @@ class MoviePlugin(Plugin): 'desc': 'Delete a movie from the wanted list', 'params': { 'id': {'desc': 'Movie ID(s) you want to delete.', 'type': 'int (comma separated)'}, + 'delete_from': {'desc': 'Delete movie from this page', 'type': 'string: all (default), wanted, manage'}, } }) @@ -358,20 +359,45 @@ class MoviePlugin(Plugin): ids = [x.strip() for x in params.get('id').split(',')] for movie_id in ids: - self.delete(movie_id) + self.delete(movie_id, delete_from = params.get('delete_from', 'all')) return jsonified({ 'success': True, }) - def delete(self, movie_id): + def delete(self, movie_id, delete_from = None): db = get_session() movie = db.query(Movie).filter_by(id = movie_id).first() if movie: - db.delete(movie) - db.commit() + if delete_from == 'all': + db.delete(movie) + db.commit() + else: + done_status = fireEvent('status.get', 'done', single = True) + + total_releases = len(movie.releases) + total_deleted = 0 + new_movie_status = None + for release in movie.releases: + if delete_from == 'wanted' and release.status_id != done_status.get('id'): + db.delete(release) + total_deleted += 1 + new_movie_status = 'done' + elif delete_from == 'manage' and release.status_id == done_status.get('id'): + db.delete(release) + total_deleted += 1 + new_movie_status = 'active' + db.commit() + + if total_releases == total_deleted: + db.delete(movie) + db.commit() + elif new_movie_status: + new_status = fireEvent('status.get', new_movie_status, single = True) + movie.status_id = new_status.get('id') + db.commit() return True diff --git a/couchpotato/core/plugins/movie/static/list.js b/couchpotato/core/plugins/movie/static/list.js index d70db1f540f8f3947195f594b02fca315b9cbdbd..becdc141c9f78d0048f3f7fbd067c5784946dd93 100644 --- a/couchpotato/core/plugins/movie/static/list.js +++ b/couchpotato/core/plugins/movie/static/list.js @@ -253,7 +253,8 @@ var MovieList = new Class({ (e).preventDefault(); Api.request('movie.delete', { 'data': { - 'id': ids.join(',') + 'id': ids.join(','), + 'delete_from': self.options.identifier }, 'onSuccess': function(){ qObj.close(); @@ -381,6 +382,8 @@ var MovieList = new Class({ update: function(){ var self = this; + self.reset(); + self.movie_list.empty(); self.getMovies(); }, diff --git a/couchpotato/core/plugins/movie/static/movie.js b/couchpotato/core/plugins/movie/static/movie.js index 5544ed4e167a913e62e91bd0825353d0cddaa2af..78e00fd0b19056997b7ea07f12dff72aeb26fb24 100644 --- a/couchpotato/core/plugins/movie/static/movie.js +++ b/couchpotato/core/plugins/movie/static/movie.js @@ -4,11 +4,12 @@ var Movie = new Class({ action: {}, - initialize: function(self, options, data){ + initialize: function(list, options, data){ var self = this; self.data = data; self.view = options.view || 'thumbs'; + self.list = list; self.profile = Quality.getProfile(data.profile_id) || {}; self.parent(self, options); diff --git a/couchpotato/core/plugins/movie/static/search.js b/couchpotato/core/plugins/movie/static/search.js index 10381b56f30b5643ca8ec01ec109b13175efa71e..8d6b2af7693833c466ca87f40a9c5a28984f6030 100644 --- a/couchpotato/core/plugins/movie/static/search.js +++ b/couchpotato/core/plugins/movie/static/search.js @@ -326,9 +326,9 @@ Block.Search.Item = new Class({ 'src': self.info.images.poster[0] }) : null, self.info.in_wanted ? new Element('span.in_wanted', { - 'text': 'Already in wanted list: ' + self.info.in_wanted.label + 'text': 'Already in wanted list: ' + self.info.in_wanted.profile.label }) : (self.info.in_library ? new Element('span.in_library', { - 'text': 'Already in library: ' + self.info.in_library.label + 'text': 'Already in library: ' + self.info.in_library.profile.label }) : null), self.title_select = new Element('select', { 'name': 'title' diff --git a/couchpotato/core/providers/movie/_modifier/main.py b/couchpotato/core/providers/movie/_modifier/main.py index f131adf78286858ec5786a7b42fcf360a8dcfdc5..527c7b98893fa79b6154c57343b8c79cdf726de3 100644 --- a/couchpotato/core/providers/movie/_modifier/main.py +++ b/couchpotato/core/providers/movie/_modifier/main.py @@ -55,11 +55,11 @@ class MovieResultModifier(Plugin): for movie in l.movies: if movie.status_id == active_status['id']: - temp['in_wanted'] = movie.profile.to_dict() + temp['in_wanted'] = fireEvent('movie.get', movie.id, single = True) for release in movie.releases: if release.status_id == done_status['id']: - temp['in_library'] = release.quality.to_dict() + temp['in_library'] = fireEvent('movie.get', movie.id, single = True) except: log.error('Tried getting more info on searched movies: %s' % traceback.format_exc()) diff --git a/couchpotato/runner.py b/couchpotato/runner.py index 66d9d7d03dfb8de5d6c5b52bcce8146836cf334a..0be3bdbc2c44fb1f1f8e9c0edca1fef9388cd118 100644 --- a/couchpotato/runner.py +++ b/couchpotato/runner.py @@ -172,13 +172,13 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En # Static path app.static_folder = os.path.join(base_path, 'couchpotato', 'static') - web.add_url_rule('%s/static/<path:filename>' % api_key, + web.add_url_rule('api/%s/static/<path:filename>' % api_key, endpoint = 'static', view_func = app.send_static_file) # Register modules app.register_blueprint(web, url_prefix = '%s/' % url_base) - app.register_blueprint(api, url_prefix = '%s/%s/' % (url_base, api_key)) + app.register_blueprint(api, url_prefix = '%s/api/%s/' % (url_base, api_key)) # Some logging and fire load event try: log.info('Starting server on port %(port)s' % config) diff --git a/couchpotato/static/scripts/page/wanted.js b/couchpotato/static/scripts/page/wanted.js index af6d774ca33e7135852184cb372884d77c185791..ef7ddc883b09c51bf3b785c7dff66f5c6df4fc6f 100644 --- a/couchpotato/static/scripts/page/wanted.js +++ b/couchpotato/static/scripts/page/wanted.js @@ -206,7 +206,8 @@ window.addEvent('domready', function(){ function(){ Api.request('movie.delete', { 'data': { - 'id': self.movie.get('id') + 'id': self.movie.get('id'), + 'delete_from': self.movie.list.options.identifier }, 'onComplete': function(){ movie.set('tween', { diff --git a/couchpotato/templates/api.html b/couchpotato/templates/api.html index f0e76e36228bda43d04f61e26c0f34fe3a9bbfe5..45d20f1547f989f5092ff62173624775f6ded943 100644 --- a/couchpotato/templates/api.html +++ b/couchpotato/templates/api.html @@ -21,7 +21,7 @@ <br /> <br /> Get the API key: - <pre><a href="/getkey/?p=md5(password)&u=md5(username)">/getkey/?p=md5(password)&u=md5(username)</a></pre> + <pre><a href="{{ url_for('web.index') }}getkey/?p=md5(password)&u=md5(username)">{{ url_for('web.index') }}getkey/?p=md5(password)&u=md5(username)</a></pre> Will return {"api_key": "XXXXXXXXXX", "success": true}. When username or password is empty you don't need to md5 it. <br /> </div>