예제 #1
0
def _fingerprint_worker(filename, limit=None, song_name=None):
    # Pool.imap sends arguments as tuples so we have to unpack
    # them ourself.
    try:
        filename, limit = filename
    except ValueError:
        pass

    songname, extension = os.path.splitext(os.path.basename(filename))
    song_name = song_name or songname
    channels, Fs, file_hash = decoder.read(filename, limit)
    result = set()
    channel_amount = len(channels)

    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" % (channeln + 1,
                                                       channel_amount,
                                                       filename))
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount,
                                                 filename))
        result |= set(hashes)

    return song_name, result, file_hash
예제 #2
0
파일: __init__.py 프로젝트: 9nehS/dejavu
def _fingerprint_worker(filename, limit=None, song_name=None):
    # Pool.imap sends arguments as tuples so we have to unpack
    # them ourself.
    try:
        filename, limit = filename
    except ValueError:
        pass

    songname, extension = os.path.splitext(os.path.basename(filename))
    song_name = song_name or songname
    channels, Fs, file_hash, audio_length = decoder.read(filename, limit)
    result = set()
    channel_amount = len(channels)

    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" % (channeln + 1,
                                                       channel_amount,
                                                       filename))
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        # Added by Sheng Zhao for debug issue https://github.com/worldveil/dejavu/issues/142
        #print("Type of hashes in _fingerprint_worker: %s" % (type(hashes)))
        #print(hashes)
        print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount,
                                                 filename))
        result |= set(hashes)

    return song_name, result, file_hash, audio_length
예제 #3
0
def _fingerprint_worker(filename, limit=None, song_name=None):
    # Pool.imap sends arguments as tuples so we have to unpack
    # them ourself.
    try:
        filename, limit = filename
    except ValueError:
        pass

    songname, extension = os.path.splitext(os.path.basename(filename))
    song_name = song_name or songname
    channels, Fs, file_hash = decoder.read(filename, limit)
    result = set()
    channel_amount = len(channels)

    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        # print("Fingerprinting channel %d/%d for %s" % (channeln + 1,
        #                                                channel_amount,
        #                                                filename))
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        # print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount,
        #                                          filename))
        result |= set(hashes)

    return song_name, result, file_hash
예제 #4
0
파일: __init__.py 프로젝트: HrBDev/dejavu
def _fingerprint_worker(filename, limit=None, song_name=None):
    # Pool.imap sends arguments as tuples so we have to unpack
    # them ourself.
    try:
        filename, limit = filename
    except ValueError:
        pass

    songname, extension = os.path.splitext(os.path.basename(filename))
    song_name = song_name or songname
    channels, Fs, file_hash, audio_length = decoder.read(filename, limit)
    result = set()
    channel_amount = len(channels)

    for channeln, channel in enumerate(channels):
        logging.getLogger('dejavu').info(
            "Fingerprinting channel %d/%d for %s" %
            (channeln + 1, channel_amount, filename))
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        logging.getLogger('dejavu').debug(
            "Finished channel %d/%d for %s" %
            (channeln + 1, channel_amount, filename))
        result |= set(hashes)

    return song_name, result, file_hash, audio_length
예제 #5
0
파일: __init__.py 프로젝트: GavinHwa/dejavu
def _fingerprint_worker(filename, db, limit):
    song_name, extension = os.path.splitext(os.path.basename(filename))

    channels, Fs = decoder.read(filename, limit)

    # insert song into database
    sid = db.insert_song(song_name)

    channel_amount = len(channels)
    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" % (channeln + 1,
                                                       channel_amount,
                                                       filename))
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount,
                                                 filename))

        print("Inserting fingerprints for channel %d/%d for %s" %
              (channeln + 1, channel_amount, filename))
        db.insert_hashes(sid, hashes)
        print("Finished inserting for channel %d/%d for  %s" %
              (channeln + 1, channel_amount, filename))

    print("Marking %s finished" % (filename,))
    db.set_song_fingerprinted(sid)
    print("%s finished" % (filename,))
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)
        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t

        return match
예제 #7
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t
        logger.debug("Recognizig using file. Match: %s" % match)
        return match
예제 #8
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t

        return match
예제 #9
0
    def recognize_file(self, filename,start=None,limit=None):
        #print limit
        frames, self.Fs, file_hash = decoder.read(filename,start,limit)
        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t

        return match
예제 #10
0
파일: recognize.py 프로젝트: snd/dejavu
    def recognize_file(self, filename):
        with Timer("decorder.read") as t:
            frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)

        with Timer() as t:
            match = self._recognize(*frames)

        if match:
            match['match_time'] = t.ms

        return match
예제 #11
0
파일: __init__.py 프로젝트: GavinHwa/dejavu
    def fingerprint_file(self, filepath, song_name=None):
        channels, Fs = decoder.read(filepath)

        if not song_name:
            print "Song name: %s" % song_name
            song_name = decoder.path_to_songname(filepath)
        song_id = self.db.insert_song(song_name)

        for data in channels:
            hashes = fingerprint.fingerprint(data, Fs=Fs)
            self.db.insert_hashes(song_id, hashes)
예제 #12
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)
        print "sample rate is %d \n" %self.Fs
        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match_time = t

        return match, match_time
예제 #13
0
    def recognize_file(self, filename):
        frames, self.Fs = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        matches = self._recognize(*frames)
        t = time.time() - t

        if matches:
            for match in matches:
                match['match_time'] = t / len(matches)

        return matches
예제 #14
0
    def recognize_file(self, filename):
        # 获得filename的每个通道的数据,是个list; 采样帧率; sha1唯一编码
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t 

        return match
예제 #15
0
    def recognize_file(self, filename):
        frames, self.Fs = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        matches = self._recognize(*frames)
        t = time.time() - t

        if matches:
            for match in matches:
                match['match_time'] = t/len(matches)

        return matches
예제 #16
0
def fp_printing(filename):
    songname, extension = os.path.splitext(os.path.basename(filename))
    channels, Fs, file_hash = decoder.read(filename, None)
    result = set()
    channel_amount = len(channels)

    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" % (channeln + 1, channel_amount, filename))
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        print("Finished channel %d/%d for %s" % (channeln + 1, channel_amount, filename))
        result |= set(hashes)
    return song_name, result, file_hash
예제 #17
0
    def recognize_file(self, filename, limit):
        if not limit:
            limit = self.dejavu.limit
        frames, self.Fs = decoder.read(filename, limit)

        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        if match:
            match['match_time'] = t

        return match
def generate_hashes(mp3file):
    channels, Fs, file_hash = decoder.read(mp3file, None)
    chunk_sz = Fs * 2048
    all_hashes = deque()
    begin_chunk = 0
    for chunk in chunker(channels[0], chunk_sz):
        hashes = fingerprint.fingerprint(chunk, Fs=Fs, plot=False)
        for hash, t_offset in hashes:
            all_hashes.append((
                hash,
                t_offset + int(begin_chunk / 2048),
            ))
        begin_chunk += chunk_sz
    return all_hashes
예제 #19
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash, song_length = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        hashes, match = self._recognize(*frames)
        t = time.time() - t

        if match:
            if self.dejavu.multiple_match:
                for track in match:
                    track['match_time'] = t/len(match)
            else:
                match['match_time'] = t

        return hashes, match
예제 #20
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash, song_length = decoder.read(
            filename, self.dejavu.limit)

        t = time.time()
        hashes, match = self._recognize(*frames)
        t = time.time() - t

        if match:
            if self.dejavu.multiple_match:
                for track in match:
                    track['match_time'] = t / len(match)
            else:
                match['match_time'] = t

        return hashes, match
예제 #21
0
    def recognize_file(self, filename):
        frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)

        t = time.time()
        match = self._recognize(*frames)
        t = time.time() - t

        msg = ("recognize_file match %s" % match)
        msg = "[" + datetime.datetime.now().strftime(
            "%Y-%m-%d %H:%M:%S") + "]" + msg
        print msg
        logging.info(msg)

        if match:
            match['match_time'] = t

        return match
