This file is indexed.

/usr/share/doc/python-daap/examples/itshell.py is in python-daap 0.7.1-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/python
from cmd import Cmd
from daap import DAAPClient
import sys
import re

# darwin doesn't ship with readline!?
try: import readline
except: pass

class ItShell(Cmd):
    intro = """
    The python/daap interactive shell.
    Type 'help' for help.
    """

    def preloop(self):
        self.prompt = "(no server): "
        self.session = None
        self.database = None

    def emptyline(self):
        pass

    def do_EOF(self, other):
        self.do_exit(other)
        
    def do_exit(self, other):
        """
        exit - Quits. Duh.
        """
        print "bye."
        sys.exit(0)

    def do_connect(self, spec):
        """
        connect [<server> [<port>] ]
        Connects to the give server/port. Defaults to localhost.
        """
        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:
            print "Need server and port"
            return

        print "Connecting to %s:%s"%(repr(server), repr(port))
        client = DAAPClient()
        client.connect(server, port)
        self.session = client.login()
        self.do_database( self.session.library().id )
        self.prompt = "(%s:%s): "%(server,port)

    def do_databases(self, other):
        """
        Lists the databases of the connected server
        """
        if not self.session:
            print "Not connected"
            return
        databases = self.session.databases()
        for d in databases:
            print "%s: %s"%(d.id, repr(d.name))

    def do_database(self, id):
        """
        database <id> - use a particular database
        """
        if not self.session:
            print "Not connected"
            return
        databases = self.session.databases()
        for d in databases:
            if str(d.id) == str(id):
                self.database = d
                print "using database '%s'"%repr(d.name)
                self.get_tracks(reset = 1)
                print "Got %s tracks"%len(self._tracks)
                return

        print "No such database"

    def do_playlists(self, other):
        """
        Lists the playlists of the selected database
        """
        if not self.database:
            print "No current database"
            return
        playlists = self.database.playlists()
        print "%s playlists in the selected database."%len(playlists)
        for p in playlists:
            print "%s: %s"%(p.id, repr(p.name))

    def do_playlist(self, id):
        """
        playlist <id> - use a particular playlist
        """
        if not self.session:
            print "Not connected"
            return
        if not self.database:
            print "No current database"
            return
        playlists = self.database.playlists()
        for p in playlists:
            if str(p.id) == str(id):
                self.database = p
                print "using playlist '%s'"%repr(p.name)
                self._tracks = p.tracks()
                print "Got %s tracks"%len(self._tracks)
                return

        print "No such database"

    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()
        print "%s tracks in the selected database."%len(tracks)
        if len(tracks) > 50: print "displaying 1-50"
        for t in tracks[:50]:
            print "%s: %s - %s - %s"%(t.id, repr(t.artist), repr(t.album), repr(t.name))

    def do_search(self, other):
        """search <term> - list all tracks matching the given term"""
        if not self.database:
            print "No current database"
            return
        tracks = self.get_tracks()
        found = []
        for t in tracks:
            # TODO - wow, what a hacky search
            if re.search(other, "%s %s %s"%(t.name, t.artist, t.album), re.IGNORECASE ):
                found.append( t )

        # [ t.atom.printTree() for t in found ]
        print "%s tracks found."%len(found)
        if len(found) > 50: print "displaying 1-50"
        for t in found[:50]:
            print "%s: %s - %s - %s"%(t.id, repr(t.artist), repr(t.album), repr(t.name))
        
    
    def do_download(self, spec):
        """download <track id> [<filename>] - download the given track to the local machine"""
        if not self.database:
            print "No current database"
            return

        if len(spec) == 0:
            print "Need a track id"
            return
        elif spec.count(" ") == 0:
            id = spec
            filename = None
        elif spec.count(" ") == 1:
            (id, filename) = spec.split(" ")
        else:
            print "Need track id and filename only"
            return

        tracks = self.get_tracks()
        for t in tracks:
            if str(t.id) == id:
                if filename == None:
                    filename = "%s - %s.%s"%(repr(t.artist), repr(t.name), t.type)
                t.save( filename )
                return
        print "No such track"



try:
    import logging
    logging.basicConfig(level=logging.DEBUG,
            format='%(asctime)s %(levelname)s %(message)s')
    # run the shell
    shell = ItShell()
    #shell.do_connect("")
    shell.cmdloop()
finally:
    if shell and shell.session:
        shell.session.logout()