Add interface for setting automark state.

This commit is contained in:
voussoir 2020-05-21 17:28:34 -07:00
parent 0c5823cbeb
commit 57d87560a4
4 changed files with 51 additions and 1 deletions

View file

@ -132,6 +132,18 @@ def post_refresh_channel():
channel.refresh(force=force)
return jsonify.make_json_response({})
@site.route('/channel/<channel_id>/set_automark', methods=['POST'])
def post_set_automark(channel_id):
state = request.form['state']
channel = common.ycdldb.get_channel(channel_id)
try:
channel.set_automark(state)
except exceptions.InvalidVideoState:
flask.abort(400)
return jsonify.make_json_response({})
@site.route('/start_download', methods=['POST'])
def post_start_download():
if 'video_ids' not in request.form:

View file

@ -172,6 +172,19 @@ https://stackoverflow.com/a/35153397
<p><!-- spacer --></p>
{% if channel is not none %}
<span>
New videos are:
<select onchange="set_automark_hook(event)">
<option value="pending" {{"selected" if channel.automark == "pending" else ""}} >pending</option>
<option value="downloaded" {{"selected" if channel.automark == "downloaded" else ""}} >downloaded</option>
<option value="ignored" {{"selected" if channel.automark == "ignored" else ""}} >ignored</option>
</select>
</span>
{% endif %}
<p><!-- spacer --></p>
<span>Sort by
<a class="merge_params" href="?orderby=published">Date</a>,
<a class="merge_params" href="?orderby=duration">Duration</a>,
@ -477,6 +490,15 @@ function refresh_channel(channel_id, force, callback)
return common.post(url, data, callback);
}
function set_automark_hook(event)
{
console.log("What");
var url = "/channel/{{channel.id}}/set_automark";
data = new FormData();
data.append("state", event.target.value);
return common.post(url, data);
}
function mark_video_state(video_ids, state, callback)
{
var url = "/mark_video_state";

View file

@ -50,6 +50,8 @@ DEFAULT_DATADIR = '.'
DEFAULT_DBNAME = 'ycdl.db'
DEFAULT_CONFIGNAME = 'ycdl.json'
VIDEO_STATES = ['ignored', 'pending', 'downloaded']
DEFAULT_CONFIGURATION = {
'download_directory': '.',
}

View file

@ -55,6 +55,20 @@ class Channel(Base):
if commit:
self.ycdldb.commit()
def set_automark(self, state, commit=True):
if state not in constants.VIDEO_STATES:
raise exceptions.InvalidVideoState(state)
pairs = {
'id': self.id,
'automark': state,
}
self.ycdldb.sql_update(table='channels', pairs=pairs, where_key='id')
self.automark = state
if commit:
self.ycdldb.commit()
class Video(Base):
table = 'videos'
@ -83,7 +97,7 @@ class Video(Base):
'''
Mark the video as ignored, pending, or downloaded.
'''
if state not in ['ignored', 'pending', 'downloaded']:
if state not in constants.VIDEO_STATES:
raise exceptions.InvalidVideoState(state)
pairs = {