示例#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")
示例#2
0
def runExportJobs(inDirectory, tempDirectory):
    listJob = [
        o for o in os.listdir(tempDirectory) if
        (os.path.isfile(os.path.join(tempDirectory, o)) and o.endswith('.fej'))
    ]
    allArray = []
    if len(listJob) > 0:
        allArray = ["All"]
    dirChoiceList = allArray + listJob + ["Return to Main menu"]
    theRunDirectoryChoice = 0
    while (theRunDirectoryChoice != -1 and theRunDirectoryChoice !=
           (len(dirChoiceList) - 1)):
        targetedJob = []
        theRunDirectoryChoice = InteractionUtils.query_choice_list(
            "Choose the targeted directory(ies).", dirChoiceList, True)
        if (theRunDirectoryChoice > 0 and theRunDirectoryChoice !=
            (len(dirChoiceList) - 1)):
            targetedJob.append(listJob[theRunDirectoryChoice - 1])
        elif theRunDirectoryChoice == 0:
            targetedJob = listJob
        elif (theRunDirectoryChoice == -1
              or theRunDirectoryChoice == (len(dirChoiceList) - 1)):
            break
        for aJobFile in targetedJob:
            excludedEpisodePath = os.path.join(tempDirectory,
                                               aJobFile[:-4] + '.ejd')
            jobListPath = os.path.join(tempDirectory, aJobFile)
            excludedEpisode = FileUtils.importFileOrCreateArray(
                excludedEpisodePath)
            jobList = FileUtils.importFileOrCreateDict(jobListPath)
            print(jobList)
            jobListBis = copy.deepcopy(jobList)
            indexJobList = 1
            for src, dest in jobList.items():
                print("[" + str(indexJobList) + "/" +
                      str(len(jobList.items())) + "]Move '" + src[14:] +
                      "' to '" + dest + "'.")
                newDest = os.path.join(dest, src[14:])
                oldDest = os.path.join(inDirectory, src)
                if os.path.exists(newDest) and not filecmp.cmp(
                        oldDest, newDest):
                    os.remove(newDest)
                if not os.path.exists(newDest):
                    shutil.copy(oldDest, dest)
                excludedEpisode.append(src[14:])
                del jobListBis[src]
                FileUtils.writeFile(jobListPath, jobListBis)
                FileUtils.writeFile(excludedEpisodePath, excludedEpisode)
                indexJobList += 1
示例#3
0
                peers = None
                torrentFileName = None
                rawLinkTorrent = None
                ns = {'torrent':'//kastatic.com/xmlns/0.1/'}
                for aTorrentFile in anItem.findall('torrent:seeds', ns):
                    seeds= int(aTorrentFile.text)
                for aTorrentFile in anItem.findall('torrent:peers', ns):
                    peers = int(aTorrentFile.text)
                for aTorrentFile in anItem.findall('torrent:fileName', ns):
                    title = (aTorrentFile.text).replace('.torrent','')
                for aTorrentFile in anItem.iter('enclosure'):
                    rawLinkTorrent = aTorrentFile.attrib['url']
                    torrentFileName = (re.search('\?title=(.*)', rawLinkTorrent, re.IGNORECASE).group(1))+'.torrent'
                    linkTorrent = re.sub(r'\?title=.*', '', rawLinkTorrent)
                if torrentFileName is not None:
                    torrentList.append({'title':title, 'rawLink': rawLinkTorrent, 'link':linkTorrent, 'fileName': torrentFileName, 'seeds':seeds, 'peers': peers})
    if len(torrentList) > 0:
        sortedTorrent = sorted(torrentList, key=lambda k: k['seeds'], reverse=True)
        anIndex = 0
        for aTorrent in sortedTorrent:
            aTorrent['index'] = anIndex
            anIndex += 1
        aDisplayObject = DisplayListUtils()
        print('Choose the torrent to download for %s' % anEpisode)
        aDisplayObject.displayList(sortedTorrent,
                                   ['index', 'title', 'seeds', 'peers'],
                                   {'index':'c','title':'l','seeds':'c','peers':'c'})
        theChoice = InteractionUtils.query_int('> Make your Choice :')
        result.append({'title':anEpisode, 'link':sortedTorrent[theChoice]['rawLink']})
