Skip to content

Instantly share code, notes, and snippets.

@jjjake
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjjake/80377b1bd9f57712875d to your computer and use it in GitHub Desktop.
Save jjjake/80377b1bd9f57712875d to your computer and use it in GitHub Desktop.
#!/bin/bash
function get_identifier() {
# Get ia identifier using youtube json file.
# Format is title-id, with title being limited to 70 chars.
#stitle=$(cat "$json_file" | jq -r '.title' | tr -cd '[[:alnum:]]_-' | cut -c 1-80)
stitle=$(cat "$json_file" | jq -r '.title' | gsed -e 's/^./\U&/g; s/ ./\U&/g' | tr -cd '[[:alnum:]]_-' | cut -c 1-80)
ytid=$(cat "$json_file" | jq -r '.id')
identifier="${stitle}_${ytid}"
echo "${stitle}_${ytid}-test4"
}
function get_yt_md_args() {
description=$(jq '"\(.description)"' < "$json_file" | sed -e 's/\\n/<br \/>/g' -e 's/"//')
# Generate a string of `ia upload` --metadata args from the youtube json file.
##jq '"-m \"description:\(.description)\" -m \"title:\(.fulltitle)\" -m \"creator:\(.uploader)\""' < "$json_file" |
jq '"-m \"title:\(.fulltitle)\" -m \"creator:\(.uploader)\""' < "$json_file" |
sed 's/\\n/<br \/>/g' |
echo "-m \"description:${description} $(jq -r '.')"
}
function get_ia_cmd() {
json_file="$1"
video_file="$(echo $json_file | sed 's/.info.json$/.mp4/')"
upload_args="--retries 30 --delete --log"
ia_md_args="-m collection:INSERT_COLLECTION_HERE -m mediatype:movies"
echo "ia upload $(get_identifier) \"${json_file}\" \"${video_file}\" ${upload_args} ${ia_md_args} $(get_yt_md_args)"
}
export -f get_identifier
export -f get_yt_md_args
export -f get_ia_cmd
find . -name '*.info.json' -exec bash -c 'get_ia_cmd "$0"' {} \; | parallel -j10 '{}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment