Skip to main content
The Shares class manages file sharing functionality, including scanning shared folders, building file indexes, and handling share requests.

Overview

The Shares module is responsible for:
  • Scanning and indexing shared folders
  • Managing shared file databases
  • Handling file search queries
  • Computing share statistics
  • Processing buddy-only shares

Shares Class

Initialization

Core Methods

rescan_shares()

Rescans all shared folders and rebuilds the file index.
bool
default:false
Whether this is an initial scan on startup
bool
default:true
Whether to perform a rescan of shared folders
bool
default:false
Whether to rebuild the entire share database from scratch
bool
default:true
Whether to run the scan in a separate thread
bool
default:false
Force rescan even if shares haven’t changed
Rescanning can take significant time for large share collections. The scan runs in a separate thread by default to avoid blocking.

convert_shares()

Converts shared folder paths to the internal format.
list
required
List of folder paths to convert
str
The virtual name for the shared folder
str
The actual filesystem path

get_shared_folders()

Returns the list of currently shared folders.
list
List of tuples containing (virtual_name, actual_path)

get_compressed_shares_message()

Generates a compressed representation of shared files for sending to peers.
str
required
Type of shares: “normal” or “buddy”
SharedFileList
Compressed file list message ready to send

Search Methods

search_files()

Searches shared files for a given query.
str
required
The search query string
int
default:"50"
Maximum number of results to return
int
default:"0"
Search mode: 0=global, 1=buddy, 2=rooms, 3=user
set
Set of words to exclude from results
list
List of matching files with metadata

file_is_shared()

Checks if a specific file is shared.
str
required
Username requesting the file
str
required
Virtual path of the file
bool
True if file is shared and accessible to the user

Statistics Methods

get_num_shared_folders()

Returns the number of shared folders.

get_num_shared_files()

Returns the total number of shared files.

get_compressed_shares_size()

Returns the size of the compressed shares database.
str
required
Type of shares: “normal” or “buddy”

Share Configuration

Shared Folder Structure

Shared folders are configured as tuples:

Buddy Shares

Buddy-only shares are only accessible to users on your buddy list:

File Attributes

The Shares module automatically extracts metadata from shared files:

Events

The Shares module emits several events during operation:

Complete Example

Best Practices

  • Rescan shares periodically to keep the index up to date
  • Use buddy shares for content you only want to share with trusted users
  • Monitor scan progress for large share collections
  • Handle scan events to update UI progress indicators
  • Cache search results to avoid repeated scans