createWebPageReult(result, downloadDir)
示例#4
0
     else:
         result = {}
         title = ''
         if re.match('.*[.|\s]S[0-9][0-9]E[0-3][0-9]', truncatedVideo, re.IGNORECASE):
             title = re.search('(.*)[.|\s]S[0-9][0-9]E[0-3][0-9]', truncatedVideo, re.IGNORECASE).group(1)
         if re.match('.*[.|\s][0-9]?[0-9][0-3][0-9]', truncatedVideo, re.IGNORECASE):
             title = re.search('(.*)[.|\s][0-9]?[0-9][0-3][0-9]', truncatedVideo, re.IGNORECASE).group(1)
         title = title.replace(' ','')
         title = title.replace('.','')
         title = title.lower()
         for aSub in listSubtitle:
             subTitle = None
             if re.match('.* - [0-9][0-9]x[0-3][0-9]', aSub, re.IGNORECASE):
                 subTitle = re.search('(.*) - [0-9][0-9]x[0-3][0-9]', aSub, re.IGNORECASE).group(1)
             if subTitle is not None:
                 subTitle = subTitle.lower()
                 subTitle = subTitle.replace(' ','')
                 seq=SequenceMatcher(None,title, subTitle)
                 result[aSub]=seq.ratio()
         sortedSub = reversed(sorted(result.items(), key=operator.itemgetter(1)))
         print ("##################################")
         print ("For episode : "+aVideo)
         for aResult in sortedSub:
             if aResult[0] not in excludedSub and InteractionUtils.query_yes_no("Associate '"+aResult[0]+"' with this episode ?"):
                 association[aVideo] = aResult[0]
                 excludedSub.append(aResult[0])
                 break
 for anAsso in association.keys():
     newSrtFileName = (anAsso[:-4])+".srt"
     if InteractionUtils.query_yes_no("Rename '"+association[anAsso]+"' to "+newSrtFileName):
         os.rename(os.path.join(aDir,association[anAsso]), os.path.join(aDir,newSrtFileName))
示例#5
0
def buildExportJobs(inDirectory, outDirectory, tempDirectory):
    listDir = [
        o for o in os.listdir(inDirectory)
        if (os.path.isdir(os.path.join(inDirectory, o)) and re.search(
            "[0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9]", o)
            )
    ]
    allArray = []
    targetedArray = []
    if len(listDir) > 0:
        allArray = ["All"]
    dirChoiceList = allArray + listDir + ["Return to Main menu"]
    theBuildDirectoryChoice = 0
    while (theBuildDirectoryChoice != -1 and theBuildDirectoryChoice !=
           (len(dirChoiceList) - 1)):
        theBuildDirectoryChoice = InteractionUtils.query_choice_list(
            "Choose the targeted directory(ies).", dirChoiceList, True)
        if (theBuildDirectoryChoice > 0 and theBuildDirectoryChoice !=
            (len(dirChoiceList) - 1)):
            targetedArray.append(listDir[theBuildDirectoryChoice - 1])
        elif theBuildDirectoryChoice == 0:
            targetedArray = listDir
        elif (theBuildDirectoryChoice == -1
              or theBuildDirectoryChoice == (len(dirChoiceList) - 1)):
            break
        for aDir in targetedArray:
            print(
                "##########################################################################"
            )
            print("We build the export Jobs for directory '" + aDir +
                  "' with file '" + aDir + ".fej'")
            exportJobDoneFileName = os.path.join(tempDirectory, aDir + ".ejd")
            jobOrderFileName = os.path.join(tempDirectory, aDir + ".fej")
            associationTable = FileUtils.importFileOrCreateDict(
                jobOrderFileName)
            excludedArray = FileUtils.importFileOrCreateArray(
                exportJobDoneFileName)
            aWeekDirPath = os.path.join(inDirectory, aDir)
            listEpisode = [
                o for o in os.listdir(aWeekDirPath)
                if (os.path.isfile(os.path.join(aWeekDirPath, o))
                    and not o.endswith('.srt'))
            ]
            for anEpisode in listEpisode:
                if (anEpisode not in excludedArray and os.path.join(
                        aDir, anEpisode) not in associationTable.keys()):
                    episodeChoiceList = [
                        "Build export for this episode", "Skip the episode",
                        "Ignore the episode", "Return to folder choice"
                    ]
                    exportAnswer = int(
                        InteractionUtils.query_choice_list(
                            "Choose your action for '" + anEpisode + "'.",
                            episodeChoiceList, True))
                    if exportAnswer == 0:
                        buildJobForEpisode(aDir, anEpisode, associationTable,
                                           outDirectory)
                    elif exportAnswer == 2:
                        excludedAnEpisode(anEpisode, excludedArray,
                                          aWeekDirPath)
                    elif exportAnswer == 3:
                        break
            FileUtils.writeFile(jobOrderFileName, associationTable)
            FileUtils.writeFile(exportJobDoneFileName, excludedArray)
