Ejemplo n.º 1
0
def remove_empty_dirs(working_dir, excluded_dirs):
    logger.print_log('Checking for empty folders.. ')
    list_of_dirs = getters.get_all_dirs(working_dir, excluded_dirs)

    # reversed order: bottom up
    for d in list_of_dirs[::-1]:
        d = d.replace(working_dir + '/', '')
        if not os.listdir(d):
            logger.print_ok(' -> deleting empty directory: ' + d)
            send2trash(d)
Ejemplo n.º 2
0
def unzip(working_dir, archive):
    try:
        logger.print_log('Unzipping ' + archive)
        with ZipFile(archive) as zip_file:
            zip_file.extractall(working_dir)
    except:
        logger.print_err('Error while unzipping!')
        raise
    else:
        logger.print_ok(' -> finished. Removing ' + archive)
        send2trash(archive)
Ejemplo n.º 3
0
def remove_unneeded_files(dirname):
    logger.print_log('Checking for cleanup in folder: ' + dirname)
    files_to_delete = _get_filtered_file_list(dirname)

    for file in files_to_delete:
        logger.print_ok(' -> deleting ' + file)
        send2trash(dirname + '/' + file)

    if len(os.listdir(dirname)) < 2:
        return
    else:
        _remove_movie_featurettes(dirname)
Ejemplo n.º 4
0
def create_movie_folder(filename):
    if regex_utils.is_tv_episode(filename):
        logger.print_exit('Exit: ' + filename + ' is not a movie.')
        return
    if '/' in filename:
        logger.print_exit('Exit: Folder already exists for: ' + filename)
        return

    logger.print_log('Creating folder for: ' + filename)
    result = regex_utils.get_movie_name_with_year_in_parenthesis(filename)
    result = regex_utils.remove_special_chars(result)
    os.mkdir(result)
    shutil.move(filename, result)
    logger.print_ok('   -> created: ' + result)
Ejemplo n.º 5
0
def main():
    # Create backup, mkvmerge, output folder, if necessary
    for dirname in excluded_dirs:
        if not os.path.isdir(working_dir + '/' + dirname):
            os.mkdir(dirname)

    while True:
        logger.print_log('\n' + 'ᕙ(⇀‸↼‶)ᕗ awaiting input..')
        user_input = input(
            ' 1: Unzip archives\n'
            ' 2: Clean up files (except .mkv .srt)\n'
            ' 3: Renaming episodes/movies\n'
            ' 4: Mkvmerging (keep only eng tracks)\n'
            ' q: quit!\n-> ')

        switch_case(user_input)
Ejemplo n.º 6
0
def rename_dir(dirname, destination_path):
    if 'season' in dirname.lower():
        logger.print_exit('Exit: ' + dirname + ' is not a movie folder.')
        return
    if regex_utils.is_movie_folder_already_named(dirname):
        logger.print_ok('Exit: Folder already named: ' + dirname)
        rename_movie(dirname, os.listdir(dirname)[0], destination_path)
        return

    logger.print_log('Directory: ' + dirname)
    dirname = _rename_special_chars('', dirname)
    dir_tmp = regex_utils.get_movie_name_with_year_in_parenthesis(dirname)

    if getters.ask_for_confirmation('   -> ' + dir_tmp):
        os.rename(dirname, dir_tmp)
        rename_movie(dir_tmp, os.listdir(dir_tmp)[0], destination_path)
Ejemplo n.º 7
0
def rename_movie(dirname, filename, destination_path):
    filename = _rename_special_chars(dirname + '/', filename)
    if regex_utils.is_movie_already_named(filename):
        logger.print_ok('Exit: Movie already named: ' + filename)
        shutil.move(dirname, destination_path)
        return

    logger.print_log('Movie: ' + filename)
    old_filename = filename
    stream_info = getters.get_mkvmerge_info(dirname + '/' + old_filename)
    filename = regex_utils.remove_special_chars(filename)
    result = mkv_utils.append_media_info_tags(filename, stream_info)
    result = _append_mkv_extension(result)

    if getters.ask_for_confirmation('   -> ' + result):
        os.rename(dirname + '/' + old_filename, dirname + '/' + result)
        shutil.move(dirname, destination_path)
