[SOLVED] API Call /api/dvr/entry/create and character '
Added by M A Ben Amara about 5 years ago
Hi, as im writing a small script too add all my existing recordings to TVH im on the last hurdle ...
i have plenty episodes with the character ' in its name, and it seems i cant escape it on the api call.
i already regex it in the subtitle cause i dont really need it, but its also in the filename ... wich makes it break.
sample output from my script wich causes a fail ... She's ...
curl --data 'conf={"start":"1570132761","stop":"1570136361","channelname":"Sky 1 HD","title":{"ger":"The Outpost"},"files":[{"filename":"/Media/TVRIPS/The Outpost/Season 02/The Outpost - S02E06 - Because She's Worth It.mkv"}],"episode":{"enum":"6","snum":"2"},"subtitle":{"ger":"Because She s Worth It mkv"} }' 'http://user:[email protected]:9981/api/dvr/entry/create'
i already tested --data-urlencode, tried to escape with \, \ with "", etc etc .. always same result ...
i could now add a routine to first also regex in filepath, add to tvheadend (with wrong path), then use a /api/dvr/entry/filemoved where the ... She's ... is then accepted ... would be the dirty way then
may a hint howto use this character in the api call for /create ?
for any tipps, thanks ahead.
Replies (3)
RE: API Call /api/dvr/entry/create and character ' - Added by Joe User about 5 years ago
I ran into this before.
She'\''s
See here for also an alternate way: https://stackoverflow.com/questions/32122586/curl-escape-single-quote
The alternate way would be a lot more typing, but could be easier to implement in an automated script.
BTW - just to be clear, it is not an "api" problem, it is how the shell parses the curl command.
I will leave it as an exercise for you to find out why it is not a problem with the filemoved curl command...
RE: API Call /api/dvr/entry/create and character ' - Added by M A Ben Amara about 5 years ago
Joe User wrote:
I ran into this before.
[...]See here for also an alternate way: https://stackoverflow.com/questions/32122586/curl-escape-single-quote
The alternate way would be a lot more typing, but could be easier to implement in an automated script.
BTW - just to be clear, it is not an "api" problem, it is how the shell parses the curl command.
I will leave it as an exercise for you to find out why it is not a problem with the filemoved curl command...
thank you very much, i searched wrong it seems and works as expected.
RE: API Call /api/dvr/entry/create and character ' - Added by M A Ben Amara about 5 years ago
in case its usefule for somebody, worked here nice now for my existing records ...
could be sure shortend, but it made its job here, so im ok
#!/bin/bash
startpath="/mnt/user/Media/" ### main place where to look for
searchpattern="*.mkv" ### what type of files to look for
mediafolder="/Media/" ### add to path beginning for TVHeadend update
duration=3600 ### duration in seconds to add as length
channame="Sky 1 HD" ### duration in seconds to add as length
tvhuser="username" ### TVHeadend Username
tvhpass="password" ### TVHeadend Password
tvhip="192.168.1.2" ### TVHeadend IP
tvhport="9981" ### TVHeadend Port
tvhlogpath="/mnt/user/appdata/tvheadend/dvr/log/" ### path to the tvheadend log dir to check existing records
### CHECK Buttom Lines about unlock usage ###
cd $startpath
rm curllist.txt
find . -mindepth 4 -iname $searchpattern | sed "s|^\./||"|while read fname; do
grepreturn=""
grepreturn=$(grep -rn "$tvhlogpath" -e "$fname")
if [[ $grepreturn == "" ]]; then
starttime=$(date -r "$fname" +%s)
endtime=$(( $starttime + $duration ))
title=$(basename "$fname")
title=$(echo "$title" | sed 's/-/ /g')
title=$(echo "$title" | sed 's/S[0-99]*E[0-99]/- &/')
seasonepisode=$(cut -sd '-' -f 2 <<<"$title")
subtitle=$(cut -sd ' ' -f 3- <<<"$seasonepisode")
seasonepisode=$(cut -sd ' ' -f 2 <<<"$seasonepisode")
episode=$(cut -c 5-6 <<<"$seasonepisode")
episode=$(echo $episode | sed 's/^0*//')
season=$(cut -c 2-3 <<<"$seasonepisode")
season=$(echo $season | sed 's/^0*//')
subtitle="${subtitle%.*}"
subtitle=$(echo "$subtitle" | sed "s/[^a-zA-Z0-9+'\ä\ö\ü\Ä\Ö\Ü\ß]/ /g")
subtitle=$(echo "$subtitle" | awk '{gsub(/^ +| +$/,"")} {print $0}')
subtitle=$(echo "$subtitle" | sed "s|'|'\\\''|g")
subtitle=$(echo "$subtitle" | sed "s|+|%2B|g")
subtitle=$(echo "$subtitle" | sed "s|&|%26|g")
title=$(cut -sd '-' -f 1 <<<"$title")
title=$(echo "$title" | awk '{gsub(/^ +| +$/,"")} {print $0}')
title=$(echo "$title" | sed "s|'|'\\\''|g")
title=$(echo "$title" | sed "s|+|%2B|g")
title=$(echo "$title" | sed "s|&|%26|g")
fname=$(echo "$fname" | sed "s|'|'\\\''|g")
fname=$(echo "$fname" | sed "s|+|%2B|g")
fname=$(echo "$fname" | sed "s|&|%26|g")
echo "curl --data 'conf={\"start\":\"$starttime\",\"stop\":\"$endtime\",\"channelname\":\"$channame\",\"title\":{\"ger\":\"$title\"},\"files\":[{\"filename\":\"$mediafolder$fname\"}],\"episode\":{\"enum\":\"$episode\",\"snum\":\"$season\"},\"subtitle\":{\"ger\":\"$subtitle\"} }' 'http://$tvhuser:$tvhpass@$tvhip:$tvhport/api/dvr/entry/create'" >> curllist.txt
else
echo "Skipping existing: $fname"
fi
done
### uncomment from here when sure, check curllist.txt, make some tests if the results are as expected, when sure uncomment from here on
#chmod +x curllist.txt
#nohup ./curllist.txt > /dev/null 2>&1 &