Last active
August 30, 2020 09:55
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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