DV Wright Music

DistroKid, play totals ruby scripting fun

Recently, I visited my DistroKid ‘Bank’ page to see how much money I haven’t made from streaming this year, ๐Ÿ˜€
Anyway, after browsing the results, I became more interested in seeing what songs have been streamed the most. (I don’t do any advertising so how and why my tunes are found is a different topic ๐Ÿ˜‰

Anyway, I downloaded the results which are a TSV file. My version of OpenOffice didn’t recognize this as a delimited file and opened it as a straight text file, which is not useful. (OK, yes, I could have forced the point or installed many other xls type parsing applications which would have worked but I wasn’t really doing anything else and knew this was only a few scripting lines anyway, so here goes).

I started out in awk but it’s been awhile, so I switched to ruby. This isn’t the most elegant code and isn’t ideal for huge files but it does ‘work’…

# careful your file is not too large...
dk = open('/home/dwright/downloads/DistroKid_.tsv', 'r').readlines 

song_stats = Hash.new 0
dk.map{|l|
  song = l.split("\t")[4]
  plays = l.split("\t")[5].to_i
  song_stats[song] += plays
}
song_stats = song_stats.sort{|k,v| k[1] <=> v[1]}.reverse
song_stats.each do |k,v|
  puts "Song: #{k} - #{v}"
end

which for me, produces this:
Song: Blue Conga – 88
Song: Am Pm – 83
Song: Moms and Daughters – 61
Song: Lounging Chair – 60
Song: Blue Miles – 59
Song: Sandy Beach Bossa – 54
Song: These Times – 52
Song: Missed What You Meant – 47
Song: Sleepy Time – 45
Song: Pt – 45
Song: Cloth Hat Bossa – 44
Song: Mood Ring – 38
Song: Well If That’s What You Want, Try to Do That – 37
Song: Sunset Sands – 35
Song: Soccer Ball On the Roof – 31
Song: Reach – 2
Song: Right Turn At Albuquerque – 2
Song: Hugs – 2
Song: Firmware Upgrade – 2
Song: Pop Talk – 1
Song: Stay-Cation – 1
Song: SleepThree – 1
Song: Blue Beach Boardwalk – 1
Song: Tymer – 1
Song: Title – 0

The results aren’t a huge surprise, since “Blue Conga” and “AM/PM” are the
two title tracks from two of my three albums on DistroKid and I just added the 3rd
album “3rd Shift” so it’s doesn’t really have any plays yet.
Cheers.

Leave a Reply