Skip to content

Instantly share code, notes, and snippets.

@ashimregme
Last active August 30, 2020 09:55
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 ashimregme/8cf9c97eadf9aab37f1c352727678f49 to your computer and use it in GitHub Desktop.
Save ashimregme/8cf9c97eadf9aab37f1c352727678f49 to your computer and use it in GitHub Desktop.
Generates movie ratings using OMDB api (for linux) (tested on Ubuntu 16.04)
#!/bin/bash
#Copyright Asim Regmi :D
IFS='
'
count=0
for d in */ ; do
newD=$(echo $d | sed -e 's/\(\[imdbRating:[0-9]*.*[0-9]*\]\)*//g');
if [ $d != $newD ]; then
count=$((count+1))
mv $d ${newD:0:${#newD}-1}
fi
done
notify-send $count" ratings deleted";
#!/bin/bash
#Copyright Asim Regmi :D
IFS='
'
wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -ne 0 ]]; then
notify-send "Please connect to internet first!!"
exit;
fi
count=0
for d in */ ; do
movieName="";
directory=$(echo $d | sed 's/[^a-zA-Z0-9]/ /g');
directory=$(echo $directory | xargs);
year=$(echo $directory | grep -Po '^(.*?)\d{4}');
year=$(echo $year | grep -Po '\d{4}');
directory=${directory// /+};
for (( i=0; i<${#directory}; i++ )); do
if [[ $(echo ${directory:$i:1} | sed -e 's/[0-9]//g') != "" ]]; then
movieName="$movieName${directory:$i:1}";
else
if [[ $(echo ${directory:0:$i} | sed -e 's/[0-9]//g') == "" ]]; then
movieName="$movieName${directory:$i:1}";
else
[[ ${movieName:$i-1:1} == [[:space:]] ]] && echo $movieName;movieName="${movieName:0:$i-1}";
break;
fi
fi
done
if [ ${#year} > 0 ] && [ ${#movieName} > 0 ]; then
STR=$(curl -s "http://www.omdbapi.com/?t=$movieName&y=$year");
imdbRating=$(echo $STR | grep -Po '"imdbRating":"\d.\d"');
rating=$(echo $imdbRating | grep -Po '\d.\d');
#echo $rating;
count=$((count+1))
mv $d ${d:0:${#d}-1}"[imdbRating:"$rating"]"
fi
rm 0
done
notify-send $count" ratings added";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment