def testOpenSubtitles(self, opensubtitlesuser, opensubtitlespasswd, dummy):
     log.info('OpenSubtitles: Testing Login with user %s' % opensubtitlesuser)
     result= OpenSubtitlesLogin(opensubtitlesuser,opensubtitlespasswd)
     if result:
         log.info('OpenSubtitles: login successful')
         return "<strong>Success</strong>."
     else:
         return "<strong>Failure</strong>."
Пример #2
0
 def testOpenSubtitles(self, opensubtitlesuser, opensubtitlespasswd):
     log.info('OpenSubtitles: Testing Login with user %s' % opensubtitlesuser)
     result= OpenSubtitlesLogin(opensubtitlesuser,opensubtitlespasswd)
     if result:
         log.info('OpenSubtitles: login successful')
         return "Auto-Sub successfully logged on to <strong>OpenSubtitles</strong>."
     else:
         return "Failed to login to <strong>OpenSubtitles</strong>."
Пример #3
0
    def run(self):
        StartTime = time.time()
        autosub.DBCONNECTION = sqlite3.connect(autosub.DBFILE)
        autosub.DBIDCACHE = idCache()
        del autosub.WANTEDQUEUE[:]
        autosub.scanDisk.scanDisk().run()

        log.info("checkSub: Starting round of subs searching." )
                             
        # Initiate a session to OpenSubtitles and log in if OpenSubtitles is choosen
        if autosub.OPENSUBTITLES and autosub.OPENSUBTITLESUSER and autosub.OPENSUBTITLESPASSWD:
            OpenSubtitlesLogin()

        Index = 0
        End = len(autosub.WANTEDQUEUE)
        # loop through the wanted list and try to find subs for the video's
        # because we remove a video from the list we cannot use the internal counter from a for loop
        # so we track the position in the list with the variable 'Index'
        while Index < End:
            time.sleep(0)
            Wanted = {}
            Wanted = autosub.WANTEDQUEUE[Index]
            if not Wanted:
                Index += 1
                continue
            #First we check we have enough info to try to find a sub else we skip this one
            Skip = False
            if   autosub.MINMATCHSCORE & 8 and not Wanted['source']    : Skip = True
            elif autosub.MINMATCHSCORE & 4 and not Wanted['quality']   : Skip = True
            elif autosub.MINMATCHSCORE & 2 and not Wanted['codec']     : Skip = True
            elif autosub.MINMATCHSCORE & 1 and not Wanted['releasegrp']: Skip = True
            elif not Wanted['ImdbId'] : Skip = True
            if Skip:
                log.debug('checkSub: Skipped for not meeting the minmatch score. File is: %s' % Wanted['file'] )
                Index += 1
                continue


            if not Wanted['ImdbId']:
                Index += 1
                continue

            log.debug("checkSub: trying to get a downloadlink for %s, language is %s" % (Wanted['file'], Wanted['langs']))
            log.debug("checkSub: ID's are. IMDB: %s, Addic7ed: %s" %(Wanted['ImdbId'],Wanted['A7Id']))
            # get all links above the minimal match score as input for downloadSub
            SubsNL,SubsEN = autosub.getSubLinks.getSubLinks(Wanted)

            if not SubsNL and not SubsEN:
                log.debug("checkSub: no suitable subs were found for %s based on your minimal match score" % Wanted['file'])
                Index += 1
                continue
            if SubsNL:
                log.debug('checkSub: Dutch Subtitle(s) found trying to download the highest scored.')
                if DownloadSub(Wanted,SubsNL):
                    Wanted['langs'].remove(autosub.DUTCH)
                    if not autosub.DOWNLOADENG and autosub.ENGLISH in Wanted['langs']:
                        Wanted['langs'].remove(autosub.ENGLISH)
                        SubsEN =[]
                    if autosub.ENGLISHSUBDELETE and os.path.exists(os.path.join(Wanted['folder'],Wanted['file'] + Wanted['ENext'])):
                        try:
                            os.unlink(os.path.join(Wanted['folder'],Wanted['file'] + Wanted['ENext']))
                            log.info("checkSub: Removed English subtitle for : %s" % Wanted['file'])
                        except Exception as error:
                            log.error("checkSub: Error while trying to remove English subtitle message is:%s." % error)
            if SubsEN:
                log.debug('checkSub: English Subtitle(s) found trying to download the highest scored.')
                if DownloadSub(Wanted,SubsEN):
                    Wanted['langs'].remove(autosub.ENGLISH)
            if len(Wanted['langs']) == 0:
                del autosub.WANTEDQUEUE[Index]
                End -= 1
            else:
                Index += 1


        autosub.DBCONNECTION.close()
        del autosub.DBCONNECTION
        del autosub.DBIDCACHE
        if autosub.ADDIC7EDAPI:
            autosub.ADDIC7EDAPI.logout()

        if autosub.OPENSUBTITLESTOKEN:
            OpenSubtitlesLogout()
                                        
        log.info("checkSub: Finished round of subs Search. Go to sleep until the next round.")
        autosub.SEARCHTIME = time.time() - StartTime
        return True
