Exemple #1
0
 def test_big(self):
     path_to_file = os.path.join(current_directory, 'webm_files/big_0.webm')
     filename = strip_webm(path_to_file)
     assert os.path.isfile(filename)
     md5 = hash_stripped_webm(filename)
     assert os.path.isfile(filename) is False
     assert md5 == "c48cb49d94ebcea4afd685f4fcbf9c0a"
Exemple #2
0
 def test_not_webm_extension(self):
     path_to_file = os.path.join(current_directory,
                                 'webm_files/duplicates/1')
     filename = strip_webm(path_to_file)
     assert os.path.isfile(filename)
     md5 = hash_stripped_webm(filename)
     assert os.path.isfile(filename) is False
     assert md5 == self.orig_md5
Exemple #3
0
 def test_strange_meta(self):
     path_to_file = os.path.join(current_directory,
                                 'webm_files/strange_meta.webm')
     filename = strip_webm(path_to_file)
     assert os.path.isfile(filename)
     md5 = hash_stripped_webm(filename)
     assert os.path.isfile(filename) is False
     assert md5 == "527ad18aa45b0d22ae961cf2216c8ef6"
Exemple #4
0
 def test_duplicate_doll_EXIF(self):
     path_to_file = os.path.join(current_directory,
                                 'webm_files/duplicates/1_dollEXIF.webm')
     filename = strip_webm(path_to_file)
     assert os.path.isfile(filename)
     md5 = hash_stripped_webm(filename)
     assert os.path.isfile(filename) is False
     assert md5 == self.orig_md5
Exemple #5
0
def analyse_video(md5, url):  # TODO: Rename to smth
    try:
        # celery_log.info('Downloading new video with url of %s' % (url,))
        file = download_file(url)
        if get_file_md5(file) != md5:
            raise Exception('md5 not the same.')
        screamer_chance = get_scream_chance(file.name)
        # TODO: check file extension
        if file.name.split('.')[1] == 'webm':
            strip_filename = strip_webm(file.name)
            strip_md5 = hash_stripped_webm(strip_filename)
        else:
            strip_md5 = md5
        # celery_log.info('Calculated screamer chance is %s. Adding WEBM to DB' % (screamer_chance,))
        #print(screamer_chance)
        session = Session()
        print(strip_md5, screamer_chance)
        webm = session.query(WEBM).get(strip_md5)
        # Was not in DB
        if webm is None:
            webm = WEBM(id_=strip_md5, screamer_chance=screamer_chance)
            session.add(webm)
            set_cache(webm.to_dict())
        dirty_webm = DirtyWEBM(md5=md5, webm_id=strip_md5)
        print('dirty_webm: ', dirty_webm)
        session.add(dirty_webm)
        session.commit()
        # session.remove()
        del_dirty_cache(
            md5
        )  # TODO: Delete Delayed message and set new in one transaction to prevent possible race condition
        set_dirty_cache(md5, strip_md5)
        # celery_log.info('Releasing WEBM from Celery')
        return webm.to_dict()
    except Exception as e:
        print('Error encountered: {}'.format(e))
        traceback.print_exc()