Пример #1
0
    def musicEntryFromFileIds(self,
                              filerowids,
                              incompleteMusicEntries=None,
                              mode='normal'):
        reload(cherrymusicserver.tweak)
        file_search_limit = cherrymusicserver.tweak.SearchTweaks.normal_file_search_limit

        #incompleteMusicEntries maps db parentid to incomplete musicEntry
        assert mode in ('normal', 'dironly', 'fileonly'), mode
        if incompleteMusicEntries is None:
            incompleteMusicEntries = {}
        musicEntries = []  #result list

        if self.file_db_in_memory():
            db = self.file_db_mem.db
        else:
            db = self.conn

        cursor = db.cursor()
        sqlquery = '''  SELECT rowid, parent, filename, filetype, isdir
                        FROM files WHERE rowid IN ({ids})'''.format(
            ids=', '.join('?' * len(filerowids)))
        sqlparams = tuple(filerowids)

        if not incompleteMusicEntries:
            #only filter 1st recursion level
            if mode != 'normal':
                sqlquery += ' AND isdir = ?'
                sqlparams += ('dironly' == mode, )
            sqlquery += ' LIMIT 0, ?'
            sqlparams += (file_search_limit, )

        cursor.execute(sqlquery, sqlparams)
        for id, parent_id, filename, fileext, isdir in cursor.fetchall():
            path = filename + fileext
            #check if fetched row is parent of existing entry
            if id in incompleteMusicEntries:
                #remove item and map to new parent id
                entries = incompleteMusicEntries.pop(id)
                for entry in entries:
                    entry.path = os.path.join(path, entry.path)
            else:
                #id is not parent of any entry, so make a new one
                entries = [MusicEntry(path, dir=bool(isdir))]

            if parent_id == -1:
                #put entries in result list if they've reached top level
                musicEntries += entries
            else:
                #otherwise map parent id to dict
                incompleteMusicEntries[parent_id] = incompleteMusicEntries.get(
                    parent_id, []) + entries

        if incompleteMusicEntries:
            #recurse for all incomplete entries
            musicEntries += self.musicEntryFromFileIds(
                incompleteMusicEntries.keys(),
                incompleteMusicEntries=incompleteMusicEntries,
                mode=mode)
        return musicEntries
Пример #2
0
    def musicEntryFromFileIds(self,
                              filerowids,
                              incompleteMusicEntries={},
                              mode='normal'):
        #incompleteMusicEntries maps db parentid to incomplete musicEntry
        musicEntries = []  #result list

        if self.file_db_in_memory():
            db = self.file_db_mem.db
        else:
            db = self.conn

        cursor = db.cursor()
        sqlquery = '''  SELECT rowid, parent, filename, filetype, isdir
                        FROM files WHERE rowid IN (''' + ', '.join(
            map(str, filerowids)) + ''') '''

        if not incompleteMusicEntries:
            #only filter 1st recursion level
            if mode != 'normal':
                sqlquery += ' AND isdir = ' + str(int('dironly' == mode))
            sqlquery += ' LIMIT 0,' + str(NORMAL_FILE_SEARCH_LIMIT)

        tempIncompleteEntries = {}
        for rowid, parent, filename, fileext, isdir in cursor.execute(
                sqlquery).fetchall():
            path = filename + fileext
            #check if fetched row is parent of existing entry
            if rowid in incompleteMusicEntries:
                #remove item and map to new parent id
                entries = incompleteMusicEntries.pop(rowid)
                for entry in entries:
                    entry.path = os.path.join(path, entry.path)
            else:
                #rowid is not parent of any entry, so make a new one
                entries = [MusicEntry(path, dir=bool(isdir))]

            if parent == -1:
                #put entries in result list if they've reached top level
                musicEntries += entries
            else:
                #otherwise map parent id to dict
                tempIncompleteEntries[parent] = tempIncompleteEntries.get(
                    parent, []) + entries

        for k, v in tempIncompleteEntries.items():
            incompleteMusicEntries[k] = v

        if incompleteMusicEntries:
            #recurse for all incomplete entries
            musicEntries += self.musicEntryFromFileIds(
                incompleteMusicEntries.keys(),
                incompleteMusicEntries=incompleteMusicEntries,
                mode=mode)
        return musicEntries
Пример #3
0
 def loadPlaylist(self, playlistid, userid):
     cursor = self.conn.cursor()
     cursor.execute(
         """SELECT rowid FROM playlists WHERE
         rowid = ? AND (public = 1 OR userid = ?) LIMIT 0,1""",
         (playlistid, userid))
     result = cursor.fetchone()
     if result:
         cursor.execute(
             """SELECT title, url FROM tracks WHERE
             playlistid = ? ORDER BY track ASC""", (playlistid, ))
         alltracks = cursor.fetchall()
         apiplaylist = []
         for track in alltracks:
             #TODO ugly hack: playlistdb saves the "serve" dir as well...
             apiplaylist.append(
                 MusicEntry(path=unquote(track[1])[7:],
                            repr=unquote(track[0])))
         return apiplaylist
 def search(self, value, isFastSearch=False):
     if isFastSearch:
         return [MusicEntry('fast mock result', 'fast mock result')]
     else:
         return [MusicEntry('mock result', 'mock result')]