Пример #4
0
    def run(self):
        autosub.SEARCHBUSY = True
        StartTime = time.time()
        autosub.DBCONNECTION = sqlite3.connect(autosub.DBFILE)
        autosub.DBIDCACHE = idCache()
        del autosub.WANTEDQUEUE[:]
        autosub.scanDisk.scanDisk().run()

        log.info("checkSub: Starting round of subs searching.")

        # Initiate a session to OpenSubtitles and log in if OpenSubtitles is choosen
        if autosub.OPENSUBTITLES and autosub.OPENSUBTITLESUSER and autosub.OPENSUBTITLESPASSWD:
            OpenSubtitlesLogin()
        Index = 0
        End = len(autosub.WANTEDQUEUE)
        # loop through the wanted list and try to find subs for the video's
        # because we remove a video from the list we cannot use the internal counter from a for loop
        # so we track the position in the list with the variable 'Index'
        if not autosub.SEARCHSTOP:
            while Index < End:
                if autosub.SEARCHSTOP:
                    log.info('checkSub: Search stopped by User')
                    break
                Wanted = {}
                Wanted = autosub.WANTEDQUEUE[Index]
                if not Wanted:
                    Index += 1
                    continue

                log.info("checkSub: Searching downloadlink(s) for %s, for %s" %
                         (Wanted['file'], Wanted['langs']))
                # get all links above the minimal match score as input for downloadSub
                SubsNL, SubsEN = autosub.getSubLinks.getSubLinks(Wanted)

                if not SubsNL and not SubsEN:
                    log.debug("checkSub: No subs found for %s" %
                              Wanted['file'])
                    Index += 1
                    continue
                if SubsNL:
                    log.debug(
                        'checkSub: Dutch Subtitle(s) found trying to download the highest scored.'
                    )
                    if DownloadSub(Wanted, SubsNL):
                        Wanted['langs'].remove(autosub.DUTCH)
                        if not autosub.DOWNLOADENG and autosub.ENGLISH in Wanted[
                                'langs']:
                            Wanted['langs'].remove(autosub.ENGLISH)
                            SubsEN = []
                        if autosub.ENGLISHSUBDELETE and os.path.exists(
                                os.path.join(Wanted['folder'], Wanted['file'] +
                                             Wanted['ENext'])):
                            try:
                                os.unlink(
                                    os.path.join(
                                        Wanted['folder'],
                                        Wanted['file'] + Wanted['ENext']))
                                log.info(
                                    "checkSub: Removed English subtitle for : %s"
                                    % Wanted['file'])
                            except Exception as error:
                                log.error(
                                    "checkSub: Error while trying to remove English subtitle message is:%s."
                                    % error)
                if SubsEN:
                    log.debug(
                        'checkSub: English Subtitle(s) found trying to download the highest scored.'
                    )
                    if DownloadSub(Wanted, SubsEN):
                        Wanted['langs'].remove(autosub.ENGLISH)
                        time.sleep(0)

                if len(Wanted['langs']) == 0:
                    del autosub.WANTEDQUEUE[Index]
                    time.sleep(0)
                    End -= 1
                else:
                    Index += 1

        autosub.DBCONNECTION.close()
        del autosub.DBCONNECTION
        del autosub.DBIDCACHE
        if autosub.ADDIC7EDAPI:
            autosub.ADDIC7EDAPI.logout()

        if autosub.OPENSUBTITLESTOKEN:
            OpenSubtitlesLogout()

        log.info(
            "checkSub: Finished round of subs Search. Go to sleep until the next round."
        )
        autosub.SEARCHTIME = time.time() - StartTime
        autosub.SEARCHBUSY = False
        autosub.SEARCHSTOP = False
        return True
