Exemple #1
0
def getShowid(show_name):
    log.debug('getShowid: trying to get showid for %s' %show_name)
    show_id = nameMapping(show_name)
    if show_id:
        log.debug('getShowid: showid from namemapping %s' %show_id)
        return int(show_id)
    
    show_id = idCache().getId(show_name)
    if show_id:
        log.debug('getShowid: showid from cache %s' %show_id)
        if show_id == -1:
            log.error('getShowid: showid not found for %s' %show_name)
            return
        return int(show_id)
    
    #do we have enough api calls?
    if checkAPICalls(use=False):
        show_id = autosub.Bierdopje.getShowidApi(show_name)
    else:
        log.warning("getShowid: Out of API calls")
        return None
    
    if show_id:
        log.debug('getShowid: showid from api %s' %show_id)
        idCache().setId(show_id, show_name)
        log.info('getShowid: %r added to cache with %s' %(show_name, show_id))
        return int(show_id)
    
    log.error('getShowid: showid not found for %s' %show_name)
    idCache().setId(-1, show_name)
def getShowid(show_name):
    log.debug('getShowid: trying to get showid for %s' % show_name)
    show_id = nameMapping(show_name)
    if show_id:
        log.debug('getShowid: showid from namemapping %s' % show_id)
        return int(show_id)

    show_id = idCache().getId(show_name)
    if show_id:
        log.debug('getShowid: showid from cache %s' % show_id)
        if show_id == -1:
            log.error('getShowid: showid not found for %s' % show_name)
            return
        return int(show_id)

    #do we have enough api calls?
    if checkAPICalls(use=False):
        show_id = autosub.Bierdopje.getShowidApi(show_name)
    else:
        log.warning("getShowid: Out of API calls")
        return None

    if show_id:
        log.debug('getShowid: showid from api %s' % show_id)
        idCache().setId(show_id, show_name)
        log.info('getShowid: %r added to cache with %s' % (show_name, show_id))
        return int(show_id)

    log.error('getShowid: showid not found for %s' % show_name)
    idCache().setId(-1, show_name)
def getShowid(ShowName):
    ImdbId = AddicId = AddicUserId= TvdbId = ImdbNameMappingId = TvdbShowName = None
    UpdateCache = False
    SearchName, Suffix = _getShow(ShowName)
    SearchList =[]
    if Suffix:
        SearchList.append(SearchName +  ' (' + Suffix +')' )
        SearchList.append(SearchName +  ' ' + Suffix )
    SearchList.append(SearchName)
    log.debug('getShowid: Trying to get info for %s' %ShowName)
    for Name in SearchList:
        # First we try the User Namemapping
        if Name.upper() in autosub.NAMEMAPPING.keys():
            ImdbNameMappingId,TvdbShowName = autosub.NAMEMAPPING[Name.upper()]
            if ImdbNameMappingId:
                # Now look for info in the cache
                AddicId, TvdbId, TvdbCacheName = idCache().getInfo(ImdbNameMappingId)
                # no Tvdb name, then it is a user mappen and we missing the formal tvdb name
                if not TvdbShowName:
                    # if name in cache we add to the user mapping
                    if TvdbCacheName:
                        TvdbShowName = TvdbCacheName
                    elif checkAPICallsTvdb():
                        # still no tvdb name we fetch it form the tvdb website
                        TvdbShowName,TvdbId = Tvdb.getShowName(ImdbNameMappingId)
                        if TvdbShowName:
                            autosub.NAMEMAPPING[Name.upper()][1] = TvdbShowName
        else:
            # Not found in NameMapping so check the cache
            ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(Name.upper())
            # No info in the cache we try Tvdb
            if not ImdbId and checkAPICallsTvdb():
                ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(Name)  
                if ImdbId:
                    UpdateCache = True
        if (ImdbNameMappingId or ImdbId):
            if not AddicId:
                Id = ImdbNameMappingId if ImdbNameMappingId else ImdbId
                if Id:
                    if Id in autosub.ADDIC7EDMAPPING.keys():
                        AddicId = autosub.ADDIC7EDMAPPING[Id]
                    elif Id in autosub.USERADDIC7EDMAPPING.keys():
                        AddicUserId = autosub.USERADDIC7EDMAPPING[Id]
                    elif autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(ShowName, TvdbShowName)
                        if AddicId and ImdbId:
                            UpdateCache = True
            break
    if UpdateCache:
        idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId, TvdbShowName)
    if ImdbNameMappingId: ImdbId = ImdbNameMappingId
    if not TvdbShowName: TvdbShowName = ShowName
    if AddicUserId: AddicId = AddicUserId
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %(ImdbId,AddicId,TvdbShowName))
    return ImdbId, AddicId, TvdbId, TvdbShowName
    # no ImdbId found for this showname
    log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
    return None, None, None, ShowName
