def insert_song(self , songname ): """ This function takes a song object and insert the data into apropriate table if the table where song has to insert are not present the function will raise error specifing the problem . It will also raise error message for an attempt to cache a particular song more than ones. """ extract_object = song.extract() song_object = extract_object.extract_file(songname) if not ( os.path.exists(songname)): raise IOError(" The file named %s not found" %songname) if not (self.is_cached_folder(os.path.dirname(songname))): self.create_folder( os.path.dirname( songname ) ) try : iscached = self.is_cached_song(songname) except IOError,error: raise IOError(" cannot insert the song object filename = {0} because {1} ".format(song_object.get_filename() ,error))
def insert_song(self , songname ): """ This function takes a song object and insert the data into apropriate table if the table where song has to insert are not present the function will raise error specifing the problem . It will also raise error message for an attempt to cache a particular song more than ones. """ extract_object = song.extract() song_object = extract_object.extract_file(songname) if not ( os.path.exists(songname)): raise IOError(" The file named %s not found" %songname) #if not (self.is_cached_folder(os.path.dirname(songname))): # self.create_folder( os.path.dirname( songname ) ) iscached = self.is_cached_song(songname) if ( self.is_cached_song(songname)) : raise IOError(" Attempt to insert an already cached file : %s " %song_object.get_filename()) else : conn = self.connectDB() c = conn.cursor() mrow = song_object.get_info() row = self.filt(mrow) crow = ( row[1],row[2],row[3],row[4],row[5],row[6], row[7],row[8],row[9],row[10],row[11],row[12], row[13],row[14],row[0] ) c.execute("""insert into CachedList values ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? ,? )""",crow) conn.commit() print " properly inserted " # todo not needed step #
import cache import song import sqlite3 import os extru = song.extract() song_obj = extru.extract_file("/home/nikhcc/neeyam.mp3") print song_obj.get_info()
def insert_song(self , songname ): """ This function takes a song object and insert the data into apropriate table if the table where song has to insert are not present the function will raise error specifing the problem . It will also raise error message for an attempt to cache a particular song more than ones. """ extract_object = song.extract() song_object = extract_object.extract_file(songname) if not ( os.path.exists(songname)): raise IOError(" The file named %s not found" %songname) #if not (self.is_cached_folder(os.path.dirname(songname))): # self.create_folder( os.path.dirname( songname ) ) iscached = self.is_cached_song(songname) if ( self.is_cached_song(songname)) : raise IOError(" Attempt to insert an already cached file : %s " %song_object.get_filename()) else : conn = self.connectDB() c = conn.cursor() mrow = song_object.get_info() row = self.filt(mrow) crow = ( row[1],row[2],row[3],row[4],row[5],row[6], row[7],row[8],row[9],row[10],row[11],row[12], row[13],row[14],row[0] ) #print "kkkkkk" #print row[0] #print os.path.dirname(row[0]).replace('/','_') #print "kkkkkkkkkkkkkkkkkkkkkkkk" #for i in range(15): # print row[i] # print i #for i in range(15): # print crow[i] # print i c.execute("""insert into CachedList values ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? ,? )""",crow) #c.execute(""" insert into {0} values # ( '{1}','{2}','{3}','{4}',{5},{6},'{7}',{8}, # '{9}','{10}','{11}','{12}','{13}','{14}' ,'{15}' )""".format( # os.path.dirname(row[14]).replace('/','_'), # row[1],row[2],row[3],row[4],row[5],row[6], # row[7],row[8],row[9],row[10],row[11],row[12], # row[13],row[14],row[0] ) ) #except : pass conn.commit() print " properly inserted " # todo not needed step #