Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Monday, September 2, 2013

Editing ID3 tags from command line using Python.

You can build a Python module from scratch just to edit ID3 tags, but there is no need to reinvent the wheel since there are many modules ready for this job.I have been using http://id3-py.sourceforge.net which is very straightforward , anyway, here is a little How-to
* Download the module and extract it to any directory you like
* Navigate to the directory where you extracted the module to
cd /ID3/id3-py-1.2
*Install the module
sudo python setup.py install
* If there is no errors , you are ready to go.
download this python script created by the same author ,
http://id3-py.sourceforge.net/ID3/id3-tagger.py
make it executable
chmod  a+x id3-tagger.py
 , you can copy the file to the home directory for an easier access
we are almost done,
here is an example on how to use the file
find ./ -d 1 -name '*.mp3' -exec ~/id3-tagger.py -A 'soundcloud' {} \;

this command will search for any mp3 file in the directory [not recursively] , then will modify the Album tag to soundcloud , you can modify/add different tags to the command as you wish.

Wednesday, August 28, 2013

Bash Script To Extract Subtitles From MKV file.

well ,some times I prefer to do things using the command line ,especially when logging into my server remotely ,so I created a little bash script to help me extract subtitles from mkv files using mkvextract ( you have to install  mkvtoolnix-cli) , still , the file extension need to be added though.

 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
 nano sub-extractor.sh   
 ###paste the following  
filename="$1"
if [[ $filename ]]
then 
 m=$(mkvinfo $filename|grep 'No EBML head found');
 if [[ $m ]];
  then echo "This is not a valid mkv file";
  else  
    echo "proceeding...";
    mm=$(mkvinfo $filename|grep -i -A 2 -B 2 subtitle);
    if [[ $mm ]];
     then
      echo "subtitles found, proceeding...";
      mmm=$(echo $mm|grep -o 'mkvextract: [0-9]*'|grep -o '[0-9]*')
      arry1=$(echo $mmm|tr " " "\n ");
      for m in $arry1
       do mkvextract tracks $filename $mmm:${filename:0:-4}"_"$mmm; 
      done
    else 
     echo "no subs";
 fi;
 
   fi;
else
 echo "no file name given";
fi;