Skip to content

Commit

Permalink
New video.subtitles plugin baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
murbaniak committed May 7, 2012
1 parent 35f3d00 commit b8da2f3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 46 deletions.
5 changes: 2 additions & 3 deletions Docs/plugins/subtitles.txt
Expand Up @@ -28,7 +28,6 @@ decompress and save subtitles.
By default the plugin support following subtitle langauges:

English
French
German
Polish

Expand Down Expand Up @@ -96,7 +95,7 @@ of main Subtitles plugin as well as individual handlers (with default values):


If you define SUBS_FORCE_LANG_EXT or SUBS_FORCE_HANDLER_ID make sure
you use -fuzzines command line option with mplayer, so it'll use all
you use sub-fuzziness 1 command line option with mplayer, so it'll use all
locally available subtitles with extended filenames.
If you do not define both of those variables, even if you are presented
with a choice of multiple subfiles available and choose to save them all,
Expand Down Expand Up @@ -138,4 +137,4 @@ in your local_config.py:

# Prevents freevo from using mplayer's show_ext_prop_text to display
# current subs and audio track info on the screen
MPLAYER_DONT_USE_EXT_PROPS = True
MPLAYER_DONT_USE_OSD_SHOW_PROPS = True
12 changes: 12 additions & 0 deletions freevo_config.py
Expand Up @@ -789,6 +789,11 @@
# Use the local file lenght or runtime value from IMDB?
IMDB_USE_IMDB_RUNTIME = False

# add imdb search to the video item menu
plugin.activate('video.subtitles')
SUBS_HANDLERS = [('video.opensubtitles'), ]
SUBS_LANGS = { 'eng': ('English'), }

# delete file in menu
plugin.activate('file_ops', level=20)

Expand Down Expand Up @@ -1696,6 +1701,13 @@
#
MPLAYER_OLDTVCHANNELCHANGE = False

#
# DO not use the osd_show_property_text slave mode command to display current
# subtitle and audio tracks. See Docs/plugins/subtitle.txt for details and
# explanation.
#
MPLAYER_DONT_USE_OSD_SHOW_PROPS = 0

# ======================================================================
# Xine settings:
# ======================================================================
Expand Down
3 changes: 2 additions & 1 deletion src/video/plugins/napiprojekt.py
Expand Up @@ -57,7 +57,6 @@
from md5 import md5

# http://www.joachim-bauch.de/projects/pylzma/
NAPI_URL = "http://napiprojekt.pl/unit_napisy/dl.php?l=%s&f=%s&t=%s&v=other&kolejka=false&nick=&pass=&napios=%s"
NAPI_LANGS = [ 'pol', 'eng' ]

from subtitles import SubsHandler, SubsError, Subtitles
Expand Down Expand Up @@ -105,6 +104,8 @@ def config(self):
'Maps ISO 639-2 lang code to the one used by napiprojekt.pl'),
('NAPI_PWD', 'iBlm8NTigvru0Jr0',
'Password for the compressed file'),
('NAPI_URL' 'http://napiprojekt.pl/unit_napisy/dl.php?l=%s&f=%s&t=%s&v=other&kolejka=false&nick=&pass=&napios=%s',
'Napiprojekt fetch URL'),
]


Expand Down
44 changes: 11 additions & 33 deletions src/video/plugins/opensubtitles.py
Expand Up @@ -6,9 +6,7 @@
#
# Notes: opensubtitles plugin.
# You can donwload subtitles from the http://opensubtitles.org
# OSUBS_LANGS = [ 'eng', 'ger' ...]
# to just use the lang of your choice
# Check out the video.subtitles plugin for more configuration options
# Check out the video.subtitles plugin for configuration options
#
# Todo: none
#
Expand Down Expand Up @@ -57,9 +55,6 @@

# User agent is essential to request opensubtitles
# be sure to update it before any change
OSUBS_USER_AGENT = "OS Test User Agent"
OSUBS_DOMAIN = "http://api.opensubtitles.org/xml-rpc"
OSUBS_LANGS = [ 'pol', 'eng', 'ger', 'fre' ]

class PluginInterface(plugin.Plugin):
"""
Expand All @@ -68,37 +63,22 @@ class PluginInterface(plugin.Plugin):
Activate with:
| plugin.activate('video.napiprojekt')
| plugin.activate('video.opensubtitles')
and make sure the SUBS_AVAILABLE_HANDLERS = [ ('opensubtitles'), ]
is set for the main subtitles plugin to be able to use this plugin.
Even if this plugin is not explicitly activated in the local_config.py, main
video.subtitles plugin will activate it automagically, providing that
SUBS_AVAILABLE_HANDLERS variable is properly initialised with
'video.opensubtitles' plugin name.
SUBS_HANDLERS variable is properly initialised with 'video.opensubtitles'
plugin name.
and of course make sure the main subtitles plugin is activated too:
| plugin.activate('video.subtitles')
Last but not least, by default this plugin supports only Polish,
English, German and French subtitles. If you want other languages,
please set the OSUBS_LANGS variable in your local_config.py so
this plugin recognises additional language codes etc. OSUBS_LANGS define
capability of this plugin!
OpenSubtitles.org supports so many different languages that it's impossible
to list all available language codes here.
See http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes for the codes and
names, and http://opensubtitles.org for supported languages.
Regardless of how many languages this plugin supports, only langauges as
defined in SUBS_LANGS in the main 'video.subtitles' plugin will be
retrieved. Basically, only intersect of these two variables, SUBS_LANGS
and OSUBS_LANGS is retrived. If you are only interested in English
subtitles, declare it in SUBS_LANGS, do not modify OSUBS_LANGS.
If, for example, you are after Italian subtitles, you'd have to extend
OSUBS_LANGS AND add language code and name in SUBS_LANGS.
Uff, hope this is simple enough to follow.
"""