def getShowid(ShowName):
    ImdbId = AddicId = TvdbId = AddicMappingId = ImdbNameMappingId = TvdbShowName = None
    UpdateCache = False
    SearchName, Suffix = _getShow(ShowName)
    SearchList =[]
    if Suffix:
        SearchList.append(SearchName +  ' (' + Suffix +')' )
        SearchList.append(SearchName +  ' ' + Suffix )
    SearchList.append(SearchName)
    for ShowName in SearchList:
        ShowNameUpper = ShowName.upper()
        log.debug('getShowid: Trying to get info for %s' %ShowName)

        # First we try the User Namemapping
        if ShowNameUpper in autosub.NAMEMAPPING.keys():
            ImdbNameMappingId = autosub.NAMEMAPPING[ShowNameUpper]
            if ImdbNameMappingId:
                # Try to find the addicId in the cache
                if ImdbNameMappingId in autosub.ADDIC7EDMAPPING.keys():
                    AddicMappingId = autosub.ADDIC7EDMAPPING[ImdbNameMappingId]
                if not AddicMappingId:
                    ImdbId, AddicMappingId, TvdbId, TvdbShowName = idCache().getId(ShowNameUpper)
                    if not AddicMappingId and autosub.ADDIC7EDLOGGED_IN:
                        AddicMappingId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
        else:
            # Not found in NameMapping so check the cache
            ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(ShowNameUpper)
            # No info in the cache we try Tvdb
            if not ImdbId and checkAPICallsTvdb():
                ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
                if ImdbId:
                    UpdateCache = True
                    if ImdbId in autosub.ADDIC7EDMAPPING.keys():
                        AddicId = autosub.ADDIC7EDMAPPING[ImdbId]
                    if not AddicId and autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
            else:
                if not AddicId:           
                    if ImdbId in autosub.ADDIC7EDMAPPING.keys():
                        AddicMappingId = autosub.ADDIC7EDMAPPING[ImdbId]
                    if not AddicMappingId and autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
                        UpdateCache = True
        if ImdbId or ImdbNameMappingId:
            if UpdateCache:
                idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId, TvdbShowName)
            if ImdbNameMappingId: ImdbId = ImdbNameMappingId
            if AddicMappingId: AddicId = AddicMappingId
            if not TvdbShowName: TvdbShowName = ShowName
            log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %(ImdbId,AddicId,TvdbShowName))
            return ImdbId, AddicId, TvdbId, TvdbShowName
    # no ImdbId found for this showname
    log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
    return None, None, None, ShowName
