Browse Source

first commit

lotus 10 months ago
commit
692a71240f
5 changed files with 218 additions and 0 deletions
  1. 11 0
      LICENSE.md
  2. 37 0
      README.md
  3. 17 0
      makefile
  4. 22 0
      mp3me.1
  5. 131 0
      mp3me.sh

File diff suppressed because it is too large
+ 11 - 0
LICENSE.md


+ 37 - 0
README.md

@@ -0,0 +1,37 @@
+# mp3me
+
+[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
+
+### Motivation
+I was using the [soundconverter](https://git.zx2c4.com/ctmg/about/) tool on my main workstation. I've found myself using less and less applications with a GUI; so, I figured I found give it a shot and see if this would satisfy my needs. I've tried to make this tool as intuitive as possible, with sane defaults, and no weird flags. 
+
+### Installation
+Simply run:
+```bash
+make install      #(as root)
+
+# to uninstall
+make uninstall    #(as root)
+```
+
+### Dependencies
+In order to use this tool, you will need two things installed:
++ [FFmpeg](https://ffmpeg.org)
++ [GNU Parallel](https://www.gnu.org/software/parallel)
+
+>There are no requirements to use a specific shell, but I have not tested on all of them, only ksh and bash.
+
+### Usage
+```bash
+mp3me -j 8 ./mymusicdir"     # convert music files, starting 8 jobs (i.e. threads)
+mp3me -h                     # show this help message"
+mp3me -v                     # show the version info"
+```
+
+### Limitations
+To make this tool simpler, I have made a few assumptions. We only convert to mp3. Files are output in the same folder. We only convert to a constant bitrate (320kbps). We only convert one folder at a time. These are my preferred settings. I'll add some flags in soon to handle other preferences.
+
+### License / Disclaimer
+This project is licensed under the 3-clause BSD license. (See LICENSE.md)
+No WAVs were harmed in the making of this tool.
+

+ 17 - 0
makefile

@@ -0,0 +1,17 @@
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+MANDIR ?= $(PREFIX)/man/man1
+
+.POSIX: install
+
+all: help
+
+help:
+	@echo "please run 'make install' as root"
+install:
+	cp ./mp3me.sh $(BINDIR)/mp3me
+	cp ./mp3me.1 $(MANDIR)
+uninstall:
+	rm $(BINDIR)/mp3me
+	rm $(MANDIR)/mp3me.1
+

+ 22 - 0
mp3me.1

@@ -0,0 +1,22 @@
+.TH MP3ME 1
+.SH NAME
+mp3me \- convert audio files to mp3, in parallel
+.SH SYNOPSIS
+.B mp3me
+[\fB-j\fR]
+[\fB-h\fR]
+[\fB-v\fR]
+.IR file ...
+.SH DESCRIPTION
+.B mp3me
+a portable shell script for converting directories of audio files to mp3.
+.SH OPTIONS
+.TP
+.BR -j " " \fInum\fR
+The number of jobs (i.e. threads) to start and process files with.
+.TP
+.BR -h "      "
+Display help information.
+.TP
+.BR -v
+Display version information.

+ 131 - 0
mp3me.sh

@@ -0,0 +1,131 @@
+#!/bin/sh
+# mp3me
+# author: lotus
+# https://git.zerohack.xyz/lotus
+# license: BSD 3-clause
+#
+# A portable shell script for converting audio files to mp3.
+# It works on directories of music in parallel.
+#
+# Dependencies: ffmpeg, gnu parallel
+#
+VERSION="0.1"
+
+# default bitrate and jobs
+BITRATE=320000
+JOBS=4
+
+EXT[0]="flac"
+EXT[1]="m4a"
+EXT[2]="ogg"
+EXT[3]="wav"
+EXT[4]="aac"
+
+
+# check if the file provided is a has a valid music extension
+# cuts off extension and compares it to the ext array items
+fun_is_music () {
+    local FILE_EXT=$(echo $1 | cut -d"." -f 2)
+    for E in "${EXT[@]}" ; do
+	if [ $E = $FILE_EXT ] ; then
+	    return 0
+	fi
+    done
+    return 1
+}
+
+
+# echoes out all the valid music files in a directory
+fun_echo_files () {
+    for FILE in $(ls $1) ; do
+	if fun_is_music $FILE ; then
+	    echo $FILE
+	fi
+    done
+}
+
+
+# take user input as kbps and return bps
+fun_get_bitrate () {
+    if [ $1 > 0 ] && [ $1 < 321 ] ; then
+	BITRATE=$(($1*1000))
+	return 0
+    fi
+    return 1
+}
+
+
+# parse the user input using getopts
+fun_parse_options () {
+    
+}
+
+
+# call this function to start the script
+fun_run () {
+    JOBS=$1
+    fun_echo_files $2 | parallel -j $JOBS ffmpeg -i $2/{} -b:a $BITRATE $2/{.}.mp3
+}
+
+
+# run when ctrl-c is pressed
+fun_cleanup () {
+    echo "caught sigint, exiting.."
+    exit 0
+}
+
+
+# print help/version info
+fun_print_info () {
+    echo "mp3me - parallel mp3 converter script"
+    fun_print_ver
+    echo "license: bsd 3-clause"
+    echo "author: lotus"
+    fun_print_usage
+}
+
+
+# print usage info
+fun_print_usage () {
+    echo "-- usage: --------------------"
+    echo "       mp3me -j 8 ./mymusicdir"
+    echo "       mp3me -h   # shows this help message"
+    echo "       mp3me -v   # show the version info"
+}
+
+
+# print version info
+fun_print_ver () {
+    echo "version: $VERSION"
+}
+
+
+# print error message
+fun_error () {
+    echo "Please use one of the following flags:"
+    fun_print_usage
+    exit 1
+}
+
+#fun_parse_options
+
+while getopts 'b:j:i:' OPT ; do
+	case "$OPT" in
+	b)	echo "bitrate";;
+	j)	echo "jobs";;
+	i)      echo "input files";;
+	[?])	fun_error();;
+	esac
+done
+shift $OPTIND-1
+
+# parse what arguments were passed in
+# call a corresponding function
+#trap 'fun_cleanup' INT # catch a ctrl-c
+#case "$1" in
+#    -h) shift;	    fun_print_info "$@" ;;
+#    -v) shift;      fun_print_ver "$@" ;;
+#    -j) shift;	    fun_run "$@" ;;
+#    *)		    fun_error "$@" ;;
+#esac
+exit 0