SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/bin/sh | |
| 2 | ||
| 3 | - | ########################################################################################################## |
| 3 | + | #--------------------------------------------------------------------------- |
| 4 | - | # RENAMING SCRIPT |
| 4 | + | #------- Script "bereinigt" Datei / Ordner - Namen und entfernt |
| 5 | - | # CONFIG |
| 5 | + | #------- ungewollte u. unoetige Dateien / Dateinamen-Parts wie |
| 6 | #------- Scene-Tags oder Sprachangaben und bringt die Dateien in | |
| 7 | - | PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/pyload/scripts/unrar_finished |
| 7 | + | #------- eine saubere Dateikultur |
| 8 | - | DESTINATION="/volume1/Video/" #path where downloaded files should be moved to |
| 8 | + | #------- |
| 9 | #------- Initial-Script für pyLoad "package_finished" / "unrar_finished" | |
| 10 | #------- findet ihr unter http://pastebin.com/veq9miyX | |
| 11 | - | ########################################################################################################## |
| 11 | + | #------- |
| 12 | - | # find and delete unnecessary files and folders |
| 12 | + | #------- aktuelle "ipkg tr" "ipkg sed" "ipkg find" Pakete vorausgesetzt! |
| 13 | #------- "ipkg update" "ipkg install tr sed find" | |
| 14 | - | find . \( -name '*.sfv' -o -name '*.nfo' -o -name '*.txt' -o -name '*.rev' \) -type f -exec rm '{}' \;
|
| 14 | + | #--------------------------------------------------------------------------- |
| 15 | - | find . \( -iname '*sample*' -o -iname 'subs' -o -iname '*imdb*' \) -type d -exec rm -rf '{}' \;
|
| 15 | + | |
| 16 | #--------------------------------------------------------------------------- | |
| 17 | #------- persoenliche Pfadangaben in http://pastebin.com/veq9miyX bearbeiten | |
| 18 | - | ########################################################################################################## |
| 18 | + | #--------------------------------------------------------------------------- |
| 19 | - | # start cleanup filenames and foldernames - first replace spaces with dots |
| 19 | + | |
| 20 | PATH=/opt/bin:/opt/sbin | |
| 21 | - | rmSpacesDir() |
| 21 | + | |
| 22 | - | {
|
| 22 | + | #--------------------------------------------------------------------------- |
| 23 | - | find `$UF_FOLDER/`* -name "* *" -type d -print | while read FILE |
| 23 | + | #------- entferne unnoetige Dateien und Ordner |
| 24 | - | do |
| 24 | + | #------- Textdateien / Info-Dateien / Reparatur-Dateien / Untertitel ... |
| 25 | - | NEW=`echo "$FILE" | sed -r 's/ +/./g'` |
| 25 | + | #--------------------------------------------------------------------------- |
| 26 | ||
| 27 | - | done |
| 27 | + | |
| 28 | - | } |
| 28 | + | /opt/bin/find . \( -name '*.sfv' -o -name '*.nfo' -o -name '*.txt' -o -name '*.rev' \) -type f -exec rm '{}' \;
|
| 29 | /opt/bin/find . \( -iname '*sample*' -o -iname 'subs' -o -iname '*imdb*' \) -type d -exec rm -rf '{}' \;
| |
| 30 | ||
| 31 | - | rmSpaces() |
| 31 | + | #--------------------------------------------------------------------------- |
| 32 | - | {
|
| 32 | + | #------- entferne Leerzeichen und ersetze Sonderzeichen mit Punkten |
| 33 | - | find `$UF_FOLDER/`* -name "* *" -type f -print | while read FILE |
| 33 | + | #--------------------------------------------------------------------------- |
| 34 | ||
| 35 | - | NEW=`echo "$FILE" | sed -r 's/ +/./g'` |
| 35 | + | |
| 36 | {
| |
| 37 | - | done |
| 37 | + | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -type d -print | while read FILE |
| 38 | do | |
| 39 | if [ -d $FILE ]; then | |
| 40 | - | rmSpacesDir |
| 40 | + | |
| 41 | - | rmSpaces |
| 41 | + | renRecursive |
| 42 | - | rmSpacesDir |
| 42 | + | renFolder |
| 43 | - | rmSpaces |
| 43 | + | renFiles |
| 44 | - | rmSpacesDir |
| 44 | + | |
| 45 | - | rmSpaces |
| 45 | + | fi |
| 46 | done | |
| 47 | } | |
| 48 | - | ########################################################################################################## |
| 48 | + | |
| 49 | - | # replace - and _ and .. with dots |
| 49 | + | renFolder() |
| 50 | {
| |
| 51 | - | cleanRecursive() |
| 51 | + | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -type d -print | while read FILE |
| 52 | do | |
| 53 | - | for FILE in `ls` |
| 53 | + | if [ -d "$FILE" ]; then |
| 54 | NEW=`echo "$FILE" | sed -r 's/ +/./g' | sed -r 's/-/./g;s/_/./g;s/^\.+//;s/\.+$//' | tr -s '.'` | |
| 55 | if [ $NEW != $FILE -a ! -f $NEW -a ! -d $NEW ]; then | |
| 56 | mv "$FILE" "$NEW" | |
| 57 | - | cleanRecursive |
| 57 | + | fi |
| 58 | - | cleanFiles |
| 58 | + | fi |
| 59 | done | |
| 60 | } | |
| 61 | ||
| 62 | renFiles() | |
| 63 | {
| |
| 64 | - | cleanFiles() |
| 64 | + | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -type f -print | while read FILE |
| 65 | do | |
| 66 | - | for FILE in `ls` |
| 66 | + | if [ -f "$FILE" ]; then |
| 67 | NEW=`echo "$FILE" | sed -r 's/ +/./g' | sed -r 's/-/./g;s/_/./g;s/^\.+//;s/\.+$//' | tr -s '.'` | |
| 68 | - | if [ -f $FILE -o -d $FILE ]; then |
| 68 | + | if [ $NEW != $FILE -a ! -f $NEW -a ! -d $NEW ]; then |
| 69 | - | convert=`echo $FILE | sed -r 's/-/./g;s/_/./g;s/\.+/./g'` |
| 69 | + | |
| 70 | - | mv $FILE $convert |
| 70 | + | fi |
| 71 | fi | |
| 72 | done | |
| 73 | } | |
| 74 | ||
| 75 | - | cleanRecursive |
| 75 | + | #--------------------------------------------------------------------------- |
| 76 | - | cleanFiles > /dev/null |
| 76 | + | #------- aendere rekursiv alles in Kleinbuchstaben |
| 77 | - | cleanRecursive |
| 77 | + | #--------------------------------------------------------------------------- |
| 78 | - | cleanFiles > /dev/null |
| 78 | + | |
| 79 | lowRecursive() | |
| 80 | {
| |
| 81 | - | ########################################################################################################## |
| 81 | + | /opt/bin/find `$UF_FOLDER/`* -name "*" -type d -print | while read FILE |
| 82 | - | # set everthing to lowercase |
| 82 | + | |
| 83 | if [ -d $FILE ]; then | |
| 84 | cd $FILE | |
| 85 | lowRecursive | |
| 86 | - | for FILE in `ls` |
| 86 | + | lowFiles |
| 87 | cd .. | |
| 88 | fi | |
| 89 | - | cd $FILE |
| 89 | + | |
| 90 | - | renRecursive |
| 90 | + | |
| 91 | - | renFiles |
| 91 | + | |
| 92 | - | cd .. |
| 92 | + | lowFiles() |
| 93 | {
| |
| 94 | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" | while read FILE | |
| 95 | do | |
| 96 | if [ -f $FILE -o -d $FILE ]; then | |
| 97 | NEW=`echo $FILE | tr 'A-Z' 'a-z'` | |
| 98 | if [ $NEW != $FILE -a ! -f $NEW -a ! -d $NEW ]; then | |
| 99 | - | for FILE in `ls` |
| 99 | + | |
| 100 | fi | |
| 101 | - | if [ -f $FILE -o -d $FILE ]; then |
| 101 | + | fi |
| 102 | - | convert=`echo $FILE | tr [:upper:] [:lower:]` |
| 102 | + | |
| 103 | - | mv $FILE $convert |
| 103 | + | |
| 104 | - | fi |
| 104 | + | |
| 105 | #--------------------------------------------------------------------------- | |
| 106 | #------- entferne Szene-Tags und / oder unnoetige Dateinamenteile | |
| 107 | #------- "$DELNAME" Pfadangabe unter http://pastebin.com/veq9miyX | |
| 108 | #------- anpassen und die entsprechende Datei erstellen / editieren | |
| 109 | - | renRecursive |
| 109 | + | #--------------------------------------------------------------------------- |
| 110 | - | renFiles > /dev/null |
| 110 | + | |
| 111 | rmTagsRecursive() | |
| 112 | {
| |
| 113 | - | ########################################################################################################## |
| 113 | + | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -type d -print | while read FILE |
| 114 | - | # uppercase first character (after dot) and do renaming |
| 114 | + | |
| 115 | if [ -d $FILE ]; then | |
| 116 | cd "$FILE" | |
| 117 | rmTagsRecursive | |
| 118 | - | for FILE in `ls` |
| 118 | + | rmTags |
| 119 | cd .. | |
| 120 | fi | |
| 121 | - | cd $FILE |
| 121 | + | |
| 122 | - | upRecursive |
| 122 | + | |
| 123 | - | renUpperfolders |
| 123 | + | |
| 124 | - | renUpperfiles |
| 124 | + | |
| 125 | - | cd .. |
| 125 | + | |
| 126 | for i in `cat $DELNAME` | |
| 127 | do | |
| 128 | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -print | while read FILE | |
| 129 | - | |
| 129 | + | |
| 130 | - | renUpperfolders() |
| 130 | + | if [ -d $FILE ]; then |
| 131 | - | {
|
| 131 | + | NEW=`echo $FILE | sed -r 's/'"$i"'\.//g' | sed -r 's/\.'"$i"'//g'` |
| 132 | - | for FILE in `ls` |
| 132 | + | if [ $NEW != $FILE -a ! -f $NEW -a ! -d $NEW ]; then |
| 133 | - | do |
| 133 | + | |
| 134 | fi | |
| 135 | - | # pay attention not to break this line |
| 135 | + | fi |
| 136 | - | convert=`echo $FILE | sed -r 's/(\<.)/\u\1/g;s/s0/S0/;s/s1/S1/;s/e0/E0/;s/e1/E1/;s/e2/E2/;s/Dvd/DVD/;s/Dts/DTS/;s/Ac/AC/;s/Md/MD/;s/Bd/BD/;s/3d/3D/;s/Ld/LD/;s/Dl/DL/;s/Hd/HD/'` |
| 136 | + | if [ -f $FILE ]; then |
| 137 | - | mv $FILE $convert |
| 137 | + | NEW=`echo $FILE | sed -r 's/'"$i"'\.//g' | sed -r 's/'"$i"'//g'` |
| 138 | if [ $NEW != $FILE -a ! -f $NEW -a ! -d $NEW ]; then | |
| 139 | mv "$FILE" "$NEW" | |
| 140 | fi | |
| 141 | fi | |
| 142 | - | renUpperfiles() |
| 142 | + | |
| 143 | - | {
|
| 143 | + | |
| 144 | - | for FILE in `ls` |
| 144 | + | |
| 145 | - | do |
| 145 | + | |
| 146 | - | if [ -f $FILE ]; then |
| 146 | + | #--------------------------------------------------------------------------- |
| 147 | - | # pay attention not to break this line |
| 147 | + | #------- aendere ersten Buchstaben nach einem Punkt in einen Grossbuchstaben |
| 148 | - | convert=`echo $FILE | sed -r 's/(\<.)/\u\1/g;s/s0/S0/;s/s1/S1/;s/e0/E0/;s/e1/E1/;s/e2/E2/;s/Dvd/DVD/;s/Dts/DTS/;s/Ac/AC/;s/3d/3D/;s/Md/MD/;s/Bd/BD/;s/Hd/HD/;s/\.Sh$/.sh/;s/\.Mkv$/.mkv/;s/\.Avi$/.avi/;s/\.Img$/.img/;s/\.Iso$/.iso/;s/\.Wmv$/.wmv/;s/\.Vob$/.vob/;s/\.Mp4$/.mp4/'` |
| 148 | + | #--------------------------------------------------------------------------- |
| 149 | - | mv $FILE $convert |
| 149 | + | |
| 150 | upRecursive() | |
| 151 | - | done |
| 151 | + | |
| 152 | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -type d -print | while read FILE | |
| 153 | do | |
| 154 | if [ -d $FILE ]; then | |
| 155 | - | renUpperfolders > /dev/null |
| 155 | + | cd "$FILE" |
| 156 | - | renUpperfiles > /dev/null |
| 156 | + | upRecursive |
| 157 | upFolder | |
| 158 | upFiles | |
| 159 | - | ########################################################################################################## |
| 159 | + | |
| 160 | - | # start remove scene tags |
| 160 | + | fi |
| 161 | done | |
| 162 | } | |
| 163 | ||
| 164 | - | for FILE in `ls` |
| 164 | + | upFolder() |
| 165 | {
| |
| 166 | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -type d -print | while read FILE | |
| 167 | - | cd $FILE |
| 167 | + | |
| 168 | - | rmTagsRecursive |
| 168 | + | |
| 169 | - | rmTags |
| 169 | + | # nachfolgende Codezeile darf nicht "gelinebreakt" werden! |
| 170 | - | cd .. |
| 170 | + | NEW=`echo $FILE | sed -r 's/(\<.)/\u\1/g;s/([se][0123456789])/\u\1/g;s/Dvd/DVD/;s/Dts/DTS/;s/Csi/CSI/;s/Hd/HD/'` |
| 171 | if [ $NEW != $FILE -a ! -f $NEW -a ! -d $NEW ]; then | |
| 172 | mv "$FILE" "$NEW" | |
| 173 | fi | |
| 174 | fi | |
| 175 | done | |
| 176 | } | |
| 177 | - | for FILE in `ls` |
| 177 | + | |
| 178 | upFiles() | |
| 179 | - | if [ -d $FILE -o -f $FILE ]; then |
| 179 | + | |
| 180 | - | # pay attention not to break this line |
| 180 | + | /opt/bin/find `$UF_FOLDER/`* ! -name "*.sh" -type f -print | while read FILE |
| 181 | - | convert=`echo $FILE | sed -r 's/Itg//g;s/Zzgtv//g;s/Runscript/runscript/;s/Qom//g;s/Tvs//g;s/Zg//g;s/Kinowelt//g;s/German//g;s/Jcm//g;s/Ldtv//g;s/Internal//g;s/Tvp//g;s/Deli//g;s/Euhd//g;s/Amb//g;s/Encounters//g;s/Sow//g;s/Sof//g;s/Videowelt//g;s/HDa//g;s/Vcf//g;s/Fbi//g;s/Empire//g;s/Nva//g;s/Tvh//g;s/Aaf//g;s/Isd//g;s/Klassiger//g;s/Idtv//g;s/Mb//g;s/Tuf//g;s/Rsg//g;s/Dec//g;s/Hdw//g;s/7p/720p/;s/Ithd//g;s/Ded//g;s/Centi//g;s/Haco//g;s/Dubbed//g;s/Dl//g;s/Gtvg//g;s/DL//g;s/Web//g;s/Details//g;s/Ws//g;s/X264//g;s/Euhd//g;s/Termi//g;s/Xvid//g;s/Ituneshd//g;s/\.+/./g;s/^\.+//;s/\.+$//'` |
| 181 | + | |
| 182 | - | mv $FILE $convert |
| 182 | + | if [ -f $FILE ]; then |
| 183 | # nachfolgende Codezeile darf nicht "gelinebreakt" werden! | |
| 184 | NEW=`echo $FILE | sed -r 's/(\<.)/\u\1/g;s/([se][0123456789])/\U\1/g;s/Dvd/DVD/;s/Dts/DTS/;s/Hd/HD/;s/Csi/CSI/' | sed -r 's/(\....)$/\L\1/'` | |
| 185 | if [ $NEW != $FILE -a ! -f $NEW -a ! -d $NEW ]; then | |
| 186 | mv "$FILE" "$NEW" | |
| 187 | - | rmTagsRecursive > /dev/null |
| 187 | + | fi |
| 188 | - | rmTags > /dev/null |
| 188 | + | |
| 189 | done | |
| 190 | } | |
| 191 | - | ########################################################################################################## |
| 191 | + | |
| 192 | - | # move files to destinated folder |
| 192 | + | renRecursive |
| 193 | sleep 1 | |
| 194 | - | sleep 12 |
| 194 | + | renFolder |
| 195 | sleep 1 | |
| 196 | - | ls -A runscript.sh |xargs rm |
| 196 | + | renFiles |
| 197 | ||
| 198 | sleep 1 | |
| 199 | lowRecursive | |
| 200 | sleep 1 | |
| 201 | - | for FILE in `ls` |
| 201 | + | lowFiles |
| 202 | ||
| 203 | - | if [ -d "$FILE" -o -f "$FILE" ]; then |
| 203 | + | sleep 1 |
| 204 | - | mv "$FILE" "$DESTINATION" |
| 204 | + | rmTagsRecursive |
| 205 | sleep 1 | |
| 206 | - | # index files and folders - only for synology nas |
| 206 | + | rmTags |
| 207 | - | # cd "$DESTINATION" |
| 207 | + | |
| 208 | - | # if [ -d "$FILE" ] ; then |
| 208 | + | sleep 1 |
| 209 | - | # /usr/syno/bin/synoindex -A "$FILE" > /dev/null |
| 209 | + | renRecursive |
| 210 | - | # fi |
| 210 | + | sleep 1 |
| 211 | - | # if [ -f "$FILE" ] ; then |
| 211 | + | renFolder |
| 212 | - | # /usr/syno/bin/synoindex -a "$FILE" > /dev/null |
| 212 | + | sleep 1 |
| 213 | - | # fi |
| 213 | + | renFiles |
| 214 | ||
| 215 | sleep 1 | |
| 216 | upRecursive | |
| 217 | sleep 1 | |
| 218 | - | copy2destination |
| 218 | + | upFolder |
| 219 | sleep 1 | |
| 220 | upFiles | |
| 221 | - | ########################################################################################################## |
| 221 | + | |
| 222 | - | # remove created folder for dlc |
| 222 | + | #--------------------------------------------------------------------------- |
| 223 | #------- verschiebe Dateien und Ordner ins Zielverzeichnis | |
| 224 | - | rmdir "$UF_FOLDER" |
| 224 | + | #------- loesche "runscript.sh" aus dem Downloadverzeichnis |
| 225 | #--------------------------------------------------------------------------- | |
| 226 | ||
| 227 | - | ########################################################################################################## |
| 227 | + | sleep 5 |
| 228 | - | # end of script |
| 228 | + | /opt/bin/find `$UF_FOLDER/`* -iname "Runscript.sh" -print | while read FILE |
| 229 | do | |
| 230 | - | exit |
| 230 | + | rm "$FILE" |
| 231 | done | |
| 232 | ||
| 233 | copy2destination() | |
| 234 | {
| |
| 235 | echo "`date` /opt/bin/find `$UF_FOLDER/`* ! -iname "*.sh"" >> $LOGFILE | |
| 236 | /opt/bin/find `$UF_FOLDER/`* ! -iname "*.sh" -print | while read FILE | |
| 237 | do | |
| 238 | echo "mv "$FILE" "$DESTINATION/"" >> $LOGFILE | |
| 239 | mv "$FILE" "$DESTINATION/" | |
| 240 | done | |
| 241 | } | |
| 242 | ||
| 243 | copyseries() | |
| 244 | {
| |
| 245 | for SERIEN in `cat $SERIES` | |
| 246 | do | |
| 247 | #--------------------------------------------------------------------------- | |
| 248 | #------- entferne "-type f" um die Datei inkl. Ordner, falls vorhanden, zu verschieben | |
| 249 | #--------------------------------------------------------------------------- | |
| 250 | echo "`date` /opt/bin/find `$UF_FOLDER/`* -iname "*"$SERIEN"*" -type f" >> $LOGFILE | |
| 251 | /opt/bin/find `$UF_FOLDER/`* -iname "*"$SERIEN"*" -type f -print | while read SERIE | |
| 252 | do | |
| 253 | echo "mv "$SERIE" "$DESTISERIEN/"$SERIEN"/"" >> $LOGFILE | |
| 254 | mv "$SERIE" "$DESTISERIEN/"$SERIEN"/" | |
| 255 | done | |
| 256 | done | |
| 257 | } | |
| 258 | copyseries | |
| 259 | ||
| 260 | #--------------------------------------------------------------------------- | |
| 261 | #------- loesche das - leere - Downloadverzeichnis | |
| 262 | #--------------------------------------------------------------------------- | |
| 263 | ||
| 264 | if [ $? -eq 0 ] ; then | |
| 265 | sleep 25; rm -rf "$UF_FOLDER" | |
| 266 | else | |
| 267 | copy2destination | |
| 268 | fi | |
| 269 | ||
| 270 | if [ $? -eq 0 ] ; then | |
| 271 | sleep 25; rm -rf "$UF_FOLDER" | |
| 272 | fi | |
| 273 | ||
| 274 | #--------------------------------------------------------------------------- | |
| 275 | #------- Scriptende | |
| 276 | #--------------------------------------------------------------------------- | |
| 277 | ||
| 278 | exit 0 |