property tothg : 0
property tmng : 0
property tsecg : 0
tell application "Finder"
    set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
   
    my inspecter(chemin)
end tell
on inspecter(un_dossier)
    tell application "Finder"
       
        set nomdos to name of un_dossier -- recupere le nom du dossier
        set FVideo to {"dv", "DV", "mov", "MOV", "VOB", "vob", "divx", "mp4", "MP4"} -- liste des extensions a traiter
        -- mise a 0 des variables duree fichier
        set toth to 0
        set totmn to 0
        set totsec to 0
        -- traitement des fichiers :
        set les_fichiers to files of un_dossier
        repeat with chaque_fichier in les_fichiers
            -- traitement d'un fichier
            tell application "Finder"
                set nom to name of chaque_fichier --récupère le nom du fichier
                set AppleScript's text item delimiters to {"."} -- defini le separateur
                set lextension to get last text item of nom -- recupère l'extension
                set duree to "" -- mise a blanc de la durée
                set lefichier to chaque_fichier as string
                if lextension is in FVideo then -- si fichier video
                    set duree to do shell script "/usr/local/bin/exiftool -Duration " & quoted form of POSIX path of lefichier --récupère la duréeau format teste exiftool
                    set AppleScript's text item delimiters to {":"}
                   
                    set NB to count of text items of duree
                    if NB = 2 then
                        set lesseconde to text item 2 of duree
                        set AppleScript's text item delimiters to {"."}
                        set seconde to text item 1 of lesseconde
                        set minute to 0
                        set heure to 0
                        set AppleScript's text item delimiters to {":"}
                    else
                        set seconde to get last text item of duree as string -- récupère les secondes
                        set minute to text item 3 of duree as string -- récupère les minutes
                        set heure to text item 2 of duree as string --récupère les heures
                    end if
                    -- fait le total du dossier en cours
                    set toth to toth + heure as string
                    set totmn to totmn + minute as string
                    set totsec to totsec + seconde as string
                    -- fait total general
                    set tothg to tothg + heure
                    set tmng to tmng + minute
                    set tsecg to tsecg + seconde
                    my ecriture(lefichier, heure, minute, seconde) --appel pour ecriture dans fichier texte du fichier
                   
                end if
            end tell
        end repeat
        my total(nomdos, toth, totmn, totsec) --appel pour ecriture dans fichier texte total dossier
        -- traitement des dossiers :
        set les_dossiers to folders of un_dossier
        repeat with chaque_dossier in les_dossiers
            my inspecter(chaque_dossier) -- dossier suivant
        end repeat
    end tell
end inspecter
on ecriture(nom, heure, minute, seconde)
    --Ecrit dans la fichier texte le nom + tabulation  + la durée   
    set lelog to open for access ((path to desktop folder as text) & "le dossier.txt") as text with write permission
    write nom & (ASCII character 9) & heure & " h " & minute & " mn " & seconde & " sec " & return to lelog starting at eof
    close access lelog
end ecriture
on total(nomdos, toth, totmn, totsec)
    -- calcule le temps total heure-minutes-secondes et ecrit dans fichier texte total dossier+dans fichierprovisoire listh+listmn+listsec
    set toth to toth + totmn div 60 as string
    set totmn to totmn mod 60 + totsec div 60 as string
    set totsec to totsec mod 60 as string
    set lelog to open for access ((path to desktop folder as text) & "le dossier.txt") as text with write permission
    write " total dossier " & nomdos & (ASCII character 9) & toth & " h " & totmn & " mn " & totsec & " sec" & (ASCII character 13) & return to lelog starting at eof
    close access lelog
end total
tell application "Finder"
    -- calcule le temps total heure-minutes-secondes
    set totgh to tothg + tmng div 60 as string
    set tmng to tmng mod 60 + tsecg div 60 as string
    set tsecg to tsecg mod 60 as string
    --Ecrit dans la fichier texte le nom + tabulation  + la durée   
    set lelog to open for access ((path to desktop folder as text) & "le dossier.txt") as text with write permission
    write " total général du dossier " & (ASCII character 9) & tothg & " h " & tmng & " mn " & tsecg & " sec" & return to lelog starting at eof
    close access lelog
end tell
tell application "Finder"
    (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell