Skip to content

Commit

Permalink
Add Embedded Subtitles mergerfs mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko98 committed Jan 24, 2022
1 parent dc6bd1f commit 4c15a50
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bazarr/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def get(self, section, option, raw=False, vars=None):
'embeddedsubtitles': {
'include_ass': 'True',
'include_srt': 'True',
'hi_fallback': 'False'
'hi_fallback': 'False',
'mergerfs_mode': 'False'
},
'subsync': {
'use_subsync': 'False',
Expand Down
1 change: 1 addition & 0 deletions bazarr/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def get_providers_auth():
'include_ass': settings.embeddedsubtitles.getboolean('include_ass'),
'include_srt': settings.embeddedsubtitles.getboolean('include_srt'),
'hi_fallback': settings.embeddedsubtitles.getboolean('hi_fallback'),
'mergerfs_mode': settings.embeddedsubtitles.getboolean('mergerfs_mode'),
'cache_dir': os.path.join(args.config_dir, "cache"),
'ffprobe_path': _FFPROBE_BINARY,
'ffmpeg_path': _FFMPEG_BINARY,
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/Settings/Providers/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const ProviderList: Readonly<ProviderInfo[]> = [
include_srt: true,
include_ass: true,
hi_fallback: false,
mergerfs_mode: false,
},
message:
"Warning for cloud users: this provider needs to read the entire file in order to extract subtitles.",
Expand All @@ -72,6 +73,8 @@ export const ProviderList: Readonly<ProviderInfo[]> = [
include_ass: "Include ASS (will be converted to SRT)",
hi_fallback:
"Use HI subtitles as a fallback (don't enable it if you have a HI language profile)",
mergerfs_mode:
"[EXPERIMENTAL] Ignore cloud video files from rclone/mergerfs",
},
},
{
Expand Down
35 changes: 33 additions & 2 deletions libs/subliminal_patch/providers/embeddedsubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __init__(
ffprobe_path=None,
ffmpeg_path=None,
hi_fallback=False,
mergerfs_mode=False,
):
self._include_ass = include_ass
self._include_srt = include_srt
Expand All @@ -86,6 +87,7 @@ def __init__(
)
self._hi_fallback = hi_fallback
self._cached_paths = {}
self._mergerfs_mode = mergerfs_mode

fese.FFPROBE_PATH = ffprobe_path or fese.FFPROBE_PATH
fese.FFMPEG_PATH = ffmpeg_path or fese.FFMPEG_PATH
Expand Down Expand Up @@ -163,8 +165,8 @@ def query(self, path: str, languages, media_type):
]

def list_subtitles(self, video, languages):
if not os.path.isfile(video.original_path):
logger.debug("Ignoring inexistent file: %s", video.original_path)
if not self._is_path_valid(video.original_path):
logger.debug("Ignoring video: %s", video)
return []

return self.query(
Expand Down Expand Up @@ -207,6 +209,21 @@ def _get_subtitle_path(self, subtitle: EmbeddedSubtitle):

return new_subtitle_path

def _is_path_valid(self, path):
if path in self._blacklist:
logger.debug("Blacklisted path: %s", path)
return False

if not os.path.isfile(path):
logger.debug("Inexistent file: %s", path)
return False

if self._mergerfs_mode and _is_fuse_rclone_mount(path):
logger.debug("Potential cloud file: %s", path)
return False

return True


class _MemoizedFFprobeVideoContainer(FFprobeVideoContainer):
@functools.lru_cache
Expand Down Expand Up @@ -240,3 +257,17 @@ def _check_hi_fallback(streams, languages):

else:
logger.debug("HI fallback not needed: %s", compatible_streams)


def _is_fuse_rclone_mount(path: str):
# Experimental!

# This function only makes sense if you are combining a rclone mount with a local mount
# with mergerfs or similar tools. Don't use it otherwise.

# It tries to guess whether a file is a cloud mount by the length
# of the inode number. See the following links for reference.

# https://forum.rclone.org/t/fuse-inode-number-aufs/215/5
# https://pkg.go.dev/bazil.org/fuse/fs?utm_source=godoc#GenerateDynamicInode
return len(str(os.stat(path).st_ino)) > 18

0 comments on commit 4c15a50

Please sign in to comment.