Allow checking for unsubmitted video files

This commit is contained in:
Hugo Peixoto 2023-08-01 02:04:25 +01:00
parent 95c8b982bf
commit a55294e7e4
2 changed files with 33 additions and 0 deletions

16
main.rb
View File

@ -83,11 +83,27 @@ post '/video' do
{ status: 'ok' }.to_json
end
post '/check' do
content_type 'application/json'
ids = JSON.parse(request.body.read)
videos = Video
.left_outer_joins(:downloads)
.where(randname: ids)
.pluck(:randname, :sha256, :size)
.map { |v| %w[randname sha256 size].zip(v).to_h }
{ videos: videos }.to_json
end
get '/config.json' do
content_type 'application/json'
{
videos_url: "https://sapo.pxto.pt/videos.json",
upload_url: "https://sapo.pxto.pt/video",
check_url: "https://sapo.pxto.pt/check",
max_amount: 100_000,
}.to_json
end

View File

@ -80,6 +80,20 @@ download() {
fi
}
unknown() {
CONFIG="$(get_config)"
SAPO_CHECK_VIDEOS_URL="$(echo "$CONFIG" | jq -r .check_url)"
find videos/ -name "*.mp4" |
sed -e 's|videos/\(.*\).mp4|\1|g' |
xargs -n1000 |
sed -e 's/ /","/g' -e 's/^/["/' -e 's/$/"]/' |
while read body; do
echo "$body" | curl --silent --json "@-" "$SAPO_CHECK_VIDEOS_URL"
done |
jq -rc '.videos[]|select(.sha256==null)|("videos/" + .randname + ".mp4")'
}
case "$1" in
"download")
indexer "$2" "$3"
@ -87,6 +101,9 @@ case "$1" in
"single")
download "$2"
;;
"unknown")
unknown
;;
"stats")
BYTES="$(du -b videos/ | awk '{print $1}')"
NUM="$(ls -1 videos/ | wc -l)"