-
Notifications
You must be signed in to change notification settings - Fork 4
/
spotify-scrape.pl
43 lines (32 loc) · 973 Bytes
/
spotify-scrape.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#requirement
#if not installed: sudo cpan install Web:Scraper
#example call:
#perl ./spotify-scrape.pl 'spotify:track:2qpmEFEoc6bVpYhc4Lp5Uo'
#perl ./spotify-scrape.pl 'spotify-uri'
#Author: Jonathan Spruytte
#Author twitter: http://twitter.com/spruyttej
#CoAuthor: Wouter Vandenneucker
#CoAuthor twitter: http://twitter.com/woutervddn
use strict;
use URI;
use Web::Scraper;
#init
my @songs=();
#scraper
my $data = scraper {
# we will save the urls from the teams
process "ul.track-info", "tracks[]" => scraper {
process "ul.track-info>li.track-title", 'title' => 'TEXT';
process "ul.track-info>li.artist", 'artist' => 'TEXT';
};
};
#loop over infput
foreach ($ARGV[0]=~/(.*)/){
# scrape the data
my $res = $data->scrape(URI->new("https://embed.spotify.com/?uri=$_"));
#push(@songs,$res->{titles}[0] . " " . $res->{artists}[0]);
#print join("\n",@songs),"\n";
for my $track (@{$res->{tracks}}) {
print "$track->{title} - $track->{artist} \n";
}
}