def getShowid(ShowName, UseAddic, UseOs):
    AddicId = ImdbId = OsId = AddicIdMapping = None
    UpdateCache = False
    log.debug("getShowid: Trying to get IMDB, Addic7ed and OpenSubtitles ID for %s" % ShowName)

    # First we try the cache
    ImdbId, AddicId, OsId = idCache().getId(ShowName)
    if ImdbId:
        TvdbShowName = ShowName
    else:
        # Now we try Tvdb
        log.debug("getShowid: Trying TvdbID to find info")
        ImdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
        if ImdbId:
            UpdateCache = True
        else:
            # Last resort the name mapping from the config page
            ImdbNameMappingId = nameMapping(ShowName)
            if ImdbNameMappingId:
                # Check whether the Namemapping is an existing Imdb Id and if so find the official showname
                TvdbShowName = Tvdb.getShowName(ImdbNameMappingId)
                if TvdbShowName:
                    ImdbId = ImdbNameMappingId
                    UpdateCache = True
            else:
                return None, None, None

    if UseAddic and not AddicId:
        # Try to find the Addice7ed Id on the show page of the Addic7ed website
        AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
        if AddicId:
            log.debug("getShowid: Addic7ed ID found on website: %s" % AddicId)
            UpdateCache = True
        else:
            # Try the Addic7ed ID mapping from the config
            AddicIdMapping = Addic7edMapping(ImdbId)
            # if Addic7edIdMapping:
            #    Addic7edId = Addic7edIdMapping

    if UseOs and not OsId:
        # Try to find the OpenSubtitles ID on the OpenSubtitles website
        OsId = GetOpensubtitlesId(ImdbId, TvdbShowName)
        if OsId:
            UpdateCache = True

    if UpdateCache:
        idCache().setId(ImdbId, AddicId, OsId, TvdbShowName)
    AddicId = AddicIdMapping if AddicIdMapping else AddicId
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, OpenSubtitles: %s" % (ImdbId, AddicId, OsId))
    return ImdbId, AddicId, OsId
Exemple #6
0
def getShowid(ShowName, UseAddic, UseOs):
    if not ShowName:
        return None,None,None
    AddicId = ImdbId = OsId = AddicIdMapping = None
    UpdateCache = False
    log.debug('getShowid: Trying to get IMDB, Addic7ed and OpenSubtitles ID for %s' %ShowName)

    ImdbNameMappingId = nameMapping(ShowName)
    if ImdbNameMappingId:
        # Check whether the Namemapping is an existing Imdb Id and if so find the official showname
        TvdbShowName = Tvdb.getShowName(ImdbNameMappingId)
        if TvdbShowName:
            ImdbId = ImdbNameMappingId
            UpdateCache = True
    else:
        # No mapping we try the cache
        ImdbId, AddicId, OsId = idCache().getId(ShowName)
        if ImdbId:
            TvdbShowName = ShowName
        else:
            # No chache hit we try the Tvdb website
            log.debug('getShowid: Trying TvdbID to find info')
            ImdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
            if ImdbId and TvdbShowName:
                UpdateCache = True

    if UseAddic and not AddicId:
        #First we try the namemapping from the config
        AddicIdMapping = Addic7edMapping(ImdbId)
        if not AddicIdMapping:
            #No mapping en no cache hit then try to find the Addice7ed Id on the show page of the Addic7ed website
            AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
            if AddicId:
                UpdateCache = True

    if UseOs and not OsId:
        #Try to find the OpenSubtitles ID on the OpenSubtitles website
        OsId = GetOpensubtitlesId(ImdbId,TvdbShowName)
        if OsId:
            UpdateCache = True

    if UpdateCache and ImdbId and TvdbShowName:
        idCache().setId(ImdbId, AddicId, OsId, TvdbShowName)
    AddicId = AddicIdMapping    if AddicIdMapping    else AddicId
    ImdbId  = ImdbNameMappingId if ImdbNameMappingId else ImdbId
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, OpenSubtitles: %s" %(ImdbId,AddicId,OsId))
    return ImdbId, AddicId, OsId
