conversor.sh 4.19 KB
Newer Older
Podcast Linux's avatar
Podcast Linux committed
1
2
#!/bin/bash
set -eEuo pipefail
3
# Este comando anterior activa el modo estricto en BASH, si algo falla para la ejecución del script
Podcast Linux's avatar
Podcast Linux committed
4

5
# Colores a usar con el echo -e
Podcast Linux's avatar
Podcast Linux committed
6
7
8
9
10
11
HL='\033[1;32m'   # Bold Green
WL='\033[1;33m'   # Bold Yellow
NL='\033[0m'      # Text Reset

GITLAB="$HOME/Documentos/podcastlinux.gitlab.io"

12
f_convertir () {
13

14
    echo "$PWD" # Mostramos en la carpeta en la que estamos (DEBUG)
15
16
17
18
19
    ffmpeg -hide_banner -y -i "$FUENTE" -metadata title="$TITLE" -metadata artist="Podcast Linux" -metadata genre="Podcast" -metadata track="$PISTA" -metadata copyright="CC BY - SA 4.0" -metadata year="$(date +"%Y")" -metadata comment="Podcast realizado por Juan Febles con $GRABADOR" -metadata language=esp -ar 44100 -ac 1 -ab "${BITRATE}k" "$DESTINO.$FORMATO"

    # -i $IMAGEN -map_metadata 0 -map 0 -map 1
    # ffmpeg no se lleva bien con meter caratulas en ogg, en mp3 funciona con el anterior comando
    kid3-cli -c "set picture:${IMAGEN} 'Portada'" "$DESTINO.$FORMATO"
Podcast Linux's avatar
Podcast Linux committed
20
21
}

22
f_metadatos() {
Podcast Linux's avatar
Podcast Linux committed
23
24
    RUTAART="$GITLAB/content/posts/$SECCION/$episodio-$ARTICULO"

25
    f_nuevohugo # Lanzamos la función de crear articulos
Podcast Linux's avatar
Podcast Linux committed
26

Podcast Linux's avatar
Podcast Linux committed
27
28
29
30
31
32
    if [[ $FORMATO == "ogg" ]]; then
        olength=$(wc -c "$DESTINO.ogg" | awk '{print $1}')
        sed -i "s/olength.*/olength : $olength/" "$RUTAART"
    else
        mlength=$(wc -c "$DESTINO.mp3" | awk '{print $1}')
        sed -i "s/mlength.*/mlength : $mlength/" "$RUTAART"
Podcast Linux's avatar
Podcast Linux committed
33
        sed -i "s/title:.*/title: \"$TITLE\"/" "$RUTAART"
Podcast Linux's avatar
Podcast Linux committed
34
    fi
35
    # Este dato es siempre el mismo estemos dentro del bucle for en MP3 u OGG
Podcast Linux's avatar
Podcast Linux committed
36
37
38
39
    iduration=$(ffprobe -hide_banner -i "$DESTINO.$FORMATO" 2>&1 | grep Duration| cut -c 13-20)
    sed -i "s/iduration.*/iduration : \"$iduration\"/" "$RUTAART"
}

40
f_nuevohugo() {
41
    # Comprobamos si ya existe el articulo
Podcast Linux's avatar
Podcast Linux committed
42
    if ! [[ -s $RUTAART ]]; then
43
        # Y si no existe lo creamos con el archetype correspondiente que sacamos $SECCION
Podcast Linux's avatar
Podcast Linux committed
44
        cd "$GITLAB"
Podcast Linux's avatar
Podcast Linux committed
45
        hugo new --kind "$SECCION" "posts/$SECCION/$episodio-$ARTICULO"
Podcast Linux's avatar
Podcast Linux committed
46
        cd "$DIRECTORIO"
Podcast Linux's avatar
Podcast Linux committed
47
48
49
    fi
}

Podcast Linux's avatar
Podcast Linux committed
50
51
f_sube_ia () {
    ia upload "$IA" "$DESTINO.ogg" "$DESTINO.mp3"
52
53
}

Podcast Linux's avatar
Podcast Linux committed
54
echo -e "${HL}¿${WL}(P)${HL}odcast Linux o ${WL}(L)${HL}inux Express?: ${NL}"
Podcast Linux's avatar
Podcast Linux committed
55
read -r podcast
Podcast Linux's avatar
Podcast Linux committed
56
echo -e "${HL}Episodio: ${NL}"
Podcast Linux's avatar
Podcast Linux committed
57
read -r episodio
Podcast Linux's avatar
Podcast Linux committed
58
echo -e "${HL}¿Quieres ${WL}(C)${HL}onvertir / ${WL}(M)${HL}etadatos / ${WL}(A)${HL}mbos / sólo ${WL}(S)${HL}ubir episodio?: ${NL}"
59
read -r r_acciones
David Marzal's avatar
David Marzal committed
60

Podcast Linux's avatar
Podcast Linux committed
61
62
63
if [[ $podcast == "P" ]] ;then
    echo -e "${HL}Título episodio: ${NL}"
    read -r titulo
David Marzal's avatar
David Marzal committed
64
    echo -e "${HL}¿Subo a Archive.org?: ${NL}"
65
    read -r r_ia
Podcast Linux's avatar
Podcast Linux committed
66

67
    # Ajustamos las variables y la carpeta en funcion de que tipo de podcast es para la ejecución de comandos
Podcast Linux's avatar
Podcast Linux committed
68
    cd "$HOME/Música/PL${episodio}/export/" || exit 1
Podcast Linux's avatar
Podcast Linux committed
69
    DIRECTORIO="$HOME/Música/PL${episodio}/export/"
Podcast Linux's avatar
Podcast Linux committed
70
71
72
73
74
75
76
    FUENTE="PL${episodio}.flac"
    IMAGEN="$HOME/Imágenes/PL${episodio}.png"
    TITLE="#$episodio $titulo"
    PISTA=$(("$episodio" + 1))
    DESTINO="PL${episodio}"
    SECCION='podcastlinux'
    ARTICULO='Podcast-Linux.md'
David Marzal's avatar
David Marzal committed
77
78
    BITRATE=80
    GRABADOR='Ardour'
Podcast Linux's avatar
Podcast Linux committed
79
    IA='podcast_linux'
80
    # Ejecutamos los comandos dos veces, una con FORMATO=mp3 y otra con FORMATO=ogg
Podcast Linux's avatar
Podcast Linux committed
81
    for FORMATO in mp3 ogg ; do
82
        # Solo ejecutamos los comandos en funcion de las respuestas que hemos dado
83
84
        [[ "$r_acciones" =~ ^(A|a|C|c)$ ]] && f_convertir
        [[ "$r_acciones" =~ ^(A|a|M|m)$ ]] && f_metadatos
Podcast Linux's avatar
Podcast Linux committed
85
        
Podcast Linux's avatar
Podcast Linux committed
86
    done
87

Podcast Linux's avatar
Podcast Linux committed
88
89
    [[ "$r_ia" =~ ^(SI|si|S|s|y|yes|Y|YES)$ ]] || [[ "$r_acciones" =~ ^(S|s)$ ]] && f_sube_ia
    
Podcast Linux's avatar
Podcast Linux committed
90
elif [[ $podcast == "L" ]] ;then
Podcast Linux's avatar
Podcast Linux committed
91
92
    echo -e "${HL}¿Subo a Archive.org?: ${NL}"
    read -r r_ia
93
    cd "$HOME/Música/" || exit 2
Podcast Linux's avatar
Podcast Linux committed
94
    DIRECTORIO="$HOME/Música/"
Podcast Linux's avatar
Podcast Linux committed
95
96
97
98
    FUENTE="${episodio}linuxexpress.flac"
    IMAGEN="$HOME/Imágenes/linuxexpress.png"
    TITLE="#$episodio Linux Express"
    PISTA="$episodio"
Podcast Linux's avatar
Podcast Linux committed
99
    DESTINO="${episodio}linuxexpress"
Podcast Linux's avatar
Podcast Linux committed
100
101
    SECCION='linuxexpress'
    ARTICULO='Linux-Express.md'
David Marzal's avatar
David Marzal committed
102
103
    BITRATE=64
    GRABADOR='Audacity'
Podcast Linux's avatar
Podcast Linux committed
104
    IA='linuxexpress'
Podcast Linux's avatar
Podcast Linux committed
105
    for FORMATO in mp3 ogg ; do
106
107
        [[ "$r_acciones" =~ ^(A|a|C|c)$ ]] && f_convertir
        [[ "$r_acciones" =~ ^(A|a|M|m)$ ]] && f_metadatos
Podcast Linux's avatar
Podcast Linux committed
108
    done
Podcast Linux's avatar
Podcast Linux committed
109
110
111
 
    [[ "$r_ia" =~ ^(SI|si|S|s|y|yes|Y|YES)$ ]] || [[ "$r_acciones" =~ ^(S|s)$ ]] && f_sube_ia
    
Podcast Linux's avatar
Podcast Linux committed
112
else
113
    echo -e "${WL}Debes elegir un Podcast${NL}"
Podcast Linux's avatar
Podcast Linux committed
114
115
fi

116
echo -e "${HL}FIN!${NL}"