2020-05-22 03:04:02 +00:00
|
|
|
import flask; from flask import request
|
|
|
|
|
2021-06-05 04:50:09 +00:00
|
|
|
from voussoirkit import flasktools
|
|
|
|
|
2020-05-22 03:04:02 +00:00
|
|
|
import ycdl
|
|
|
|
|
|
|
|
from .. import common
|
|
|
|
|
|
|
|
site = common.site
|
|
|
|
|
|
|
|
@site.route('/mark_video_state', methods=['POST'])
|
|
|
|
def post_mark_video_state():
|
|
|
|
if 'video_ids' not in request.form or 'state' not in request.form:
|
|
|
|
flask.abort(400)
|
|
|
|
video_ids = request.form['video_ids']
|
|
|
|
state = request.form['state']
|
|
|
|
try:
|
|
|
|
video_ids = video_ids.split(',')
|
|
|
|
for video_id in video_ids:
|
|
|
|
video = common.ycdldb.get_video(video_id)
|
|
|
|
video.mark_state(state, commit=False)
|
|
|
|
common.ycdldb.sql.commit()
|
|
|
|
|
|
|
|
except ycdl.exceptions.NoSuchVideo:
|
|
|
|
common.ycdldb.rollback()
|
|
|
|
flask.abort(404)
|
|
|
|
|
|
|
|
except ycdl.exceptions.InvalidVideoState:
|
|
|
|
common.ycdldb.rollback()
|
|
|
|
flask.abort(400)
|
|
|
|
|
2021-06-05 04:50:09 +00:00
|
|
|
return flasktools.make_json_response({'video_ids': video_ids, 'state': state})
|
2020-05-22 03:04:02 +00:00
|
|
|
|
|
|
|
@site.route('/start_download', methods=['POST'])
|
|
|
|
def post_start_download():
|
|
|
|
if 'video_ids' not in request.form:
|
|
|
|
flask.abort(400)
|
|
|
|
video_ids = request.form['video_ids']
|
|
|
|
try:
|
|
|
|
video_ids = video_ids.split(',')
|
|
|
|
for video_id in video_ids:
|
|
|
|
common.ycdldb.download_video(video_id, commit=False)
|
|
|
|
common.ycdldb.sql.commit()
|
|
|
|
|
|
|
|
except ycdl.ytapi.VideoNotFound:
|
|
|
|
common.ycdldb.rollback()
|
|
|
|
flask.abort(404)
|
|
|
|
|
2021-06-05 04:50:09 +00:00
|
|
|
return flasktools.make_json_response({'video_ids': video_ids, 'state': 'downloaded'})
|