Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
I wanted to see if I could find earworms in my last.fm data which I've used more or less reliably for many years. Yes, I found some. Little Fluffy Clouds I'm pretty sure is an error - I made a playlist with just that and it ran over a weekend on a work computer. But the rest look pretty legit to me. Sequential plays of the same song over and over.
Found earworm on 2020-05-12: An Angry Thunderstorm by White Noise Meditation: played 238 times.
Found earworm on 2018-10-18: Little Fluffy Clouds (7" Edit) by The Orb: played 245 times.
Found earworm on 2018-10-18: Little Fluffy Clouds (7" Edit) by The Orb: played 25 times.
Found earworm on 2015-04-15: Johannesburg by Gil Scott-Heron: played 16 times.
Found earworm on 2015-04-15: Ring Capacity (Green Lantern Song) by Kirby Krackle: played 39 times.
Found earworm on 2015-04-15: Senses Working Overtime by XTC: played 23 times.
Found earworm on 2015-04-15: Ch-Check It Out by Beastie Boys: played 22 times.
Found earworm on 2015-04-15: She's An Angel (live) by They Might Be Giants: played 32 times.
Found earworm on 2015-04-15: Kansas by The Wolfgang Press: played 24 times.
Found earworm on 2015-04-15: A Real Hero (feat. Electric Youth) by College: played 29 times.
Found earworm on 2015-04-15: St. James Infirmary by Lily Tomlin & Howard Shore And His All-Nurse Band: played 22 times.
Found earworm on 2015-04-15: Automatic by Dead Disco: played 23 times.
Found earworm on 2015-04-15: águas de março by Elis Regina: played 34 times.
Found earworm on 2015-04-15: British Racing Green by Black Box Recorder: played 86 times.
Found earworm on 2015-04-15: Don't Go Back To Rockville (Live) by R.E.M.: played 58 times.
Found earworm on 2015-04-11: It's Not Right But It's Okay by CHVRCHES: played 88 times.
Found earworm on 2015-04-11: I Gotta Feeling by Jeff Tweedy: played 17 times.
Found earworm on 2015-04-10: That Lady (Part 1 & 2) by The Isley Brothers: played 29 times.
Found earworm on 2015-04-10: Black Friday by Steely Dan: played 31 times.
Found earworm on 2015-04-10: Confusion by New Order: played 59 times.
Found earworm on 2015-04-04: Coming Home by Blooper: played 74 times.
Found earworm on 2015-04-04: Boom Clap by Charli XCX: played 71 times.
Found earworm on 2015-04-04: Rikki Don't Lose That Number by Hospitality: played 106 times.
Found earworm on 2015-04-03: Peter Jennings by The Negro Problem: played 44 times.
Found earworm on 2014-10-03: Rikki Don't Lose That Number by Hospitality: played 20 times.
Found earworm on 2014-10-03: Ring Capacity (Green Lantern Song) by Kirby Krackle: played 17 times.
Found earworm on 2014-10-03: (I Don't Want To Go To) Chelsea by Elvis Costello: played 15 times.
Found earworm on 2014-10-03: Waters Of March by Sérgio Mendes: played 16 times.
Found earworm on 2014-10-03: águas de março by Elis Regina: played 15 times.
Found earworm on 2014-10-03: British Racing Green by Black Box Recorder: played 15 times.
Found earworm on 2014-10-03: Don't Go Back To Rockville (Live) by R.E.M.: played 15 times.
Found earworm on 2014-10-03: Next to You by Misty Miller: played 15 times.
Found earworm on 2014-10-03: Superlove (Live Acoustic) by Charli XCX: played 17 times.
Found earworm on 2014-09-30: Ch-Check It Out by Beastie Boys: played 15 times.
Found earworm on 2014-09-30: Kansas by The Wolfgang Press: played 16 times.
Found earworm on 2014-09-25: She's An Angel (live) by They Might Be Giants: played 24 times.
Found earworm on 2014-07-01: Superlove (Live Acoustic) by Charli XCX: played 26 times.
Found earworm on 2014-07-01: Automatic by Dead Disco: played 27 times.
Found earworm on 2014-06-24: Don't Go Back To Rockville (Live) by R.E.M.: played 18 times.
Found earworm on 2013-02-08: Okay Cupid by Kitty Pryde: played 15 times.
Found earworm on 2005-09-03: Yr Own World by The Blue Aeroplanes: played 22 times.
<?php
require 'vendor/autoload.php';
// install with composer require league/csv
use League\Csv\Reader;
use League\Csv\Statement;
$reader = Reader::createFromPath('exported_data', 'r');
// data exported with https://gist.github.com/bitmorse/5201491
// command does not export headers for the data
// fields in tab separated file are ts, song title, artist, album name, guid1, guid2, guid3
// I have no idea what the guids are - permalinks for the song artist and title maybe?
try {
$reader->setDelimiter("\t");
} catch (\League\Csv\InvalidArgument $e) {}
$records = $reader->getRecords();
$prior_record = false;
$prior_song_title = false;
$titles_and_records = [];
foreach ($records as $offset => $record) {
$date = date('Y-m-d', $record[0]); // probably introducing a bug where the repeat is over day boundaries
$song_title = $record[1];
$song_key = $date . "___" . $song_title;
if ($prior_song_title) {
if ($song_title === $prior_song_title) {
if (!array_key_exists($song_key, $titles_and_records)) {
$titles_and_records[$song_key] = [];
$titles_and_records[$song_key][] = $prior_record;
// noisy script
printf("found repeat of song: %s\n", $prior_song_title);
}
$titles_and_records[$song_key][] = $record;
$count = count($titles_and_records[$song_key]);
// noisy script
printf("found repeat %s of song: %s\n", $count, $prior_song_title);
}
}
$prior_record = $record;
$prior_song_title = $song_title;
}
const EARWORM_THRESHOLD = 15; // how many plays in a row shows an earworm?
// note does not flag accidental repeats!
foreach ($titles_and_records as $key => $records) {
if (count($records) >= EARWORM_THRESHOLD) {
$record = $records[0];
$date = date('Y-m-d', $record[0]);
$title = $record[1];
$artist = $record[2];
$playcount = count($records);
printf("Found earworm on %s: %s by %s: played %s times.\n", $date, $title, $artist, $playcount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment