Instantly share code, notes, and snippets.
Created
June 4, 2023 10:31
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save mrnejc/bf5acf7bc6f7cb2e2fcaec25a8666f47 to your computer and use it in GitHub Desktop.
extract metadata from filename and fill CBZ data with comictagger application
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 | |
# script requires comictagger-cli in path (https://github.com/comictagger/comictagger) | |
# save the default field separators so we can work with spaces in filenames | |
SAVEIFS="$IFS" | |
IFS=$(echo -en "\n\b") | |
declare -A NUMTOMON | |
NUMTOMON["01"]="January" | |
NUMTOMON+=( ["02"]="February" ["03"]="March" ["04"]="April" ["05"]="May" ["06"]="June" ["07"]="July" ['08']="August" ["09"]="September" ["10"]="October" ["11"]="November" ["12"]="December" ) | |
function tagFile() { | |
comictagger -t CR -s --terse --nosummary -m "series=$SERIE, issue=$ISSUENO, title=$TITLE, year=$YEAR, month=$MONTH, day=$DAY" "$C" | |
SERIE="" | |
ISSUENO="" | |
YEAR="" | |
MONTH="" | |
DAY="" | |
MONTHTXT="" | |
EXT="" | |
TITLE="" | |
} | |
for C in "$@" | |
do | |
echo "Working on [$C]" | |
# filename pattern 'Issue Title 2022-01.cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]{4})-([0-9]{2})\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
YEAR=${BASH_REMATCH[2]} | |
MONTH=${BASH_REMATCH[3]} | |
ISSUENO="$YEAR$MONTH" | |
TITLE="${NUMTOMON[${MONTH}]} $YEAR" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 2022-02-01.cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]{4})-([0-9]{2})-([0-9]{2})\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
YEAR=${BASH_REMATCH[2]} | |
MONTH=${BASH_REMATCH[3]} | |
DAY=${BASH_REMATCH[4]} | |
ISSUENO="$YEAR$MONTH$DAY" | |
TITLE="$(echo $DAY|bc). ${NUMTOMON[${MONTH}]} $YEAR" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title v01 123 (2022-07-03).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) v([0-9]*) ([0-9]*) \(([0-9]*)-([0-9]{2})-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
ISSUENO=${BASH_REMATCH[3]} | |
YEAR=${BASH_REMATCH[4]} | |
MONTH=${BASH_REMATCH[5]} | |
DAY=${BASH_REMATCH[6]} | |
TITLE="$(echo $DAY|bc). ${NUMTOMON[${MONTH}]} $YEAR" | |
ISSUENO="$VOLUME.$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title v01 123 (2022-07).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) v([0-9]*) ([0-9]*) \(([0-9]*)-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
ISSUENO=${BASH_REMATCH[3]} | |
YEAR=${BASH_REMATCH[4]} | |
MONTH=${BASH_REMATCH[5]} | |
TITLE="${NUMTOMON[${MONTH}]} $YEAR" | |
ISSUENO="$VOLUME.$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title v01 123 (2022-Summer).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) v([0-9]*) ([0-9]*) \(([0-9]*)-([a-zA-Z]*)\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
ISSUENO=${BASH_REMATCH[3]} | |
YEAR=${BASH_REMATCH[4]} | |
SEASON=${BASH_REMATCH[5]} # Summer | |
TITLE="$SEASON $YEAR" # Summer 2022 | |
ISSUENO="$VOLUME.$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title v01 123 (2022).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) v([0-9]*) ([0-9]*) \(([0-9]{4})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
ISSUENO=${BASH_REMATCH[3]} | |
YEAR=${BASH_REMATCH[4]} | |
TITLE="Volume $(echo $VOLUME|bc) Issue $(echo $ISSUENO|bc)" | |
ISSUENO="$VOLUME.$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title v01 123.cbz' | |
regex='^([-a-zA-Z0-9+ ]*) v([0-9]*) ([0-9]*)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
ISSUENO=${BASH_REMATCH[3]} | |
TITLE="Volume $(echo $VOLUME|bc) Issue $(echo $ISSUENO|bc)" | |
ISSUENO="$VOLUME.$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 12th Edition (2022-07-03).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*)(st|nd|rd|th) Edition \(([0-9]*)-([0-9]{2})-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
ISSUENO=${BASH_REMATCH[2]} | |
ISSUEPOST=${BASH_REMATCH[3]} | |
YEAR=${BASH_REMATCH[4]} | |
MONTH=${BASH_REMATCH[5]} | |
DAY=${BASH_REMATCH[6]} | |
TITLE="$(echo $ISSUENO|bc)$ISSUEPOST Edition" | |
ISSUENO="$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 12th Edition (2022-07).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*)(st|nd|rd|th) Edition \(([0-9]*)-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
ISSUENO=${BASH_REMATCH[2]} | |
ISSUEPOST=${BASH_REMATCH[3]} | |
YEAR=${BASH_REMATCH[4]} | |
MONTH=${BASH_REMATCH[5]} | |
TITLE="$(echo $ISSUENO|bc)$ISSUEPOST Edition" | |
ISSUENO="$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 12th Edition (2022).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*)(st|nd|rd|th) Edition \(([0-9]*)\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
ISSUENO=${BASH_REMATCH[2]} | |
ISSUEPOST=${BASH_REMATCH[3]} | |
YEAR=${BASH_REMATCH[4]} | |
TITLE="$(echo $ISSUENO|bc)$ISSUEPOST Edition" | |
ISSUENO="$(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title vol 12 (2022-07-03).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) vol ([0-9]*) \(([0-9]*)-([0-9]{2})-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
YEAR=${BASH_REMATCH[3]} | |
MONTH=${BASH_REMATCH[4]} | |
DAY=${BASH_REMATCH[5]} | |
TITLE="Volume $(echo $VOLUME|bc)" | |
ISSUENO="$(echo $VOLUME|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title vol 12 (2022-07).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) vol ([0-9]*) \(([0-9]*)-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
YEAR=${BASH_REMATCH[3]} | |
MONTH=${BASH_REMATCH[4]} | |
TITLE="Volume $(echo $VOLUME|bc)" | |
ISSUENO="$(echo $VOLUME|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title vol 12 (2022).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) vol ([0-9]*) \(([0-9]*)\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
VOLUME=${BASH_REMATCH[2]} | |
YEAR=${BASH_REMATCH[3]} | |
TITLE="Volume $(echo $VOLUME|bc)" | |
ISSUENO="$(echo $VOLUME|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 123 (2022-02-03).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*) \(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
ISSUENO=${BASH_REMATCH[2]} | |
YEAR=${BASH_REMATCH[3]} | |
MONTH=${BASH_REMATCH[4]} | |
DAY=${BASH_REMATCH[5]} | |
TITLE="$(echo $DAY|bc). ${NUMTOMON[${MONTH}]} $YEAR" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 123 (2022-02).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*) \(([0-9]{4})-([0-9]{2})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
ISSUENO=${BASH_REMATCH[2]} | |
YEAR=${BASH_REMATCH[3]} | |
MONTH=${BASH_REMATCH[4]} | |
TITLE="${NUMTOMON[${MONTH}]} $YEAR" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 123 (2022-Summer).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*) \(([0-9]{4})-([a-zA-Z]*)\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} # Issue Title | |
ISSUENO=${BASH_REMATCH[2]} # 123 | |
YEAR=${BASH_REMATCH[3]} # 2002 | |
SEASON=${BASH_REMATCH[4]} # Summer | |
TITLE="$SEASON $YEAR" # Summer 2002 | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 123 (2022).cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*) \(([0-9]{4})\)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
ISSUENO=${BASH_REMATCH[2]} | |
YEAR=${BASH_REMATCH[3]} | |
EXT=${BASH_REMATCH[4]} | |
TITLE="Issue $(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
# filename pattern 'Issue Title 123.cbz' | |
regex='^([-a-zA-Z0-9+ ]*) ([0-9]*)\.' | |
if [[ $C =~ $regex ]]; then | |
SERIE=${BASH_REMATCH[1]} | |
ISSUENO=${BASH_REMATCH[2]} | |
EXT=${BASH_REMATCH[4]} | |
TITLE="Issue $(echo $ISSUENO|bc)" | |
tagFile && continue | |
fi | |
echo "Error: failed getting data from filename [$C]" | |
done | |
IFS="$SAVEIFS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment