Merge branch 'development' into morpheus

This commit is contained in:
Louis Vézina 2019-07-22 18:57:54 -04:00
commit 33954f2459
12 changed files with 239 additions and 5 deletions

View file

@ -37,18 +37,20 @@ If you need something that is not already part of Bazarr, feel free to create a
* Manual search so you can download subtitles on demand
* Upgrade subtitles previously downloaded when a better one is found
* Ability to delete external subtitles from disk
* Currently support 184 subtitles languages
* Currently support 184 subtitles languages with support for forced/foreign subtitles (depending of providers)
* And a beautiful UI based on Sonarr
## Supported subtitles providers:
* Addic7ed
* Argenteam
* Assrt
* BetaSeries
* GreekSubtitles
* Hosszupuska
* LegendasTV
* Napiprojekt
* Napisy24
* Nekur
* OpenSubtitles
* Podnapisi
* Subdivx

View file

@ -120,6 +120,9 @@ defaults = {
'subscene': {
'username': '',
'password': ''
},
'betaseries': {
'token': ''
}
}

View file

@ -113,7 +113,8 @@ def get_providers_auth():
'assrt': {'token': settings.assrt.token, },
'napisy24': {'username': settings.napisy24.username,
'password': settings.napisy24.password,
}
},
'betaseries': {'token': settings.betaseries.token}
}
return providers_auth

View file

