Skip to content

Instantly share code, notes, and snippets.

@DasLampe
Created April 26, 2013 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DasLampe/5468833 to your computer and use it in GitHub Desktop.
Save DasLampe/5468833 to your computer and use it in GitHub Desktop.
Create 7z archive from m3u file.
#!/bin/bash
###################################################
#### (c) DasLampe <daslampe@lano-crew.org> 2013
#### Description: Read m3u file and create an 7z archiv with all files.
#### Important: Replace ^M in line 40 with special character!
####
#### Licence Information:
#### 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 3 of the License, or 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.
####
#### See <http://www.gnu.org/licenses/> for more informations.
####################################################
echo "Check command"
command -v 7z >/dev/null 2>&1 || { echo "I require 7z but it's not installed. Aborting." >&2; exit 1; }
echo "Check syntax"
if [ ! "$1" ]; then
echo "Usage: $0 [m3u file] [[split-size-in-mb]]";
exit 1;
fi
command=`which 7z`
echo "Check file"
if [ ! -f "$1" ]; then
echo "$1 doesn't exsits!"
exit 1;
fi
echo "Converte filename"
filename=`echo $(basename "$1") | tr ' ' '_'`;
echo "Create tmp file list"
tmpfile="/tmp/tmp_m3u7z.$RANDOM"
cat "$1" | tr '^M' '\n' | tr -d '\r' | grep -v "#" > $tmpfile
if [ ! $2 ]; then
$command a -t7z -m0=LZMA -mmt=on -mx=9 -md=128m -mfb=256 $filename.7z @$tmpfile
else
#if need to split into files
$command a -t7z -m0=LZMA -mmt=on -mx=9 -md=128m -mfb=256 -v${2}m $filename.7z @$tmpfile
fi
echo "Cleaning up"
rm $tmpfile
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment