Posts Tagged ‘music’

Music clock

Monday, January 11th, 2010

The music clock is an invisible clock. It tells the time through musical
tones. For now, it reads the hour and the minutes mod 12. Hopefully I will be
able to explore this idea and come up with a universally understandable and
recognizable system.

I use ajax requests and ruby and sox on the backend to make this work.

Copy iTunes selection to a new album

Friday, December 4th, 2009

Now that nobody burns CDs for each other, lately when making mixes I go through a painful process:

  • make an iTunes playlist with tracks order how I want them
  • copy all those files individually, manually
  • reinsert them into iTunes
  • change all their album tags to my mix name
  • (super painful) change all their track number tags to reflect the track order in my mix
  • (so painful I usually skip) change all their file names to uniformly reflect my track order and album changes
  • zip up and email to friend

I set and found a few applescripts to handle automating one or two of the above tasks, but I thought I might as encapsulate the whole thing. So here’s my solution as an applescript:


(*
Copy selected tracks and re-add into itunes with album = to given text and track numbers according to selection order

Author: Alec Jacobson (alecjacobsonATgmailDOTcom)
 *)
-------------------------------------

-- check if iTunes is running
tell application "System Events"
  if (get name of every process) contains "iTunes" then set okflag to true
end tell
if okflag then

  tell application "iTunes"
    set mix_name to ""
    set prompt to "Mix name:"
    repeat while length of mix_name is equal to 0
      display dialog prompt default answer "My new mix" buttons {"OK", "Cancel"} default button 1
      copy the result as list to {text_returned, button_pressed}
      set mix_name to text_returned
      set prompt to "Mix name (must enter something):"
    end repeat

    set selected_tracks to selection
    if selected_tracks is {} then -- no selection
      display dialog "Select some tracks first..." buttons {"OK"} default button 1
    else
      set selected_songs to ""
      set track_number to 1
      set number_of_tracks to length of selected_tracks
      repeat with this_track in selected_tracks
        do shell script "cp " & (quoted form of POSIX path of (get this_track's location)) & " " & (quoted form of (POSIX path of (get this_track's location) & ".tmp.mp3"))
        set new_copy to add (POSIX file (POSIX path of (get this_track's location) & ".tmp.mp3")) as alias to source "Library"

        set errNum to -54 -- expect a file permission error (itunes takes a second...)
        repeat while (errNum is equal to -54)
          try
            set album of new_copy to mix_name
            set track number of new_copy to track_number
            set track count of new_copy to number_of_tracks
            set compilation of new_copy to true

            set track_number_string to track_number as string
            if (track_number < 10) then
              set track_number_string to "0" & track_number_string
            end if

            set new_path to location of new_copy
            tell application "Finder" to set name of new_path to "" & track_number_string & " " & (name of new_copy) & ".mp3"

            set errNum to 0
          on error errText number errNum
            if errNum is not equal to -54 then
              error errText number errNum
            end if
            delay 1.0E-4
          end try
        end repeat

        set track_number to track_number + 1
      end repeat
    end if
  end tell
end if

List audiobooks and/or music based on directories: Ruby Version

Thursday, November 5th, 2009

I previously posted a bash script to count and print plain text and html listings of a directory: intended for displaying audiobook and music libraries. I recently tried to use the bash script on a large directory and it stalled because sed can’t handle large input. Here’s a ruby version that does the same thing:


#!/usr/bin/ruby -w
usage = "Usage: list [filename] [directory]
If filename ends with .html then output will be html,
else output will be plain text."
if not ARGV[0] or not ARGV[1]
  puts usage
elsif not File.directory? ARGV[1]
  puts "list: #{ARGV[1]} is not a directory"
  puts usage
else
  dir = ARGV[1]
  # should be quoted?
  plain = (`ls -1 "#{dir}"/*`+"\n")
  if(ARGV[0] =~ /.html$/i)
    plain = plain.split("\n")
    author_count = plain.find_all{|line| line=~/:$/}.length
    title_count = plain.find_all{|line| line=~/[^:]$/}.length
    body = plain.collect do |line|
      line.gsub(
        /(.*)([^:])$/,'      \1\2</br>').gsub(
        /^\s*$/,'    </div>').gsub(
        /.*\/(.*):$/,'    <h3>\1</h3>'+"\n"+'    <div class="books">')
    end
    output = "<html>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <head>
    <style type='text/css'>
      body {
        font : 10pt verdana;
        background: white;
        width: 95%
      }
      h2 {
        margin: 15px 0px 5px 0px;
      }
      h3 {
        margin: 15px 0px 5px 0px;
      }
      .books {
        border: 1px solid #dddddd;
        padding: 5px 5px 5px 10px;
        background: #eeeeff;
      }
    </style>
  </head>
  <body>
    <h2>#{title_count} titles and #{author_count} authors</h2>
  #{body.join("\n")}</div>
  </body>
</html>"
  else
    output = plain;
  end
  File.open(ARGV[0], 'w') {|f| f.write(output) }
end

Detective Defenestrator – Jaw Disorder, Women All in Tents (mash up)

Tuesday, October 13th, 2009

I’m reposting the mashup track, “Jaw Disorder, Women All in Tents” by Detective Defenstrator, featuring Quasi, the Gorillaz, Vincent D’Onofrio, Kathryn Erbe, Robert Knepper, and K-Ci & JoJo.

Remove all duplicate songs/mp3s iTunes creates using bash script

Tuesday, September 22nd, 2009

I gave up using iTunes to play music about year ago, but I haven’t found a free alternative to iTunes’s exceptional file management based on mp3 ID3 tags (If you know of one — I mean better than iTunes one — let me know). So occasionally I let iTunes organize my music library. I drop in folders containing new music and let iTunes go at it. The problem is that if I have folders containing an mp3 and an m3u playlist I get duplicates. If I don’t notice this right away the duplicates build up.

Here’s a bash script to delete all true duplicates. The files must be exactly the same and have almost the same name (the difference being the number iTunes appends on a copy: “song.mp3″ becomes “song 1.mp3″).

Verbose version:


#!/bin/bash
find "$1" -regex ".* [0-9][0-9]*\.[^.]*" -print0 | while read -d $'\0' copy
do
  original=`echo "$copy" | sed "s/\(.*\) [0-9][0-9]*\(\.[^.]*\)/\1\2/"`
  # check that  the hypothetical original exists
  if [ -e "$original" ];then
    # check that the original is exactly the same file as the copy
    if diff "$original" "$copy" >/dev/null ;then
      rm "$copy"
      echo "$copy deleted..."
    else
      echo "$copy is different..."
      echo "  $copy not deleted..."
    fi
  else
    echo "$original does not exist..."
    echo "  $copy not deleted..."
  fi
done

Quiet Version


#!/bin/bash
find "$1" -regex ".* [0-9][0-9]*\.[^.]*" -print0 | while read -d $'\0' copy
do
  original=`echo "$copy" | sed "s/\(.*\) [0-9][0-9]*\(\.[^.]*\)/\1\2/"`
  # check that  the hypothetical original exists
  if [ -e "$original" ];then
    # check that the original is exactly the same file as the copy
    if diff "$original" "$copy" >/dev/null ;then
      rm "$copy"
    fi
  fi
done