Пример #5
0
 def testOpenSubtitles(self, opensubtitlesuser, opensubtitlespasswd, dummy):
     if OpenSubtitlesLogin(opensubtitlesuser, opensubtitlespasswd):
         return "<strong>Success</strong>."
     else:
         return "<strong>Failure</strong>."
Пример #6
0
    def run(self):
        log.debug("checkSub: Starting round of checkSub")
        # First we check if checksub in not still running
        if autosub.WANTEDQUEUELOCK:
            log.info(
                "checkSub: Exiting, another threat is using the queues. Will try again in 60 seconds"
            )
            time.sleep(60)
            return False
        else:
            autosub.WANTEDQUEUELOCK = True
        autosub.DBCONNECTION = sqlite3.connect(autosub.DBFILE)
        autosub.DBIDCACHE = idCache()
        autosub.DBEPISODECACHE = EpisodeIdCache()

        toDelete_wantedQueue = []
        if not Helpers.checkAPICallsTvdb(
        ) or not Helpers.checkAPICallsSubSeeker():
            log.warning("checkSub: out of api calls")
            return True

        # Initiate the Addic7ed API and check the current number of downloads
        UseAddic = False
        if autosub.ADDIC7EDUSER and autosub.ADDIC7EDPASSWD and autosub.ADDIC7EDLANG != 'None':
            try:
                # Sets autosub.DOWNLOADS_A7 and autosub.DOWNLOADS_A7MAX
                # and gives a True response if it's ok to download from a7
                autosub.ADDIC7EDAPI = autosub.Addic7ed.Addic7edAPI()
                UseAddic = autosub.ADDIC7EDAPI.checkCurrentDownloads(
                    logout=False)
            except:
                log.debug("checkSub: Couldn't connect with Addic7ed.com")
        # Initiate a session to OpenSubtitles and log in if OpenSubtitles is choosen
        if autosub.OPENSUBTITLESLANG != 'None' and autosub.OPENSUBTITLESUSER and autosub.OPENSUBTITLESPASSWD:
            UseOpensubtitles = OpenSubtitlesLogin()
        else:
            UseOpensubtitles = False
        for index, wantedItem in enumerate(autosub.WANTEDQUEUE):
            title = wantedItem['title']
            season = wantedItem['season']
            episode = wantedItem['episode']
            originalfile = wantedItem['originalFileLocationOnDisk']
            languages = wantedItem['lang']

            if not Helpers.checkAPICallsTvdb(
            ) or not Helpers.checkAPICallsSubSeeker():
                #Make sure that we are allow to connect to SubtitleSeeker and TvDB
                log.warning("checkSub: out of api calls")
                break

            if autosub.SUBNL != "":
                nlsrtfile = os.path.splitext(
                    originalfile)[0] + u"." + autosub.SUBNL + u".srt"
            else:
                nlsrtfile = os.path.splitext(originalfile)[0] + u".srt"

            if autosub.SUBENG == "":
                # Check for overlapping names
                if autosub.SUBNL != "" or not autosub.DOWNLOADDUTCH:
                    engsrtfile = os.path.splitext(originalfile)[0] + u".srt"
                # Hardcoded fallback
                else:
                    engsrtfile = os.path.splitext(originalfile)[0] + u".en.srt"
            else:
                engsrtfile = os.path.splitext(
                    originalfile)[0] + u"." + autosub.SUBENG + u".srt"

            #lets try to find a showid; no showid? skip this item
            showid, a7_id, OsId = Helpers.getShowid(title, UseAddic,
                                                    UseOpensubtitles)
            if UseOpensubtitles and OsId:
                EpisodeId = GetEpisodeId(OsId, season, episode)
            else:
                EpisodeId = None
            log.debug(
                "checkSub: ID's - IMDB: %s, Addic7ed: %s, OpenSubtitles: %s" %
                (showid, a7_id, OsId))
            if not showid:
                continue

            for lang in languages[:]:
                downloadItem = wantedItem.copy()
                downloadItem['downlang'] = lang

                # Check if Addic7ed download limit has been reached
                if UseAddic and autosub.DOWNLOADS_A7 >= autosub.DOWNLOADS_A7MAX:
                    UseAddic = False
                    log.debug(
                        "checkSub: You have reached your 24h limit of %s  Addic7ed downloads!"
                        % autosub.DOWNLOADS_A7MAX)

                log.debug(
                    "checkSub: trying to get a downloadlink for %s, language is %s"
                    % (originalfile, lang))
                # get all links higher than the minmatch as input for downloadSub
                allResults = autosub.getSubLinks.getSubLinks(
                    showid, a7_id, EpisodeId, lang, wantedItem)

                if not allResults:
                    log.debug(
                        "checkSub: no suitable subtitles were found for %s based on your minmatchscore"
                        % downloadItem['originalFileLocationOnDisk'])
                    continue

                if lang == autosub.DUTCH:
                    downloadItem['destinationFileLocationOnDisk'] = nlsrtfile
                elif lang == autosub.ENGLISH:
                    downloadItem['destinationFileLocationOnDisk'] = engsrtfile

                if allResults:
                    log.info(
                        "checkSub: The episode %s - Season %s Episode %s has 1 or more matching subtitles on SubtitleSeeker, downloading it!"
                        % (title, season, episode))
                    log.debug("checkSub: destination filename %s" %
                              downloadItem['destinationFileLocationOnDisk'])

                if not DownloadSub(allResults, UseAddic, downloadItem):
                    continue

                #Remove downloaded language
                languages.remove(lang)

                if lang == autosub.DUTCH:
                    if (autosub.FALLBACKTOENG and not autosub.DOWNLOADENG
                        ) and autosub.ENGLISH in languages:
                        log.debug(
                            'checkSub: We found a Dutch subtitle and fallback is true. Removing the English subtitle from the wantedlist.'
                        )
                        languages.remove(autosub.ENGLISH)

                    if autosub.ENGLISHSUBDELETE:
                        log.info("checkSub: Clean up English enabled")
                        if os.path.exists(engsrtfile):
                            log.debug(
                                "checkSub: Trying to delete English subtitle: %s"
                                % engsrtfile)
                            try:
                                os.unlink(engsrtfile)
                                log.info(
                                    "checkSub: Removed English subtitle: %s" %
                                    engsrtfile)
                            except:
                                log.error(
                                    "checkSub: Error while trying to remove subtitle %s."
                                    % engsrtfile)
                        else:
                            log.info("checkSub: English subtitle not found.")

                if len(languages) == 0:
                    toDelete_wantedQueue.append(index)
                    break

        autosub.DBCONNECTION.close()
        del autosub.DBCONNECTION
        del autosub.DBIDCACHE
        del autosub.DBEPISODECACHE
        if autosub.ADDIC7EDAPI:
            autosub.ADDIC7EDAPI.logout()

        if autosub.OPENSUBTITLESLOGGED_IN:
            OpenSubtitlesLogout()

        i = len(toDelete_wantedQueue) - 1
        while i >= 0:
            log.debug(
                "checkSub: Removed item from the wantedQueue at index %s" %
                toDelete_wantedQueue[i])
            autosub.WANTEDQUEUE.pop(toDelete_wantedQueue[i])
            i = i - 1

        log.debug("checkSub: Finished round of checkSub")
        autosub.WANTEDQUEUELOCK = False
        return True