Exemple #1
0
def identify(args):
    """
    compute the snippet's siganature and compare it with the 
    signatures of songs in the database. Return the closest match.
    ----------
    args : Namespace
        the namespace that was pasrsed from the commind line input
    """
    logger = setuplogger(args.verbose, "./log/identify_log")
    filename = args.filename
    if filename is None:
        # record the audio, set duration in s and fs in Hz
        (dur, fs) = (30, 44100)
        print("*recording")
        myrecording = sd.rec(int(dur * fs), fs, 1, blocking=True)
        print("*end")
        print("*playing")
        sd.play(myrecording, fs, blocking=True)
        print("*end")
        #mono_signal = np.mean(myrecording, axis=1)
        mono_signal = np.reshape(myrecording, (int(dur * fs), ))
        snippet = Song("recording", "user", "from recording", "None", True,
                       mono_signal, fs)
    else:
        if filename.startswith("http"):
            filePath = filename
        else:
            filePath = os.path.join("./snippets", filename)
        libPath = './Library/'
        snippet = Song("recording", "user", filePath, libPath, True)
    db = Database("localhost", "postgres", "postgres", "Ivan@1995")
    matched_result = db.search(snippet)

    logger.info("find the matched song {}".format(matched_result))
Exemple #2
0
 def setUp(self):
     self.db = Database("localhost", "postgres", "postgres", "Ivan@1995")
     self.logger = setuplogger(False, "./log/test_log")
     self.song1 = Song("sinetest", "unknown", "./test_audio/sinetest.wav",
                       "./test_audio/", False)
     self.song2 = Song("sine", "unknown", "./test_audio/sine.mp3",
                       "./test_audio/", False)
Exemple #3
0
def manage_args(args):
    database = Database()
    database.start()
    database.create_tables()

    if args.new_job is not None:
        print(args.new_job)
        args.new_job[1] = int(args.new_job[1])
        database.create_new_job(args.new_job)

    elif args.list:
        database.list_jobs()

    elif args.job is not None and (args.period is None and not args.earnings):
        today = date.today()
        time = start_stopwatch()

        session = Session(args.job, today, time)

        if want_to_save():
            database.store_session(session)

    elif args.earnings or args.period is not None:
        database.get_stats(args.job, args.earnings, args.period)
    else:
        print("Something went wrong somewhere")

    database.close()
Exemple #4
0
 def __init__(self, api_key):
     self.token = api_key
     self.secure_url = end_point
     self.secure_headers = {
         'content-type': 'application/json',
         'Accept': 'application/json',
         'Authorization': 'Token token=' + self.token
     }
     self.database = Database()
Exemple #5
0
def add(args):
    """
    compute the song's siganature and add the song's info and 
    signature to the database. 
    ----------
    args : Namespace
        the namespace that was pasrsed from the commind line input
    """
    filename = args.filename
    if filename.startswith("http"):
        filePath = filename
    else:
        filePath = os.path.join("./Library", filename)

    libPath = './Library/'
    if args.filename == 'all':
        # adding all songs in the Library folder
        audio_paths = getListOfFiles(libPath)
        db = Database("localhost", "postgres", "postgres", "*********")
        songs = []
        for audio_path in audio_paths:
            title = os.path.basename(audio_path)
            artist = "various"
            song = Song(title, artist, audio_path, libPath, True)
            songs.append(song)
            db = Database("localhost", "postgres", "postgres", "*********")
            db.save_to_database([song])
            print("{} added".format(title))
    else:
        if args.title is None:
            title = os.path.basename(filePath)
        else:
            title = args.title
        song = Song(title, args.artist, filePath, libPath, True)
        db = Database("localhost", "postgres", "postgres", "Ivan@1995")
        db.save_to_database([song])
Exemple #6
0
 def __init__(self):
     self.database = Database()
     self.gera_query = Gera_query()
     self.controller = Controller()
Exemple #7
0
 def __init__(self):
     self.database = Database()
log_to_file = False

#https://realpython.com/python-logging/
if  log_to_file:
   logging.basicConfig(filename='app.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s')
   print("The logs are logged in app.log")
else:
    logging.basicConfig(level=1, format='%(name)s - %(levelname)s - %(message)s')
    logging.info('This will get logged to terminal')

#Global Variables
SUCCESS_STATUS = 200
GITHUB_URI = "https://jobs.github.com/positions.json?"
PAGES = 6
DB = Database()
SESSION = DB.get_session()

def get_connection(url: str, method: str, **kargs) -> bytes:
    """
    This method creates an Http client and makes a
    call based on the method specified
    (**kargs) -> lets the user of the method pass a args to the method
    for more on this method go through this documentation
    https://urllib3.readthedocs.io/en/latest/user-guide.html
    :param url: uri resource
    :param method: method to call on resource GET | POST etc
    :param kargs: any other configurations for the connection
    :return Response: Response to the call
    """
    http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',ca_certs=certifi.where())