Browse Source

ultimacartella

boyska 6 years ago
parent
commit
323d4eefc2
1 changed files with 73 additions and 0 deletions
  1. 73 0
      ultimacartella

+ 73 - 0
ultimacartella

@@ -0,0 +1,73 @@
+#!/bin/bash
+
+usage() {
+	echo "Usage: $0 [options] BASEDIR"
+	echo "  Accoda tutti i file presenti nella cartella "
+	echo "  piu' recente (usando l mtime) all interno di BASEDIR"
+	echo ""
+	echo "  I file sono messi tutti, ordinati in ordine alfabetico"
+	echo ""
+	echo "Options:"
+	echo "  -p    DIRPREFIX     La directory deve iniziare con questa stringa"
+}
+
+pickdir() {
+	base=$1
+	prefix=$2
+	sorting="-r"  # time-based; use "-r" for name-based
+	if [[ -z "$prefix" ]]; then
+		ls -1d $sorting "$base"/*/|head -n1
+	else
+		ls -1d $sorting "$base/${prefix}"*/|head -n1
+	fi
+}
+
+prefix=
+while getopts p: opt; do
+	case $opt in 
+		p)
+			prefix=$OPTARG
+			;;
+	esac
+done
+shift $((OPTIND-1))
+if [[ $# -ne 1 ]]; then
+	usage >&2
+	exit 2
+fi
+base=$1
+shift
+
+set -e
+set -u
+
+if [[ ! -d "$base" ]]; then
+	echo "Errore: cartella non esistente" >&2
+	usage >&2
+	exit 2
+fi
+
+pickeddir=$(pickdir "$base" "$prefix")
+if [[ -z "$pickeddir" ]]; then
+	echo "Errore: cartella vuota" >&2
+	exit 2
+fi
+if [[ ! -d "$pickeddir" ]]; then
+	echo "Errore: cartella trovata non esistente ($pickeddir)"
+	exit 2
+fi
+
+empty=true
+while read fpath
+do
+	empty=false
+	fpath=$(readlink -f "$fpath")
+	echo "file://$fpath"
+done < <(find "$pickeddir" -type f -size +10k \( -iname '*.mp3'  -o -iname '*.ogg' \)| sort)
+
+if $empty; then
+	echo "Warning: no file output ($pickeddir)" >&2
+	exit 1
+else
+	exit 0
+fi