Skip to content

Instantly share code, notes, and snippets.

@jivanpal
Last active June 17, 2022 19:21
Show Gist options
  • Save jivanpal/9b6f5d51ad976daaccc1f0f841807bb0 to your computer and use it in GitHub Desktop.
Save jivanpal/9b6f5d51ad976daaccc1f0f841807bb0 to your computer and use it in GitHub Desktop.
#!/bin/bash
IFS=$'\n'
for d in $(cat dir-list.txt); do (
cd "$d"
echo
echo "$d/"
if [ -f thumbnail-url.txt ]; then
echo "- Thumbnail already uploaded, see \`thumbnail-url.txt\`."
continue
fi
if [ -f thumbnail-submission-response.json ]; then
echo "- Thumbnail upload was previously attempted, but probably failed, see \`thumbnail-submission-repsonse.json\`."
continue
fi
echo -n "- Generating thumbnail ... "
if [ -f thumbnail.jpg ]; then
echo "already exists."
else
thumb_src='video.jpg'
if ! [ -f "$thumb_src" ]; then
thumb_src='video.webp'
fi
if ! [ -f "$thumb_src" ]; then
>&2 echo "cannot find thumbnail."
continue
fi
echo -n "source is \`$thumb_src\` ... "
if ! ffmpeg -i "$thumb_src" thumbnail.jpg > ffmpeg-out.txt 2> ffmpeg-err.txt; then
echo "FAILED. See \`ffmpeg-{out,err}.txt\`."
continue
fi
echo "OK."
fi
# Get a random 24-character alphanumeric string to use as the thumbnail
# name, just as is done in LBRY Desktop when uploading thumbnails to
# spee.ch or lbry.tv.
echo -n "- Generating thumbnail name ..."
thumbnail_name=$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 24)
while [ ${#thumbnail_name} -ne 24 ]; do
echo -n "."
thumbnail_name=$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c 24)
done
echo " \`$thumbnail_name\`."
curl -F "name=$thumbnail_name" -F "file=@$PWD/thumbnail.jpg" 'https://spee.ch/api/claim/publish' > thumbnail-submission-response.json
thumbnail_url=$(cat thumbnail-submission-response.json | egrep --color=none -o ',?"serveUrl": *"[^"]*"' | sed -E 's/^.*:"(.*)"$/\1/')
echo $thumbnail_url > thumbnail-url.txt
) done
#!/bin/bash
IFS=$'\n'
for d in $(cat upload-dirlist.txt); do (
cd "$d"
echo
echo "$d/"
skip=false
if ! [ -f name.txt ]; then
echo "- No name.txt found."
skip=true
else
name=$(cat name.txt)
fi
bid="0.0001"
file_path="$PWD/video.mkv"
if ! [ -f "$file_path" ]; then
echo "- Cannot find specified file to upload, \`$file_path\`."
skip=true
fi
if ! [ -f title.txt ]; then
echo "- No title.txt found."
skip=true
else
title=$(cat title.txt)
fi
### Generate description
if ! [ -f date.txt ]; then
echo "- No date.txt found."
skip=true
else
date=$(cat date.txt)
fi
if ! [ -f yt-code.txt ]; then
echo "- No yt-code.txt found."
skip=true
else
yt_code=$(cat yt-code.txt)
yt_url='https://www.youtube.com/watch?v='"$yt_code"
fi
if ! [ -f video.description ]; then
echo "- No video.description found."
skip=true
else
description=$(
echo '[Originally uploaded to YouTube]('"$yt_url"') on '"$date"'.'
echo
cat video.description
)
fi
## END --- Generate description
if ! [ -f tags.txt ]; then
echo "- No tags.txt found."
skip=true
fi
languages="en"
if ! [ -f thumbnail-url.txt ]; then
echo "- No thumbnail-url.txt found."
skip=true
else
thumbnail_url=$(cat thumbnail-url.txt)
fi
release_time=$(gdate -d "$date 12:00:00 UTC" +%s)
channel_name='@MyChannelName' # CHANGE THIS!
## Upload video
if [ -f lbrynet-out.txt ]; then
echo "- Upload already previously attempted."
skip=true
fi
if $skip; then
continue
fi
lbrynet stream create \
--name="$name" \
--bid="$bid" \
--file_path="$file_path" \
--title="$title" \
--description="$description" \
$( for tag in $(cat tags.txt); do echo "--tags=$tag"; done ) \
--languages="$languages" \
--thumbnail_url="$thumbnail_url" \
--release_time="$release_time" \
--channel_name="$channel_name" \
\
1> lbrynet-out.txt \
2> lbrynet-err.txt
) done
@jivanpal
Copy link
Author

jivanpal commented Feb 22, 2022

Some scripts I made last year to assist with batch-uploading videos to LBRY (accessible at Odysee.com). The intended usage is:

  1. Use youtube-dl to download videos to directories in the working directory, each of which contains a video (video.mkv) and video metadata like title, description, tags, and thumbnail, etc. in dedicated files (i.e. title.txt, description.txt, tags.txt, video.jpg, etc.).
  2. Create a file dir-list.txt containing a list of all the directories, one for each video to upload.
  3. Run lbry-upload-thumbnails.sh to upload the thumbnails to Spee.ch.
  4. Create a file upload-dirlist.txt containing a list of all the videos to actually upload (useful in case some of the thumbnails weren't uploaded successfully in step (3), or some of the videos weren't uploaded successfully in step (5) and you're repeating this step).
  5. Run lbry-upload-videos.sh to upload the videos to LBRY.

The upload-thumbnails script expects each directory to contain a thumbnail image, either called thumbnail.jpg, video.jpg, or video.webp, in that order of priority. If it's called video.*, the assumption is that this came directly from youtube-dl, so it runs it through FFmpeg just to make sure it's in proper JPEG format rather than WebP (I had issues uploading such unconverted files to Spee.ch). It then uploads the file to Spee.ch using Curl, saving the URL of the uploaded image to thumbnail-url.txt in that directory for later use by the upload-videos script, which does the job using lbrynet stream create.

Note for macOS users: The usage of sed near the end of the upload-thumbnails script is assumed to be GNU sed (as opposed to BSD sed). You can install this as gsed using Brew with brew install gsed, and then change sed to gsed in the script. Alternatively, we could actually parse the JSON fully using something like jq, but that just wouldn't be fun, now, would it? (Also, I didn't know jq existed when I originally wrote this and can't be bothered to change it and introduce another dependency for Linux users.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment