Well, I use SickBeard. And sometimes (very often actually) the names are rather screwed up…. So I wrote myself a script, that’ll fix most episode errors (I’ve caught so far …).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 #!/opt/bin/bash OPTS="$@" [ "$( cat /etc/distribution 2>/dev/null )" == "OpenELEC" ] && openelec=1 || openelec=0 [ "$( mount | /opt/bin/grep "$( echo $PWD | /opt/bin/sed "s,/tvshows,," )" | awk '{ print $5 }' )" == "cifs" ] && cifs=1 || cifs=0 if [ $openelec -eq 0 -a $cifs -eq 0 ] ; then # Fix permissions chown -R nobody.users "$PWD" /opt/bin/findutils-find "$PWD" -type f ! -perm 0664 -exec chmod 0664 {} \; /opt/bin/findutils-find "$PWD" -type d ! -perm 0775 -exec chmod 0775 {} \; fi EXTENSIONS=".avi .mp4 .mkv .srt .tbn .nfo .xml -thumb.jpg" # Needs renaming: PATTERN="WEB.DL,WEB-DL Web-Dl,WEB-DL AVC.AC3,DD5.1.H.264 .AC3.PSIV,-PSIV DD.5.1,DD5.1 DD5-1,DD5.1 Dd5.1,DD5.1 DD.2.0,DD2.0 WEB-DLAAC2,WEB-DL.AAC2 H.264.DD5.1,DD5.1.H.264 AAC.2.0,AAC2.0 DD5.1.AAC2.0,DD5.1 WEB-DL-pcsyndicate,WEB-DL.DD5.1.H.264-pcsyndicate x264,H.264 X264,H.264 h264,H.264 H264,H.264 Forever.S0,Forever.2014.S0 H-264,H.264 h.264,H.264 DD5.1-H.264,DD5.1.H.264 .KiNGS,-KiNGS -KINGS,-KiNGS .TB,-TB .BS,-BS .~DG2~, .~DG~, .CtrlHD,-CtrlHD 1x,S01E .ECI,-ECI .NFHD,-NFHD .POD,-POD \.NTb,\-NTb .DNR,-DNR .pcsyndicate,-pcsyndicate German.DD20.Synced.DL.720p.iTunesHD.AVC,720p.WEB-DL.DD2.0.DL.H.264 -ss,-SS .Reaperza,-Reaperza Grey's.Anatomy,Greys.Anatomy Five-0,Five.0 Hawaii.Five.0.2010\.S0,Hawaii.Five.0.S0 WEBRip,WEB-DL WEB-DL.H.264.AAC2.0,WEB-DL.AAC2.0.H.264 Hell.On.Wheels,Hell.on.Wheels Mythbusters,MythBusters Dont.Trust.The.B----.In.Apartment.23,Dont.Trust.The.B.In.Apartment.23 Dont.Trust.the.Bitch.in.Apartment.23,Dont.Trust.The.B.In.Apartment.23 Dont.Trust.the.B.in.Apartment.23,Dont.Trust.The.B.In.Apartment.23 Rizzoli.&.Isles,Rizzoli.and.Isles Revolution.2012,Revolution Orange.Is.The.New.Black,Orange.Is.the.New.Black Castle.S,Castle.2009.S /Agents.of.S.H.I.E.L.D.,/Marvels.Agents.Of.S.H.I.E.L.D. Marvel.Agents.Of.SHIELD,Marvels.Agents.Of.S.H.I.E.L.D. Marvel.Agents.Of.S.H.I.E.L.D..S,Marvels.Agents.Of.S.H.I.E.L.D.S Marvel.Agents.Of.S.H.I.E.L.D.S,Marvels.Agents.Of.S.H.I.E.L.D.S Marvels.Agents.Of.S.H.I.E.L.D..S,Marvels.Agents.Of.S.H.I.E.L.D.S Marvels.Agents.of.S.H.I.E.L.D.,Marvels.Agents.Of.S.H.I.E.L.D. Rizzoli.Isles,Rizzoli.and.Isles The.Bridge.S,The.Bridge.US.S Last.Man.Standing.US,Last.Man.Standing.2011 The.Americans.S,The.Americans.2013.S Person.Of.Interest,Person.of.Interest The.Tomorrow.People.S0,The.Tomorrow.People.US.S0 The.Code.AU,The.Code.2014 How.to.Get.Away.With.Murder,How.To.Get.Away.With.Murder How.to.Get.Away.with.Murder,How.To.Get.Away.With.Murder How.To.Get.Away.with.Murder,How.To.Get.Away.With.Murder Izombie,iZombie -SiCKBEARD,.720p.WEB-DL.DD5.1.H.264 DL.DD5.1.WEB-DL,WEB-DL.DD5.1.DL XIII.The.Series.2011,XIII.2011" FILEEXT="\\.nfo\\. \\.par2\\." # Find files containing spaces and rename them according to the scene rules for ext in $EXTENSIONS; do [ "$ext" != ".srt" ] && \ /opt/bin/find . -name "* *$ext" -type f -exec sh -c ' fp="${0%/*}" fn="${0##*/}" fn="$( echo $fn | /opt/bin/sed -e "s,\!,," )" fn="$( echo $fn | /opt/bin/egrep -oi "[A-Z][A-Za-z0-9.-]+.$ext" | sort -u | tail -n1 )" echo "Enforcing naming scheme for $0" mv "$0" "$fp/$fn" read -t 1 line </dev/tty ' {} ';' done # Build the list of replacements. Do it here, since we need to # do it only once, and not for each file. for pat in $PATTERN; do set -- `echo $pat | tr , \ ` REN="$REN -e ""s,$1,$2,g""" done for pat in $FILEEXT; do REN="$REN -e ""s,${pat},,g""" done REN="$REN -e ""s/[()]//g""" # Main loop starts here. Only handle files with the specified extensions. for ext in $EXTENSIONS; do REGEX="$REGEX|$ext" done REGEX="$( echo $REGEX | sed "s,|,," )" MAIN_REN=$REN for file in $( /opt/bin/find . -regextype posix-egrep -type f -regex ".*($REGEX)" ! -wholename '*tvshow*' ! -wholename '*season*' ! -wholename '*actors' | sort ); do OLD="$file" NEW="$file" REN="$MAIN_REN" if [ "$( echo $file | /opt/bin/egrep "\.(REPACK|REREPACK|PROPER|iNTERNAL|RERIP|REAL)\." )" == "" ] ; then if [ "$( echo $file | /opt/bin/grep "720p" )" != "" ] ; then REN="$REN -e ""s/\(.*S[0-9]\+\(E[0-9]\+\)\+\)\+.*\(720p.*\)/\1.\3/""" fi if [ "$( echo $file | /opt/bin/grep "1080p" )" != "" ] ; then REN="$REN -e ""s/\(.*S[0-9]\+\(E[0-9]\+\)\+\)\+.*\(1080p.*\)/\1.\3/""" fi fi NEW="$( echo $OLD | /opt/bin/sed $REN )" if [ ! -z "$NEW" -a "$NEW" != "$OLD" ] ; then echo "Enforcing naming scheme for $file" mv "$OLD" "$NEW" fi done [ "$OPTS" = "--force" ] && RESCAN_ALL=1 || RESCAN_ALL=0 IFS=" " if [ $RESCAN_ALL -eq 1 ] ; then FILES="`/opt/bin/grep -rl 'episodedetails' */*/*.nfo 2>/dev/null`" else # Get a list of all NFO files having incorrect information FILES="`/opt/bin/egrep -rli '(\(Guest Star\)|\(Writer\))' */*/*.nfo 2>/dev/null`" fi for episode in $FILES; do # First convert the nfo-file to use linux line-breaks. /opt/bin/sed -i 's/^M$//' $episode if [ "$( /opt/bin/grep '<director>.*</director>' $episode )" == "" ] ; then DIRECTOR_MISSING="$DIRECTOR_MISSING $episode" fi if [ "$( /opt/bin/grep '<credits>.*</credits>' $episode )" == "" ]; then CREDITS_MISSING="$CREDITS_MISSING $episode" fi if [ "$( /opt/bin/grep '<credits>.*\(Writer\).*</credits>' $episode )" == "" ]; then WRITER_MISSING="$WRITER_MISSING $episode" fi if [ "$( /opt/bin/grep '<credits>.*\&.*</credits>' $episode )" != "" ]; then CREDITS_JUNK="$CREDITS_JUNK $episode" else # see if the file has new-style (multi-line) or old-style (single-line) credits. if [ "$( /opt/bin/grep '<credits>' $episode | wc -l )" -gt 1 ] ; then echo "Updating episode information in $episode (new-style)" mv $episode $episode.old /opt/bin/grep -v "(Guest Star)</credits>" $episode.old | /opt/bin/sed \ -e "s, (Writer),,g" -e -e "s,|, / ,g" \ -e "s, , ,g" -e 's/^[ \t]*//' | \ tee $episode &>/dev/null else # Mangle the list, so we can work with it old_credits="$( /opt/bin/grep "<credits>" $episode | /opt/bin/sed -n \ -e 's/.*<credits>\(.*\)<\/credits>.*/\1/p' )" # Fixup the credits line new_credits="$( echo $old_credits | tr '/' '\n' | /opt/bin/grep -v "Guest Star" | \ tr '\n' '/' | /opt/bin/sed -e "s, (Writer),,g" \ -e "s,|, / ,g" -e "s, , ,g" | /opt/bin/sed -e 's/^[ \t]*//' \ -e "s/\/*$//" )" shopt -q -s extglob echo "Updating episode information in $episode (old-style)" if [ -n "$new_credits" ] ; then /opt/bin/sed -i "s|${old_credits##+([[:space:]])}|$new_credits|g" $episode fi shopt -q -u extglob fi fi done IFS=" " if [ -n "$DIRECTOR_MISSING" ] ; then echo "The following episodes are missing a director:" for episode in $DIRECTOR_MISSING; do echo " $episode" done echo fi if [ -n "$CREDITS_JUNK" ] ; then echo "The following episodes credits' contain junk and should be fixed at thetvdb.com:" for episode in $CREDITS_JUNK; do echo " $episode" done echo fi if [ -n "$CREDITS_MISSING" ] ; then echo "The following episodes are missing credits:" for episode in $CREDITS_MISSING; do echo " $episode" done echo fi if [ -n "$WRITER_MISSING" ] ; then echo "The following episodes are missing a writer:" for episode in $WRITER_MISSING; do echo " $episode" done fi /opt/bin/findutils-find . -name "*.old" -exec rm {} \; Bear in mind, this script is using ipkg/optware executables, mainly because the provided BusyBox ones are lacking some features.