Exemplo n.º 1
0
def subseeker(subSeekerLink,website):

    baselink = 'http://www.' + website 
    Session = requests.session()
    SubLinkPage = Session.get(subSeekerLink)

    try:
        SubLink = re.findall('Download : <a href="(.*?)"', SubLinkPage.text)[0]
    except Exception as error:
        log.error("subseeker: Failed to find the redirect link on SubtitleSeekers")        
        return None
    Result= requests.get(SubLink)
    Result.encoding = 'utf-8'
    if website == 'podnapisi.net':
        DownLoadLink = re.findall('form-inline download-form\" action=(.*?)>', Result.text)[0]
        DownLoadLink = urljoin(baselink, DownLoadLink) if DownLoadLink else None
    elif website =='subscene.com':
        DownLoadLink = re.findall('<a href=\"/subtitle/download(.*?)\"', Result.text)[0]
        DownLoadLink = urljoin(baselink + '/subtitle/download', DownLoadLink) if DownLoadLink else None
    if not DownLoadLink:
        log.error('downloadsubs: Could not find the downloadlink %s on %s' % (DownLoadLink, website))
    try:
        SubData = unzip(DownLoadLink)
        return(SubData)
    except:
        log.error('downloadsubs:Problem unzipping file %s from %s.' % (DownLoadLink,website))
    return None
Exemplo n.º 2
0
def SubtitleSeeker(ImdbId, lang, Wanted, sourceWebsites):
    # Get the scored list for all SubtitleSeeker hits

    SearchUrl = "%s&imdb=%s&season=%s&episode=%s&language=%s&return_type=json" % (autosub.API, ImdbId, Wanted['season'], Wanted['episode'], lang)
    log.info('getSubLinks: SubtitleSeeker request URL: %s' % SearchUrl)
    if autosub.Helpers.checkAPICallsSubSeeker(use=True):
        try:
            SubseekerSession = requests.session()
            Result = SubseekerSession.get(SearchUrl).json()
            SubseekerSession.close()
        except:
            log.error("getSubLink: The server returned an error for request %s" % getSubLinkUrl)
            return
    else:
        log.error("API: out of api calls for SubtitleSeeker.com")
        return
    scoreList = []
    if int(Result['results']['total_matches']) == 0:
        return

    for Item in Result['results']['items']:
        if (Item['site'].lower() == u'podnapisi.net' and (autosub.PODNAPISILANG == lang or autosub.PODNAPISILANG == 'Both')) or \
           (Item['site'].lower() == u'subscene.com' and (autosub.SUBSCENELANG == lang or  autosub.SUBSCENELANG == 'Both')):
            Item['release'] = Item['release'][:-4].lower() if Item['release'].endswith(".srt") else Item['release'].lower()
            NameDict = ProcessFilename(Item['release'],Wanted['container'])
            score = autosub.Helpers.scoreMatch(NameDict, Item['release'], Wanted['quality'], Wanted['releasegrp'], Wanted['source'], Wanted['codec'])
            if score >= autosub.MINMATCHSCORE:
                scoreList.append({'score':score, 'url':Item['url'] , 'website':Item['site'].lower(), 'releaseName':Item['release'],'SubCodec':''})
    return scoreList
Exemplo n.º 3
0
def unzip(url):
    # returns a file-like StringIO object    
    try:
        Session = requests.session()
        Result = Session.get(url)
    except:
        log.debug("unzip: Zip file at %s couldn't be retrieved" % url)
        return None
    try: 
       zip =  zipfile.ZipFile(io.BytesIO(Result.content))
    except Exception as error:
        log.debug("unzip: Expected a zip file but got error for link %s" % url)
        log.debug("unzip: %s is likely a dead link" % url)
        return None
    nameList = zip.namelist()
    for name in nameList:
        # sometimes .nfo files are in the zip container
        if name.lower().endswith('srt'):
            try:
                Codec = chardet.detect(zip.read(name))['encoding']
                fpr = io.TextIOWrapper(zip.open(name),encoding = Codec,newline='')
                SubData = fpr.read()
                fpr.close()
                if SubData:
                    return SubData
            except Exception as error:
                pass
    log.debug("unzip: No subtitle files was found in the zip archive for %s" % url)
    return None
