summaryrefslogtreecommitdiff
path: root/lcl-edit
blob: 16b39370f72224aefff624be377444b459426405 (plain)
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
#! /bin/zsh

filepath="$(find ~/Archive -type d \( -name node_modules -o -name .git \) -prune -o \
                           -type f -name '*' -print | dmenu -i -l 15 -p 'Search File')"
[ ! -f "$filepath" ] && exit 1

CHOICES=('[Video]Strip' \
         '[Video]Transcode' \
         '[Video]Scale' \
         '[Video]Clip' \
         '[Video]Extract-Chapters' \
         '[Video]Insert-Chapters' \
         '[Video]Split-Chapters' \
         '[Image]Strip' \
         '[Image]Convert' \
         '[Image]Resize'
         '[Image]Trim' \
         '[Image]Border-Radius')

[ ! -z "$1" ] && selected="$1" \
              || selected="$(echo "${CHOICES[@]}" | tr ' ' '\n' \
                                                  | dmenu -i -l 15 -p 'Select Edit')"

filename="$(basename "$filepath")"

case "$selected" in
    "${CHOICES[1]}")
        ffmpeg -n \
               -sn \
               -i "$filepath" \
               -map_metadata -1 \
               -map_chapters -1 \
               -c:v copy \
               -c:a copy \
               "$HOME/[STRIP] $filename" ;;
    "${CHOICES[2]}")
        fileext="$(print | dmenu -p 'File Extension (mp3)')"
        [ ! -z "$fileext" ] && ffmpeg -n \
                                      -i "$filepath" \
                                      "${filepath%.*}.$fileext" ;;
    "${CHOICES[3]}")
        scale="$(print | dmenu -p 'Scale (854:480)')"
        [ ! -z "$scale" ] && ffmpeg -y \
                                    -i "$filepath" \
                                    -vf scale="$scale" \
                                    "$HOME/[$scale] $filename" ;;
    "${CHOICES[4]}")
        from="$(print | dmenu -p 'From (00:00/n)')"
        [ -z "$from" ] && exit 0

        to="$(print | dmenu -p 'To (00:00/n)')"
        [ -z "$to" ] && exit 0

        ffmpeg -y \
               -ss "$from" \
               -to "$to" \
               -i "$filepath" \
               "$HOME/[CLIP] $filename" ;;
    "${CHOICES[5]}")
        ffmpeg -n \
               -i "$filepath" \
               -f ffmetadata \
               "$HOME/[CHAPTERS] ${filename%.*}" ;;
    "${CHOICES[6]}")
        chapterpath="$(print | dmenu -p 'Chapter Filepath')"
        [ -z "$chapterpath" ] && exit 0

        ffmpeg -n \
               -i "$filepath" \
               -i "$chapterpath" \
               -map_metadata 1 \
               -codec copy \
               "$HOME/[WITH-CHAPTERS] $filename" ;;
    "${CHOICES[7]}")
        mkdir -p "$HOME/${filename%.*}"
        ffprobe -print_format csv \
                -show_chapters \
                "$filepath" \
                    | cut -d ',' -f '5,7,8' \
                    | while IFS=, read start end chapter
                        do
                            ffmpeg -n \
                                   -nostdin \
                                   -i "$filepath" \
                                   -ss "$start" \
                                   -to "$end" \
                                   -c copy \
                                   -map 0 \
                                   -map_chapters -1 \
                                   "$HOME/${filename%.*}/$chapter.${filepath##*.}"
                        done ;;
    "${CHOICES[8]}")
        cp "$filepath" "$HOME/[STRIP] $filename"
        exiftool -overwrite_original -all= "$HOME/[STRIP] $filename" ;;
    "${CHOICES[9]}")
        fileext="$(print | dmenu -p 'File Extension (png)')"
        [ ! -z "$fileext" ] && convert "$filepath" "$HOME/${filename%.*}.$fileext" ;;
    "${CHOICES[10]}")
        size="$(print | dmenu -p 'Size (75x75)')"
        [ ! -z "$size" ] && convert "$filepath" -resize "$size" "$HOME/[$size] $filename" ;;
    "${CHOICES[11]}")
        convert "$filepath" -trim "$HOME/[TRIM] $filename" ;;
    "${CHOICES[12]}")
        n="$(print | dmenu -p 'Border Radius (n)')"
        [ ! -z "$n" ] && convert "$filepath" \
                      \( +clone  -alpha extract \
                         -draw "fill black polygon 0,0 0,$n $n,0 fill white circle $n,$n $n,0" \
                         \( +clone -flip \) -compose Multiply -composite \
                         \( +clone -flop \) -compose Multiply -composite \
                      \) -alpha off -compose CopyOpacity -composite "$HOME/[RADIUS] $filename" ;;
    '') exit 0 ;;
    *) exit 1 ;;
esac