clDB.py

00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 # ----------------------------------------------------------------------------
00005 # pyjama - python jamendo audioplayer
00006 # Copyright (c) 2008 Daniel Nögel
00007 #
00008 # This program is free software: you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation, either version 3 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # This program is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 # You should have received a copy of the GNU General Public License
00018 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 # ----------------------------------------------------------------------------
00020 
00021 ## @package clDB
00022 # clDB holds database related functions
00023 
00024 import os, sys
00025 from time import time
00026 try:
00027     from pysqlite2 import dbapi2 as sqlite3
00028 except ImportError:
00029     import sqlite3
00030 
00031 from modules import functions
00032 
00033 # Gettext - Übersetzung
00034 functions.translation_gettext()
00035 #def _(string):
00036 #    return string
00037 
00038 from clGstreamer010 import Track
00039 
00040 ## Settings Database Class
00041 # This settings-class is going to become
00042 # a more powerfull settings interface than
00043 # the current ConfigParser is.
00044 # Of course you can still use the ConfigParser
00045 # but have in mind, that this class also allows
00046 # you to have own tables and real db queries.
00047 ## \todo 
00048 # - Implementation
00049 class DB_Settings():
00050     ## The Constructor
00051     # @param self The Object pointer
00052     # @param pyjama Reference to pyjama
00053     def __init__(self, pyjama):
00054         ## Reference to pyjama
00055         self.pyjama = pyjama
00056         ## Database file
00057         self.db = os.path.join(functions.preparedirs(), "settings.db")
00058         ## Holds the databse connection
00059         self.connection = None
00060 
00061         self.query_counter = 0
00062 
00063         if not os.path.exists(self.db):
00064             self.open() 
00065             self.create_database()
00066         else:
00067             self.open() 
00068 
00069     ## Set a option's value
00070     # @param self The Object pointer
00071     # @param section The table to write to
00072     # @param option The option as string
00073     # @param value The value to set as string
00074     # @return bool
00075     def set_value(self, section, option, value, table="settings"):
00076         sql = "SELECT COUNT(*) FROM %s WHERE section='%s' and option='%s'" % (table, section, option)
00077         ret = self.query(sql)
00078 
00079         if ret[0][0] == 0:
00080             sql = "INSERT INTO %s (section, option, value) values('%s', '%s', '%s')" % (table, section, option, value)
00081         else:
00082             sql = "UPDATE %s SET value='%s' WHERE section='%s' and option='%s'" % (table, value, section, option)
00083 
00084         self.connection.execute(sql)
00085         self.connection.commit()
00086 
00087         self.query_counter += 1
00088 
00089     def increase_value(self, section, option, table="settings"):
00090         sql = "SELECT value FROM %s WHERE section='%s' and option='%s'" % (table, section, option)
00091         ret = self.query(sql)
00092 
00093         if ret == []:
00094             sql = "INSERT INTO %s (section, option, value) values('%s', '%s', '1')" % (table, section, option)
00095         else:
00096             sql = "UPDATE %s SET value=value+1 WHERE section='%s' and option='%s'" % (table, section, option)
00097 
00098         self.connection.execute(sql)
00099         self.connection.commit()
00100 
00101         self.query_counter += 1
00102 
00103     ## Reads a value from an option
00104     # @param self The Object pointer
00105     # @param section The table to read from
00106     # @param option An option as string
00107     # @param default A default value
00108     # @return The option's value or default if section or option do not exist
00109     def get_value(self, section, option, default=None, table="settings"):
00110         sql = "SELECT value FROM %s WHERE section='%s' and option='%s'" % (table, section, option)
00111         ret = self.query(sql)
00112         if ret == [] or ret == -1: 
00113             return default
00114         else:
00115             if len(ret[0]) == 1: 
00116                 return ret[0][0]
00117             else:
00118                 return ret[0]
00119 
00120 #    def create_table(self, option):
00121 #        sql = """
00122 #        CREATE TABLE %s (
00123 #          uid INTEGER PRIMARY KEY,
00124 #          option INTEGER,
00125 #          value INTEGER
00126 #        )
00127 #        """ % option
00128 #        self.connection.execute(sql)
00129 #        self.connection.commit()
00130 
00131     def create_table(self, table_name):
00132         sql = "select count(name) from sqlite_master where name = '%s'" % table_name
00133         ret = self.query(sql)
00134 
00135         if ret[0][0] == 0:
00136             sql = """
00137             CREATE TABLE %s (
00138               uid INTEGER PRIMARY KEY,
00139               section STRING,
00140               option STRING,
00141               value string
00142             )
00143             """ % table_name
00144             self.connection.execute(sql)
00145             self.connection.commit()
00146             return "created"
00147         else:
00148             return "existant"
00149 
00150     ## Create Database if not existant
00151     # @param self The Object Pointer
00152     def create_database(self):
00153         print("Creating settings database 'settings.db'")
00154 
00155 #        sql = """
00156 #        CREATE TABLE tracks (
00157 #          uid INTEGER PRIMARY KEY,
00158 #          id INTEGER,
00159 #          listencounter INTEGER
00160 #        )
00161 #        """
00162 #        self.connection.execute(sql)
00163 #        self.connection.commit()
00164 
00165         sql = """
00166         CREATE TABLE settings (
00167           uid INTEGER PRIMARY KEY,
00168           section STRING,
00169           option STRING,
00170           value string
00171         )
00172         """
00173         self.connection.execute(sql)
00174         self.connection.commit()
00175 
00176     ## Open Database connection
00177     # @param self The Object pointer
00178     def open(self):
00179         self.connection = sqlite3.connect(self.db)
00180 
00181     ## Close Database connection
00182     # @param self The Object poi
00183     def close(self):
00184         self.connection.close()
00185 
00186     def quit(self):
00187         pass
00188 
00189     ## Queries the SQLite database
00190     # @param self The Object pointer
00191     # @param query A SQL Query
00192     def query(self, query):
00193         self.query_counter += 1
00194         try:
00195             cur = self.connection.cursor()
00196             cur.execute(query)
00197             rows = cur.fetchall()
00198             return rows
00199         except Exception, inst:
00200             desc = "There was an error while querying the settings database"
00201             self.pyjama.Events.raise_event("error", inst, desc)
00202             return -1
00203 
00204 ## Main Database Class
00205 #
00206 # Holds methods to search the databse
00207 # for albums, artists, tracks and
00208 # related informations
00209 class DB():
00210     ## The constructor
00211     # @param self The object pointer
00212     # @param par Pyjama reference
00213     def __init__(self, par):
00214         ## reference to pyjama
00215         self.parent = par
00216         ## pyjama's home directory
00217         self.home=functions.preparedirs()
00218         ## pyjama's database file
00219         self.db = os.path.join(self.home, "pyjama.db")
00220 
00221         self.tracks, self.albums, self.artists = 0, 0, 0
00222         self.query_counter = 0
00223 
00224         ## stores results for threaded queries
00225         self.results = {}
00226 
00227         # not implemented, yet
00228         self.queue = []
00229 
00230         ## holds the connection to our database
00231         self.connection = None
00232 
00233         self.database_ok = True
00234         if not os.path.exists(os.path.join(functions.preparedirs(),"pyjama.db")):
00235             self.database_ok = False
00236         else:
00237             sql = "select count(name) from sqlite_master where name = 'albums' or name = 'artists' or name = 'tracks'" 
00238             try:
00239                 tablecount =  self.__query(sql)
00240                 if tablecount[0][0] < 3:
00241                     print("Some tables in the database seems to be missing")
00242                     print ("Marking the database as corrupt")
00243                     self.database_ok = False
00244             except Exception:
00245                 self.database_ok = False
00246 
00247         if self.database_ok:
00248             try:
00249                 ## number of tracks in the database
00250                 self.tracks = self.__query("SELECT COUNT (*) FROM tracks WHERE 1")[0][0]
00251                 ## number of albums in the database
00252                 self.albums = self.__query("SELECT COUNT (*) FROM albums WHERE 1")[0][0]
00253                 ## number of artists in the database
00254                 self.artists = self.__query("SELECT COUNT (*) FROM artists WHERE 1")[0][0]
00255             except TypeError, inst:
00256                 self.tracks = 0
00257                 self.albums = 0
00258                 self.artists = 0
00259                 
00260                 self.database_ok = False
00261                 desc =  "\n\n+-------------------------------------------------------+\n"
00262                 desc += "|          A neccessary table wasn't found.             |\n"
00263                 desc += "| Pyjama will now download and convert the needed files |\n"
00264                 desc += "|         If any problems occur, run 'pyjama -u'        |\n"
00265                 desc += "+-------------------------------------------------------+"
00266                 #self.parent.Events.raise_event("error", inst, desc)
00267                 print desc
00268     #            sys.exit(1)
00269 
00270             if self.tracks < 135000 or self.albums < 19000 or self.artists < 10000:
00271                 print ("There seem to be a lot of entries missing in the database")
00272                 print ("Marking the database as corrupt")
00273                 self.database_ok = False
00274 
00275         # run this in its own thread
00276 #        self.watch_queue()
00277 
00278 
00279     ## Opens a database connection
00280     # @return None
00281     # @param self The Object pointer
00282     def open(self):
00283         self.connection = sqlite3.connect(self.db)
00284 
00285     ## Closes the database connection
00286     # @return None
00287     # @param self The Object pointer
00288     def close(self):
00289         self.connection.close()
00290 
00291     ## queries the database
00292     # @return list
00293     # @param self The Object pointer
00294     # @param query a string with a sql command
00295     def query(self, query):
00296         if not self.parent.window.check_alldone():
00297             self.parent.Events.raise_event("error", None, "You are not allowed to query the database before the main-module was loaded succesfully. If you are writing a plugin, please connect to the 'alldone' event.")
00298             return -2
00299 
00300         self.query_counter += 1
00301 
00302         try:
00303             self.open()
00304             cur = self.connection.cursor()
00305             cur.execute(query)
00306             rows = cur.fetchall()
00307        
00308             self.close()
00309         
00310             return rows
00311         except Exception, inst:
00312             desc = "There was an error while querying the database"
00313             self.parent.Events.raise_event("error", inst, desc)
00314             return -1
00315 
00316     ## Private methode
00317     # Use query() for your plugins
00318     def __query(self, query):
00319         self.query_counter += 1
00320 
00321         try:
00322             self.open()
00323             cur = self.connection.cursor()
00324             cur.execute(query)
00325             rows = cur.fetchall()
00326        
00327             self.close()
00328         
00329             return rows
00330         except Exception, inst:
00331             desc = "There was an error while querying the database"
00332             self.parent.Events.raise_event("error", inst, desc)
00333             return -1
00334 
00335 #    ## add a query to the queue
00336 #    # /todo Rename this fkt to query()
00337 #    def query_to_come(self, query):
00338 #        self.query.insert(0, query)
00339 
00340 #    def watch_queue(self):
00341 #        # run this in a thread
00342 #        while 1:
00343 #            while len(self.queue) > 0:
00344 #                query = queue.pop()
00345 #                self.__do_query()
00346 
00347 #    ## queries the database - never call this function directly
00348 #    # use query() instead
00349 #    # @return list
00350 #    # @param self The Object pointer
00351 #    # @param query a string with a sql command
00352 #    def __do_query(self, query):
00353 #        self.query_counter += 1
00354 
00355 #        try:
00356 #            self.open()
00357 #            cur = self.connection.cursor()
00358 #            cur.execute(query)
00359 #            rows = cur.fetchall()
00360 #       
00361 #            self.close()
00362 #        
00363 #            return rows
00364 #        except Exception, inst:
00365 #            desc = "There was an error while querying the database"
00366 #            self.parent.Events.raise_event("error", inst, desc)
00367 #            return -1
00368 
00369     ## get several informations for a spicific artist-id
00370     # @return dictionary
00371     # @param self The Object pointer
00372     # @param id An artist id as int or string
00373     # @param thread_id If this function is called by a thread,
00374     # this is the thread's id
00375     def artistinfos(self, id, thread_id = 0):
00376         sql = """
00377             SELECT
00378                 artists.name, artists.country, artists.image, artists.url, artists.id, albums.name, albums.id, artists.albumcount
00379             FROM
00380                 artists, albums
00381             WHERE
00382                 artists.id=%s and albums.artist_id=artists.id
00383             """ % str(id)
00384         ret = self.query(sql)
00385         counter = 0
00386         artist = {}
00387         for info in ret:
00388             artist[counter] = {}
00389             artist[counter]['artist_name'] = info[0]
00390             artist[counter]['artist_country'] = info[1]
00391             artist[counter]['artist_image'] = info[2]
00392             artist[counter]['artist_url'] = info[3]
00393             artist[counter]['artist_id'] = info[4]
00394             artist[counter]['album_name'] = info[5]
00395             artist[counter]['album_id'] = info[6]
00396             artist[counter]['artist_albumcount'] = info[7]
00397             counter += 1
00398         self.results[thread_id]=artist
00399         return artist
00400 
00401     def multiple_albuminfos(self, ids):
00402         album_string = "("
00403         for album in ids:
00404             album_string += " albums.id=%s or" % album
00405         album_string = album_string[:-3] + ") and albums.artist_id=artists.id"
00406 
00407         sql = """
00408             SELECT
00409                 albums.id, albums.name, artists.id, artists.name
00410             FROM
00411                 albums, artists
00412             WHERE
00413                 %s
00414             """ % album_string
00415 
00416         ret = self.query(sql)
00417         return ret
00418 
00419 #    ## get track-informations for several track-ids
00420 #    # @return dictionary
00421 #    # @param self The Object pointer
00422 #    # @param ids A list of ids as strings
00423 #    def multiple_albumtracks(self, ids):
00424 #        where_clause = ") OR ("
00425 #        strings = []
00426 #        for id in ids:
00427 #            strings.append( "tracks.albumID='%s'" % id)
00428 #        where_clause = "(" + where_clause.join(strings) + ")"
00429 #        sql = """
00430 #            SELECT
00431 #                tracks.dispname, tracks.lengths, tracks.trackno, tracks.id, albums.id, albums.dispname, artists.id, artists.dispname, artists.name
00432 #            FROM
00433 #                albums, artists
00434 #            INNER JOIN tracks ON albums.artistID=tracks.albumID
00435 #            """# % where_clause #order by tracks.albumID
00436 #        ret = self.query(sql)
00437 #        counter = 0
00438 #        tracks={}
00439 #        for track in ret:
00440 #            tracks[counter] = {}
00441 #            #tracks[counter]['uid'] = time()
00442 #            tracks[counter]['dispname'] = track[0]
00443 #            tracks[counter]['lengths'] = track[1]
00444 #            tracks[counter]['trackno'] = track[2]
00445 #            tracks[counter]['id'] = track[3]
00446 #            tracks[counter]['album_id'] = track[4]
00447 #            tracks[counter]['album_dispname'] = track[5]
00448 #            tracks[counter]['artist_id'] = track[6]
00449 #            tracks[counter]['artist_dispname'] = track[7]
00450 #            tracks[counter]['artist_name'] = track[8]
00451 ##            tracks[counter]['stream'] = "query" 
00452 #            tracks[counter]['stream'] = "http://api.jamendo.com/get2/stream/track/redirect/?id=%i&streamencoding=%s" % (track[3], self.parent.settings.get_value("JAMENDO", "format_stream", "mp31"))
00453 #            counter += 1
00454 #        return tracks
00455 
00456     ## Get trackinfos for a list of tracks
00457     # @return dictionary
00458     # @param self The Object pointer
00459     # @param tracks a list of strings 
00460     def get_multiple_trackinfos(self, tracks):
00461         track_string = "("
00462         for track in tracks:
00463             track_string += " tracks.id=%s or" % track
00464         track_string = track_string[:-3] + ") and tracks.artist_id=artists.id and albums.id=tracks.album_id"
00465         sql = """
00466             SELECT
00467                 tracks.name, tracks.duration, tracks.numalbum, tracks.license, tracks.album_id, tracks.artist_id, artists.name, albums.name, tracks.uid, tracks.id3genre, tracks.id
00468             FROM
00469                 tracks, artists, albums
00470             WHERE 
00471                 %s
00472             """ % track_string
00473 
00474         ret = self.query(sql)
00475 
00476         tracks=[]
00477         for track in ret:
00478             tr = Track()
00479             tr.name = track[0]
00480             tr.duration = track[1]
00481             tr.numalbum = track[2]
00482             tr.license = track[3]
00483             tr.album_id = track[4]
00484             tr.artist_id = track[5]
00485             tr.artist_name = track[6]
00486             tr.album_name = track[7]
00487             tr.uid = track[8]
00488             tr.id3genre = track[9]
00489             tr.id = track[10]
00490             tr.stream = "http://api.jamendo.com/get2/stream/track/redirect/?id=%i&streamencoding=%s" % (track[10], self.parent.settings.get_value("JAMENDO", "format_stream", "mp31"))
00491             tracks.append(tr)
00492         return tracks
00493 
00494     ## Get trackinfos for a single track
00495     # @return dictionary
00496     # @param self The Object pointer
00497     # @param trackid a track-id as string or int
00498     def get_trackinfos2(self, trackid):
00499         sql = """
00500             SELECT
00501                 tracks.name, tracks.duration, tracks.numalbum, tracks.license, tracks.album_id, tracks.artist_id, artists.name, albums.name, tracks.uid, tracks.id3genre, tracks.id
00502             FROM
00503                 tracks, albums, artists
00504             WHERE
00505                 tracks.id=%s and albums.id=tracks.album_id and artists.id=tracks.artist_id
00506             """ % str(trackid)
00507         ret = self.query(sql)
00508         if ret == []:
00509             return []
00510         ret = ret[0]
00511         tr = Track()
00512         tr.name = ret[0]
00513         tr.duration = ret[1]
00514         tr.numalbum = ret[2]
00515         tr.license = ret[3]
00516         tr.album_id = ret[4]
00517         tr.artist_id = ret[5]
00518         tr.artist_name = ret[6]
00519         tr.album_name = ret[7]
00520         tr.uid = ret[8]
00521         tr.id3genre = ret[9]
00522         tr.id = ret[10]
00523         tr.stream = "http://api.jamendo.com/get2/stream/track/redirect/?id=%i&streamencoding=%s" % (ret[10], self.parent.settings.get_value("JAMENDO", "format_stream", "mp31"))
00524 #        tracks.append(tr)
00525         return tr
00526 
00527   
00528         
00529 #http://api.jamendo.com/get2/track_name+track_duration+track_url+license_url+album_id+album_name+artist_id+artist_idstr+artist_name/track/jsonpretty/album_artist/
00530 
00531     ## Get all artist's tracks
00532     # @return dictionary
00533     # @param self The Object pointer
00534     # @param id an artist's id as string or int
00535     def artisttracks(self, id):
00536         sql = """
00537             SELECT
00538                 tracks.name, tracks.duration, tracks.numalbum, tracks.license, tracks.album_id, tracks.artist_id, artists.name, albums.name, tracks.uid, tracks.id3genre, tracks.id
00539             FROM
00540                 tracks, albums, artists
00541             WHERE
00542                 tracks.album_id=albums.id and tracks.artist_id=%s and albums.artist_id=%s and artists.id=tracks.artist_id
00543             """ % (str(id), str(id))
00544         ret = self.query(sql)                
00545         tracks=[]
00546         for track in ret:
00547             tr = Track()
00548             tr.name = track[0]
00549             tr.duration = track[1]
00550             tr.numalbum = track[2]
00551             tr.license = track[3]
00552             tr.album_id = track[4]
00553             tr.artist_id = track[5]
00554             tr.artist_name = track[6]
00555             tr.album_name = track[7]
00556             tr.uid = track[8]
00557             tr.id3genre = track[9]
00558             tr.id = track[10]
00559             tr.stream = "http://api.jamendo.com/get2/stream/track/redirect/?id=%i&streamencoding=%s" % (track[10], self.parent.settings.get_value("JAMENDO", "format_stream", "mp31"))
00560             tracks.append(tr)
00561         return tracks
00562 
00563     ## get all tracks of an album
00564     # @return dictionary
00565     # @param self The Object pointer
00566     # @param id an album's id
00567     def albumtracks(self, id):
00568         sql = """
00569             SELECT
00570                 tracks.name, tracks.duration, tracks.numalbum, tracks.license, tracks.album_id, tracks.artist_id, artists.name, albums.name, tracks.uid, tracks.id3genre, tracks.id
00571             FROM
00572                 tracks, albums, artists
00573             WHERE
00574                 tracks.album_id=%s and albums.id=%s and artists.id=albums.artist_id
00575             """ % (str(id), str(id))
00576         ret = self.query(sql)
00577         tracks=[]
00578         for track in ret:
00579             tr = Track()
00580             tr.name = track[0]
00581             tr.duration = track[1]
00582             tr.numalbum = track[2]
00583             tr.license = track[3]
00584             tr.album_id = track[4]
00585             tr.artist_id = track[5]
00586             tr.artist_name = track[6]
00587             tr.album_name = track[7]
00588             tr.uid = track[8]
00589             tr.id3genre = track[9]
00590             tr.id = track[10]
00591             tr.stream = "http://api.jamendo.com/get2/stream/track/redirect/?id=%i&streamencoding=%s" % (track[10], self.parent.settings.get_value("JAMENDO", "format_stream", "mp31"))
00592             tracks.append(tr)
00593         return tracks
00594 
00595     ## search tags
00596     # @return dictionary
00597     # @param self The Object pointer
00598     # @param string a string to search for
00599     def Search_tag(self, string):
00600     
00601         sql = """
00602             SELECT
00603                 albums.name, albums.id, artists.name, artists.id
00604             FROM
00605                 albums, artists, tags
00606             WHERE
00607                 tags.idstr='""" + string + """' and albums.id=tags.album_id LIMIT """ + str(self.parent.settings.get_value("PERFORMANCE", "db_search_limit"))
00608         ret = self.query(sql)
00609         tags = {}
00610         counter = 0
00611         for tag in ret:
00612             tags[counter] = {}
00613             tags[counter]['album_name'] = tag[0]
00614             tags[counter]['album_id'] = tag[1]
00615             tags[counter]['artist_name'] = tag[2]
00616             tags[counter]['artist_id'] = tag[3]
00617             counter += 1
00618         print tags
00619         return tags
00620 
00621 
00622     ## Search tracks
00623     # @return dictionary
00624     # @param self The Object pointer
00625     # @param string a string to search for
00626     def search_track(self, string):
00627     
00628         sql = """
00629             SELECT
00630                 tracks.name, tracks.duration, tracks.numalbum, tracks.id, tracks.license, tracks.id3genre, albums.id, albums.name, artists.id, artists.name, tracks.uid
00631             FROM
00632                 tracks, albums, artists
00633             WHERE
00634                 tracks.name LIKE '%""" + string + """%' and tracks.album_id=albums.id and albums.artist_id=artists.id LIMIT """ + str(self.parent.settings.get_value("PERFORMANCE", "db_search_limit"))
00635         ret = self.query(sql)
00636         tracks=[]
00637         for track in ret:
00638             tr = Track()
00639             tr.name = track[0]
00640             tr.duration = track[1]
00641             tr.numalbum = track[2]
00642             tr.id = track[3]
00643             tr.license = track[4]
00644             tr.id3genre = track[5]
00645             tr.album_id = track[6]
00646             tr.album_name = track[7]
00647             tr.artist_id = track[8]
00648             tr.artist_name = track[9]
00649             tr.uid = track[10]
00650             tr.stream = "http://api.jamendo.com/get2/stream/track/redirect/?id=%i&streamencoding=%s" % (track[3], self.parent.settings.get_value("JAMENDO", "format_stream", "mp31"))
00651             tracks.append(tr)
00652         return tracks
00653 
00654     ## Search artists
00655     # @return dictionary
00656     # @param self The Object pointer
00657     # @param string a string to search for
00658     def search_artist(self, string):
00659         sql = """
00660             SELECT
00661                 artists.name, artists.id
00662             FROM
00663                 artists
00664             WHERE
00665                 artists.name LIKE '%""" + string + """%' LIMIT """ + str(self.parent.settings.get_value("PERFORMANCE", "db_search_limit"))
00666         ret = self.query(sql)
00667         artists = {}
00668         counter = 0
00669         for artist in ret:
00670             artists[counter] = {}
00671             artists[counter]['artist_name'] = artist[0]
00672             artists[counter]['artist_id'] = artist[1]
00673 #            artists[counter]['album_dispname'] = artist[2]
00674 #            artists[counter]['album_id'] = artist[3]
00675             counter += 1
00676         return artists
00677 
00678     ## Search albums
00679     # @return dictionary
00680     # @param self The Object pointer
00681     # @param string a string to search for 
00682     def search_album(self, string):
00683     
00684         sql = """
00685             SELECT
00686                 albums.name, albums.id, artists.name, artists.id
00687             FROM
00688                 albums, artists
00689             WHERE
00690                 albums.name LIKE '%""" + string + """%' and albums.artist_id=artists.id LIMIT """ + str(self.parent.settings.get_value("PERFORMANCE", "db_search_limit"))
00691         ret = self.query(sql)
00692         albums = {}
00693         counter = 0
00694         for album in ret:
00695             albums[counter] = {}
00696             albums[counter]['album_name'] = album[0]
00697             albums[counter]['album_id'] = album[1]
00698             albums[counter]['artist_name'] = album[2]
00699             albums[counter]['artist_id'] = album[3]
00700             counter += 1
00701         return albums
00702 
00703     ## Get an album's tags
00704     # @return list
00705     # @param self The Object pointer
00706     # @param id an album to search for as string or int
00707     def gettags(self, id):
00708         
00709         sql = """
00710             SELECT
00711                 tags
00712             FROM
00713                 albums
00714             WHERE
00715                 id=%s
00716             """ % str(id)
00717         ret = self.query(sql)
00718         return ret
00719 
00720 #    def albuminfos(self, id):
00721 #        strQuery = "track/id/album/data/json/ID?ali=full&ari=full+object&tri=full&item_o=track_no_asc&showhidden=1&shownotmod=1"
00722 #        strQuery = strQuery.replace("ID", str(id))
00723 #        ret = self.__queryold__(strQuery)
00724 #        return ret
00725 
00726 
00727 
00728 
00729 
00730 
00731 
00732 #    def albumtracks(self, id):         
00733 #        ret = self.get("track_id+track_name+track_stream+track_duration+album_name", "track", "album_track/?album_id=" + str(id)+"&streamencoding=ogg2")       
00734 #        return ret
00735 #        
00736 
00737 #    def artistalbums(self, idstr):
00738 #        ret = self.get("album_id+album_name+album_playlist", "artist", "?idstr=" + idstr + "&ali=full")
00739 #        print ret
00740 #        return ret
00741 
00742 #    def artistlist(self):
00743 #        ret =  self.get("id+idstr+name", "artist", "?artist_hasalbums&n=50")
00744 #        return ret
00745 

Generated on Thu Jun 4 19:08:24 2009 for Pyjama by  doxygen 1.5.8