Ejemplo n.º 8
0
def rename_episode(dirname, filename, destination_path):
    if not regex_utils.is_tv_episode(filename):
        logger.print_exit('Exit: ' + filename + ' is not a TV episode.')
        return

    filename = _rename_special_chars(dirname, filename)
    # Episode already named -> move file
    if regex_utils.is_tv_episode_already_named(filename):
        logger.print_exit('Exit: TV episode already named - moving file: ' +
                          filename)
        shutil.move(dirname + filename, destination_path + filename)
        return

    logger.print_log('TV episode: ' + filename)
    stream_info = getters.get_mkvmerge_info(filename)
    result = mkv_utils.append_media_info_tags(filename, stream_info)
    result = _append_mkv_extension(result)

    if getters.ask_for_confirmation('   -> ' + result):
        os.rename(dirname + filename, destination_path + result)
Ejemplo n.º 9
0
def multiplex_episode(filename, destination_path):
    media_info = getters.get_mkvmerge_info(filename)
    logger.print_log('Multiplexing: ' + filename)

    if len(media_info['streams']) <= 2:
        logger.print_exit('No subtitle found.')
        return

    if len(media_info['streams']) <= 3:
        # TODO make this better only one get method needed?
        media_info = getters.get_mkvmerge_info_alt(filename)

        audio_stream, subtitle_stream = [], []
        for stream in media_info['tracks']:
            if stream['type'] == 'audio':
                audio_stream.append(stream)
            if stream['type'] == 'subtitles':
                subtitle_stream.append(stream)

        audio, subtitle = '', ''

        if len(audio_stream) == 1:
            # if audio tag is und --> set to eng
            if audio_stream[0]['properties']['language'] == 'und':
                audio += ' --edit track:a1 --set language=eng'
            audio += ' --edit track:a1 --set flag-default=1'

        if len(subtitle_stream) == 1:
            # if audio tag is und --> set to eng
            if subtitle_stream[0]['properties']['language'] == 'und':
                subtitle += ' --edit track:s1 --set language=eng'
            subtitle += ' --edit track:s1 --set flag-default=1'

        if audio and subtitle is not '':
            logger.print_ok('Run mkvpropedit on: ' + filename)
            cmd = "mkvpropedit " + audio + subtitle + " '" + filename + "'"
            getters.run_terminal_cmd(cmd)

            if not regex_utils.is_tv_episode(filename):
                filename = regex_utils.get_name_until_year(filename)

            shutil.move(filename, filename.replace('#mkvmerge', '#output'))
    else:
        print('Run mkvmerge on: ' + filename)

        tmp_file = filename.replace('#mkvmerge', '#backup')
        # TODO instead of using 1 -> use index of first audio track
        cmd = "mkvmerge -o '" + tmp_file + "' -a 1 -s 'und,eng,ger' --default-track 0 --default-track 1"
        cmd += " --no-chapters --no-attachments --no-global-tags '" + filename + "'"
        getters.run_terminal_cmd(cmd)

        media_info_tmp = getters.get_mkvmerge_info(tmp_file)

        # TODO remove forced subtitle tracks - das muss ja schon vor mkvmerge passieren....
        # TODO set eng sub as default
        subtitle_stream_tmp = []
        for stream in media_info_tmp['streams']:
            if stream['codec_type'] == 'subtitle':
                subtitle_stream_tmp.append(stream)

        logger.print_ok('Run mkvpropedit on: ' + filename)
        cmd = "mkvpropedit --edit track:s1 --set flag-default=1 '" + tmp_file + "'"
        getters.run_terminal_cmd(cmd)

        # Remove everything after (YEAR) if the file is not a tv episode
        if not regex_utils.is_tv_episode(filename):
            filename = regex_utils.get_name_until_year(filename)
            tmp_file = regex_utils.get_name_until_year(tmp_file)

        # Move resulted tmp file to output
        shutil.move(tmp_file, filename.replace('#mkvmerge', '#output'))
        # Move original file to backup
        shutil.move(filename, filename.replace('#mkvmerge', '#backup'))