def _search_subtitles(video, lang, best_only): log.debug("Searching for subtitles") # Determine language language = babelfish.Language.fromietf(lang) if not language: log.error("Invalid language '%s' specified" % lang) return # Determine if language alpha2 code suffix is needed in srt file name (f.e. <episode_name>.nl.srt) single = False if lang == autosubliminal.DEFAULTLANGUAGE and not autosubliminal.DEFAULTLANGUAGESUFFIX: single = True # Get min match score if isinstance(video, Episode): min_score = autosubliminal.SHOWMINMATCHSCORE elif isinstance(video, Movie): min_score = autosubliminal.MOVIEMINMATCHSCORE else: log.error("Invalid video found '%s'" % video) return # Search for subtitles videos = {video} languages = {language} if best_only: # Download the best subtitle with min_score (without saving it in to file) subtitles = subliminal.download_best_subtitles( videos, languages, min_score=min_score, hearing_impaired=utils.include_hearing_impaired(), only_one=True, providers=autosubliminal.SUBLIMINALPROVIDERLIST, provider_configs=autosubliminal.SUBLIMINALPROVIDERCONFIGS) else: # Download all subtitles with default min score (without saving it to file) subtitles = subliminal.list_subtitles( videos, languages, providers=autosubliminal.SUBLIMINALPROVIDERLIST) subliminal.download_subtitles(subtitles[video]) return subtitles, language, single
def _search_subtitles(video, lang, best_only): log.debug("Searching for subtitles") # Determine language language = babelfish.Language.fromietf(lang) if not language: log.error("Invalid language '%s' specified" % lang) return # Determine if language alpha2 code suffix is needed in srt file name (f.e. <episode_name>.nl.srt) single = False if lang == autosubliminal.DEFAULTLANGUAGE and not autosubliminal.DEFAULTLANGUAGESUFFIX: single = True # Get min match score if isinstance(video, Episode): min_score = autosubliminal.SHOWMINMATCHSCORE elif isinstance(video, Movie): min_score = autosubliminal.MOVIEMINMATCHSCORE else: log.error("Invalid video found '%s'" % video) return # Search for subtitles videos = {video} languages = {language} if best_only: # Download the best subtitle with min_score (without saving it in to file) subtitles = subliminal.download_best_subtitles(videos, languages, min_score=min_score, hearing_impaired=utils.include_hearing_impaired(), only_one=True, providers=autosubliminal.SUBLIMINALPROVIDERLIST, provider_configs=autosubliminal.SUBLIMINALPROVIDERCONFIGS) else: # Download all subtitles with default min score (without saving it to file) subtitles = subliminal.list_subtitles(videos, languages, providers=autosubliminal.SUBLIMINALPROVIDERLIST) subliminal.download_subtitles(subtitles[video]) return subtitles, language, single
def search_subtitle(wanted_item_index, lang): log.info("Searching for an individual subtitle") subs = [] # Get wanted queue lock if not utils.get_wanted_queue_lock(): return subs, "Skipping! Cannot get a wanted queue lock because another threat is using the queues!" # Get wanted_item wanted_item = autosubliminal.WANTEDQUEUE[int(wanted_item_index)] # Scan wanted_item for video video = _scan_wanted_item_for_video(wanted_item) if video: # Search the subtitles with the default minimal score (to get all the possibilities to select from) subtitles, language, single = _search_subtitles(video, lang, False) # Check if subtitles are found for the video if subtitles[video]: # Add found subtitles to wanted_item wanted_item['found_subtitles'] = { 'subtitles': subtitles, 'language': language, 'single': single } # Order subtitles by score and create new dict # Use subliminal scoring (scores=None) for index, subtitle, score in sorted([ (index, s, subliminal.compute_score(s.get_matches( video, hearing_impaired=utils.include_hearing_impaired()), video, scores=None)) for index, s in enumerate(subtitles[video]) ], key=operator.itemgetter(2), reverse=True): # Only add subtitle when content is found if subtitle.content: # Create new sub dict for showing result sub = { 'subtitle_index': index, 'score': score, 'provider_name': subtitle.provider_name, 'content': subtitle.content, 'language': language, 'single': single, 'page_link': subtitle.page_link, 'releases': _get_releases(subtitle), 'wanted_item_index': wanted_item_index, 'playvideo_url': _construct_playvideo_url(wanted_item) } # Get content preview (the first 28 lines and last 30 lines of the subtitle) content_split = subtitle.content.splitlines(False) if len(content_split) < 58: content_preview = "This seems to be an invalid subtitle." content_preview += "<br> It has less than 58 lines to preview." else: try: # First 28 lines content_preview = "<br>".join( x.replace('"', "'") for x in content_split[:28]) # Separator content_preview += "<br>" content_preview += "<br>" content_preview += "..." content_preview += "<br>" content_preview += "<br>" # Last 30 lines content_preview += "<br>".join( x.replace('"', "'") for x in content_split[len(content_split) - 30:]) except: content_preview = "Problem with parsing the first 28 and/or last 30 lines of the file." sub['content_preview'] = content_preview subs.append(sub) # Release wanted queue lock utils.release_wanted_queue_lock() if not len(subs): return subs, "No subtitles could be found or downloaded!" return subs, None
def search_subtitle(wanted_item_index, lang): log.info("Searching for an individual subtitle") subs = [] # Get wanted queue lock if not utils.get_wanted_queue_lock(): return subs, "Skipping! Cannot get a wanted queue lock because another threat is using the queues!" # Get wanted_item wanted_item = autosubliminal.WANTEDQUEUE[int(wanted_item_index)] # Scan wanted_item for video video = _scan_wanted_item_for_video(wanted_item) if video: # Search the subtitles with the default minimal score (to get all the possibilities to select from) subtitles, language, single = _search_subtitles(video, lang, False) # Check if subtitles are found for the video if subtitles[video]: # Add found subtitles to wanted_item wanted_item['found_subtitles'] = {'subtitles': subtitles, 'language': language, 'single': single} # Order subtitles by score and create new dict # Use subliminal scoring (scores=None) for index, subtitle, score in sorted([(index, s, subliminal.compute_score( s.get_matches(video, hearing_impaired=utils.include_hearing_impaired()), video, scores=None)) for index, s in enumerate(subtitles[video])], key=operator.itemgetter(2), reverse=True): # Only add subtitle when content is found if subtitle.content: # Create new sub dict for showing result sub = {'subtitle_index': index, 'score': score, 'provider_name': subtitle.provider_name, 'content': subtitle.content, 'language': language, 'single': single, 'page_link': subtitle.page_link, 'releases': _get_releases(subtitle), 'wanted_item_index': wanted_item_index, 'playvideo_url': _construct_playvideo_url(wanted_item)} # Get content preview (the first 28 lines and last 30 lines of the subtitle) content_split = subtitle.content.splitlines(False) if len(content_split) < 58: content_preview = "This seems to be an invalid subtitle." content_preview += "<br> It has less than 58 lines to preview." else: try: # First 28 lines content_preview = "<br>".join( x.replace('"', "'") for x in content_split[:28]) # Separator content_preview += "<br>" content_preview += "<br>" content_preview += "..." content_preview += "<br>" content_preview += "<br>" # Last 30 lines content_preview += "<br>".join( x.replace('"', "'") for x in content_split[len(content_split) - 30:]) except: content_preview = "Problem with parsing the first 28 and/or last 30 lines of the file." sub['content_preview'] = content_preview subs.append(sub) # Release wanted queue lock utils.release_wanted_queue_lock() if not len(subs): return subs, "No subtitles could be found or downloaded!" return subs, None