Add an alternate manual upload mode specifically for youtube

Adds a built-in "youtube-manual" location which is like "manual" except that it only works
with youtube URLs and populates the video_id column.

The intent is so that we can have playlist_manager manage videos we upload manually,
while still being able to distinguish between that and other manual links that shouldn't
be included (eg. links to third party youtube videos).

This is set when setting a manual link in thrimbletrimmer with a new checkbox, default off.
pull/207/head
Mike Lang 4 years ago committed by Mike Lang
parent ad03a087ab
commit f8c877775d

@ -119,7 +119,7 @@
</div> </div>
<div id="ManualLinkPane" style="display:none"> <div id="ManualLinkPane" style="display:none">
<input id="ManualLink" /> <input type="button" id="ManualButton" onclick="thrimbletrimmerManualLink()" value="Set Link" /> <input id="ManualLink" /> <input type="button" id="ManualButton" onclick="thrimbletrimmerManualLink()" value="Set Link" />
</div> Is Youtube Upload (add to playlists)? <input id="ManualYoutube" type="checkbox" />
<div id="HelpPane" style="display:none;"> <div id="HelpPane" style="display:none;">
<ul> <ul>
<li>J/K/L - Back 10 seconds, Play/Pause, Advance 10 seconds</li> <li>J/K/L - Back 10 seconds, Play/Pause, Advance 10 seconds</li>

@ -340,7 +340,8 @@ thrimbletrimmerDownload = function(isEditor) {
thrimbletrimmerManualLink = function() { thrimbletrimmerManualLink = function() {
document.getElementById("ManualButton").disabled = true; document.getElementById("ManualButton").disabled = true;
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
var body = {link: document.getElementById("ManualLink").value}; var upload_location = (document.getElementById("ManualYoutube").checked) ? "youtube-manual" : "manual";
var body = {link: document.getElementById("ManualLink").value, upload_location: upload_location};
if (!!user) { if (!!user) {
body.token = user.getAuthResponse().id_token; body.token = user.getAuthResponse().id_token;
} }

@ -2,6 +2,7 @@ import datetime
from functools import wraps from functools import wraps
import json import json
import logging import logging
import re
import signal import signal
import sys import sys
@ -303,25 +304,39 @@ def update_row(ident, editor=None):
@authenticate @authenticate
def manual_link(ident, editor=None): def manual_link(ident, editor=None):
"""Manually set a video_link if the state is 'UNEDITED' or 'DONE' and the """Manually set a video_link if the state is 'UNEDITED' or 'DONE' and the
upload_location is 'manual'.""" upload_location is 'manual' or 'youtube-manual'."""
link = flask.request.json['link'] link = flask.request.json['link']
upload_location = flask.request.json.get('upload_location', 'manual')
if upload_location == 'youtube-manual':
YOUTUBE_URL_RE = r'^https?://(?:youtu\.be/|youtube.com/watch\?v=)([a-zA-Z0-9_-]{11})$'
match = re.match(YOUTUBE_URL_RE, link)
if not match:
return 'Link does not appear to be a youtube.com or youtu.be video link. Try removing any extra query params (after the video id).', 400
video_id, = match.groups()
elif upload_location == 'manual':
video_id = None
else:
return 'Upload location must be "manual" or "youtube-manual"', 400
conn = app.db_manager.get_conn() conn = app.db_manager.get_conn()
results = database.query(conn, """ results = database.query(conn, """
SELECT id, state, upload_location SELECT id, state
FROM events FROM events
WHERE id = %s""", ident) WHERE id = %s""", ident)
old_row = results.fetchone() old_row = results.fetchone()
if old_row is None: if old_row is None:
return 'Row {} not found'.format(ident), 404 return 'Row {} not found'.format(ident), 404
if old_row.state != 'UNEDITED' and not (old_row.state == 'DONE' and old_row.upload_location == 'manual'): if old_row.state != 'UNEDITED':
return 'Invalid state {} for manual video link'.format(old_row.state), 403 return 'Invalid state {} for manual video link'.format(old_row.state), 403
now = datetime.datetime.utcnow() now = datetime.datetime.utcnow()
results = database.query(conn, """ results = database.query(conn, """
UPDATE events UPDATE events
SET state='DONE', upload_location = 'manual', video_link = %s, SET state='DONE', upload_location = %s, video_link = %s, video_id = %s,
editor = %s, edit_time = %s, upload_time = %s editor = %s, edit_time = %s, upload_time = %s
WHERE id = %s AND (state = 'UNEDITED' OR (state = 'DONE' AND WHERE id = %s AND state = 'UNEDITED'
upload_location = 'manual'))""", link, editor, now, now, ident) """, upload_location, link, video_id, editor, now, now, ident)
logging.info("Row {} video_link set to {}".format(ident, link)) logging.info("Row {} video_link set to {}".format(ident, link))
return '' return ''

Loading…
Cancel
Save