@ -67,8 +67,8 @@ def get_video(path, title, sceneName, use_scenename, use_mediainfo, providers=No
video.original_path = original_path
refine_from_db(original_path, video)
#if use_mediainfo:
# refine_from_mediainfo(original_path, video)
if use_mediainfo:
refine_from_mediainfo(original_path, video)
logging.debug('BAZARR is using those video object properties: %s', vars(video))
return video

View file

@ -397,6 +397,7 @@ def save_wizard():
settings.napisy24.password = request.forms.get('settings_napisy24_password')
settings.subscene.username = request.forms.get('settings_subscene_username')
settings.subscene.password = request.forms.get('settings_subscene_password')
settings.betaseries.token = request.forms.get('settings_betaseries_token')
settings_subliminal_languages = request.forms.getall('settings_subliminal_languages')
c.execute("UPDATE table_settings_languages SET enabled = 0")
@ -1536,7 +1537,8 @@ def save_settings():
settings.napisy24.password = request.forms.get('settings_napisy24_password')
settings.subscene.username = request.forms.get('settings_subscene_username')
settings.subscene.password = request.forms.get('settings_subscene_password')
settings.betaseries.token = request.forms.get('settings_betaseries_token')
settings_subliminal_languages = request.forms.getall('settings_subliminal_languages')
c.execute("UPDATE table_settings_languages SET enabled = 0")
for item in settings_subliminal_languages:

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,181 @@
# -*- coding: utf-8 -*-
import json
import logging
import os
import re
import io
import rarfile
import zipfile
from babelfish import language_converters
from guessit import guessit
from requests import Session
from subzero.language import Language
from subliminal import Movie, Episode, ProviderError, __short_version__
from subliminal.exceptions import AuthenticationError, ConfigurationError, DownloadLimitExceeded, ProviderError
from subliminal_patch.subtitle import Subtitle, guess_matches
from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS
from subliminal_patch.providers import Provider
from subzero.language import Language
logger = logging.getLogger(__name__)
server_url = 'https://api.betaseries.com/'
class BetaSeriesSubtitle(Subtitle):
provider_name = 'betaseries'
def __init__(self, subtitle_id, language, video_name, url, matches, source):
super(BetaSeriesSubtitle, self).__init__(language, page_link=url)
self.subtitle_id = subtitle_id
self.video_name = video_name
self.download_url = url
self.matches = matches
self.source = source
@property
def id(self):
return self.subtitle_id
@property
def download_link(self):
return self.download_url
def get_matches(self, video):
matches = self.matches
if isinstance(video, Episode):
matches |= guess_matches(video, guessit(
self.video_name, {'type': 'episode'}), partial=True)
return matches
class BetaSeriesProvider(Provider):
"""BetaSeries Provider"""
languages = {Language(l) for l in ['fra', 'eng']}
video_types = (Episode,)
def __init__(self, token=None):
if not token:
raise ConfigurationError('Token must be specified')
self.token = token
def initialize(self):
self.session = Session()
self.session.headers = {
'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")}
def terminate(self):
self.session.close()
def query(self, languages, video):
# query the server
result = None
matches = set()
if video.tvdb_id:
params = {'key': self.token,
'thetvdb_id': video.tvdb_id,
'v': 3.0,
'subtitles': 1}
logger.debug('Searching subtitles %r', params)
res = self.session.get(
server_url + 'episodes/display', params=params, timeout=10)
res.raise_for_status()
result = res.json()
matches.add('tvdb_id')
elif video.series_tvdb_id:
params = {'key': self.token,
'thetvdb_id': video.series_tvdb_id,
'season': video.season,
'episode': video.episode,
'subtitles': 1,
'v': 3.0}
logger.debug('Searching subtitles %r', params)
res = self.session.get(
server_url + 'shows/episodes', params=params, timeout=10)
res.raise_for_status()
result = res.json()
matches.add('series_tvdb_id')
else:
logger.debug(
'The show has no tvdb_id and series_tvdb_id: the search can\'t be done')
return []
if result['errors'] != []:
logger.debug('Status error: %r', result['errors'])
return []
# parse the subtitles
subtitles = []
if 'episode' in result:
subs = result['episode']['subtitles']
elif 'episodes' in result:
subs = result['episodes'][0]['subtitles']
else:
return []
for sub in subs:
language = _translateLanguageCodeToLanguage(sub['language'])
if language in languages:
# Filter seriessub source because it shut down so the links are all 404
if str(sub['source']) != 'seriessub':
subtitles.append(BetaSeriesSubtitle(
sub['id'], language, sub['file'], sub['url'], matches, str(sub['source'])))
return subtitles
def list_subtitles(self, video, languages):
return self.query(languages, video)
def download_subtitle(self, subtitle):
logger.info('Downloading subtitle %r', subtitle)
r = self.session.get(subtitle.download_link, timeout=10)
r.raise_for_status()
archive = _get_archive(r.content)
subtitle_content = _get_subtitle_from_archive(
archive) if archive else r.content
if subtitle_content:
subtitle.content = fix_line_ending(subtitle_content)
else:
logger.debug('Could not extract subtitle from %r', archive)
def _get_archive(content):
# open the archive
archive_stream = io.BytesIO(content)
archive = None
if rarfile.is_rarfile(archive_stream):
logger.debug('Identified rar archive')
archive = rarfile.RarFile(archive_stream)
elif zipfile.is_zipfile(archive_stream):
logger.debug('Identified zip archive')
archive = zipfile.ZipFile(archive_stream)
return archive
def _get_subtitle_from_archive(archive):
for name in archive.namelist():
# discard hidden files
if os.path.split(name)[-1].startswith('.'):
continue
# discard non-subtitle files
if not name.lower().endswith(SUBTITLE_EXTENSIONS):
continue
return archive.read(name)
return None
def _translateLanguageCodeToLanguage(languageCode):
if languageCode.lower() == 'vo':
return Language.fromalpha2('en')
elif languageCode.lower() == 'vf':
return Language.fromalpha2('fr')

View file

@ -106,6 +106,44 @@
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>BetaSeries</label>
</div>
<div class="one wide column">
<div id="betaseries" class="ui toggle checkbox provider">
<input type="checkbox">
<label></label>
</div>
</div>
<div class="collapsed column">
<div class="collapsed center aligned column">
<div class="ui basic icon" data-tooltip="French/English provider for TV Shows only." data-inverted="">
<i class="help circle large icon"></i>
</div>
</div>
</div>
<div class="collapsed column">
<div class="collapsed center aligned column">
<div class="ui basic icon" data-tooltip="This provider only uses the subtitle filename to find release group matches, subtitles may thus be out of sync." data-inverted="">
<i class="yellow warning sign icon"></i>
</div>
</div>
</div>
</div>
<div id="betaseries_option" class="ui grid container">
<div class="middle aligned row">
<div class="right aligned six wide column">
<label>Token</label>
</div>
<div class="six wide column">
<div class="ui fluid input">
<input name="settings_betaseries_token" type="text" value="{{settings.betaseries.token if settings.betaseries.token != None else ''}}">
</div>
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>GreekSubtitles</label>

View file

@ -37,6 +37,13 @@
</div>
</div>
</div>
<div class="collapsed column">
<div class="collapsed center aligned column">
<div class="ui basic icon" data-tooltip="To use this feature on linux, please install mediainfo and its dependencies." data-inverted="">
<i class="yellow warning sign icon"></i>
</div>
</div>
</div>
</div>
<div class="middle aligned row">