def __init__(self):
Expand All @@ -120,8 +100,10 @@ def __init__(self):
def config(self):
"""returns the config variables used by this plugin"""
return [
('OSUBS_LANGS', [ 'pol', 'eng', 'ger', 'fre' ],
'ISO 639-2 subtitle languages codes this plugin supports'),
(OSUBS_USER_AGENT, 'OS Test User Agent',
'Opensubtitles User Agent String'),
(OSUBS_DOMAIN, 'http://api.opensubtitles.org/xml-rpc',
'Opensubtitles domain'),
]


Expand Down Expand Up @@ -273,12 +255,7 @@ def __init__(self):
self.server = None
self.token = None

try:
langs = config.OSUBS_LANGS
except:
langs = OSUBS_LANGS

SubsHandler.__init__(self, 'os', 'opensubtitles.org', langs)
SubsHandler.__init__(self, 'os', 'opensubtitles.org', [])


def __getitem__(self, key):
Expand All @@ -293,7 +270,8 @@ def __getitem__(self, key):
def get_subs(self, vfile_, langs_):
subs = {}
# based on requested languages, create intersect of capabilites vs. request
langs = filter(lambda x: x in langs_, self.langs)
# langs = filter(lambda x: x in langs_, self.langs)
langs = langs_

hash = self._hash(vfile_)

Expand Down
41 changes: 32 additions & 9 deletions src/video/plugins/subtitles.py
Expand Up @@ -54,7 +54,11 @@
__license__ = 'GPL'

# Module Imports
import logging
logger = logging.getLogger("freevo.video.plugins.subtitles")

import os
import glob
from operator import itemgetter, attrgetter

import menu
Expand Down Expand Up @@ -250,16 +254,22 @@ def __init__(self):
self.subs = {}
self.subfiles = []

_debug_('Available Handlers : %s' % (config.SUBS_AVAILABLE_HANDLERS), DINFO)
try:
handlers = config.SUBS_HANDLERS
except:
self.reason = 'Plugin \'video.subtitles\' activated but SUBS_HANDLERS not defined'
return

logger.info('Available Handlers : %s' % (handlers))

for item in config.SUBS_AVAILABLE_HANDLERS:
for item in handlers:
if not plugin.is_active(item):
_debug_('Plugin %s listed as available but not activated, activating now!' % (item), DWARNING)
logger.warning('Plugin %s listed as available but not activated, activating now!' % (item))
plugin.activate(item)

handler = plugin.getbyname(item)['handler']
self.handlers[handler['id']] = handler
_debug_('Successfuly loaded subtitle handler %s' % (handler.name), DINFO)
logger.info('Successfuly loaded subtitle handler %s' % (handler.name))

plugin.ItemPlugin.__init__(self)

Expand All @@ -271,7 +281,7 @@ def config(self):
return [
('SUBS_LANGS', { 'pol': ('Polish'), 'eng': ('English'), 'ger': ('German') },
'Subtitles to download'),
('SUBS_EXTS', [ 'srt', 'sub', 'txt', 'ssa', 'smi', 'ass', 'mpl'],
('SUBS_EXTS', [ '.srt', '.sub', '.txt', '.ssa', '.smi', '.ass', '.mpl'],
'Known subtitles file extensions'),
('SUBS_AUTOACCEPT', False,
'Autoaccept all found subtitles, language coded filenames'),
Expand Down Expand Up @@ -313,6 +323,22 @@ def check_existing_subs(self, file):
"""
Check if any existing subitle files that match the pattern
"""
return len(self.get_existing_subs(file))


def get_existing_subs(self, file):
"""
Get all existing subitle files that match the pattern
into the collection and return it.
"""
base = os.path.splitext(file)[0]

return [n for n in glob.glob(base + ".*") \
if os.path.splitext(n)[1] in config.SUBS_EXTS]


"""
def check_existing_subs(self, file):
base = os.path.splitext(file)[0]
for ext in config.SUBS_EXTS:
Expand Down Expand Up @@ -342,10 +368,6 @@ def check_existing_subs(self, file):
def get_existing_subs(self, file):
"""
Get all existing subitle files that match the pattern
into the collection and return it.
"""
results = []
base = os.path.splitext(file)[0]
Expand Down Expand Up @@ -374,6 +396,7 @@ def get_existing_subs(self, file):
return results
"""

def subs_search(self, arg=None, menuw=None):
"""
Expand Down

0 comments on commit b8da2f3

Please sign in to comment.