Exemplo n.º 4
0
def SubtitleSeeker(Wanted, sourceWebsites):
    # Get the scored list for all SubtitleSeeker hits
    ScoreListFR, ScoreListEN = [],[]
    log.debug('getSubLinks: SubtitlesSeeker search started for %s on sites: %s ' % (Wanted['ImdbId'],sourceWebsites))

    # Compose the search URL for the subtitle and language we want.
    langs = Wanted['langs'][0] + ',' + Wanted['langs'][1] if len(Wanted['langs']) == 2 else Wanted['langs'][0]
    SearchUrl = "%s&imdb=%s&season=%s&episode=%s&language=%s&return_type=json" % (autosub.API, Wanted['ImdbId'], Wanted['season'], Wanted['episode'], langs)

    # Let Subtitle seeker do a search voor the wanted sub
    if autosub.Helpers.checkAPICallsSubSeeker(use=True):
        try:
            SubseekerSession = requests.session()
            Result = SubseekerSession.get(SearchUrl).json()
            SubseekerSession.close()
        except Exception as error:
            log.error("getSubLink: The SubtitleSeeker server returned an error. Message is %s" % error)
            return ScoreListFR,ScoreListEN
    else:
        log.error("getSubLink: out of api calls for SubtitleSeeker.com")
        return ScoreListFR,ScoreListEN

    # Check to see whether we have results or not
    try:
        if not 'total_matches' in Result['results'].keys():
            return ScoreListFR,ScoreListEN
    except Exception as error:
        log.info('getSublink: No subtitle found on Subtitleseeker for this video : %s' % Wanted['file'])
        return ScoreListFR,ScoreListEN
    if int(Result['results']['total_matches']) == 0:
        return ScoreListFR,ScoreListEN

    # Split the result in the two languages(if needed) and score the subs
    NameDict = {}
    for Item in Result['results']['items']:
        if Item['site'].lower() in sourceWebsites:
            Item['release'] = Item['release'][:-4] if Item['release'].lower().endswith(".srt") else Item['release']
            NameDict.clear()
            NameDict = ProcessFilename(Item['release'],Wanted['container'])
            if not NameDict:
                continue
            score = autosub.Helpers.scoreMatch(NameDict,Wanted)
            if score == 0:
                continue
            log.debug('SubtitleSeeker: Score = %s of %s for %s sub of %s on %s.' % (score, autosub.MINMATCHSCORE, Item['language'], Item['release'], Item['site']))
            if score >= autosub.MINMATCHSCORE:
                if Item['language'] == autosub.ENGLISH:
                    ScoreListEN.append({'score':score, 'url':Item['url'] , 'website':Item['site'].lower(),'Lang':Item['language'], 'releaseName':Item['release'],'SubCodec':u''})
                if Item['language'] == autosub.FRENCH:
                    ScoreListFR.append({'score':score, 'url':Item['url'] , 'website':Item['site'].lower(),'Lang':Item['language'], 'releaseName':Item['release'],'SubCodec':u''})
    return ScoreListFR,ScoreListEN
