Hey !
It’s me again ^^ I’m trying to write a script to upload entire folders to peertube, generating playlist and tags automatically. But I’m stuck with the tags.
I get a error saying the value of my tags is invalid.
The doc explain the variable “tags” is a array of strings. So i declare it as an array with genre=(genre1 genre2)
. But I get a error.
Here is my code :
## DEPENDENCIES: httpie, jq
# pip install httpie
USERNAME="user"
PASSWORD="psswd"
CHANNEL_ID="2"
API_PATH="https://peertube.exemple/api/v1"
## AUTH
client_id=$(http -b GET "$API_PATH/oauth-clients/local" | jq -r ".client_id")
client_secret=$(http -b GET "$API_PATH/oauth-clients/local" | jq -r ".client_secret")
token=$(http -b --form POST "$API_PATH/users/token" \
client_id="$client_id" client_secret="$client_secret" grant_type=password response_type=code \
username=$USERNAME \
password=$PASSWORD \
| jq -r ".access_token")
echo "token is : $token"
#if [ -z "$token"]
#then
# echo "auth fail"
# exit 1
#else
echo "Authentification ok :D"
##Playlist
FOLDER_PATH="/mnt/test/"
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
cd $FOLDER_PATH
SON=$(find . -type f -name '*.mp3' )
# LOOP
echo "starting loop"
for file in $SON
do
filename="${file##*/}"
filename="${filename%.*}"
echo "this is the filename : "$filename" "
echo "file path = $file"
file="${file:2}"
echo "file without ./ : $file"
file="$FOLDER_PATH$file"
echo "file path is now $file"
echo "this is the file with is path : $file"
genre=$(id3v2 -l "$file" | sed -n '/^TCON/s/^.*: //p' | sed 's/ (.*//')
if [ -z "$genre" ]
then
genre=("notag" "nono")
fi
echo "this is the genre 1 : ${genre[0]}"
echo "array 2 is : ${genre[1]}"
FILE_PATH="$file"
NAME="$filename"
echo "this is name $NAME"
## VIDEO UPLOAD
echo "Uploading "$filename""
http -b --form --timeout 6000 POST "$API_PATH/videos/upload" \
videofile@"$FILE_PATH" \
channelId=$CHANNEL_ID \
name="$NAME" \
category=1 \
privacy=1 \
tags=$genre \
commentsEnabled=true \
"Authorization:Bearer $token" \
IFS=$SAVEIFS
done
And here is the error message :
"errors": {
"tags": {
"location": "body",
"msg": "Should have correct tags",
"param": "tags",
"value": "notag"
thx ! 
Hello,
As I read in the documentation, tags
should be set with an array of strings.
I read HTTPie documentation to find how to pass such value but I failed having precise response. So, I guess you might use something like this:
tags:='["notag", "atag"]'
thx for your help 
The api still give an error :s
{
"errors": {
"tags": {
"location": "body",
"msg": "Should have correct tags",
"param": "tags",
"value": "[\"notag\", \"tag\"]"
}
}
}
oups, I forget the :
. With it I we have :
Traceback (most recent call last):
File "/usr/bin/http", line 11, in <module>
load_entry_point('httpie==0.9.8', 'console_scripts', 'http')()
File "/usr/lib/python3/dist-packages/httpie/__main__.py", line 11, in main
sys.exit(main())
File "/usr/lib/python3/dist-packages/httpie/core.py", line 210, in main
parsed_args = parser.parse_args(args=args, env=env)
File "/usr/lib/python3/dist-packages/httpie/input.py", line 151, in parse_args
self._parse_items()
File "/usr/lib/python3/dist-packages/httpie/input.py", line 355, in _parse_items
data_class=ParamsDict if self.args.form else OrderedDict
File "/usr/lib/python3/dist-packages/httpie/input.py", line 745, in parse_items
data_class(data),
File "/usr/lib/python3/dist-packages/httpie/input.py", line 635, in __setitem__
assert not isinstance(value, list)
AssertionError
http command might contain something like : tags:='["notag", "tag"]' \
Remark single quotes, double quote and :=
.
It think you should make sure the variable genre
is initialized with each tag’s name enclosed with double quotes and seperated by comma (except last one).
For example: genre=\"notag\",\ \"tag\"
And insert this variable’s value in the http command via tags:='['$genre']' \
Regard the single quotes position; they are important.
I don’t understand your solution but I tried it.
With tags:='[notag, tag]' \
I get a http: error: "tags:=[notag, tag]": Expecting value: line 1 column 2 (char 1)
With genre=\"notag\",\ \"tag\"
and tags:='['$genre']' \
I get a http: error: argument REQUEST_ITEM: ""tag"]" is not a valid value
You should have tags:='["notag", "tag"]'
in your resulting http
command
Try this in your script:
genre=$(id3v2 -l "$file" | sed -n '/^TCON/s/^.*: //p' | sed 's/ (.*//')
genre=\'[$( echo $genre | sed '/ /, /' )]\'
if [ -z "$genre" ]
then
genre=\'[\"notag\",\ \"nono\"]\'
fi
echo "this is the genre 1 : ${genre[0]}"
echo "array 2 is : ${genre[1]}"
tags:=$genre \
I tested without the loop (with genre=\'[\"notag\",\ \"nono\"]\'
) and I have the same result : http: error: argument REQUEST_ITEM: ""nono"]'" is not a valid value
Try
genre=\'[\"notag\",\"nono\"]\'
instead
Sorry for the test and try, I did not have the application installed (indeed I installed it today to help you further) and I’m not used to handle it. I try what I told you here and there’s no http: error:
message.
thx you a loooot o/
At home I have : http: error: "tags:='["notag","nono"]'": Expecting value: line 1 column 1 (char 0)
I re-opens it because I’m stil stuck
When i use genre=\{\"$genre1\"": 0, "\"$genre2\"": 1 "\}
It upload
But when i use genre={\"$genre0\"": 0 "}
I have :
{
"errors": {
"tags": {
"location": "body",
"msg": "Should have correct tags",
"param": "tags",
"value": "Music"
}
}
}
what the ? ^^
Ok so here is the script. It’s very ugly but I’m not a programmer at all ^^
I created Defaults tag so I don’t have to bother with the tag issues…
# DEPENDENCIES: httpie, jq, ffmpeg, ImageMagick
# pip install httpie
#######
##VAR
USERNAME="user"
PASSWORD="psswd »
CHANNEL_ID="3"
API_PATH="https://peertube.exemple/api/v1"
FOLDER_PATH="/path/" #must contain final slash
error_index=index_error.txt
success_index=index_success.txt
defaultcover=defaultcover.jpg
#########
## AUTH
client_id=$(http -b GET "$API_PATH/oauth-clients/local" | jq -r ".client_id")
client_secret=$(http -b GET "$API_PATH/oauth-clients/local" | jq -r ".client_secret")
token=$(http -b --form POST "$API_PATH/users/token" \
client_id="$client_id" client_secret="$client_secret" grant_type=password response_type=code \
username=$USERNAME \
password=$PASSWORD \
| jq -r ".access_token")
echo "token is : $token"
#if [ -z "$token"]
#then
# echo "auth fail"
# exit 1
#else
echo "Authentification ok :D"
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
cd $FOLDER_PATH
SON=$(find . -type f -name '*.mp3' )
########
## LOOP
echo "Starting loop"
for file in $SON
do
filename="${file##*/}"
filename="${filename%.*}"
echo "this is the filename : "$filename" "
echo "file path = $file"
file="${file:2}"
echo "file without ./ $file"
file="$FOLDER_PATH$file"
echo "file path is now $file"
echo "this is the file with is path : $file"
NAME="$filename"
FILE_PATH="$file"
echo "this is name $NAME"
#Check if file was already uploaded
alreadydone=mdrjamaisjauréunsoncommeca
alreadydone=$(grep -x $NAME $success_index)
echo "alreadydone is : $alreadydone"
if [ "$alreadydone" = "$NAME" ]
then
echo "File already uploaded, passing"
continue
fi
echo "Processing loop"
#Artwork
coverpath=$(echo $filename | sed 's/ //g')
coverpath=/coverpath/$coverpath
echo "cover path is $coverpath"
mkdir $coverpath
eyeD3 "$file" --write-image=$coverpath
gm mogrify -bordercolor black -border '35%x0%' "$coverpath/*"
if [ $? -eq 0 ]
then
cover=$(ls -t $coverpath | head -n 1)
cover=$coverpath/$cover
if [[ ${cover: -4} != ".jpg" || ${cover: -5} != ".jpeg" ]]
then rename -v s/$/.jpg/ $cover
fi
cover=$cover.jpg
else
cover=$defaultcover
fi
echo "coverpath is $cover"
#Genre
genre=$(ffprobe -loglevel error -show_entries format_tags=genre -of default=noprint_wrappers=1:nokey=1 $file)
genre=$(echo $genre | sed 's/ //g')
echo "this is genre de base : '$genre'"
genre0=Music
genre1=$(echo $genre | cut -d',' -f1)
echo "this is genre1 $genre1"
genre2=$(echo $genre | cut -d',' -f2)
echo "this is genre2 $genre2"
genre3=$(echo $genre | cut -d',' -f3)
echo "this is genre3 $genre3"
genre4=$(echo $genre | cut -d',' -f4)
echo "this is genre4 $genre4"
genre5=$(echo $genre | cut -d',' -f5)
echo "this is genre5 $genre5"
#genre=\{\[\"$genre1\"\]": 0 "\}
#echo "this is array genre : $genre"
#genre=\'$genre\'
if [ -z $genre5 ]
then
genre=\{\"$genre0\"": 0, "\"$genre1\"": 1, "\"$genre2\"": 2, "\"$genre3\"": 3, "\"$genre4\"": 4 "}
else
genre=\{\"$genre5\"": 5, "\"$genre1\"": 1, "\"$genre2\"": 2, "\"$genre3\"": 3, "\"$genre4\"": 4 "}
fi
echo $genre
if [ -z $genre4 ]
then
genre=\{\"$genre0\"": 0, "\"$genre1\"": 1, "\"$genre2\"": 2, "\"$genre3\"": 3 "}
fi
echo $genre
if [ -z $genre3 ]
then
genre=\{\"$genre0\"": 0, "\"$genre1\"": 1, "\"$genre2\"": 2 "\}
fi
echo $genre
if [ -z $genre2 ]
then
genre=\{\"$genre0\"": 0, "\"$genre1\"": 1 "\}
fi
echo $genre
if [ -z $genre1 ]
then
genre=\{\"$genre0\"": 0, "\"Flex\"": 2 "\}
fi
echo $genre
## VIDEO UPLOAD
echo "Uploading "$filename""
http -b --form --timeout 6000 POST "$API_PATH/videos/upload" \
videofile@"$FILE_PATH" \
channelId=$CHANNEL_ID \
name="$NAME" \
category=1 \
privacy=1 \
tags:=$genre \
previewfile@$cover \
thumbnailfile@$cover \
commentsEnabled=true \
"Authorization:Bearer $token" \
if [ $? -eq 0 ]
then
echo "succes writting file to index"
echo $filename >> $success_index
else echo "error, writting file to index"
echo $filename >> $error_index
fi
iFS=$SAVEIFS
done
For those who want to do similar thing, you could juste use this tools instead of the API jaja