After some database operations you might want to cause the client to automatically refetch certain queries. This is possible using $app.invalidateClientQuery - Helpers
Local files
You can interact with the scanned file entries (also called local files).
Get all
const localFiles = $database.localFiles.getAll()
Edit
// Get all 'One Piece' files
const onePieceLocalFiles = $database
.localFiles.findBy((lf) => {
return lf.mediaId === 21
})
// Lock all 'One piece' files
for (const lf of onePieceLocalFiles) {
lf.locked = true
}
$database.localFiles.save(onePieceLocalFiles)
Note that save only works for existing entries.
Insert
// Inserts a new collection of local files
// This is equivalent to doing a scan
const localFiles = $database.localFiles.insert([
//...
])
AniList
Get Token
anilist-token permission is required
$database.anilist.getToken()
Get Username
$database.anilist.getUsername()
Auto Downloader Rules
// Get all rules
$database.autoDownloaderRules.getAll()
// Get rules by media ID
const rules = $database.autoDownloaderRules.getByMediaId(21)
for (const rule of rules) {
rule.enabled = false
// Update a rule
$database.autoDownloaderRules.update(rule.dbId, rule)
}
// Remove a rule
$database.autoDownloaderRules.remove(ruleDbId)
// Insert a rule
$database.autoDownloaderRules.insert({
//...
})
Auto Downloader Items
In Seanime, an item is usually added by the auto downloader when the user has chosen not to immediately download torrents. It is shown in the queue and lets the user download that torrent later.
// Get all items
$database.autoDownloaderItems.getAll()
// Get items by media ID
const items = $database.autoDownloaderItems.getByMediaId(21)
for (const item of items) {
// Update an item
$database.autoDownloaderItems.update(item.dbId, item)
}
// Remove an item
$database.autoDownloaderItems.remove(itemDbId)
// Insert an item
$database.autoDownloaderItems.insert({
//...
})