Exemple #7
0
def getShowid(ShowName, UseAddic):
    AddicId = ImdbId = TvdbId = AddicIdMapping = ImdbNameMappingId = TvdbShowName = AddicNameMappingId = None
    UpdateCache = False
    log.debug('getShowid: Trying to get info for %s' %ShowName)

    # First we try the User Namemapping and the System Namemapping
    if ShowName.upper() in autosub.USERNAMEMAPPINGUPPER.keys():
        ImdbNameMappingId = autosub.USERNAMEMAPPINGUPPER[ShowName.upper()]
        if ImdbNameMappingId:
             AddicId, TvdbId, TvdbShowName = idCache().getInfo(ImdbNameMappingId)
             if not TvdbShowName and checkAPICallsTvdb():
                TvdbShowName, TvdbId = Tvdb.getShowName(ImdbNameMappingId)
    elif ShowName.upper() in autosub.NAMEMAPPINGUPPER.keys():
        ImdbId = autosub.NAMEMAPPINGUPPER[ShowName.upper()]
        # If found, we try to add info from the cache
        if ImdbId:
            AddicId, TvdbId, TvdbShowName = idCache().getInfo(ImdbId)
            # No info in the cache we try Tvdb
            if not TvdbShowName and checkAPICallsTvdb():
                TvdbShowName, TvdbId = Tvdb.getShowName(ImdbId)
                if TvdbShowName:
                    UpdateCache = True

    # Namemapping prevails over the cache info

    if not (ImdbId or ImdbNameMappingId):
        ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(ShowName.upper())
            # still no ImdbId then we try Tvdb
        if not ImdbId and checkAPICallsTvdb():
            ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
        if ImdbId:
            #Found a ImdbId on Tvdb try the cache for the other info.
            AddicId,CacheTvdbId, CacheName = idCache().getInfo(ImdbId)
            if not CacheName:
                UpdateCache = True
        else:
            log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
            return None, None, None, ShowName

    if UseAddic and not AddicId:
        if ImdbNameMappingId:
            AddicNameMappingId = Addic7edMapping(ImdbNameMappingId)
        else:
            AddicNameMappingId = Addic7edMapping(ImdbId)
        if AddicNameMappingId:
            log.debug('getShowid: Addic7ed ID found in Namemapping: %s' %AddicNameMappingId)
        else:
            #Try to find the Addice7ed Id on the show page of the Addic7ed website
            AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
            if AddicId:
                log.debug('getShowid: Addic7ed ID found on Website: %s' %AddicId)
                UpdateCache = True

    if UpdateCache:
        idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId, TvdbShowName)
    if ImdbNameMappingId: ImdbId = ImdbNameMappingId
    if AddicNameMappingId: AddicId = AddicNameMappingId
    if not TvdbShowName: TvdbShowName = ShowName
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %(ImdbId,AddicId,TvdbShowName))
    return ImdbId, AddicId, TvdbId, TvdbShowName
