コード例 #1
0
def move_from_orig(start_path):
    """ Moves media files from original torrent directories to a season dir and
        then deletes the original torrent dir.

        Note this relies on the media file containing a substring in its
        name of the form S(x)E(y) or s(x)e(y). Files with other naming formats
        will be left alone.

        string -> None
        :param start_path:
    """
    contents = os.listdir(start_path)
    # Find the dirs that are not season dirs.
    for item in contents:
        item_path = vou.get_new_path(start_path, item)
        if not vou.is_season_indicator(item) and os.path.isdir(item_path):
            item_contents = os.listdir(item_path)

            # Find the media files in the dirs.
            for item2 in item_contents:
                if vou.is_required_format(item2):
                    item2_path = vou.get_new_path(item_path, item2)

                    # Find the season the media file belongs to.
                    item2_list = string.split(item2, '.')
                    for i in item2_list:
                        if vou.is_season_indicator(i):
                            season = i[0:3]
                            season_path = vou.get_new_path(start_path, season)

                            # Make season dir if it doesn't exist.
                            if not os.path.isdir(season_path):
                                os.mkdir(season_path)

                            # Move media file by renaming.
                            new_item2_path = vou.get_new_path(season_path, item2)
                            os.rename(item2_path, new_item2_path)
                            break
                    break

    return None
コード例 #2
0
def move_actual_media(start_path):
    """ Moves a media file directly in a title dir to a season dir.

        Note this relies on the media file containing a substring in its
        name of the form S(x)E(y) or s(x)e(y). Files with other naming formats
        will be left alone.

        string -> None
        :param start_path:
    """
    contents = os.listdir(start_path)

    for item in contents:

        # Find the media files in contents.
        if vou.is_required_format(item):
            item_path = vou.get_new_path(start_path, item)
            item_list = string.split(item, '.')

            # Determine the season this file belongs to.
            for i in item_list:
                if vou.is_season_indicator(i):
                    season = i[0:3]
                    season_path = vou.get_new_path(start_path, season)

                    # Makes season dir if it doesn't exist.
                    if not os.path.isdir(season_path):
                        os.mkdir(season_path)

                    # Move media file by renaming.
                    new_item_path = vou.get_new_path(season_path, item)
                    os.rename(item_path, new_item_path)

                    break
            break

    return None