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
|
2021-10-26 19:23:45 +00:00
|
|
|
from voussoirkit import stringtools
|
2021-06-05 04:50:09 +00:00
|
|
|
|
2020-05-22 03:04:02 +00:00
|
|
|
import ycdl
|
|
|
|
|
|
|
|
from .. import common
|
|
|
|
|
|
|
|
site = common.site
|
|
|
|
|
2021-10-26 18:57:55 +00:00
|
|
|
@flasktools.required_fields(['video_ids', 'state'], forbid_whitespace=True)
|
2020-05-22 03:04:02 +00:00
|
|
|
@site.route('/mark_video_state', methods=['POST'])
|
|
|
|
def post_mark_video_state():
|
|
|
|
video_ids = request.form['video_ids']
|
2021-10-26 19:23:45 +00:00
|
|
|
video_ids = stringtools.comma_space_split(video_ids)
|
2020-05-22 03:04:02 +00:00
|
|
|
state = request.form['state']
|
|
|
|
|
2021-10-26 19:23:45 +00:00
|
|
|
try:
|
|
|
|
videos = [common.ycdldb.get_video(id) for id in video_ids]
|
2021-10-26 19:18:55 +00:00
|
|
|
except ycdl.exceptions.NoSuchVideo as exc:
|
|
|
|
return flasktools.json_response(exc.jsonify(), status=404)
|
2020-05-22 03:04:02 +00:00
|
|
|
|
2021-10-26 19:23:45 +00:00
|
|
|
try:
|
2022-07-16 05:30:06 +00:00
|
|
|
with common.ycdldb.transaction:
|
|
|
|
for video in videos:
|
|
|
|
video.mark_state(state)
|
2021-10-26 19:18:55 +00:00
|
|
|
except ycdl.exceptions.InvalidVideoState as exc:
|
2020-05-22 03:04:02 +00:00
|
|
|
common.ycdldb.rollback()
|
2021-10-26 19:18:55 +00:00
|
|
|
return flasktools.json_response(exc.jsonify(), status=400)
|
2020-05-22 03:04:02 +00:00
|
|
|
|
2021-10-02 06:04:41 +00:00
|
|
|
return flasktools.json_response({'video_ids': video_ids, 'state': state})
|
2020-05-22 03:04:02 +00:00
|
|
|
|
2021-10-26 18:57:55 +00:00
|
|
|
@flasktools.required_fields(['video_ids'], forbid_whitespace=True)
|
2020-05-22 03:04:02 +00:00
|
|
|
@site.route('/start_download', methods=['POST'])
|
|
|
|
def post_start_download():
|
|
|
|
video_ids = request.form['video_ids']
|
2021-10-26 19:23:45 +00:00
|
|
|
video_ids = stringtools.comma_space_split(video_ids)
|
|
|
|
|
2020-05-22 03:04:02 +00:00
|
|
|
try:
|
2021-10-26 19:23:45 +00:00
|
|
|
videos = [common.ycdldb.get_video(id) for id in video_ids]
|
|
|
|
except ycdl.exceptions.NoSuchVideo as exc:
|
|
|
|
return flasktools.json_response(exc.jsonify(), status=404)
|
2020-05-22 03:04:02 +00:00
|
|
|
|
2022-07-16 05:30:06 +00:00
|
|
|
with common.ycdldb.transaction:
|
|
|
|
for video in videos:
|
|
|
|
common.ycdldb.download_video(video)
|
2020-05-22 03:04:02 +00:00
|
|
|
|
2021-10-02 06:04:41 +00:00
|
|
|
return flasktools.json_response({'video_ids': video_ids, 'state': 'downloaded'})
|