This repository was archived by the owner on Jan 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylist.py
89 lines (78 loc) · 2.58 KB
/
playlist.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# -*- coding: utf-8 -*-
from daap import DAAPClient
import sys
class Playlist():
session = None
def do_connect(self, spec):
if len(spec) == 0:
server = "localhost"
port = 3689
elif spec.count(" ") == 0:
server = spec
port = 3689
elif spec.count(" ") == 1:
(server, port) = spec.split(" ")
else:
return
client = DAAPClient()
client.connect(server, port)
self.session = client.login()
self.do_database( self.session.library().id )
def do_database(self, id):
if not self.session:
return
databases = self.session.databases()
for d in databases:
if str(d.id) == str(id):
self.database = d
return
print "No such database"
def do_playlist(self, id):
"""
playlist <id> - use a particular playlist
"""
if not self.session:
return
if not self.database:
return
playlists = self.database.playlists()
for p in playlists:
if str(p.id) == str(id):
self.database = p
self._tracks = p.tracks()
return
def get_tracks(self, reset = 0):
if reset or "_tracks" not in self.__dict__:
self._tracks = self.database.tracks()
return self._tracks
def do_tracks(self, other):
"""tracks - list tracks in the selected database"""
if not self.database:
print "No current database"
return
tracks = self.get_tracks()
# [DAAPTrack(self.database, t) for t in track_list]
return map(self.do_url, tracks)
def do_urls(self, track):
return "http://%s:%s/databases/%s/items/%s.%s?session-id=%s"%(self.session.connection.hostname,
self.session.connection.port,
self.database.id,
track.id,
track.type,
track.database.session.sessionid)
if __name__ == '__main__':
def main():
shell = Playlist()
try:
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s')
# run the shell
shell.do_connect(sys.argv[1])
shell.do_playlist(sys.argv[2])
print
finally:
if shell and shell.session:
shell.session.logout()
main()