Subtitle support base
This commit is contained in:
@@ -21,7 +21,7 @@ class MoviePlugin(Plugin):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addApiView('movie.search', self.search)
|
addApiView('movie.search', self.search)
|
||||||
addApiView('movie.list', self.list)
|
addApiView('movie.list', self.listView)
|
||||||
addApiView('movie.refresh', self.refresh)
|
addApiView('movie.refresh', self.refresh)
|
||||||
|
|
||||||
addApiView('movie.add', self.add)
|
addApiView('movie.add', self.add)
|
||||||
@@ -29,6 +29,7 @@ class MoviePlugin(Plugin):
|
|||||||
addApiView('movie.delete', self.delete)
|
addApiView('movie.delete', self.delete)
|
||||||
|
|
||||||
addEvent('movie.get', self.get)
|
addEvent('movie.get', self.get)
|
||||||
|
addEvent('movie.list', self.list)
|
||||||
|
|
||||||
def get(self, movie_id):
|
def get(self, movie_id):
|
||||||
|
|
||||||
@@ -37,13 +38,11 @@ class MoviePlugin(Plugin):
|
|||||||
|
|
||||||
return m.to_dict(self.default_dict)
|
return m.to_dict(self.default_dict)
|
||||||
|
|
||||||
def list(self):
|
def list(self, status = ['active']):
|
||||||
|
|
||||||
params = getParams()
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
# Make a list from string
|
# Make a list from string
|
||||||
status = params.get('status', ['active'])
|
|
||||||
if not isinstance(status, (list, tuple)):
|
if not isinstance(status, (list, tuple)):
|
||||||
status = [status]
|
status = [status]
|
||||||
|
|
||||||
@@ -54,6 +53,14 @@ class MoviePlugin(Plugin):
|
|||||||
temp = movie.to_dict(self.default_dict)
|
temp = movie.to_dict(self.default_dict)
|
||||||
movies.append(temp)
|
movies.append(temp)
|
||||||
|
|
||||||
|
return movies
|
||||||
|
|
||||||
|
def listView(self):
|
||||||
|
|
||||||
|
params = getParams()
|
||||||
|
status = params.get('status', ['active'])
|
||||||
|
movies = self.list(status)
|
||||||
|
|
||||||
return jsonified({
|
return jsonified({
|
||||||
'success': True,
|
'success': True,
|
||||||
'empty': len(movies) == 0,
|
'empty': len(movies) == 0,
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
from .main import Subtitle
|
||||||
|
|
||||||
|
def start():
|
||||||
|
return Subtitle()
|
||||||
|
|
||||||
|
config = [{
|
||||||
|
'name': 'subtitle',
|
||||||
|
'groups': [
|
||||||
|
{
|
||||||
|
'tab': 'renamer',
|
||||||
|
'name': 'subtitle',
|
||||||
|
'options': [
|
||||||
|
{
|
||||||
|
'name': 'enabled',
|
||||||
|
'label': 'Search and download subtitles',
|
||||||
|
'default': True,
|
||||||
|
'type': 'enabler',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'languages',
|
||||||
|
'description': 'The languages you want to download the sub',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'name': 'automatic',
|
||||||
|
'default': True,
|
||||||
|
'type': 'bool',
|
||||||
|
'description': 'Automaticly search & download for movies in library',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}]
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
from couchpotato import get_session
|
||||||
|
from couchpotato.core.event import addEvent, fireEvent
|
||||||
|
from couchpotato.core.logger import CPLog
|
||||||
|
from couchpotato.core.plugins.base import Plugin
|
||||||
|
from couchpotato.core.settings.model import Library, FileType
|
||||||
|
|
||||||
|
log = CPLog(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class Subtitle(Plugin):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
addEvent('renamer.before', self.searchSingle)
|
||||||
|
|
||||||
|
def searchLibrary(self):
|
||||||
|
|
||||||
|
# Get all active and online movies
|
||||||
|
db = get_session()
|
||||||
|
|
||||||
|
library = db.query(Library).all()
|
||||||
|
done_status = fireEvent('status.get', 'done', single = True)
|
||||||
|
|
||||||
|
for movie in library.movies:
|
||||||
|
|
||||||
|
for release in movie.releases:
|
||||||
|
|
||||||
|
# get releases and their movie files
|
||||||
|
if release.status_id is done_status.get('id'):
|
||||||
|
|
||||||
|
files = []
|
||||||
|
for file in release.files.filter(FileType.status.has(identifier = 'movie')).all():
|
||||||
|
files.append(file.path);
|
||||||
|
|
||||||
|
# get subtitles for those files
|
||||||
|
subtitles = fireEvent('subtitle.search', files = files, languages = self.getLanguages(), merge = True)
|
||||||
|
|
||||||
|
# do something with the returned subtitles
|
||||||
|
print subtitles
|
||||||
|
|
||||||
|
|
||||||
|
def searchSingle(self, group):
|
||||||
|
|
||||||
|
subtitles = fireEvent('subtitle.search', files = group['files']['movie'], languages = self.getLanguages(), merge = True)
|
||||||
|
|
||||||
|
# do something with the returned subtitles
|
||||||
|
print subtitles
|
||||||
|
|
||||||
|
def getLanguages(self):
|
||||||
|
return self.conf('languages').split(',')
|
||||||
@@ -7,8 +7,7 @@ class SubtitleProvider(Provider):
|
|||||||
type = 'subtitle'
|
type = 'subtitle'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
addEvent('subtitle.search', self.search)
|
||||||
addEvent('renamer.before', self.search)
|
|
||||||
|
|
||||||
def search(self, group):
|
def search(self, group):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from .main import Subliminal
|
from .main import SubliminalProvider
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
return Subliminal()
|
return SubliminalProvider()
|
||||||
|
|
||||||
config = []
|
config = []
|
||||||
|
|||||||
@@ -1,8 +1,22 @@
|
|||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.providers.subtitle.base import SubtitleProvider
|
from couchpotato.core.providers.subtitle.base import SubtitleProvider
|
||||||
|
from couchpotato.environment import Env
|
||||||
|
from libs import subliminal
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Subliminal(SubtitleProvider):
|
class SubliminalProvider(SubtitleProvider):
|
||||||
pass
|
|
||||||
|
plugins = ['OpenSubtitles', 'TheSubDB', 'SubsWiki']
|
||||||
|
|
||||||
|
def search(self, files = [], languages = []):
|
||||||
|
|
||||||
|
# download subtitles
|
||||||
|
with subliminal.Subliminal(cache_dir = Env.get('cache_dir'), multi = True,
|
||||||
|
languages = self.getLanguages(), plugins = self.plugins) as subli:
|
||||||
|
subtitles = subli.downloadSubtitles(files)
|
||||||
|
|
||||||
|
print subtitles
|
||||||
|
|
||||||
|
return subtitles
|
||||||
|
|||||||
Reference in New Issue
Block a user