Exemple #8
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
Exemple #9
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
Exemple #10
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
Exemple #11
0
    def run(self):
        # setup some objects
        autosub.SEARCHBUSY = True
        autosub.ADDIC7EDAPI = Addic7edAPI()
        DbConnect = sqlite3.connect(autosub.DBFILE)
        autosub.DOWNLOADS = downloads(DbConnect)
        autosub.IDCACHE = idCache(DbConnect)
        StartTime = time()
        del autosub.WANTEDQUEUE[:]
        _UpdGithub()
        ScanDisk()
        Info = ''
        if autosub.ADDIC7ED: Info = 'Addic7ed, '
        if autosub.OPENSUBTITLES: Info += 'Opensubtitles, '
        if autosub.SUBSCENE: Info += 'Subscene, '
        if autosub.PODNAPISI: Info += 'Podnapisi, '
        if Info:
            Info = Info[:-2]
        else:
            log.info("No website selected in config")
        Downloaded = False
        if autosub.WANTEDQUEUE and Info:
            log.info("Starting round of subs searching on %s" % Info)
            # Initiate a session to OpenSubtitles and log in if OpenSubtitles is choosen
            if autosub.OPENSUBTITLES and autosub.OPENSUBTITLESUSER and autosub.OPENSUBTITLESPASSWD:
                OS_Login()
            if autosub.ADDIC7ED and autosub.ADDIC7EDUSER and autosub.ADDIC7EDPASSWD:
                autosub.ADDIC7EDAPI.A7_Login()
            if autosub.DOWNLOADS_A7 >= autosub.DOWNLOADS_A7MAX:
                log.info("Max downloads from Addic7ed reached for today.")
                autosub.ADDIC7EDAPI.A7_Logout()

            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('Search stopped by User')
                        break
                    Wanted = {}
                    Wanted = autosub.WANTEDQUEUE[Index]
                    #Check if not empty and searchable
                    if not (Wanted and Wanted['Search']):
                        Index += 1
                        continue

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

                    if not SubsNL and not SubsEN:
                        log.debug(
                            "No subs found with minmal match score for %s" %
                            Wanted['file'])
                        Index += 1
                        continue
                    if SubsNL and not autosub.SEARCHSTOP:
                        log.debug(
                            'Dutch Subtitle(s) found with the minmatch score, trying to download the highest scored.'
                        )
                        Downloaded = DownloadSub(Wanted, SubsNL)
                        if Downloaded:
                            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(
                                        "Removed English subtitle for : %s" %
                                        Wanted['file'])
                                except Exception as error:
                                    log.error(
                                        "Error while trying to remove English subtitle message is:%s."
                                        % error)
                    if SubsEN:
                        log.debug(
                            'English Subtitle(s) found trying to download the highest scored.'
                        )
                        Downloaded = DownloadSub(Wanted, SubsEN)
                        if Downloaded:
                            Wanted['langs'].remove(autosub.ENGLISH)
                            sleep(0.1)
                    if len(Wanted['langs']) == 0:
                        del autosub.WANTEDQUEUE[Index]
                        sleep(0.1)
                        End -= 1
                    else:
                        Index += 1
        else:
            log.info("Nothing to search for.")
        if autosub.ADDIC7EDLOGGED_IN:
            autosub.ADDIC7EDAPI.A7_Logout()
        del autosub.ADDIC7EDAPI
        if autosub.OPENSUBTITLESTOKEN:
            OS_Logout()
        log.info(
            "Finished round of subs Search. Go to sleep until the next round.")
        autosub.SEARCHTIME = time() - StartTime
        autosub.SEARCHBUSY = False
        autosub.SEARCHSTOP = False
        DbConnect.close()
        # prevent kodi library update with every download, just once per checksub round.
        if Downloaded and autosub.NOTIFYKODI and autosub.KODIUPDATEONCE:
            send_update_library()
        return True
 def flushCache(self):
     idCache().flushCache()
     message = 'Id Cache flushed'
     tmpl = PageTemplate(file="interface/templates/message.tmpl")
     tmpl.message = message
     return str(tmpl)
    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()
        Info = None
        if autosub.Addic7ed:
            Info = 'Addic7ed, '
        if autosub.OPENSUBTITLES:
            Info += 'Opensubtitles, '
        if autosub.SUBSCENE:
            Info += 'Sunscene, '
        if autosub.PODNAPISI:
            Info += 'Podnapisi, '
        if Info:
            Info = Info[:-2]
        else:
            log.info("checkSub: No website selected in config" )
        if autosub.WANTEDQUEUE and Info:
            log.info("checkSub: Starting round of subs searching on %s" % Info )                  
            # Initiate a session to OpenSubtitles and log in if OpenSubtitles is choosen
            if autosub.OPENSUBTITLES and autosub.OPENSUBTITLESUSER and autosub.OPENSUBTITLESPASSWD:
                OpenSubtitlesLogin()
            if autosub.ADDIC7ED and autosub.ADDIC7EDUSER and autosub.ADDIC7EDPASSWD:
                autosub.ADDIC7EDAPI = autosub.Addic7ed.Addic7edAPI()
                autosub.ADDIC7EDAPI.login()

            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
        else:
            log.info("checkSub: Nothing to search for." ) 
        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