示例#6
0
                oldDest = os.path.join(inDirectory, src)
                if os.path.exists(newDest) and not filecmp.cmp(
                        oldDest, newDest):
                    os.remove(newDest)
                if not os.path.exists(newDest):
                    shutil.copy(oldDest, dest)
                excludedEpisode.append(src[14:])
                del jobListBis[src]
                FileUtils.writeFile(jobListPath, jobListBis)
                FileUtils.writeFile(excludedEpisodePath, excludedEpisode)
                indexJobList += 1


debug = False
inDirectory = r"C:\Users\nogebour\Videos\Others"
outDirectory = r"\\DLINK-5CA002\Volume_1\Workspace\Nicolas\Série"
tempDirectory = r"C:\Users\nogebour\Videos\ScriptFolder\ExportEpisodes"
if debug:
    inDirectory = r"C:\Users\nogebour\Videos\Others\ExtractSeries"
    #directory = r"C:\Users\nogebour\Videos\Others\Subtitle"
mainMenuChoice = ["Build export orders", "Launch export jobs", "Quit"]
theMainChoice = 0
while (theMainChoice != -1 and theMainChoice != (len(mainMenuChoice) - 1)):
    theMainChoice = int(
        InteractionUtils.query_choice_list(
            "Welcome in Export Episodes. Choose your mode:", mainMenuChoice,
            True))
    if theMainChoice == 0:
        buildExportJobs(inDirectory, outDirectory, tempDirectory)
    elif theMainChoice == 1:
        runExportJobs(inDirectory, tempDirectory)
示例#7
0
         title = title.replace(' ', '')
         title = title.replace('.', '')
         title = title.lower()
         for aSub in listSubtitle:
             subTitle = None
             if re.match('.* - [0-9][0-9]x[0-3][0-9]', aSub, re.IGNORECASE):
                 subTitle = re.search('(.*) - [0-9][0-9]x[0-3][0-9]', aSub,
                                      re.IGNORECASE).group(1)
             if subTitle is not None:
                 subTitle = subTitle.lower()
                 subTitle = subTitle.replace(' ', '')
                 seq = SequenceMatcher(None, title, subTitle)
                 result[aSub] = seq.ratio()
         sortedSub = reversed(
             sorted(result.items(), key=operator.itemgetter(1)))
         print("##################################")
         print("For episode : " + aVideo)
         for aResult in sortedSub:
             if aResult[
                     0] not in excludedSub and InteractionUtils.query_yes_no(
                         "Associate '" + aResult[0] +
                         "' with this episode ?"):
                 association[aVideo] = aResult[0]
                 excludedSub.append(aResult[0])
                 break
 for anAsso in association.keys():
     newSrtFileName = (anAsso[:-4]) + ".srt"
     if InteractionUtils.query_yes_no("Rename '" + association[anAsso] +
                                      "' to " + newSrtFileName):
         os.rename(os.path.join(aDir, association[anAsso]),
                   os.path.join(aDir, newSrtFileName))