Added support for stream titles/custom date format in filename#6
Added support for stream titles/custom date format in filename#611ib wants to merge 9 commits intoHakkin:masterfrom
Conversation
There was a problem hiding this comment.
Thanks for the pull request! This looks good, but a few things need fixing.
Mostly small changes needed, but sanitizing filenames is a big one. I'm not quite sure what the best way to do this in bash is, the simplest way would probably be to nuke all non-alphanumeric characters in the filename, but that also might be slightly overkill.
| check_deps | ||
|
|
||
| while getopts ":ph" opt | ||
| while getopts "d:pht" opt |
There was a problem hiding this comment.
| while getopts "d:pht" opt | |
| while getopts ":phtd:" opt |
This should be ":phtd:", ":" at the start of a getopt argument prevents it from displaying debug errors.
| curl --silent --fail -H "Client-ID: $CLIENT_ID" "$API_URL$1" | jq -r .status | ||
| } | ||
|
|
||
| print_usage() { |
There was a problem hiding this comment.
The new switches should be added to the usage text.
| if [ "$FILENAME_TITLE" == "1" ]; | ||
| then | ||
| title=$(get_stream_title $username) | ||
| filename+="${title}_" |
There was a problem hiding this comment.
We need to sanitize the filename somehow, as it is, if a streamer has their title set to ../title, the file will be created up a directory. We also have to consider special characters that are not allowed in filenames, both on Windows and Linux.
| then | ||
| filename+=$(date $DFORMAT) | ||
| else | ||
| filename+=$(date -u '+%Y-%m-%d-%H-%M-%S-(%Z)') |
There was a problem hiding this comment.
| filename+=$(date -u '+%Y-%m-%d-%H-%M-%S-(%Z)') | |
| filename+=$(date -u '+%Y_%m_%d_%H_%M_%S_(%Z)') |
I would also prefer the date format stay the same as it was before, +%Y_%m_%d_%H_%M_%S_(%Z)
|
I've seen another go project deal with filenames by converting it to utf-8 |
|
Having the filename include the title of the stream might not be ideal for archiving. A lot of times, a streamer will set their title after going live so you'd have some duplicates. I've opened an issue with a feature request for a logging format and think logging the titles separately could be better than filenames. #12 |
|
Hi @11ib, would you mind checking to see if the new this is using a bash You can also of course write custom bash scripts to fetch whatever info you want, or any other commands for that matter, I wrote a simple bash script that does similar to the above without using youtube-dl. #!/bin/bash
id="${1}"
json="$(curl --silent --fail -H "Accept: application/vnd.twitchtv.v5+json" -H "Client-ID: jzkbprff40iqj646a697cyrvl0zt2m6" "https://api.twitch.tv/kraken/streams/${id}")"
stream="$(jq .stream <<< "${json}")"
if [ "${stream}" == "null" ]
then
sleep 1
exit 1
fi
display_name="$(jq -r .channel.display_name <<< "${stream}")"
user_id="$(jq -r .channel._id <<< "${stream}")"
created_at="$(jq -r .created_at <<< "${stream}")"
broadcast_id="$(jq -r ._id <<< "${stream}")"
status="$(jq -r .channel.status <<< "${stream}")"
printf "%s - %s (%d) - %s (%d)" "$(date -u -d "${created_at}" "+%Y%m%d%H%M%S")" "${display_name}" "${user_id}" "${status}" "${broadcast_id}"put this in a file called |
I've added the -d and -t flags for inserting a custom date format (using the Bash Date Format) and grabbing the title of a stream when recording a stream.