def getShowid(ShowName):
    ImdbId = AddicId = AddicUserId = TvdbId = ImdbNameMappingId = TvdbShowName = None
    UpdateCache = False
    SearchName, Suffix = _getShow(ShowName)
    SearchList = []
    if Suffix:
        SearchList.append(SearchName + ' (' + Suffix + ')')
        SearchList.append(SearchName + ' ' + Suffix)
    SearchList.append(SearchName)
    log.debug('getShowid: Trying to get info for %s' % ShowName)
    for Name in SearchList:
        # First we try the User Namemapping
        if Name.upper() in autosub.NAMEMAPPING.keys():
            ImdbNameMappingId, TvdbShowName = autosub.NAMEMAPPING[Name.upper()]
            if ImdbNameMappingId:
                # Now look for info in the cache
                AddicId, TvdbId, TvdbCacheName = idCache().getInfo(
                    ImdbNameMappingId)
                # no Tvdb name, then it is a user mappen and we missing the formal tvdb name
                if not TvdbShowName:
                    # if name in cache we add to the user mapping
                    if TvdbCacheName:
                        TvdbShowName = TvdbCacheName
                    elif checkAPICallsTvdb():
                        # still no tvdb name we fetch it form the tvdb website
                        TvdbShowName, TvdbId = Tvdb.getShowName(
                            ImdbNameMappingId)
                        if TvdbShowName:
                            autosub.NAMEMAPPING[Name.upper()][1] = TvdbShowName
        else:
            # Not found in NameMapping so check the cache
            ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(
                Name.upper())
            # No info in the cache we try Tvdb
            if not ImdbId and checkAPICallsTvdb():
                ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(Name)
                if ImdbId:
                    UpdateCache = True
        if (ImdbNameMappingId or ImdbId):
            if not AddicId:
                Id = ImdbNameMappingId if ImdbNameMappingId else ImdbId
                if Id:
                    if Id in autosub.ADDIC7EDMAPPING.keys():
                        AddicId = autosub.ADDIC7EDMAPPING[Id]
                    elif Id in autosub.USERADDIC7EDMAPPING.keys():
                        AddicUserId = autosub.USERADDIC7EDMAPPING[Id]
                    elif autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(ShowName, TvdbShowName)
                        if AddicId and ImdbId:
                            UpdateCache = True
            break
    if UpdateCache:
        idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId,
                        TvdbShowName)
    if ImdbNameMappingId: ImdbId = ImdbNameMappingId
    if not TvdbShowName: TvdbShowName = ShowName
    if AddicUserId: AddicId = AddicUserId
    log.debug(
        "getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %
        (ImdbId, AddicId, TvdbShowName))
    return ImdbId, AddicId, TvdbId, TvdbShowName
    # no ImdbId found for this showname
    log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
    return None, None, None, ShowName
    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
