Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kschiess/hens_and_eggs
base: 308e7b21d3
...
head fork: kschiess/hens_and_eggs
compare: d381ff49e9
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 05, 2011
@kschiess . deletes dupes
Don't ask how I got them. iTunes just plain sucks at times.
51f5a23
Commits on Apr 30, 2012
@kschiess Merge branch 'master' of github.com:kschiess/hens_and_eggs 448776e
@kschiess + Archives an area of todos d381ff4
Showing with 87 additions and 0 deletions.
  1. +17 −0 rb/archive_things/archive_area.rb
  2. +70 −0 rb/itunes/cleanup_dupes.rb
View
17 rb/archive_things/archive_area.rb
@@ -0,0 +1,17 @@
+require 'appscript'
+
+include Appscript
+app = app('Things')
+
+fail "First argument to this script should be area name." if ARGV.empty?
+
+project = app.lists["@#{ARGV.first}"].get
+project.to_dos.get.each do |todo|
+ date = todo.completion_date.get
+ text = todo.name.get
+ status = todo.status.get
+ project = todo.project.get != :missing_value && todo.project.get.name.get || '(none)'
+ tags = todo.tag_names.get
+
+ puts [project, text, date, status, tags].join('\t')
+end
View
70 rb/itunes/cleanup_dupes.rb
@@ -0,0 +1,70 @@
+#!/usr/bin/env ruby
+require "appscript"
+include Appscript
+itunes = app('iTunes')
+
+library = itunes.library_playlists.get.first
+
+def strip_trailing_one(str)
+ if md=str.match(/(.*) 1$/)
+ return md[1]
+ end
+ return str
+end
+
+
+require 'set'
+names_seen = Set.new
+
+name_track_map = Hash.new { |h,k| h[k] = [] }
+
+# Fill name_track_map with tracks that have the same name
+library.tracks.get.each do |track|
+ name = strip_trailing_one track.name.get
+
+ name_track_map[name] << track
+end
+
+to_delete = []
+name_track_map.each do |name, tracks|
+ # Skip for tracks that have a unique name
+ next if tracks.size == 1
+
+ # TODO do this later
+ tracks.
+ reject! { |track| track.location.get == :missing_value }
+
+ tracks.
+ # Group tracks by their containing directory
+ group_by { |track|
+ File.dirname(track.location.get.path)
+ }.each { |dirname, tracks|
+ # Skip tracks that only exist once in their directory by their name
+ # (different albums)
+ next if tracks.size < 2
+
+ # Try to find the dupe track
+ dupe = tracks.find do |track|
+ path = File.basename(track.location.get.path)
+ path.match(/^.* (1|2|3)\.(mp3|m4a|m4v)$/) ||
+ path.match(/^1-.*$/)
+ end
+
+ # Break with debug message if we haven't found the dupe
+ unless dupe
+ puts "#{dirname} #{tracks.size}"
+ puts tracks.map { |t| File.basename(t.location.get.path) }
+ puts
+ else
+ to_delete << dupe
+ end
+ }
+end
+
+puts "Would delete: (#{to_delete.size})"
+to_delete.each do |track|
+ location = track.location.get.path
+
+ track.delete
+ File.unlink(location)
+end

No commit comments for this range

Something went wrong with that request. Please try again.