Created
September 25, 2012 21:01
-
-
Save kopiro/3784408 to your computer and use it in GitHub Desktop.
Auto Increment when watching TV series
This file contains hidden or 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/sh | |
cur=$(cat current); | |
serie=$(echo $cur | awk -F"x" '{print $1}'); | |
episode=$(echo $cur | awk -F"x" '{print $2}'); | |
if ! [[ "$serie" =~ ^[0-9]+$ ]]; then | |
echo "Unmatched serie, exit"; | |
exit; | |
fi; | |
if ! [[ "$episode" =~ ^[0-9]+$ ]]; then | |
echo "Unmatched episode, exit"; | |
exit; | |
fi; | |
echo "Now we are at $serie serie - $episode episode"; | |
next_episode=$(($episode+1)); | |
if (( next_episode<10 )); then | |
next_episode=$(echo '0'$next_episode) | |
fi; | |
next_episode_string=$(echo $serie'x'$next_episode); | |
echo "Next episode should be $next_episode_string" | |
next_episode_file=$(find . -name "*$next_episode_string*"); | |
if [ -z "$next_episode_file" ]; then | |
echo "No file found, you're going to the next season!"; | |
next_serie = $((serie+1)); | |
next_episode_string = $(echo $next_serie'x01'); | |
next_episode_file=$(find . -name "*$next_episode_string*"); | |
fi; | |
echo "Updating and opening"; | |
echo "$next_episode_string" > current; | |
open "$next_episode_file"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment