mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-16 01:03:16 -05:00
1d2e4dc7a8
(db upgrade to v22.00) `scan_kind` identifies the library "scanner" component that created the item and is responsible to keep it up to date (rescan). The library update now supports passing a `scan_kind` to update only the items of one particular "scanner". This allows e. g. to only update the item from the Spotify library or only update the RSS feeds. The OwnTone database is upgraded to v22.00 and the `scan_kind` columns in `files`, `playlists`, `directories` are identified by: 1. Check if item is part of a RSS playlist (podcast RSS feed), they belong to the "rssscanner" 2. Check if item has a Spotify `virtual_path`, they belong to the "spotifyscanner" 3. Remaining items belong to the "filescanner"
245 lines
5.9 KiB
C
245 lines
5.9 KiB
C
/*
|
|
* Copyright (C) 2015 Christian Meffert <christian.meffert@googlemail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#ifndef SRC_LIBRARY_H_
|
|
#define SRC_LIBRARY_H_
|
|
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
#include "commands.h"
|
|
#include "db.h"
|
|
|
|
#define LIBRARY_OK 0
|
|
#define LIBRARY_ERROR -1
|
|
#define LIBRARY_PATH_INVALID -2
|
|
|
|
typedef void (*library_cb)(void *arg);
|
|
|
|
/*
|
|
* Argument to library_callback_schedule()
|
|
*/
|
|
enum library_cb_action
|
|
{
|
|
// Add as new callback
|
|
LIBRARY_CB_ADD,
|
|
// Replace callback if it already exists
|
|
LIBRARY_CB_REPLACE,
|
|
// Replace callback if it already exists, otherwise add as new
|
|
LIBRARY_CB_ADD_OR_REPLACE,
|
|
// Delete a callback
|
|
LIBRARY_CB_DELETE,
|
|
};
|
|
|
|
/*
|
|
* Definition of a library source
|
|
*
|
|
* A library source is responsible for scanning items into the library db.
|
|
*/
|
|
struct library_source
|
|
{
|
|
enum scan_kind scan_kind;
|
|
int disabled;
|
|
|
|
/*
|
|
* Initialize library source (called from the main thread)
|
|
*/
|
|
int (*init)(void);
|
|
|
|
/*
|
|
* Shutdown library source (called from the main thread after
|
|
* terminating the library thread)
|
|
*/
|
|
void (*deinit)(void);
|
|
|
|
/*
|
|
* Run initial scan after startup (called from the library thread)
|
|
*/
|
|
int (*initscan)(void);
|
|
|
|
/*
|
|
* Run rescan (called from the library thread)
|
|
*/
|
|
int (*rescan)(void);
|
|
|
|
/*
|
|
* Run a metadata rescan of library even if files not changed (called from the library thread)
|
|
*/
|
|
int (*metarescan)(void);
|
|
|
|
/*
|
|
* Run a full rescan (purge library entries and rescan) (called from the library thread)
|
|
*/
|
|
int (*fullrescan)(void);
|
|
|
|
/*
|
|
* Add an item to the library
|
|
*/
|
|
int (*item_add)(const char *path);
|
|
|
|
/*
|
|
* Add item to playlist
|
|
*/
|
|
int (*playlist_item_add)(const char *vp_playlist, const char *vp_item);
|
|
|
|
/*
|
|
* Removes the playlist under the given virtual path
|
|
*/
|
|
int (*playlist_remove)(const char *virtual_path);
|
|
|
|
/*
|
|
* Save queue as a new playlist under the given virtual path
|
|
*/
|
|
int (*queue_save)(const char *virtual_path);
|
|
|
|
/*
|
|
* Add item for the given path to the current queue
|
|
*/
|
|
int (*queue_item_add)(const char *path, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id);
|
|
};
|
|
|
|
/* --------------------- Interface towards source backends ----------------- */
|
|
|
|
/*
|
|
* Adds a mfi if mfi->id == 0, otherwise updates.
|
|
*
|
|
* @param mfi Media to save
|
|
* @return 0 if operation succeeded, -1 on failure.
|
|
*/
|
|
int
|
|
library_media_save(struct media_file_info *mfi);
|
|
|
|
/*
|
|
* Adds a playlist if pli->id == 0, otherwise updates.
|
|
*
|
|
* @param pli Playlist to save
|
|
* @return Playlist id if operation succeeded, -1 on failure.
|
|
*/
|
|
int
|
|
library_playlist_save(struct playlist_info *pli);
|
|
|
|
int
|
|
library_directory_save(char *virtual_path, char *path, int disabled, int parent_id, enum scan_kind library_source);
|
|
|
|
/*
|
|
* @param cb Callback to call
|
|
* @param arg Argument to call back with
|
|
* @param timeval How long to wait before calling back
|
|
* @param action (see enum)
|
|
* @return id of the scheduled event, -1 on failure
|
|
*/
|
|
int
|
|
library_callback_schedule(library_cb cb, void *arg, struct timeval *wait, enum library_cb_action action);
|
|
|
|
/*
|
|
* @return true if a running scan should be aborted due to imminent shutdown
|
|
*/
|
|
bool
|
|
library_is_exiting();
|
|
|
|
|
|
/* ------------------------ Library external interface --------------------- */
|
|
|
|
/*
|
|
* Rescan library: find new, remove deleted and update modified tracks and playlists
|
|
* If a "source_name" is given, only tracks / playlists belonging to that source are
|
|
* updated.
|
|
*
|
|
* Update is done asynchronously in the library thread.
|
|
*
|
|
* @param library_source 0 to update everything, one of LIBRARY_SOURCE_xxx to only update specific source
|
|
*/
|
|
void
|
|
library_rescan(enum scan_kind library_source);
|
|
|
|
/*
|
|
* Same as library_rescan but also updates unmodified tracks and playlists
|
|
*/
|
|
void
|
|
library_metarescan(enum scan_kind library_source);
|
|
|
|
/*
|
|
* Wipe library and do a full rescan of all library sources
|
|
*/
|
|
void
|
|
library_fullrescan();
|
|
|
|
/*
|
|
* @return true if scan is running, otherwise false
|
|
*/
|
|
bool
|
|
library_is_scanning();
|
|
|
|
/*
|
|
* @param is_scanning true if scan is running, otherwise false
|
|
*/
|
|
void
|
|
library_set_scanning(bool is_scanning);
|
|
|
|
/*
|
|
* Trigger for sending the DATABASE event
|
|
*
|
|
* Needs to be called, if an update to the database (library tables) occurred. The DATABASE event
|
|
* is emitted with the delay 'library_update_wait'. It is safe to call this function from any thread.
|
|
*/
|
|
void
|
|
library_update_trigger(short update_events);
|
|
|
|
int
|
|
library_playlist_item_add(const char *vp_playlist, const char *vp_item);
|
|
|
|
int
|
|
library_playlist_remove(char *virtual_path);
|
|
|
|
int
|
|
library_playlist_remove_byid(int plid);
|
|
|
|
int
|
|
library_queue_save(char *path);
|
|
|
|
int
|
|
library_queue_item_add(const char *path, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id);
|
|
|
|
int
|
|
library_item_add(const char *path);
|
|
|
|
struct library_source **
|
|
library_sources(void);
|
|
|
|
/*
|
|
* Execute the function 'func' with the given argument 'arg' in the library thread.
|
|
*
|
|
* The pointer passed as argument is freed in the library thread after func returned.
|
|
*
|
|
* @param func The function to be executed
|
|
* @param arg Argument passed to func
|
|
* @return 0 if triggering the function execution succeeded, -1 on failure.
|
|
*/
|
|
int
|
|
library_exec_async(command_function func, void *arg);
|
|
|
|
int
|
|
library_init();
|
|
|
|
void
|
|
library_deinit();
|
|
|
|
|
|
#endif /* SRC_LIBRARY_H_ */
|