Exemple #16
0
def checkSub(Forced=False):
    # setup some objects
    autosub.SEARCHBUSY = True
    autosub.SEARCHSTOP = False
    DbConnect = sqlite3.connect(autosub.DBFILE)
    autosub.DOWNLOADS = downloads(DbConnect)
    autosub.IDCACHE = idCache(DbConnect)
    StartTime = time()
    del autosub.WANTEDQUEUE[:]
    _UpdGithub()
    Info = ''
    if autosub.ADDIC7ED: Info = 'Addic7ed,'
    if autosub.OPENSUBTITLES: Info += 'Opensubtitles,'
    if autosub.SUBSCENE: Info += 'Subscene,'
    if autosub.PODNAPISI: Info += 'Podnapisi,'
    if Info:
        Info = Info[:-1]
    else:
        log.info("No website selected in config")
    Downloaded = False
    if ScanDisk(Forced) != 0 and Info and not autosub.SEARCHSTOP:
        SiteCount = 0
        log.info("Starting round of subs searching on %s" % Info)
        # Initiate a session to OpenSubtitles and login if it is choosen
        if autosub.OPENSUBTITLES and autosub.OPENSUBTITLESUSER and autosub.OPENSUBTITLESPASSWD:
            if OS_Login():
                SiteCount += 1
            # Initiate a session to Addic7ed and login if it is choosen
        if autosub.ADDIC7ED and autosub.ADDIC7EDUSER and autosub.ADDIC7EDPASSWD:
            autosub.ADDIC7EDAPI = Addic7edAPI()
            if autosub.ADDIC7EDAPI.A7_Login():
                SiteCount += 1
                # If the daily max is reached don't use addic7ed today
            if autosub.ADDIC7EDLOGGED_IN and autosub.DOWNLOADS_A7 >= autosub.DOWNLOADS_A7MAX:
                log.info("Max downloads from Addic7ed reached for today.")
                autosub.ADDIC7EDAPI.A7_Logout()
                SiteCount -= 1
            # Initiate a session to SubtitleSeeker if it is choosen
        autosub.SS_SESSION = requests.session()
        SSavalable = True
        if autosub.PODNAPISI:
            if not autosub.SS_SESSION.head('http://www.subtitleseeker.com',
                                           timeout=7).ok:
                SSavalable = False
                SiteCount += 1
        if autosub.SUBSCENE and SSavalable:
            if not autosub.SS_SESSION.head('http://www.subtitleseeker.com',
                                           timeout=7).ok:
                SSavalable = False
                SiteCount += 1
        if SiteCount == 0:
            log.info('None of the websites are available')
        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 and SiteCount > 0:
            while Index < End:
                if autosub.SEARCHSTOP:
                    log.info('Search stopped by User')
                    break
                Wanted = {}
                Wanted = autosub.WANTEDQUEUE[Index]
                # Check if something to search for
                if not (Wanted and Wanted['Search']):
                    Index += 1
                    continue
                log.info("Searching %s subs for %s" %
                         (Wanted['langs'], Wanted['file']))
                # Find all links with minimal match score.
                SubsNL, SubsEN = getSubLinks(Wanted)
                if not SubsNL and not SubsEN:
                    log.info("No subs for %s with minmatch score" %
                             Wanted['file'])
                    Index += 1
                    continue
                if SubsNL and not autosub.SEARCHSTOP:
                    Downloaded = DownloadSub(Wanted, SubsNL)
                    if Downloaded:
                        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("Removed English subtitle for : %s" %
                                         Wanted['file'])
                            except Exception as error:
                                log.error(
                                    "Error while trying to remove English subtitle message is:%s."
                                    % error)
                if SubsEN:
                    log.info(
                        'English Subtitle(s) found trying to download the highest scored.'
                    )
                    Downloaded = DownloadSub(Wanted, SubsEN)
                    if Downloaded:
                        Wanted['langs'].remove(autosub.ENGLISH)
                sleep(0.1)
                if len(Wanted['langs']) == 0:
                    del autosub.WANTEDQUEUE[Index]
                    sleep(0.1)
                    End -= 1
                else:
                    Index += 1
    if autosub.ADDIC7EDLOGGED_IN:
        autosub.ADDIC7EDAPI.A7_Logout()
    if autosub.OPENSUBTITLESTOKEN:
        OS_Logout()
    if autosub.SS_SESSION:
        autosub.SS_SESSION.close()
    log.info(
        "Finished round of subs Search. Go to sleep until the next round.")
    autosub.SEARCHTIME = time() - StartTime
    autosub.SEARCHSTOP = False
    DbConnect.close()
    autosub.SEARCHBUSY = False
    # prevent kodi library update with every download, just once per checksub round.
    if Downloaded and autosub.NOTIFYKODI and autosub.KODIUPDATEONCE:
        send_update_library()
    sleep(0.01)
    return