def add_db(self, dbfile): filename, extension = os.path.splitext(os.path.basename(dbfile)) # initialize db dejavu.shared.DATABASE_FILE = dbfile db_cls = get_database("sqlite") #db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**self.config.get("database", {})) self.db.setup() # get songs previously indexed songs = self.db.get_songs() for song in songs: newsong = { Database.FIELD_SONG_ID: song[Database.FIELD_SONG_ID] + self.max_sid, Database.FIELD_SONGNAME: filename + "_" + song[Database.FIELD_SONGNAME], Database.FIELD_FILE_SHA1: song[Database.FIELD_FILE_SHA1], "hashes": [] } hashes = self.db.get_fingerprints_by_song_id( song[Database.FIELD_SONG_ID]) newsong["hashes"].extend(hashes) self.all_songs.append(newsong) self.max_sid = self.max_sid + len(self.all_songs)
def mp_worker(urldata): url = None station_name = None song = None name = None try: url, station_name = urldata name = station_name + '.mp3' except ValueError: pass try: u = urllib.request.urlopen(url) data = u.read(150000) with open(name, 'wb') as file: file.write(data) time.sleep(1) except Exception as e: print(e) #try: djv = Dejavu(config) song = djv.recognize(FileRecognizer, name) # print("From Stream we recognized: {}\n".format(song)) if song is None: print("NONE") elif song['confidence'] >= 40: file_data = None try: with open(station_name + ".txt", 'r') as file: file_data = file.read() except Exception as e: with open(station_name + ".txt", 'w') as file: pass if file_data == song["song_name"]: print('ad already recorded') with open('log_date.txt', 'a') as writeFile: writeFile.write( "\n Duplicate recognition with confidence %d %s " % (song["confidence"], song["song_name"])) else: with open(station_name + ".txt", 'w') as file: file.write(song["song_name"]) db_cls = get_database(config.get("database_type", None)) db = db_cls(**config.get("database", {})) db.setup() # count = db.get_song_count_by_name(song["song_name"]) # db.update_song_count(song["song_name"],count['count']+1) d_local = datetime.datetime.now(pytz.timezone("Asia/Kathmandu")) db.insert_radio_song(station_name, song["song_name"], 'Begari Guys', int(song['confidence']), d_local) print("From file we recognized: {}\n".format(song["song_name"])) with open('log_date.txt', 'a') as writeFile: writeFile.write("\n Identified with high confidence %d %s" % (song['confidence'], song['song_name'])) else: with open('log_date.txt', 'a') as writeFile: writeFile.write("\n Identified with very less confidence %d %s" % (song['confidence'], song["song_name"])) print("From file we recognized: {} {} \n".format( song["song_name"], song['confidence']))
def __init__(self, config): super(Dejavu, self).__init__() self.config = config # initialize db db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**config.get("database", {})) self.db.setup() # if we should limit seconds fingerprinted, # None|-1 means use entire track self.limit = self.config.get("fingerprint_limit", None) if self.limit == -1: # for JSON compatibility self.limit = None # get songs previously indexed # TODO: should probably use a checksum of the file instead of filename self.songs = self.db.get_songs() self.songnames_set = set() # to know which ones we've computed before for song in self.songs: song_name = song[self.db.FIELD_SONGNAME] self.songnames_set.add(song_name) print "Added: %s to the set of fingerprinted songs..." % song_name
def save_db(self, outpath): # initialize db dejavu.shared.DATABASE_FILE = outpath db_cls = get_database("sqlite") #db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**self.config.get("database", {})) self.db.setup() self.db.empty() for key in self.all_songs: song = self.all_songs[key] sid = self.db.insert_song(song[Database.FIELD_SONGNAME], song[Database.FIELD_FILE_SHA1]) self.db.insert_hashes(sid, song["hashes"].items()) self.db.set_song_fingerprinted(sid) print("hashes in %d:%d" % (sid, len(song["hashes"].items()))) print("all_songs:%d" % (len(self.all_songs))) self.all_songs = {} return
def __init__(self, config): log.debug('__init__ Dejavu') super(Dejavu, self).__init__() self.config = config # initialize db db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**config.get("database", {})) self.db.setup()
def mp_worker(urldata): url = None number = None song = None name = None try: url, number = urldata name = 'recording' + number + '.mp3' except ValueError: pass try: u = urllib.request.urlopen(url) data = u.read(100000) with open(name, 'wb') as file: file.write(data) time.sleep(1) except Exception as e: print(e) try: djv = Dejavu(config) song = djv.recognize(FileRecognizer, name) if song is None: print("NONE") elif song['confidence'] >= 100: db_cls = get_database(config.get("database_type", None)) db = db_cls(**config.get("database", {})) db.setup() # count = db.get_song_count_by_name(song["song_name"]) # db.update_song_count(song["song_name"],count['count']+1) d = datetime.datetime.now() timezone = pytz.timezone("Asia/Katmandu") d_local = timezone.localize(d) db.insert_radio_song(number, song["song_name"], 'Begari Guys', int(song['confidence']), d_local) print("From file we recognized: {} {}\n".format(song["song_name"])) with open('log.txt', 'a') as writeFile: writeFile.write("\n Identified with high confidence %d %s" % (song['confidence'], song["song_name"])) else: with open('log.txt', 'a') as writeFile: writeFile.write( "\n Identified with very less confidence %d %s" % (song['confidence'], song["song_name"])) print("From file we recognized: {} {} {}\n".format( song["song_name"], song['confidence'])) except Exception as e: print(e)
def __init__(self, config): super(Dejavu, self).__init__() self.config = config # initialize db db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**config.get("database", {})) # if we should limit seconds fingerprinted, # None|-1 means use entire track self.limit = self.config.get("fingerprint_limit", None) if self.limit == -1: # for JSON compatibility self.limit = None self.get_fingerprinted_songs()
def __init__(self, config): super(Dejavu, self).__init__() self.config = config # initialize db db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**config.get("database", {})) self.db.setup() # if we should limit seconds fingerprinted, # None|-1 means use entire track self.limit = self.config.get("fingerprint_limit", None) if self.limit == -1: # for JSON compatibility self.limit = None
def add_db(self, dbfile): filename, extension = os.path.splitext(os.path.basename(dbfile)) # initialize db dejavu.shared.DATABASE_FILE = dbfile db_cls = get_database("sqlite") #db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**self.config.get("database", {})) self.db.setup() # get songs previously indexed songs = self.db.get_songs() for song in songs: keySong = song[Database.FIELD_SONGNAME] if keySong in self.all_songs: self.newsong = self.all_songs[keySong] else: self.newsong = { Database.FIELD_SONG_ID: song[Database.FIELD_SONG_ID], Database.FIELD_SONGNAME: song[Database.FIELD_SONGNAME], Database.FIELD_FILE_SHA1: song[Database.FIELD_FILE_SHA1], "hashes": {} } hashes = self.db.get_fingerprints_by_song_id( song[Database.FIELD_SONG_ID]) existcount = len(self.newsong["hashes"].items()) totalcount = 0 actualcount = 0 for h in hashes: totalcount = totalcount + 1 keyHash = h[Database.FIELD_HASH] if keyHash not in self.newsong["hashes"]: actualcount = actualcount + 1 self.newsong["hashes"][keyHash] = h[Database.FIELD_OFFSET] print("hashes count:%d out of %d in %s of file:%s, from count:%d" % (actualcount, totalcount, keySong, filename, existcount)) self.all_songs[keySong] = self.newsong
def __init__(self, config): super(Dejavu, self).__init__() self.config = config # initialize db db_cls = get_database(config.get("database_type", None)) self.db = db_cls(**config.get("database", {})) self.db.setup() # if we should limit seconds fingerprinted, # None|-1 means use entire track # 限制fingerprint的秒数 self.limit = self.config.get( "fingerprint_limit", None) # dict的get方法,返回指定键的值,如果值不在字典中,则返回第二个参数default的值 if self.limit == -1: # for JSON compatibility self.limit = None self.get_fingerprinted_songs()
def mp_worker(urldata): url=None number=None song=None name =None try: url, number=urldata name= number+'.mp3' except ValueError: pass try: u=urllib.request.urlopen(url) data=u.read(90000) with open(os.path.join(save_path,name),'wb') as file: file.write(data) time.sleep(1) except Exception as e: print (e) try: djv = Dejavu(config) song = djv.recognize(FileRecognizer, os.path.join(save_path,name)) # print("From Stream we recognized: {}\n".format(song)) if song is None: print("NONE") elif song['confidence']>=100: db_cls = get_database(config.get("database_type", None)) db = db_cls(**config.get("database", {})) db.setup() count = db.get_song_count_by_name(song["song_name"]) db.update_song_count(song["song_name"],count['count']+1) print("From file we recognized: {} {}\n".format(song["song_name"], count)) with open(os.path.join(save_path,'log2.txt'),'a') as writeFile: writeFile.write("\n High confidence %d %s FileName=%s" %(song['confidence'],song["song_name"],name)) else: print("Low confidence %d" %song['confidence']) with open(os.path.join(save_path,'log2.txt'),'a') as writeFile: writeFile.write("\n Low confidence %d %s FileName=%s" %(song['confidence'],song["song_name"],name)) except Exception as e: print(e)
"http://streaming.softnep.net:8093" #,"http://192.168.10.82:8000" , "http://streaming.softnep.net:8031", "http://streaming.softnep.net:8057" ] #,"http://streaming.softnep.net:8061"] data2 = [ 'kantipur', 'butwal', 'kalaiya', 'softnep', 'makwanpur' ] #,'11']#,'12','13','14','15','16','17','18','19','20','21','22','23','24','25','26'] config = None db = None with open("dejavu.cnf") as f: config = json.load(f) db_cls = get_database(config.get("database_type", None)) db = db_cls(**config.get("database", {})) db.setup() def mp_worker(urldata): url = None station_name = None song = None name = None try: url, station_name = urldata name = station_name + '.mp3' except ValueError: pass try: