Beispiel #1
0
def buildJobForEpisode(aDir, anEpisode, associationTable, outDirectory):
    listSerieOut = [
        o for o in os.listdir(outDirectory)
        if os.path.isdir(os.path.join(outDirectory, o))
    ]
    listSerieOut.sort()
    answer = InteractionUtils.query_choice_list(
        "For file '" + anEpisode +
        "', is the show is in the following list ? If yes, please write the corresponding index. If not type -1.",
        listSerieOut)
    if answer is None:
        answer = InteractionUtils.query_string("Type the name of the show: ")
        newPath = os.path.join(outDirectory, answer)
        if not os.path.exists(newPath):
            os.makedirs(newPath)
    showDirectory = os.path.join(outDirectory, answer)
    if os.path.exists(showDirectory):
        listSeasonOut = [
            o for o in os.listdir(showDirectory)
            if os.path.isdir(os.path.join(showDirectory, o))
        ]
        answerSeason = InteractionUtils.query_choice_list(
            "For file '" + anEpisode +
            "', is the season is in the following list ? If yes, please write the corresponding index. If not type -1.",
            listSeasonOut)
        if answerSeason is None:
            answerSeason = InteractionUtils.query_string(
                "Type the name for the folder corresponding to the season: ")
            newPath = os.path.join(showDirectory, answerSeason)
            if not os.path.exists(newPath):
                os.makedirs(newPath)
        showSeason = os.path.join(showDirectory, answerSeason)
        if os.path.exists(showSeason):
            if InteractionUtils.query_yes_no(
                    "Do you want to copy episode '" + anEpisode +
                    "' and subtitle to this folder : '" + showSeason + "' ?"):
                videoPath = os.path.join(aDir, anEpisode)
                subPath = None
                if os.path.exists(os.path.join(showSeason, anEpisode)):
                    print("Video file already transferred")
                else:
                    associationTable[videoPath] = showSeason
                    print("Copy '" + videoPath + "' to '" + showSeason + "'")
                if not os.path.exists(
                        os.path.join(showSeason, anEpisode[:-4] + ".srt")):
                    if os.path.exists(
                            os.path.join(aDir, anEpisode[:-4] + ".srt")):
                        print("Sub file already transferred")
                    else:
                        subPath = os.path.join(aDir, anEpisode[:-4] + ".srt")
                        print("Copy '" + subPath + "' to '" + showSeason + "'")
                        associationTable[subPath] = showSeason
                else:
                    print("No Sub file found")