def SubtitleSeeker(Wanted, sourceWebsites):
    # Get the scored list for all SubtitleSeeker hits
    ScoreListNL, ScoreListEN = [],[]
    log.debug('getSubLinks: SubtitlesSeeker search started for %s on sites: %s ' % (Wanted['ImdbId'],sourceWebsites))

    # Compose the search URL for the subtitle and language we want.
    langs = Wanted['langs'][0] + ',' + Wanted['langs'][1] if len(Wanted['langs']) == 2 else Wanted['langs'][0]
    SearchUrl = "%s&imdb=%s&season=%s&episode=%s&language=%s&return_type=json" % (autosub.API, Wanted['ImdbId'], Wanted['season'], Wanted['episode'], langs)

    # Let Subtitle seeker do a search voor the wanted sub
    if autosub.Helpers.checkAPICallsSubSeeker(use=True):
        try:
            SubseekerSession = requests.session()
            Result = SubseekerSession.get(SearchUrl).json()
            SubseekerSession.close()
        except Exception as error:
            log.error("getSubLink: The SubtitleSeeker server returned an error. Message is %s" % error)
            return ScoreListNL,ScoreListEN
    else:
        log.error("getSubLink: out of api calls for SubtitleSeeker.com")
        return ScoreListNL,ScoreListEN

    # Check to see whether we have results or not
    try:
        if not 'total_matches' in Result['results'].keys():
            return ScoreListNL,ScoreListEN
    except Exception as error:
        log.info('getSublink: No subtitle found on Subtitleseeker for this video : %s' % Wanted['file'])
        return ScoreListNL,ScoreListEN
    if int(Result['results']['total_matches']) == 0:
        return ScoreListNL,ScoreListEN

    # Split the result in the two languages(if needed) and score the subs
    NameDict = {}
    for Item in Result['results']['items']:
        if Item['site'].lower() in sourceWebsites:
            Item['release'] = Item['release'][:-4] if Item['release'].lower().endswith(".srt") else Item['release']
            NameDict.clear()
            NameDict = ProcessFilename(Item['release'],Wanted['container'])
            if not NameDict:
                continue
            score = autosub.Helpers.scoreMatch(NameDict,Wanted)
            if score == 0:
                continue
            log.debug('SubtitleSeeker: Score = %s of %s for %s sub of %s on %s.' % (score, autosub.MINMATCHSCORE, Item['language'], Item['release'], Item['site']))
            if score >= autosub.MINMATCHSCORE:
                if Item['language'] == autosub.ENGLISH:
                    ScoreListEN.append({'score':score, 'url':Item['url'] , 'website':Item['site'].lower(),'Lang':Item['language'], 'releaseName':Item['release'],'SubCodec':u''})
                if Item['language'] == autosub.DUTCH:
                    ScoreListNL.append({'score':score, 'url':Item['url'] , 'website':Item['site'].lower(),'Lang':Item['language'], 'releaseName':Item['release'],'SubCodec':u''})
    return ScoreListNL,ScoreListEN
Exemplo n.º 6
0
def subseeker(subSeekerLink,website):

    Session = requests.session()
    time.sleep(6)
    try:
        SubLinkPage = Session.get(subSeekerLink)
    except Exception as error:
        log.error("subseeker: Failed to find the link on SubtitleSeekers. Message : %s" % error)        
        return None
    
    try:
        SubLink = re.findall('Download : <a href="(.*?)"', SubLinkPage.text)[0]
    except Exception as error:
        log.error("subseeker: Failed to find the redirect link on SubtitleSeekers. Message : %s" % error)        
        return None
    try:
        Result= Session.get(SubLink,verify=autosub.CERTIFICATEPATH)
    except Exception as error:
        log.error("subseeker: Failed to get the downloadpage from %s. Message : %s" % (website,error)) 
        return None

    if Result.status_code > 399 or not Result.text:
        return False
    Result.encoding = 'utf-8'

    if website == 'podnapisi.net':
        try:
            DownLoadLink = re.findall('form-inline download-form\" action=(.*?)>', Result.text)[0]
        except:
            log.error("subseeker: Could not find the subseeker link on the podnapisi website.") 
            return None
        DownLoadLink = urljoin('https://www.podnapisi.net', DownLoadLink) if DownLoadLink else None
    elif website =='subscene.com':
        try:
            DownLoadLink = re.findall('<a href=\"/subtitle/download(.*?)\"', Result.text)[0]
        except:
            log.error("subseeker: Could not find the subseeker link on the subscene website.") 
            return None
        DownLoadLink = urljoin('http://www.' + website  + '/subtitle/download', DownLoadLink) if DownLoadLink else None
    if not DownLoadLink:
        log.error('downloadsubs: Could not find the downloadlink %s on %s' % (DownLoadLink, website))
        return None
    SubData = unzip(Session, DownLoadLink)
    if SubData:
        return(SubData)
    else:
        return None
