The filesystem functions modules provide two different methods for exposing TorBox downloads as a virtual filesystem: FUSE (userspace filesystem) and STRM (media player stream files).
FUSE filesystem (fuseFilesystemFunctions.py)
The FUSE implementation creates a virtual filesystem that streams content directly from TorBox on-demand.
VirtualFileSystem class
class VirtualFileSystem:
def __init__(self, files_list)
Builds an in-memory representation of the filesystem structure based on the user’s downloads.
List of download file dictionaries from the database.
Instance methods:
is_dir
Checks if a path is a directory.
True if the path is a directory.
is_file
Checks if a path is a file.
True if the path is a file.
get_file
Retrieves file metadata for a given path.
The file metadata dictionary, or None if not found.
list_dir
Lists the contents of a directory.
A sorted list of filenames/directory names in the directory.
Example:
from functions.fuseFilesystemFunctions import VirtualFileSystem
from functions.appFunctions import getAllUserDownloads
files = getAllUserDownloads()
vfs = VirtualFileSystem(files)
if vfs.is_dir('/movies'):
contents = vfs.list_dir('/movies')
print(f"Movies folder contains: {contents}")
if vfs.is_file('/movies/The Matrix (1999)/The Matrix (1999).mkv'):
file_info = vfs.get_file('/movies/The Matrix (1999)/The Matrix (1999).mkv')
print(f"File size: {file_info['file_size']} bytes")
class TorBoxMediaCenterFuse(Fuse):
def __init__(self, *args, **kwargs)
The main FUSE filesystem implementation that handles all filesystem operations.
Key methods:
getattr
Returns file attributes (size, permissions, timestamps) for a given path.
The path to get attributes for.
A stat object with file attributes, or a negative errno value on error.
readdir
def readdir(self, path, _)
Lists directory contents.
Yields directory entries.
read
def read(self, path, size, offset)
Reads data from a file at the specified offset. Implements block-based caching for efficient streaming.
The file path to read from.
The file content bytes, or a negative errno value on error.
Caching behavior:
- Uses 64MB blocks for efficient downloading
- Caches up to 64 blocks per file (4GB total)
- Implements LRU (Least Recently Used) cache eviction
- Download links are cached for 3 hours
runFuse
Starts the FUSE filesystem server.
This function blocks until the filesystem is unmounted.
Configuration:
- Mounts at the configured
MOUNT_PATH
- Enables
allow_other flag (allows all users to access)
- On Linux, enables
nonempty flag (allows mounting over non-empty directory)
- Runs in foreground mode
Example:
from functions.fuseFilesystemFunctions import runFuse
runFuse() # Blocks until unmounted
unmountFuse
Unmounts the FUSE filesystem.
Exits the process if unmounting fails.
Example:
from functions.fuseFilesystemFunctions import unmountFuse
unmountFuse()
print("Filesystem unmounted")
STRM filesystem (stremFilesystemFunctions.py)
The STRM implementation creates .strm files that media players like Plex, Jellyfin, and Kodi can read to stream content directly.
generateFolderPath
def generateFolderPath(data: dict) -> str | None
Generates the appropriate folder path for a download based on its metadata.
The download file dictionary containing metadata.
The relative folder path, or None if unable to generate.
Folder structure:
- Movies:
{root_folder_name}/
- Series:
{root_folder_name}/{season_folder_name}/
- Raw mode: Uses original path structure
Example:
from functions.stremFilesystemFunctions import generateFolderPath
movie = {
"metadata_mediatype": "movie",
"metadata_rootfoldername": "The Matrix (1999)"
}
path = generateFolderPath(movie)
print(path) # "The Matrix (1999)"
series = {
"metadata_mediatype": "series",
"metadata_rootfoldername": "Breaking Bad (2008)",
"metadata_foldername": "Season 1"
}
path = generateFolderPath(series)
print(path) # "Breaking Bad (2008)/Season 1"
generateStremFile
def generateStremFile(file_path: str, url: str, type: str, file_name: str, download=None)
Creates a .strm file at the specified location containing the download URL.
The relative folder path where the .strm file should be created.
The download URL to write in the .strm file.
The media type: “movie”, “series”, or “anime”.
The base filename (without extension).
The full download object (used in raw mode).
True if the file was created successfully, False otherwise.
Error handling:
- Returns False on FileNotFoundError (likely bad naming scheme)
- Returns False on OSError (likely permission issues)
- Logs all errors
Example:
from functions.stremFilesystemFunctions import generateStremFile
success = generateStremFile(
file_path="The Matrix (1999)",
url="https://example.com/download/matrix.mkv",
type="movie",
file_name="The Matrix (1999)"
)
if success:
print("STRM file created successfully")
runStrm
Creates .strm files for all user downloads and removes stale files for deleted downloads.
This function does not return a value.
Process:
- Fetches all current downloads from the database
- Gets list of existing .strm files
- Creates .strm files for all current downloads
- Removes .strm files for downloads that no longer exist
- Cleans up empty directories
Example:
from functions.stremFilesystemFunctions import runStrm
runStrm()
print("STRM files updated")
unmountStrm
Deletes all .strm files and subdirectories in the mount path for cleanup.
This function does not return a value.
Example:
from functions.stremFilesystemFunctions import unmountStrm
unmountStrm()
print("All STRM files removed")
Constants
LINK_AGE (FUSE)
LINK_AGE = 3 * 60 * 60 # 3 hours
The time in seconds that download links are cached before being refreshed. TorBox download links expire after some time, so this ensures fresh links are obtained periodically.