summaryrefslogtreecommitdiff
path: root/lcl-edit
blob: 5757625d2d4f406ddd9ae3af5826150d7959a856 (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
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
#! /bin/bash

source ./util/menu/deasy-core
source ./util/notify
source ./util/dpath

run() {
    cd "$HOME/Desktop"
    filepath="$(find -L "$DPATH" \
                        . \
                        -type f | dmenu -b \
                                        -i \
                                        -l 25 \
                                        -p 'Search File:' \
                                        -nb '#ffffff' \
                                        -nf '#000080' \
                                        -sb '#000080' \
                                        -sf '#ffffff')"
    [ -f "$filepath" ] || exit 0

    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 20 \
                                                              -p 'Select Edit:' \
                                                              -nb '#ffffff' \
                                                              -nf '#000080' \
                                                              -sb '#000080' \
                                                              -sf '#ffffff')"

    basedir="$(dirname "$filepath")";
    filename="$(basename "$filepath")"
    savepath="$DPATH/$filename"
    basename="${filename%.*}"

    case "$selected" in
        "${CHOICES[0]}")
            ffmpeg -n \
                   -sn \
                   -i "$filepath" \
                   -map_metadata -1 \
                   -map_chapters -1 \
                   -c:v copy \
                   -c:a copy \
                   "$DPATH/[STRIP] $filename"
        ;;

        "${CHOICES[1]}")
            fileext="$(deasy_core 'File Extension (mp3)')"
            [ -z "$fileext" ] && exit 0

            ffmpeg -n -i "$filepath" "${savepath%.*}.$fileext"
        ;;

        "${CHOICES[2]}")
            scale="$(deasy_core 'Scale (854:480)')"
            [ -z "$scale" ] && exit 0

            ffmpeg -y \
                   -i "$filepath" \
                   -vf scale="$scale" \
                   "$DPATH/[$scale] $filename"
        ;;

        "${CHOICES[3]}")
            from="$(deasy_core 'From (00:00/n)')"
            [ -z "$from" ] && exit 0

            to="$(deasy_core 'To (00:00/n)')"
            [ -z "$to" ] && exit 0

            ffmpeg -y \
                   -ss "$from" \
                   -to "$to" \
                   -i "$filepath" \
                   "$DPATH/[CLIP] $filename"
        ;;

        "${CHOICES[4]}")
            ffmpeg -n \
                   -i "$filepath" \
                   -f ffmetadata \
                   "$DPATH/[CHAPTERS] $basename"
        ;;

        "${CHOICES[5]}")
            chapterpath="$(deasy_core 'Chapter Filepath')"
            [ -z "$chapterpath" ] && exit 0

            ffmpeg -n \
                   -i "$filepath" \
                   -i "$chapterpath" \
                   -map_metadata 1 \
                   -codec copy \
                   "$DPATH/[WITH-CHAPTERS] $filename"
        ;;

        "${CHOICES[6]}")
            mkdir -p "$DPATH/$basename"
            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 \
                                       "$DPATH/$basename/$chapter.${filepath##*.}"
                            done
        ;;

        "${CHOICES[7]}")
            cp "$filepath" "$DPATH/[STRIP] $filename"
            exiftool -overwrite_original -all= "$DPATH/[STRIP] $filename"
        ;;

        "${CHOICES[8]}")
            fileext="$(deasy_core 'File Extension (png)')"
            [ -z "$fileext" ] && exit 0

            convert "$filepath" "${savepath%.*}.$fileext"
        ;;

        "${CHOICES[9]}")
            size="$(deasy_core 'Size (75x75)')"
            [ -z "$size" ] && exit 0

            convert "$filepath" -resize "$size" "$DPATH/[$size] $filename"
        ;;

        "${CHOICES[10]}")
            convert "$filepath" -trim "$DPATH/[TRIM] $filename"
        ;;

        "${CHOICES[11]}")
            n="$(deasy_core 'Border Radius (n)')"
            [ -z "$n" ] && exit 0

            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 "$DPATH/[RADIUS] $filename"
        ;;

        '')
            exit 0
        ;;

        *)
            notify 'Invalid Entry'
        ;;
    esac
}

run "$@"; status=$?

[ ! $status -eq 0 ] && [ ! $status -eq 143 ] \
                    && notify 'Something Went Wrong'