annotate light9/ascoltami/playlist.py @ 2187:ccdfdc8183ad

remove py2-style 'object' superclass
author drewp@bigasterisk.com
date Fri, 19 May 2023 21:14:01 -0700
parents e13b62bfdaff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1244
5ef8d7c3820c remove another workaround for the graph.items bug
Drew Perttula <drewp@bigasterisk.com>
parents: 1028
diff changeset
1 from light9.showconfig import songOnDisk
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
2 from light9.namespaces import L9
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
3
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1244
diff changeset
4
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
5 class NoSuchSong(ValueError):
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
6 """Raised when a song is requested that doesn't exist (e.g. one
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
7 after the last song in the playlist)."""
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
8
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1244
diff changeset
9
2187
ccdfdc8183ad remove py2-style 'object' superclass
drewp@bigasterisk.com
parents: 2150
diff changeset
10 class Playlist:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1244
diff changeset
11
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
12 def __init__(self, graph, playlistUri):
621
9ec0396c6f1f small asco bugs left over from last year
drewp@bigasterisk.com
parents: 617
diff changeset
13 self.graph = graph
2150
e13b62bfdaff fix some warnings
drewp@bigasterisk.com
parents: 1866
diff changeset
14 self.playlistUri = playlistUri
1244
5ef8d7c3820c remove another workaround for the graph.items bug
Drew Perttula <drewp@bigasterisk.com>
parents: 1028
diff changeset
15 self.songs = list(graph.items(playlistUri))
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1244
diff changeset
16
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
17 def nextSong(self, currentSong):
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
18 """Returns the next song in the playlist or raises NoSuchSong if
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
19 we are at the end of the playlist."""
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
20 try:
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
21 currentIndex = self.songs.index(currentSong)
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
22 except IndexError:
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1858
diff changeset
23 raise ValueError("%r is not in the current playlist (%r)." %
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1858
diff changeset
24 (currentSong, self.playlistUri))
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
25
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
26 try:
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
27 nextSong = self.songs[currentIndex + 1]
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
28 except IndexError:
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1858
diff changeset
29 raise NoSuchSong("%r is the last item in the playlist." %
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
30 currentSong)
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
31
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
32 return nextSong
717
d8202a0a7fd5 fix up musicpad and wavecurve. ascoltami2 can now use relative paths in the config
Drew Perttula <drewp@bigasterisk.com>
parents: 624
diff changeset
33
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
34 def allSongs(self):
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
35 """Returns a list of all song URIs in order."""
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
36 return self.songs
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1244
diff changeset
37
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
38 def allSongPaths(self):
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
39 """Returns a list of the filesystem paths to all songs in order."""
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
40 paths = []
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
41 for song in self.songs:
717
d8202a0a7fd5 fix up musicpad and wavecurve. ascoltami2 can now use relative paths in the config
Drew Perttula <drewp@bigasterisk.com>
parents: 624
diff changeset
42 paths.append(songOnDisk(song))
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
43 return paths
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1244
diff changeset
44
624
9071cd1bb29c fix wavecurve
drewp@bigasterisk.com
parents: 621
diff changeset
45 def songPath(self, uri):
9071cd1bb29c fix wavecurve
drewp@bigasterisk.com
parents: 621
diff changeset
46 """filesystem path to a song"""
717
d8202a0a7fd5 fix up musicpad and wavecurve. ascoltami2 can now use relative paths in the config
Drew Perttula <drewp@bigasterisk.com>
parents: 624
diff changeset
47 raise NotImplementedError("see showconfig.songOnDisk")
d8202a0a7fd5 fix up musicpad and wavecurve. ascoltami2 can now use relative paths in the config
Drew Perttula <drewp@bigasterisk.com>
parents: 624
diff changeset
48 # maybe that function should be moved to this method
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
49
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
50 @classmethod
2150
e13b62bfdaff fix some warnings
drewp@bigasterisk.com
parents: 1866
diff changeset
51 def fromShow(cls, graph, show):
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
52 playlistUri = graph.value(show, L9['playList'])
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
53 if not playlistUri:
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents:
diff changeset
54 raise ValueError("%r has no l9:playList" % show)
2150
e13b62bfdaff fix some warnings
drewp@bigasterisk.com
parents: 1866
diff changeset
55 return cls(graph, playlistUri)