<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: mp3 code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 03:09:01 GMT</pubDate>
    <description>DZone Snippets: mp3 code</description>
    <item>
      <title>Reencoding MP3s to lower Bitrate  </title>
      <link>http://snippets.dzone.com/posts/show/5126</link>
      <description>http://ubuntuforums.org/showthread.php?t=347176&lt;br /&gt;Batch-reencode MP3s using a terminal tool.&lt;br /&gt;&lt;br /&gt;this installs lame (http://lame.sourceforge.net/index.php), an MP3 enconder&lt;br /&gt;&lt;code&gt;&lt;br /&gt;sudo apt-get install lame&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;this reencodes all MP3s in the current folder to a bitrate of 32&lt;br /&gt;&lt;code&gt;&lt;br /&gt;for x in [ `ls -1 *.mp3` ]; do lame --preset 32 $x new32-${x}; done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 10 Feb 2008 14:39:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5126</guid>
      <author>rootie (Alvin)</author>
    </item>
    <item>
      <title>GStreamer Pipeline for ripping MP3s</title>
      <link>http://snippets.dzone.com/posts/show/4937</link>
      <description>// GStreamer Pipeline for ripping MP3s&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;audio/x-raw-int,rate=44100,channels=2 ! lame name=enc vbr=4 vbr-quality=2 ! xingmux ! id3v2mux&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 31 Dec 2007 11:53:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4937</guid>
      <author>iansealy (Ian Sealy)</author>
    </item>
    <item>
      <title>Convert a video file to an audio file (.mp4 to .mp3)</title>
      <link>http://snippets.dzone.com/posts/show/4649</link>
      <description>Convert an mp4 file to avi, then to mp3 (including mixing the stereo down to mono). This code was executed from the command-line on Ubuntu 7.04.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;mencoder video.mp4 -ovc lavc -vf scale=123:100 -oac lavc -o video.avi&lt;br /&gt;ffmpeg -i video.avi -ac 1 audio1.mp3 &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 13 Oct 2007 10:37:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4649</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Flac to mp3</title>
      <link>http://snippets.dzone.com/posts/show/4605</link>
      <description>Converts all *.flac files in the current dir to mp3.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;for file in *.flac&lt;br /&gt;do&lt;br /&gt;	echo Converting $file&lt;br /&gt;	flac123 -q --wav=- "$file" | lame - "$file".mp3&lt;br /&gt;done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 02 Oct 2007 18:02:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4605</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Play MP3 files</title>
      <link>http://snippets.dzone.com/posts/show/3893</link>
      <description>&lt;code&gt;&lt;br /&gt;public class Player&lt;br /&gt;{&lt;br /&gt;  private string _command;&lt;br /&gt;  private bool isOpen;&lt;br /&gt; [DllImport("winmm.dll")]&lt;br /&gt;private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);&lt;br /&gt;  &lt;br /&gt;public Player()&lt;br /&gt; {&lt;br /&gt;   &lt;br /&gt; }&lt;br /&gt;public void Close()&lt;br /&gt; {&lt;br /&gt;  _command = "close MediaFile";&lt;br /&gt;  mciSendString(_command, null, 0, IntPtr.Zero);&lt;br /&gt;       isOpen=false;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;public void Open(string sFileName)&lt;br /&gt; {&lt;br /&gt;  _command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";&lt;br /&gt;  mciSendString(_command, null, 0, IntPtr.Zero);&lt;br /&gt;  isOpen = true;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;public void Play(bool loop)&lt;br /&gt; {&lt;br /&gt;  if(isOpen)&lt;br /&gt;  {&lt;br /&gt;   _command = "play MediaFile";&lt;br /&gt;   if (loop)&lt;br /&gt;    _command += " REPEAT";&lt;br /&gt;    mciSendString(_command, null, 0, IntPtr.Zero);&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;/code&gt;</description>
      <pubDate>Tue, 24 Apr 2007 22:44:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3893</guid>
      <author>mstampar (Miroslav Stampar)</author>
    </item>
    <item>
      <title>tamilbeat.com mp3 crawler</title>
      <link>http://snippets.dzone.com/posts/show/3668</link>
      <description>create a file called links.dat and put the songs link from tamilbeat.com&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'socket'&lt;br /&gt;                                                                                                                            &lt;br /&gt;Thread.abort_on_exception = true&lt;br /&gt;threads = []&lt;br /&gt;                                                                                                                            &lt;br /&gt;line = File.open("links.dat")&lt;br /&gt;IO.foreach("links.dat") {|line|&lt;br /&gt;  if %r{http://([^/]+)/([^/]+/+.+)}i =~ line&lt;br /&gt;    domain,path = $1, $2&lt;br /&gt;  end&lt;br /&gt;  web = TCPSocket.new(domain,"http")&lt;br /&gt;  web.print "GET /"+path+" HTTP/1.0\n\n"&lt;br /&gt;  web.print "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070220 Firefox/2.0.0.2"&lt;br /&gt;  answer = web.gets(nil)&lt;br /&gt;  web.close&lt;br /&gt;                                                                                                                            &lt;br /&gt;  # for mp3&lt;br /&gt;  arr = answer.scan(/http:\/\/www.+mp3/)&lt;br /&gt;                                                                                                                            &lt;br /&gt;  arr.each do |e|&lt;br /&gt;    threads &lt;&lt; Thread.new(e){|mp3|&lt;br /&gt;      if %r{http://([^/]+)/([^/]+/+.+)/(.+mp3)}i =~ mp3&lt;br /&gt;        website,song,name = $1, $2, $3&lt;br /&gt;      end&lt;br /&gt;      a=Net::HTTP.new(website,80)&lt;br /&gt;      song_get = "/"+song+"/"+name&lt;br /&gt;      puts "Fetching #{website}#{song_get}"&lt;br /&gt;      resp, data = a.get(song_get,nil)&lt;br /&gt;      puts "Got #{website}#{song_get}: #{resp.message}"&lt;br /&gt;      open(name,'w'){|f| f.write(data)}&lt;br /&gt;    }&lt;br /&gt;  end&lt;br /&gt;}&lt;br /&gt;threads.each {|aThread| aThread.join}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 Mar 2007 07:53:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3668</guid>
      <author>mbchandar (balachandar)</author>
    </item>
    <item>
      <title>Python id3 tag from containing folder</title>
      <link>http://snippets.dzone.com/posts/show/3509</link>
      <description>// Total noob python script for renaming the 'album' tag in an untagged mp3 file.  I plug it into podnova (using advanced -&gt; run command) as it downloads my podcasts so that they get sorted correctly when I copy them onto my ipod.&lt;br /&gt;&lt;br /&gt;PodNova organizes podcasts by folder.  the iPod organizes podcasts by album tag.  If you use GtkPod to copy podcasts from PodNova, this can help keep mp3 podcasts categorized properly.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/python&lt;br /&gt;import sys&lt;br /&gt;&lt;br /&gt;# requires ID3 module, easily googled&lt;br /&gt;from ID3 import *&lt;br /&gt;for arg in sys.argv:&lt;br /&gt;    fullfilename = arg&lt;br /&gt;&lt;br /&gt;# This only works for mp3 files, I would love suggestions for mp4 tags&lt;br /&gt;id3info = ID3(fullfilename)&lt;br /&gt;&lt;br /&gt;# Print command useful for logging.&lt;br /&gt;print id3info&lt;br /&gt;&lt;br /&gt;# Check if album info exists&lt;br /&gt;if not id3info.has_key('ALBUM'):&lt;br /&gt;    print 'appending album tag'&lt;br /&gt;    # truncate to just containing directory:&lt;br /&gt;    folder = fullfilename[1:rfind(fullfilename,'/')]&lt;br /&gt;    # define album based on podcast's directory&lt;br /&gt;    album = (folder[rfind(folder,'/'):]).strip('/')&lt;br /&gt;    id3info.album = album&lt;br /&gt;    if id3info.album == album:&lt;br /&gt;        print 'success!'&lt;br /&gt;else:&lt;br /&gt;    print 'nothing to change'&lt;br /&gt;    &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 12:55:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3509</guid>
      <author>dannyq (danny)</author>
    </item>
    <item>
      <title>My handy mp3 "alarm clock" written in Ruby.</title>
      <link>http://snippets.dzone.com/posts/show/3498</link>
      <description>// Simple tool to help wake me up in the morning. Not the cleanest code, but it took no time to write. Ruby rocks!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/env ruby&lt;br /&gt;#&lt;br /&gt;# A helper to setup an alarm to slowly and leisurely wake up in the morning.&lt;br /&gt;#&lt;br /&gt;# $Id: mp3wakeup.rb 6 2007-01-31 16:02:57Z btek $&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;if ARGV.length &lt; 1&lt;br /&gt;	puts "Usage: #{$0} &lt;time&gt; [mp3dir]"&lt;br /&gt;	exit 1&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;#############################&lt;br /&gt;# Configuration parameters. #&lt;br /&gt;#############################&lt;br /&gt;&lt;br /&gt;NUM_STEPS = 15&lt;br /&gt;STEP_DURATION = 60 * 1&lt;br /&gt;&lt;br /&gt;FINAL_VOLUME = 95&lt;br /&gt;INITIAL_VOLUME = 30&lt;br /&gt;VOLUME_STEP = (FINAL_VOLUME - INITIAL_VOLUME) / NUM_STEPS&lt;br /&gt;&lt;br /&gt;MIN_SEC_BEFORE_ALARM = NUM_STEPS * STEP_DURATION&lt;br /&gt;&lt;br /&gt;#############################&lt;br /&gt;#############################&lt;br /&gt;&lt;br /&gt;time = Regexp.quote ARGV[0]&lt;br /&gt;mp3dir = Regexp.quote(ARGV[1]) if ARGV.length &gt; 1&lt;br /&gt;&lt;br /&gt;def get_alarm_time(desired_hour, desired_minute)&lt;br /&gt;  now = Time.new&lt;br /&gt;  &lt;br /&gt;  alarm_time = Time.local(now.year, now.month, now.day, desired_hour, desired_minute, 0, 0)&lt;br /&gt;  &lt;br /&gt;  if alarm_time - now &lt; MIN_SEC_BEFORE_ALARM&lt;br /&gt;    alarm_time = alarm_time + 60*60*24&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  return alarm_time&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def run(cmd)&lt;br /&gt;  #puts cmd&lt;br /&gt;  system cmd&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;puts "Waking you up by #{time} with songs from #{mp3dir}."&lt;br /&gt;&lt;br /&gt;match = time.match(/(\d+)(:(\d+))?/)&lt;br /&gt;hour = match[1].to_i&lt;br /&gt;minute = if (match.length &gt; 1)&lt;br /&gt;           match[3].to_i &lt;br /&gt;         else&lt;br /&gt;           0&lt;br /&gt;         end&lt;br /&gt;&lt;br /&gt;alarm_time = get_alarm_time(hour, minute)&lt;br /&gt;&lt;br /&gt;for i in 0..NUM_STEPS&lt;br /&gt;  alert_time = alarm_time - (STEP_DURATION * i)&lt;br /&gt;  volume = FINAL_VOLUME - (VOLUME_STEP * i)&lt;br /&gt;  &lt;br /&gt;  at_cmd = "at #{alert_time.hour.to_s.rjust(2, '0')}:#{alert_time.min.to_s.rjust(2, '0')}"&lt;br /&gt;  run "echo amixer sset PCM #{volume}% | #{at_cmd}"&lt;br /&gt;  &lt;br /&gt;  if i == NUM_STEPS&lt;br /&gt;    # Start playing after time is confirmed set.&lt;br /&gt;    alert_time = alert_time + (60)&lt;br /&gt;    at_cmd = "at #{alert_time.hour.to_s.rjust(2, '0')}:#{alert_time.min.to_s.rjust(2, '0')}"&lt;br /&gt;    &lt;br /&gt;    if mp3dir != nil&lt;br /&gt;      run "echo audacious #{mp3dir} | #{at_cmd}"&lt;br /&gt;    else&lt;br /&gt;      run "echo audtool playback-play | #{at_cmd}"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 12 Feb 2007 21:21:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3498</guid>
      <author>bhtek (Boon Hian Tek)</author>
    </item>
    <item>
      <title>Java - Example Very Simple Player (JMF)</title>
      <link>http://snippets.dzone.com/posts/show/2912</link>
      <description>// Main Class&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package org.jmf.example;&lt;br /&gt;&lt;br /&gt;import javax.swing.JDialog;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;import javax.swing.UIManager;&lt;br /&gt;import javax.swing.UnsupportedLookAndFeelException;&lt;br /&gt;import javax.swing.plaf.metal.MetalLookAndFeel;&lt;br /&gt;&lt;br /&gt;public class ExampleJMF&lt;br /&gt;{&lt;br /&gt;	public static void main(String[] args)&lt;br /&gt;	{&lt;br /&gt;		JFrame.setDefaultLookAndFeelDecorated(true); &lt;br /&gt;		JDialog.setDefaultLookAndFeelDecorated(true);&lt;br /&gt;		&lt;br /&gt;		try&lt;br /&gt;		{&lt;br /&gt;			UIManager.setLookAndFeel(new MetalLookAndFeel());&lt;br /&gt;		}&lt;br /&gt;		catch(UnsupportedLookAndFeelException e)&lt;br /&gt;		{&lt;br /&gt;			e.printStackTrace();&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		new exampleFrame();&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// Frame Class&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package org.jmf.example;&lt;br /&gt;&lt;br /&gt;import java.awt.Toolkit;&lt;br /&gt;import java.awt.event.WindowAdapter;&lt;br /&gt;import java.awt.event.WindowEvent;&lt;br /&gt;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;&lt;br /&gt;public class exampleFrame extends JFrame&lt;br /&gt;{&lt;br /&gt;	private static final long serialVersionUID = 1L;&lt;br /&gt;	&lt;br /&gt;	public exampleFrame()&lt;br /&gt;	{&lt;br /&gt;		super("JMF - Example...");&lt;br /&gt;		&lt;br /&gt;		setSize(400, 300);&lt;br /&gt;		setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getWidth())/2, (Toolkit.getDefaultToolkit().getScreenSize().height - getHeight())/2);&lt;br /&gt;		&lt;br /&gt;		addWindowListener(new WindowAdapter()&lt;br /&gt;		{&lt;br /&gt;			public void windowClosing(WindowEvent evt)&lt;br /&gt;			{&lt;br /&gt;				System.exit(0);&lt;br /&gt;			}&lt;br /&gt;		});&lt;br /&gt;		&lt;br /&gt;		setContentPane(new examplePanel());&lt;br /&gt;		setVisible(true);&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// Panel Class&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package org.jmf.example;&lt;br /&gt;&lt;br /&gt;import java.awt.Component;&lt;br /&gt;import java.awt.Graphics;&lt;br /&gt;import java.awt.event.ActionEvent;&lt;br /&gt;import java.awt.event.ActionListener;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.net.MalformedURLException;&lt;br /&gt;import java.net.URL;&lt;br /&gt;&lt;br /&gt;import javax.media.ControllerEvent;&lt;br /&gt;import javax.media.ControllerListener;&lt;br /&gt;import javax.media.Manager;&lt;br /&gt;import javax.media.NoPlayerException;&lt;br /&gt;import javax.media.Player;&lt;br /&gt;import javax.media.RealizeCompleteEvent;&lt;br /&gt;import javax.swing.JPanel;&lt;br /&gt;&lt;br /&gt;public class examplePanel extends JPanel implements ActionListener, ControllerListener&lt;br /&gt;{&lt;br /&gt;	private static final long serialVersionUID = 1L;&lt;br /&gt;	&lt;br /&gt;	private Component visualComponent;&lt;br /&gt;	private Player player;&lt;br /&gt;	&lt;br /&gt;	public examplePanel()&lt;br /&gt;	{&lt;br /&gt;		try&lt;br /&gt;		{&lt;br /&gt;			player = Manager.createPlayer(new URL("file:///tmp/a.mpg"));&lt;br /&gt;			player.addControllerListener(this);&lt;br /&gt;			&lt;br /&gt;			player.start();&lt;br /&gt;		}&lt;br /&gt;		catch(NoPlayerException e)&lt;br /&gt;		{&lt;br /&gt;			e.printStackTrace();&lt;br /&gt;		}&lt;br /&gt;		catch(MalformedURLException e)&lt;br /&gt;		{&lt;br /&gt;			e.printStackTrace();&lt;br /&gt;		}&lt;br /&gt;		catch(IOException e)&lt;br /&gt;		{&lt;br /&gt;			e.printStackTrace();&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public void paintComponent(Graphics g)&lt;br /&gt;	{&lt;br /&gt;		super.paintComponent(g);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public void actionPerformed(ActionEvent e)&lt;br /&gt;	{&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	public void controllerUpdate(ControllerEvent c)&lt;br /&gt;	{&lt;br /&gt;		if(player == null)&lt;br /&gt;			return;&lt;br /&gt;		&lt;br /&gt;		if(c instanceof RealizeCompleteEvent)&lt;br /&gt;		{&lt;br /&gt;			if((visualComponent = player.getVisualComponent()) != null)&lt;br /&gt;				add(visualComponent);&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 27 Oct 2006 15:53:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2912</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Playlist generator</title>
      <link>http://snippets.dzone.com/posts/show/1883</link>
      <description>Bash script to generate a playlist with all your mp3s and oggs in.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;rm ~/Desktop/playlist.m3u&lt;br /&gt;find ~/music/ -iname "*.mp3" -print &gt;&gt; ~/Desktop/playlist.m3u&lt;br /&gt;find ~/music/ -iname "*.ogg" -print &gt;&gt; ~/Desktop/playlist.m3u&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 11 Apr 2006 19:53:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1883</guid>
      <author>lordrich ()</author>
    </item>
  </channel>
</rss>
