ubuntuusers.de

Titel:
Mediathekview txt zu Kodi nfo
Autor:
tuxfux-ch
Datum:
16. August 2017 16:55
Aktionen:
Code:
 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
#! /bin/bash

# Script to create Kodi friendly NFO files and deletes corresponding .txt files if present
# the scipt uses ffmpeg, sed, echo -e and awk
# the script assumes that the files are in the folder this scipt is run and there are 
# only video files and possibly correspodning nfo and or txt files
# it does not enter subfolders

# i use this scipt as preparation before i move them into the kodi library. 
# i add a lot of genre tags. After this scipt run i manually delete the genre tags not needed

#replace all spaces in filenames
echo -e "\033[0;33m replace spaces in filnames in this directory...\033[0m"
find . -exec rename "s/ /_/g" {} \;
echo -e "\033[0;33m generate .nfo files for files with no corresponding .nfo files...\033[0m"
for file in `find -maxdepth 1 -type f | ls`
do
  if [ $file = `basename "$0"` ] #if $file is the scipt itselfe: skip
    then
      continue
    else
      if [ -f "${file%*.*}.nfo" ]
        then 
          continue #if nfo already exists, skip this file
        else
          set=""
          plot=""
          sender=""
          
          #if the filenames indicates a movie belonging to a set rembember it          
          if [[ "$file" == *Terra_X* ]]
            then
              set="Terra X"
          fi
          if [[ "$file" == *Mit_offenen_Karten* ]]
            then
              set="Mit offenen Karten"
          fi
          if [[ "$file" == *Sternstunde_Religion* ]]
            then
              set="Sternstunde Religion"
          fi
          if [[ "$file" == *Sternstunde_Philosophie* ]] || [[ "$file" == *sternstundephilosophie* ]]
            then
              set="Sternstunde Philosophie"
          fi
          if [[ "$file" == *Einstein-* ]]
            then
              set="Einstein"
          fi
          if [[ "$file" == *Arena-* ]]
            then
              set="Arena"
          fi
          
          
          if [ -f "${file%*.*}.txt" ] #if there is a corresponding txt file, get info from there....
            then
                #Get everything after "Titel:" & any number of withe spaces from corresponding txt file
                title=`sed -n -e 's/^.*Titel:[[:space:]]\+//p' ${file%*.*}.txt`
          
                runtime=`sed -n -e 's/^.*Dauer:[[:space:]]\+//p' ${file%*.*}.txt`
                    stunden=${runtime::2}
                    minuten=${runtime:3:2}
                    runtime=$((${stunden/#0/} * 60 + ${minuten/#0/}))  #&& echo "runtime:  <runtime>$runtime</runtime>"
                    # Vorzicht: Bei führender Null werden Zahlen als octal erkannt, daher muss diese gelöscht werden!!
                    
                    
                plot=`awk 'END{print $0}' RS= ${file%*.*}.txt`
                
                sender=`sed -n -e 's/^.*Sender:[[:space:]]\+//p' ${file%*.*}.txt`
                
                rm ${file%*.*}.txt
                echo -e "file \033[0;35m${file%*.*}.txt\033[0m \033[0;31mdeleted\033[0m"
            else #... or get them from filename and with the help of ffmpeg
                title=${file//_/ }
                runtime=`ffmpeg -i $file 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//`
        fi
			
			
        #generate nfo file
        echo -e  "<movie>\n  <title>$title</title>\n  <set>$set</set>\n  <rating></rating>\n  <runtime>$runtime</runtime>\n  <plot>$plot\n--$sender\n  </plot>\n \n  <genre>Documentary</genre>\n  <genre>Kultur</genre>\n  <genre>Talkshow</genre>\n  <genre>Short</genre>\n \n  <genre>Animation</genre>\n  <genre>Action</genre>\n  <genre>Adventure</genre>\n  <genre>Biography</genre>\n  <genre>Comedy</genre>\n  <genre>Crime</genre>\n  <genre>Drama</genre>\n  <genre>Food</genre>\n  <genre>Family</genre>\n  <genre>Fantasy</genre>\n  <genre>History</genre>\n  <genre>Mystery</genre>\n  <genre>Politics</genre>\n  <genre>Romance</genre>\n  <genre>Science Fiction</genre>\n  <genre>Thriller</genre>\n  <genre>War</genre>\n  <genre>Western</genre>\n</movie>" > ${file%*.*}.nfo

        echo -e "file \033[0;35m${file%*.*}.nfo\033[0m created"
      fi
   fi
done
echo -e "\033[0;33mTask completed!\033[0m"