def subseeker(subSeekerLink,website):

    Session = requests.session()
    time.sleep(6)
    try:
        SubLinkPage = Session.get(subSeekerLink)
    except Exception as error:
        log.error("subseeker: Failed to find the link on SubtitleSeekers. Message : %s" % error)        
        return None
    
    try:
        SubLink = re.findall('Download : <a href="(.*?)"', SubLinkPage.text)[0]
    except Exception as error:
        log.error("subseeker: Failed to find the redirect link on SubtitleSeekers. Message : %s" % error)        
        return None
    try:
        Result= Session.get(SubLink,verify=autosub.CERTIFICATEPATH)
    except Exception as error:
        log.error("subseeker: Failed to get the downloadpage from %s. Message : %s" % (website,error)) 
        return None

    if Result.status_code > 399 or not Result.text:
        return False
    Result.encoding = 'utf-8'

    if website == 'podnapisi.net':
        try:
            DownLoadLink = re.findall('form-inline download-form\" action=(.*?)>', Result.text)[0]
        except:
            log.error("subseeker: Could not find the subseeker link on the podnapisi website.") 
            return None
        DownLoadLink = urljoin('https://www.podnapisi.net', DownLoadLink) if DownLoadLink else None
    elif website =='subscene.com':
        try:
            DownLoadLink = re.findall('<a href=\"/subtitle/download(.*?)\"', Result.text)[0]
        except:
            log.error("subseeker: Could not find the subseeker link on the subscene website.") 
            return None
        DownLoadLink = urljoin('http://www.' + website  + '/subtitle/download', DownLoadLink) if DownLoadLink else None
    if not DownLoadLink:
        log.error('downloadsubs: Could not find the downloadlink %s on %s' % (DownLoadLink, website))
        return None
    SubData = unzip(Session, DownLoadLink)
    if SubData:
        return(SubData)
    else:
        return None
Exemplo n.º 8
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
def SubtitleSeeker(Wanted, sourceWebsites):
    # Get the scored list for all SubtitleSeeker hits
    ScoreListNL, ScoreListEN = [], []
    log.debug("getSubLinks: SubtitlesSeeker search started for %s on sites: %s " % (Wanted["ImdbId"], sourceWebsites))

    # Compose the search URL for the subtitle and language we want.
    langs = Wanted["langs"][0] + "," + Wanted["langs"][1] if len(Wanted["langs"]) == 2 else Wanted["langs"][0]
    SearchUrl = "%s&imdb=%s&season=%s&episode=%s&language=%s&return_type=json" % (
        autosub.API,
        Wanted["ImdbId"],
        Wanted["season"],
        Wanted["episode"],
        langs,
    )

    # Let Subtitle seeker do a search voor the wanted sub
    if autosub.Helpers.checkAPICallsSubSeeker(use=True):
        try:
            SubseekerSession = requests.session()
            Result = SubseekerSession.get(SearchUrl).json()
            SubseekerSession.close()
        except Exception as error:
            log.error("getSubLink: The SubtitleSeeker server returned an error. Message is %s" % error)
            return ScoreListNL, ScoreListEN
    else:
        log.error("getSubLink: out of api calls for SubtitleSeeker.com")
        return ScoreListNL, ScoreListEN

    # Check to see whether we have results or not
    try:
        if not "total_matches" in Result["results"].keys():
            return ScoreListNL, ScoreListEN
    except Exception as error:
        log.info("getSublink: No subtitle found on Subtitleseeker for this video : %s" % Wanted["file"])
        return ScoreListNL, ScoreListEN
    if int(Result["results"]["total_matches"]) == 0:
        return ScoreListNL, ScoreListEN

    # Split the result in the two languages(if needed) and score the subs
    NameDict = {}
    for Item in Result["results"]["items"]:
        if Item["site"].lower() in sourceWebsites:
            Item["release"] = Item["release"][:-4] if Item["release"].lower().endswith(".srt") else Item["release"]
            NameDict.clear()
            NameDict = ProcessFilename(Item["release"], Wanted["container"])
            if not NameDict:
                continue
            score = autosub.Helpers.scoreMatch(NameDict, Wanted)
            if score == 0:
                continue
            log.debug(
                "SubtitleSeeker: Score = %s of %s for %s sub of %s on %s."
                % (score, autosub.MINMATCHSCORE, Item["language"], Item["release"], Item["site"])
            )
            if score >= autosub.MINMATCHSCORE:
                if Item["language"] == autosub.ENGLISH:
                    ScoreListEN.append(
                        {
                            "score": score,
                            "url": Item["url"],
                            "website": Item["site"].lower(),
                            "Lang": Item["language"],
                            "releaseName": Item["release"],
                            "SubCodec": u"",
                        }
                    )
                if Item["language"] == autosub.DUTCH:
                    ScoreListNL.append(
                        {
                            "score": score,
                            "url": Item["url"],
                            "website": Item["site"].lower(),
                            "Lang": Item["language"],
                            "releaseName": Item["release"],
                            "SubCodec": u"",
                        }
                    )
    return ScoreListNL, ScoreListEN