Move jsonify methods to the objects instead of separate file.
This commit is contained in:
parent
65fdae97da
commit
9c5fb4fec1
5 changed files with 34 additions and 34 deletions
|
@ -89,14 +89,14 @@ def post_add_channel():
|
||||||
return jsonify.make_json_response({}, status=404)
|
return jsonify.make_json_response({}, status=404)
|
||||||
|
|
||||||
channel = common.ycdldb.add_channel(channel_id, get_videos=True)
|
channel = common.ycdldb.add_channel(channel_id, get_videos=True)
|
||||||
return jsonify.make_json_response(ycdl.jsonify.channel(channel))
|
return jsonify.make_json_response(channel.jsonify())
|
||||||
|
|
||||||
@site.route('/channel/<channel_id>/delete', methods=['POST'])
|
@site.route('/channel/<channel_id>/delete', methods=['POST'])
|
||||||
def post_delete_channel(channel_id):
|
def post_delete_channel(channel_id):
|
||||||
try:
|
try:
|
||||||
channel = common.ycdldb.get_channel(channel_id)
|
channel = common.ycdldb.get_channel(channel_id)
|
||||||
except ycdl.exceptions.NoSuchChannel as exc:
|
except ycdl.exceptions.NoSuchChannel as exc:
|
||||||
return jsonify.make_json_response(ycdl.jsonify.exception(exc), status=404)
|
return jsonify.make_json_response(exc.jsonify(), status=404)
|
||||||
|
|
||||||
channel.delete()
|
channel.delete()
|
||||||
return jsonify.make_json_response({})
|
return jsonify.make_json_response({})
|
||||||
|
@ -108,10 +108,10 @@ def post_refresh_channel(channel_id):
|
||||||
try:
|
try:
|
||||||
channel = common.ycdldb.get_channel(channel_id)
|
channel = common.ycdldb.get_channel(channel_id)
|
||||||
except ycdl.exceptions.NoSuchChannel as exc:
|
except ycdl.exceptions.NoSuchChannel as exc:
|
||||||
return jsonify.make_json_response(ycdl.jsonify.exception(exc), status=404)
|
return jsonify.make_json_response(exc.jsonify(), status=404)
|
||||||
|
|
||||||
channel.refresh(force=force)
|
channel.refresh(force=force)
|
||||||
return jsonify.make_json_response(ycdl.jsonify.channel(channel))
|
return jsonify.make_json_response(channel.jsonify())
|
||||||
|
|
||||||
@site.route('/refresh_all_channels', methods=['POST'])
|
@site.route('/refresh_all_channels', methods=['POST'])
|
||||||
def post_refresh_all_channels():
|
def post_refresh_all_channels():
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
from . import helpers
|
from . import helpers
|
||||||
from . import jsonify
|
|
||||||
from . import ycdldb
|
from . import ycdldb
|
||||||
from . import ytapi
|
from . import ytapi
|
||||||
|
|
|
@ -35,6 +35,14 @@ class YCDLException(Exception, metaclass=ErrorTypeAdder):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.error_type + '\n' + self.error_message
|
return self.error_type + '\n' + self.error_message
|
||||||
|
|
||||||
|
def jsonify(self):
|
||||||
|
j = {
|
||||||
|
'type': 'error',
|
||||||
|
'error_type': self.error_type,
|
||||||
|
'error_message': self.error_message,
|
||||||
|
}
|
||||||
|
return j
|
||||||
|
|
||||||
# NO SUCH ##########################################################################################
|
# NO SUCH ##########################################################################################
|
||||||
|
|
||||||
class NoSuchChannel(YCDLException):
|
class NoSuchChannel(YCDLException):
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
def channel(c):
|
|
||||||
j = {
|
|
||||||
'id': c.id,
|
|
||||||
'name': c.name,
|
|
||||||
'automark': c.automark,
|
|
||||||
}
|
|
||||||
return j
|
|
||||||
|
|
||||||
def exception(e):
|
|
||||||
j = {
|
|
||||||
'type': 'error',
|
|
||||||
'error_type': e.error_type,
|
|
||||||
'error_message': e.error_message,
|
|
||||||
}
|
|
||||||
return j
|
|
||||||
|
|
||||||
def video(v):
|
|
||||||
j = {
|
|
||||||
'id': v.id,
|
|
||||||
'published': v.published,
|
|
||||||
'author_id': v.author_id,
|
|
||||||
'title': v.title,
|
|
||||||
'description': v.description,
|
|
||||||
'duration': v.duration,
|
|
||||||
'views': v.views,
|
|
||||||
'thumbnail': v.thumbnail,
|
|
||||||
'state': v.state,
|
|
||||||
}
|
|
||||||
return j
|
|
|
@ -60,6 +60,14 @@ class Channel(Base):
|
||||||
bindings = [self.id]
|
bindings = [self.id]
|
||||||
return self.ycdldb.sql_select_one(query, bindings) is not None
|
return self.ycdldb.sql_select_one(query, bindings) is not None
|
||||||
|
|
||||||
|
def jsonify(self):
|
||||||
|
j = {
|
||||||
|
'id': self.id,
|
||||||
|
'name': self.name,
|
||||||
|
'automark': self.automark,
|
||||||
|
}
|
||||||
|
return j
|
||||||
|
|
||||||
def refresh(self, *, force=False, rss_assisted=True, commit=True):
|
def refresh(self, *, force=False, rss_assisted=True, commit=True):
|
||||||
self.ycdldb.log.info('Refreshing %s.', self.id)
|
self.ycdldb.log.info('Refreshing %s.', self.id)
|
||||||
|
|
||||||
|
@ -181,6 +189,20 @@ class Video(Base):
|
||||||
if commit:
|
if commit:
|
||||||
self.ycdldb.commit()
|
self.ycdldb.commit()
|
||||||
|
|
||||||
|
def jsonify(self):
|
||||||
|
j = {
|
||||||
|
'id': self.id,
|
||||||
|
'published': self.published,
|
||||||
|
'author_id': self.author_id,
|
||||||
|
'title': self.title,
|
||||||
|
'description': self.description,
|
||||||
|
'duration': self.duration,
|
||||||
|
'views': self.views,
|
||||||
|
'thumbnail': self.thumbnail,
|
||||||
|
'state': self.state,
|
||||||
|
}
|
||||||
|
return j
|
||||||
|
|
||||||
def mark_state(self, state, commit=True):
|
def mark_state(self, state, commit=True):
|
||||||
'''
|
'''
|
||||||
Mark the video as ignored, pending, or downloaded.
|
Mark the video as ignored, pending, or downloaded.
|
||||||
|
|
Loading…
Reference in a new issue