Exemplo n.º 1
0
def main():
    # Set up our commang line arguments
    parser = argparse.ArgumentParser(
        description=
        "Take in a folder of video and/or audio files and find the alignment"
        "of them all.")
    parser.add_argument(
        "folder",
        type=str,
        help=
        "The folder containing your audio and video files, relative to the current directory."
    )
    args = parser.parse_args()

    # Get the files in our folder
    dir = os.path.expanduser(args.folder)
    files = os.listdir(dir)

    alignment_data = {}

    # Iterate through the files
    for index, filename in enumerate(files):
        full_path = os.path.join(dir, filename)

        # For now we'll assume all the files are valid audio or video
        if (os.path.isfile(full_path)):

            print "Attempting to match {0}...".format(filename)

            lilo = Lilo(full_path, index)

            # Try to match the song to the existing database
            songs = lilo.recognize_track()

            if not songs:
                print "No matches found."

            alignment_data[filename] = songs

            print "Adding {0} to database...".format(filename)

            # Now let's add this song to the DB
            lilo.fingerprint_song()

            print "Fingerprinting of {0} complete.".format(filename)

    pprint.pprint(alignment_data)
Exemplo n.º 2
0
    def do_upload(self, input_fh):
        video_path = self.tmp_src()
        logger.info("Writing uploaded file to {:}".format(video_path))

        with open(video_path, 'wb+') as output_fh:
            # Split file into chunks to handle upload
            for chunk in input_fh.chunks():
                output_fh.write(chunk)

        # Check to make sure that this video hasn't been uploaded already
        lilo = Lilo(settings.LILO_CONFIG, video_path, self.id)
        already_fingerprinted = lilo.check_if_fingerprinted()

        if already_fingerprinted:
            logger.warn('Video re-upload attempted by user {} - Video id: {}'.format(self.user_id,self.id))
            raise Exception('This video has already been uploaded.')

        return video_path
Exemplo n.º 3
0
    def fingerprint(self):
        "fingerprints an mp4 and inserts the fingerprints into the db"
        video_path = self.video.get_video_filepath('mp4')
        lilo = Lilo(settings.LILO_CONFIG, video_path, self.video.id)
        matched_videos = lilo.recognize_track()

        if matched_videos is not None:
            for match in matched_videos:
                match_data = {"offset": match['offset_seconds'], "confidence": match['confidence']}
                if self.video.id != int(match['video_id']):
                    try:
                        Edge.objects.get_or_create(video1_id=self.video.id, video2_id=match['video_id'], defaults=match_data)
                    except IntegrityError as e:
                        msg = "Could not create edge from {} to {} ({})".format(self.video.id, match['video_id'], e)
                        logger.error(msg)


        # Add this videos fingerprints to the Lilo DB
        data = lilo.fingerprint_song()

        if not data:
            raise RuntimeError('Video already fingerprinted: {} - {}'.format(self.video.name, self.video.uuid))

        return data.get('song_length')