예제 #22
0
def get_fingerprints(file_path, limit=None, song_name=None):
    #Fingerprints a file and send the number of fingerprints that found
    try:
        filename, limit = file_path
    except ValueError:
        pass

    songname, extension = os.path.splitext(os.path.basename(file_path))
    song_name = song_name or songname
    channels, Fs = decoder.read(file_path, limit)
    result = set()
    channel_amount = len(channels)

    for channeln, channel in enumerate(channels):
        hashes = fingerprint.fingerprint(channel, Fs=Fs)
        result |= set(hashes)

    return result
예제 #23
0
 def __init__(self, video_name):
     
     """
        Takes the video name. Creates a Dejavu object.
        Also obtains the duration and number of frames in the video.
     """
     
     file_type = mimetypes.guess_type(video_name)[0]
     
     if file_type[:3] != "vid":#The file is not a video file
         print "No video file found"
         raise Exception(INCORRECT_VIDEO_FILE_ERROR)
     
     self.video_name = video_name
     self.djv = Dejavu(CONFIG)
     
     #We create the audio of the video given to us
     ffmpeg.create_audio(self.video_name, TEMP_AUDIO)
     self.frames, self.Fs, hash_val = decoder.read(TEMP_AUDIO)
     self.frames = self.frames[0] #Since we always create single channel audio
     self.duration = int(self.frames.shape[0] / (self.Fs*1.0)) #Duration of the entire video in seconds
예제 #24
0
    def __init__(self, video_name):

        """
           Takes the video name. Creates a Dejavu object.
           Also obtains the duration and number of frames in the video.
        """

        file_type = mimetypes.guess_type(video_name)[0]

        if file_type[:3] != "vid":#The file is not a video file
            print "No video file found"
            raise Exception(INCORRECT_VIDEO_FILE_ERROR)

        self.video_name = video_name
        self.djv = Dejavu(CONFIG)

        #We create the audio of the video given to us
        ffmpeg.create_audio(self.video_name, TEMP_AUDIO)
        self.frames, self.Fs, hash_val = decoder.read(TEMP_AUDIO)
        self.frames = self.frames[0] #Since we always create single channel audio
        self.duration = int(self.frames.shape[0] / (self.Fs*1.0)) #Duration of the entire video in seconds
예제 #25
0
def _fingerprint_worker(filename, limit=None, song_name=None):
    '''对音频进行编码的总函数
        Args:
            filename: 将要fingerprint的音频(路劲/xxx.mp3)
            limit: 限制每个音频编码多少秒
            song_name: 音频的name
        Returns:
            song_name: 音频的name(不含后缀名)
            result: 整个音频使用函数fingerprint()编码的结果,set()
            file_hash: 整个音频使用sha1编码的结果
    '''
    # Pool.imap sends arguments as tuples so we have to unpack
    # them ourself.
    try:
        filename, limit = filename
    except ValueError:
        pass

    songname, extension = os.path.splitext(
        os.path.basename(filename))  # 分离歌名和后缀名
    song_name = song_name or songname  # or 找到第一个非空/逻辑非的对象
    # channels: list,每个元素是一个声道的数据
    # Fs: 音频的采样频率
    # file_hash: 该音频的sha1编码
    channels, Fs, file_hash = decoder.read(filename, limit)
    result = set()
    channel_amount = len(channels)  # 音频的声道数

    for channeln, channel in enumerate(channels):
        # TODO: Remove prints or change them into optional logging.
        print("Fingerprinting channel %d/%d for %s" %
              (channeln + 1, channel_amount, filename))
        hashes = fingerprint(channel,
                             Fs=Fs)  # 对音频进行编码,但是file_hash不是已经用sha1编码完成了吗
        print("Finished channel %d/%d for %s" %
              (channeln + 1, channel_amount, filename))
        result |= set(hashes)  # |= 类似与list的append

    return song_name, result, file_hash
예제 #26
0
파일: recognize.py 프로젝트: nmerad/dejavu
 def recognize_file(self, filename):
     frames, self.Fs, file_hash = decoder.read(filename, self.dejavu.limit)
     matches = self._recognize(*frames)
     return matches