M
moltar
I am writing a subroutine to parse DJ mix tracklistings into artist, track name and additional
information. I think It could be even a great module if it all works out well. So far my solution is pretty
ugly, but that is why I decided to raise the discussion over here with hundreds of Perl Gurus.
A tracklist consist of several lines of artist and song names, sometimes additional information is
provided such as label, or "remix by", etc... Examples are at the end of message. I want to parse it into
separate instances ($artist, $track, $extra).
I had several ideas to tuckle this problem.
1) A set of if's to satisfy individual cases. Obvisoly one regex cannot cut it.
2) Array of regex'es going from most common to less common track listing patterns. Loop and
execute regex pattern per line.
3) more not so bright ideas that I won't mention.
So far my solution looks something like the following. It's still in works. It's clumsy and dirty. I am
looking for something more logical and elegant.
sub parse_tracklist_item {
my $line = shift;
if ($line =~ / [-:]+ /) {
# plug - tuff rinse - blue angel
# dj krush - meiso ( dj crystral's drug deal vocal mix) - mo' wax
return ($line, $1, $2, $3) if $line =~ /^(.+?) [-:]+ ([^(]+?) [-:]+ ([^\(]+)?/;
# Artist - Track (Extra)
# J-Cut - They Don’t Know (Advanced Dub)
return ($line, $1, $2, $3) if $line =~ /^(.+?) [-:]+ ([^(]+) [\(\[]\s*([^)]+)\s*[\)\]]( - .*)?/;
# Duo Infernele - Positive Vibes
# T Power - Delta
return ($line, $1, $2, $3) if $line =~ /^(.+?) [-:]+ (.+?)$/;
} elsif ($line =~ /-/) {
# Qwest feat. Jamal-Where My Thugs At? (A-Sides Remix)
# NRG-I Need Your Lovin (Remix)
return ($line, $1, $2, $3) if ($line =~ /^([^\-]+)\-([^\(]+)\s*\(?([^)]+)?\)?/);
}
# Get The Record Straight (Pieter K)
# Amen Bizness (Macc + Chris Inperspective)
# Are You Someone'S Prayer? (Fanu): Miracle Rmx.
return ($line, $1, $2, $3) if ($line =~ /^([^\(]+) \(([^)]+)\)(?:\.*))?/);
# stricken roots / fex
# the way (evil nine remix) / dylan rhymes + pearlshot accapella
if ($line =~ m|([^(]+)?\s*\(([^)]+)\)\s*)? / (.+)|) {
return ($line, $1, $3, $2);
}
return ($line, $line);
}
_____________________________________________________________________
Here are a few real examples of track listing variations that I found around the net. This is of course not
limited to what people can come up with.
Zinc - Star Of Polaris (Bingo Dub)
J-Cut - They Don’t Know (Advanced Dub)
* 01 - plug - tuff rinse - blue angel
* 02 - dj krush - meiso ( dj crystral's drug deal vocal mix) - mo' wax
Duo Infernele - Positive Vibes
T Power - Delta
Are You Someone'S Prayer? (Fanu): Miracle Rmx.
Amen Bizness (Macc + Chris Inperspective)
Get The Record Straight (Pieter K)
Omni Trio>>Rollin Heights>>Moving Shadow 044
ED Rush & Nico>>Bludclot>>No U Turn
DJ Hype>>Shot In The Dark>> Sub Base Records 020
intersperce - equanimity - looking good records (9m 43s)
makoto - voices - good looking records (4m 41s)
Qwest feat. Jamal-Where My Thugs At? (A-Sides Remix)
Kane and Dynamic Duo-Doc Stoppa
NRG-I Need Your Lovin (Remix)
N20 Jungle Tools 3.5-Crunch
Hive/Echo/Tejada-FearAndLoathing
Loxy/Keaton-JudgementDay
Cause4Concern-Volcam-Subtitles
Hexer-UndergroundResistance-KrushGrooves
08_Break - Submerged :: SUBTITLES039
09_Ryme Tyme & Trace - Move 2005 (Universal Project Remix) :: 1210008
ASC - Alternate Souce [Gamma Ray MP3 release]
Twister - Watercolour [Scientific MP3 release]
Future Prophecies - Voice of Loneliness
Ink and J-Dubb - War Machine
Charlie - The Prodigy - XL Recordings
Hold It Down - 2 Bad Mice - Moving Shadow
Technical Itch - Soldiers - Penetration - 29.00
Stakka & Gridlock - Hit n Run - Cargo - 32.10
Black Sun Empire :: B’Negative (Ill Skillz rmx) :: Ill Skillz
Blame :: Cyberun :: 720 Degrees
4hero : 9 by 9 (MIST vocal rmx)
MIST & Jenna G : Lover
High Contrast : Music is everything (Influx datum rmx)
D.Kay :: Platinum (Ill.Skillz RMX)
Jammin :: Kinda Funky (Shimon RMX)
information. I think It could be even a great module if it all works out well. So far my solution is pretty
ugly, but that is why I decided to raise the discussion over here with hundreds of Perl Gurus.
A tracklist consist of several lines of artist and song names, sometimes additional information is
provided such as label, or "remix by", etc... Examples are at the end of message. I want to parse it into
separate instances ($artist, $track, $extra).
I had several ideas to tuckle this problem.
1) A set of if's to satisfy individual cases. Obvisoly one regex cannot cut it.
2) Array of regex'es going from most common to less common track listing patterns. Loop and
execute regex pattern per line.
3) more not so bright ideas that I won't mention.
So far my solution looks something like the following. It's still in works. It's clumsy and dirty. I am
looking for something more logical and elegant.
sub parse_tracklist_item {
my $line = shift;
if ($line =~ / [-:]+ /) {
# plug - tuff rinse - blue angel
# dj krush - meiso ( dj crystral's drug deal vocal mix) - mo' wax
return ($line, $1, $2, $3) if $line =~ /^(.+?) [-:]+ ([^(]+?) [-:]+ ([^\(]+)?/;
# Artist - Track (Extra)
# J-Cut - They Don’t Know (Advanced Dub)
return ($line, $1, $2, $3) if $line =~ /^(.+?) [-:]+ ([^(]+) [\(\[]\s*([^)]+)\s*[\)\]]( - .*)?/;
# Duo Infernele - Positive Vibes
# T Power - Delta
return ($line, $1, $2, $3) if $line =~ /^(.+?) [-:]+ (.+?)$/;
} elsif ($line =~ /-/) {
# Qwest feat. Jamal-Where My Thugs At? (A-Sides Remix)
# NRG-I Need Your Lovin (Remix)
return ($line, $1, $2, $3) if ($line =~ /^([^\-]+)\-([^\(]+)\s*\(?([^)]+)?\)?/);
}
# Get The Record Straight (Pieter K)
# Amen Bizness (Macc + Chris Inperspective)
# Are You Someone'S Prayer? (Fanu): Miracle Rmx.
return ($line, $1, $2, $3) if ($line =~ /^([^\(]+) \(([^)]+)\)(?:\.*))?/);
# stricken roots / fex
# the way (evil nine remix) / dylan rhymes + pearlshot accapella
if ($line =~ m|([^(]+)?\s*\(([^)]+)\)\s*)? / (.+)|) {
return ($line, $1, $3, $2);
}
return ($line, $line);
}
_____________________________________________________________________
Here are a few real examples of track listing variations that I found around the net. This is of course not
limited to what people can come up with.
Zinc - Star Of Polaris (Bingo Dub)
J-Cut - They Don’t Know (Advanced Dub)
* 01 - plug - tuff rinse - blue angel
* 02 - dj krush - meiso ( dj crystral's drug deal vocal mix) - mo' wax
Duo Infernele - Positive Vibes
T Power - Delta
Are You Someone'S Prayer? (Fanu): Miracle Rmx.
Amen Bizness (Macc + Chris Inperspective)
Get The Record Straight (Pieter K)
Omni Trio>>Rollin Heights>>Moving Shadow 044
ED Rush & Nico>>Bludclot>>No U Turn
DJ Hype>>Shot In The Dark>> Sub Base Records 020
intersperce - equanimity - looking good records (9m 43s)
makoto - voices - good looking records (4m 41s)
Qwest feat. Jamal-Where My Thugs At? (A-Sides Remix)
Kane and Dynamic Duo-Doc Stoppa
NRG-I Need Your Lovin (Remix)
N20 Jungle Tools 3.5-Crunch
Hive/Echo/Tejada-FearAndLoathing
Loxy/Keaton-JudgementDay
Cause4Concern-Volcam-Subtitles
Hexer-UndergroundResistance-KrushGrooves
08_Break - Submerged :: SUBTITLES039
09_Ryme Tyme & Trace - Move 2005 (Universal Project Remix) :: 1210008
ASC - Alternate Souce [Gamma Ray MP3 release]
Twister - Watercolour [Scientific MP3 release]
Future Prophecies - Voice of Loneliness
Ink and J-Dubb - War Machine
Charlie - The Prodigy - XL Recordings
Hold It Down - 2 Bad Mice - Moving Shadow
Technical Itch - Soldiers - Penetration - 29.00
Stakka & Gridlock - Hit n Run - Cargo - 32.10
Black Sun Empire :: B’Negative (Ill Skillz rmx) :: Ill Skillz
Blame :: Cyberun :: 720 Degrees
4hero : 9 by 9 (MIST vocal rmx)
MIST & Jenna G : Lover
High Contrast : Music is everything (Influx datum rmx)
D.Kay :: Platinum (Ill.Skillz RMX)
Jammin :: Kinda Funky (Shimon RMX)