This siteAll blogsLe 17ClémentCCBCuisineLe 3ContactSe connecterS'inscrire
  • All blogs
  • Le 17
  • Clément
  • CCB
  • Cuisine
  • Le 3
  • Contact

  • S'inscrire

Recettes informatiques

  • Page de garde
  • Contact
  • Se connecter
  • « Build a Debian package for pdmenu
  • Connexion PostgreSql / Java par Socket Unix »

Extract informations from epub file

Posted by mazet on 25 Jul 2021 in Bash

Shell

#!/bin/bash -f
# epubinfo - a script to retrieve info from epub
# Copyright (C) 2021 Laurent Mazet
 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
# Changelog:
# - 1.0.0 23/07/2021
#   * initial version
 
#DEBUG=yes
 
# formating functions
function title () { echo -e "\033[0;1m$*\033[0;0m"; }
function pass () { echo -e "\033[1;32m$*\033[0;0m"; }
function warn () { echo -e "\033[1;33m$*\033[0;0m"; }
function fail () { echo -e "\033[1;31m$*\033[0;0m"; }
function debug () { [ "$DEBUG" = yes ] && echo -e "\033[1;34m$*\033[0;0m"; }
 
# main loop
for file; do
    title "Processing: $file"
 
    # get file
    debug "input: $file"
    echo $file | grep -q '^[~/]' || file="$(pwd)/$file"
    [ -f "$file" ] || { warn "usage: $(basename $0) <file>"; exit 1; }
 
    # check file
    debug "file: $file"
    unzip -qt "$file" >&amp,/dev/null ||  { warn "$file is not a epub"; continue; }
 
    # get info file
    info=$(zipinfo "$file" | awk '/content\./ || /metadata\./ { print $(NF) }')
    [[ "$info" =~ opf ]] && type=opf
    [[ "$info" =~ xml ]] && type=xml
    debug "info: $info ($type)"
    [ "$type" ] ||  { warn "$file is not a epub"; continue; }
 
    # get info
    case $type in
    opf)
        unzip -c "$file" $info | \
        awk '/creator/ && /dc/ { gsub(/ *<[^<]*>/, ""); if (c) c=c",";c=c" "$0 }
             /title/ && /dc/ { gsub(/ *<[^<]*>/, ""); t=" "$0 }
             /language/ && /dc/ { gsub(/ *<[^<]*>/, ""); l=" "$0 }
             END { printf "Author:%s\nTitle:%s\nLanguage:%s\n", c, t, l }'
        ;;
    xml)
        unzip -c "$file" $info | \
        awk '/*<name>/ { gsub(/ *<[^<]*>/, ""); if (c) c=c","; c=c" "$0 }
             /*<title>/ { gsub(/ *<[^<]*>/, ""); t=" "$0 }
             /*<language>/ { gsub(/ *<[^<]*>/, ""); l=" "$0 }
             END { printf "Author:%s\nTitle:%s\nLanguage:%s\n", c, t, l }'
        ;;
    esac
 
done
This entry was posted by mazet and filed under Bash.

Aucun commentaire pour le moment

Catégories

  • Toutes
  • Non catégorisé
  • Programmation
    • Awk
    • Bash
    • C
    • C++
    • Javascript
    • LaTeX
    • Perl
    • Tcl/Tk
  • Systeme
    • Android
    • Debian
    • Ubuntu

Contenu

  • Creating a network between 2 virtual machines on Windows with Qemu
  • Build a Debian package for pdmenu
  • Extract informations from epub file
  • Connexion PostgreSql / Java par Socket Unix
  • Example of fork and respawn
  • Start SSH daemon on Git portable distribution
  • Create a git mirror
  • Color diff
  • Create on Debian a Minecraft server
  • GIT/HG/SVN on multiple repos simultaneously
  • Convert Comics into CBZ format
  • Random password generator function
  • Convert to camelCase
  • DKIM and SPF
  • Migration from BackupPC 3 (Debian package) to BackupPC 4 (Standalone Installation)
  • Minimal BC for Mingw
  • Diskless Debian cluster
  • Colorize log file
  • Generate certificates with (or without) a certificate authority
  • Install Mercurial (hg) on Android
Juin 2025
Lun Mar Mer Jeu Ven Sam Dim
            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            
 << <   > >>
  • Accueil
  • Récemment
  • Archives
  • Catégories
  • Derniers commentaires

Rechercher

Flux XML

  • RSS 2.0: Posts
  • Atom: Posts
What is RSS?

©2025 by Laurent Mazet • Contact • Aide • Online manual generator

Bootstrap back-end

Cookies are required to enable core site functionality.