comparison cpack/dml/lib/spotify/spotools.pl @ 0:718306e29690 tip

commiting public release
author Daniel Wolff
date Tue, 09 Feb 2016 21:05:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:718306e29690
1 /* Part of DML (Digital Music Laboratory)
2 Copyright 2014-2015 Samer Abdallah, University of London
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 :- module(spotools,
20 [ name_playlist/2
21 , user_playlist/1
22 , user_playlist/2
23 , login/1
24 , explicit/1
25 , playlist_track/2
26 , set_tracks/2
27 , spotify/1
28 ]).
29
30 :- use_module(library(dictutils)).
31 :- use_module(spotify).
32
33 :- dynamic current_app/1.
34
35 login(App) :-
36 spotify_authorise(App),
37 writeln("Logged in as:"),
38 retractall(current_app(_)),
39 assert(current_app(App)),
40 user(Me),
41 print_dict(Me).
42
43 spotify(Goal) :- current_app(App), spotify(App,Goal).
44
45 user(Me) :-
46 current_app(App),
47 spotify_user(App,Me).
48
49 name_playlist(Name,Playlist) :-
50 user_playlist(Playlist),
51 atom_string(Name,NameS),
52 Playlist.name=NameS.
53
54 user_playlist(Playlist) :-
55 user(Me),
56 user_playlist(Me,Playlist).
57
58 user_playlist(User,Playlist) :-
59 spotify(playlists(User.id,Playlists)),
60 member(Playlist,Playlists.items),
61 tag(playlist,Playlist).
62
63 playlist_entry(PL,Entry) :-
64 spotify(playlist_tracks(PL.owner.id,PL.id,Tracks)),
65 member(Entry,Tracks.items),
66 tag(track,Entry.track).
67
68 playlist_track(PL,Track) :-
69 playlist_entry(PL,Entry),
70 Track = Entry.track,
71 maplist(tag(artist),Track.artists),
72 tag(album,Track.album).
73
74 add_tracks(PL,Tracks) :-
75 maplist(get_dict(uri),Tracks,URIs),
76 spotify(add_tracks(PL.owner.id,PL.id,URIs)).
77
78 del_tracks(PL,Tracks) :-
79 findall(_{uri:URI}, (member(T,Tracks),get_dict(uri,T,URI)), Ts),
80 spotify(del_tracks(PL.owner.id,PL.id,_{tracks:Ts})).
81
82 clear_playlist(PL) :-
83 findall(T,playlist_track(PL,T),Tracks),
84 del_tracks(PL,Tracks).
85
86 set_tracks(PL,Tracks) :-
87 maplist(get_dict(uri),Tracks,URIs),
88 spotify(set_tracks(PL.owner.id,PL.id,URIs)).
89
90 set_playlist_tracks(Name,Tracks) :-
91 atom_string(Name,NameS),
92 name_playlist(NameS,PL),
93 spotify(set_tracks(PL.owner.id,PL.id,Tracks)).
94
95 explicit(Track) :- Track.explicit=true.
96
97