예제 #1
0
파일: download.py 프로젝트: jererc/media-py
def run():
    path = Settings.get_settings('paths')['finished_download']
    if os.path.exists(path):
        media_paths = Settings.get_settings('paths')['media']

        for download in downloads(path):
            if not check_download(download.file):
                if remove_file(download.file):
                    logger.info('removed %s (bad download)', download.filename)
                continue

            # Move the download
            if download.type not in media_paths:
                download.type = 'misc'
            dst = media_paths[download.type]
            res = move_file(download.file, dst)
            if res:
                Media.add_file(res)
                Download.insert({
                        'name': download.filename,
                        'category': download.type,
                        'path': dst,
                        'created': datetime.utcnow(),
                        }, safe=True)
                logger.info('moved %s to %s', download.filename, dst)
예제 #2
0
파일: file.py 프로젝트: jererc/media-py
def update_path():
    paths = Settings.get_settings('paths')

    excl = paths['media_root_exclude']
    re_excl = re.compile(r'^(%s)/' % '|'.join([re.escape(p.rstrip('/')) for p in excl]))

    for file in iter_files(str(paths['media_root'])):
        if not re_excl.search(file):
            Media.add_file(file)
        time.sleep(.05)

    for media in Media.find({'files': {'$exists': True}}, timeout=False):
        files_orig = media['files'][:]
        for file in files_orig:
            if not os.path.exists(file) or re_excl.search(file):
                media['files'].remove(file)

        if not media['files'] and not media.get('urls'):
            Media.remove({'_id': media['_id']}, safe=True)
        elif media['files'] != files_orig:
            Media.save(media, safe=True)

    Work.set_info(NAME, 'updated', datetime.utcnow())