annotate foosdk/sdk/foobar2000/SDK/playlist_loader.h @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
1 #pragma once
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
2
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
3 //! Callback interface receiving item locations from playlist loader. \n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
4 //! Typically, you call one of standard services such as playlist_incoming_item_filter instead of implementing this interface and calling playlist_loader methods directly.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
5 class NOVTABLE playlist_loader_callback : public service_base {
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
6 FB2K_MAKE_SERVICE_INTERFACE(playlist_loader_callback, service_base)
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
7 public:
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
8 //! Enumeration type representing origin of item passed to playlist_loader_callback.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
9 enum t_entry_type {
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
10 //! User-requested (such as directly dropped to window or picked in openfiledialog).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
11 entry_user_requested,
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
12 //! From directory content enumeration.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
13 entry_directory_enumerated,
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
14 //! Referenced by playlist file.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
15 entry_from_playlist,
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
16 };
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
17 //! Indicates specified path being processed; provided for updating GUI. Note that optimally GUI should not be updated every time this is called because that could introduce a bottleneck.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
18 virtual void on_progress(const char * p_path) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
19
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
20 //! Receives an item from one of playlist_loader functions.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
21 //! @param p_item Item location, in form of metadb_handle pointer.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
22 //! @param p_type Origin of this item - see t_entry_type for more info.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
23 //! @param p_stats File stats of this item; set to filestats_invalid if not available.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
24 //! @param p_fresh Fresh flag; indicates whether stats are directly from filesystem (true) or as stored earlier in a playlist file (false).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
25 virtual void on_entry(const metadb_handle_ptr & p_item,t_entry_type p_type,const t_filestats & p_stats,bool p_fresh) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
26 //! Queries whether file_info for specified item is requested. In typical scenario, if want_info() returns false, on_entry() will be called with same parameters; otherwise caller will attempt to read info from the item and call on_entry_info() with same parameters and file_info read from the item.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
27 //! @param p_item Item location, in form of metadb_handle pointer.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
28 //! @param p_type Origin of this item - see t_entry_type for more info.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
29 //! @param p_stats File stats of this item; set to filestats_invalid if not available.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
30 //! @param p_fresh Fresh flag; indicates whether stats are directly from filesystem (true) or as stored earlier in a playlist file (false).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
31 virtual bool want_info(const metadb_handle_ptr & p_item,t_entry_type p_type,const t_filestats & p_stats,bool p_fresh) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
32 //! Receives an item from one of playlist_loader functions; including file_info data. Except for file_info to be typically used as hint for metadb backend, behavior of this method is same as on_entry().
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
33 //! @param p_item Item location, in form of metadb_handle pointer.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
34 //! @param p_type Origin of this item - see t_entry_type for more info.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
35 //! @param p_stats File stats of this item; set to filestats_invalid if not available.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
36 //! @param p_info Information about the item, read from the file directly (if p_fresh is set to true) or from e.g. playlist file (if p_fresh is set to false).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
37 //! @param p_fresh Fresh flag; indicates whether stats are directly from filesystem (true) or as stored earlier in a playlist file (false).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
38 virtual void on_entry_info(const metadb_handle_ptr & p_item,t_entry_type p_type,const t_filestats & p_stats,const file_info & p_info,bool p_fresh) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
39
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
40 //! Same as metadb::handle_create(); provided here to avoid repeated metadb instantiation bottleneck since calling code will need this function often.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
41 virtual void handle_create(metadb_handle_ptr & p_out,const playable_location & p_location) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
42
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
43 //! Returns whether further on_entry() calls for this file are wanted. Typically always returns true, can be used to optimize cases when directories are searched for files matching specific pattern only so unwanted files aren't parsed unnecessarily.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
44 //! @param path Canonical path to the media file being processed.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
45 virtual bool is_path_wanted(const char * path, t_entry_type type) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
46
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
47 virtual bool want_browse_info(const metadb_handle_ptr & p_item,t_entry_type p_type,t_filetimestamp ts) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
48 virtual void on_browse_info(const metadb_handle_ptr & p_item,t_entry_type p_type,const file_info & info, t_filetimestamp ts) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
49 };
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
50
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
51 //! \since 1.3
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
52 //! Extended version of playlist_loader_callback, allowing caller to pass pre-made metadb_info_container \n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
53 class NOVTABLE playlist_loader_callback_v2 : public playlist_loader_callback {
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
54 FB2K_MAKE_SERVICE_INTERFACE(playlist_loader_callback_v2, playlist_loader_callback)
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
55 public:
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
56 virtual void on_entry_info_v2(const metadb_handle_ptr & p_item,t_entry_type p_type,metadb_info_container::ptr info,bool p_fresh) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
57 virtual void on_browse_info_v2(const metadb_handle_ptr & p_item,t_entry_type p_type,metadb_info_container::ptr info) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
58 private:
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
59 };
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
60
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
61
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
62 //! Service handling playlist file operations. There are multiple implementations handling different playlist formats; you can add new implementations to allow new custom playlist file formats to be read or written.\n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
63 //! Also provides static helper functions for turning a filesystem path into a list of playable item locations. \n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
64 //! Note that you should typically call playlist_incoming_item_filter methods instead of calling playlist_loader methods directly to get a list of playable items from a specified path; this way you get a core-implemented threading and abortable dialog displaying progress.\n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
65 //! To register your own implementation, use playlist_loader_factory_t template.\n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
66 //! To call existing implementations, use static helper methods of playlist_loader class.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
67 class NOVTABLE playlist_loader : public service_base {
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
68 public:
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
69 //! Parses specified playlist file into list of playable locations. Throws exception_io or derivatives on failure, exception_aborted on abort. If specified file is not a recognized playlist file, exception_io_unsupported_format is thrown.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
70 //! @param p_path Path of playlist file to parse. Used for relative path handling purposes (p_file parameter is used for actual file access).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
71 //! @param p_file File interface to use for reading. Read/write pointer must be set to beginning by caller before calling.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
72 //! @param p_callback Callback object receiving enumerated playable item locations.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
73 virtual void open(const char * p_path, const service_ptr_t<file> & p_file,playlist_loader_callback::ptr p_callback, abort_callback & p_abort) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
74 //! Writes a playlist file containing specific item list to specified file. Will fail (pfc::exception_not_implemented) if specified playlist_loader is read-only (can_write() returns false).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
75 //! @param p_path Path of playlist file to write. Used for relative path handling purposes (p_file parameter is used for actual file access).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
76 //! @param p_file File interface to use for writing. Caller should ensure that the file is empty (0 bytes long) before calling.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
77 //! @param p_data List of items to save to playlist file.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
78 //! @param p_abort abort_callback object signaling user aborting the operation. Note that aborting a save playlist operation will most likely leave user with corrupted/incomplete file.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
79 virtual void write(const char * p_path, const service_ptr_t<file> & p_file,metadb_handle_list_cref p_data,abort_callback & p_abort) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
80 //! Returns extension of file format handled by this playlist_loader implementation (a UTF-8 encoded null-terminated string).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
81 virtual const char * get_extension() = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
82 //! Returns whether this playlist_loader implementation supports writing. If can_write() returns false, all write() calls will fail.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
83 virtual bool can_write() = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
84 //! Returns whether specified content type is one of playlist types supported by this playlist_loader implementation or not.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
85 //! @param p_content_type Content type to query, a UTF-8 encoded null-terminated string.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
86 virtual bool is_our_content_type(const char* p_content_type) = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
87 //! Returns whether playlist format extension supported by this implementation should be listed on file types associations page.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
88 virtual bool is_associatable() = 0;
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
89
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
90 //! Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives on failure, exception_aborted on abort. If specified file is not a recognized playlist file, exception_io_unsupported_format is thrown. \n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
91 //! Equivalent to g_load_playlist_filehint(NULL,p_path,p_callback).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
92 //! @param p_path Filesystem path to load playlist from, a UTF-8 encoded null-terminated string.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
93 //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
94 static void g_load_playlist(const char * p_path,playlist_loader_callback::ptr p_callback, abort_callback & p_abort);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
95
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
96 //! Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives on failure, exception_aborted on abort. If specified file is not a recognized playlist file, exception_io_unsupported_format is thrown.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
97 //! @param p_path Filesystem path to load playlist from, a UTF-8 encoded null-terminated string.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
98 //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
99 //! @param fileHint File object to read from, can be NULL if not available.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
100 static void g_load_playlist_filehint(file::ptr fileHint,const char * p_path,playlist_loader_callback::ptr p_callback, abort_callback & p_abort);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
101
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
102 //! Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives on failure, exception_aborted on abort. If specified file is not a recognized playlist file, returns false; returns true upon successful playlist load.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
103 //! @param p_path Filesystem path to load playlist from, a UTF-8 encoded null-terminated string.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
104 //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
105 //! @param fileHint File object to read from, can be NULL if not available.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
106 static bool g_try_load_playlist(file::ptr fileHint,const char * p_path,playlist_loader_callback::ptr p_callback, abort_callback & p_abort);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
107
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
108 //! Saves specified list of locations into a playlist file. Throws exception_io or derivatives on failure, exception_aborted on abort.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
109 //! @param p_path Filesystem path to save playlist to, a UTF-8 encoded null-terminated string.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
110 //! @param p_data List of items to save to playlist file.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
111 //! @param p_abort abort_callback object signaling user aborting the operation. Note that aborting a save playlist operation will most likely leave user with corrupted/incomplete file.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
112 static void g_save_playlist(const char * p_path,metadb_handle_list_cref p_data,abort_callback & p_abort);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
113
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
114 //! Processes specified path to generate list of playable items. Includes recursive directory/archive enumeration. \n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
115 //! Does not touch playlist files encountered - use g_process_path_ex() if specified path is possibly a playlist file; playlist files found inside directories or archives are ignored regardless.\n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
116 //! Warning: caller must handle exceptions which will occur in case of I/O failure.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
117 //! @param p_path Filesystem path to process; a UTF-8 encoded null-terminated string.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
118 //! @param p_callback Callback object receiving enumerated playable item locations as well as signaling user aborting the operation.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
119 //! @param p_type Origin of p_path string. Reserved for internal use in recursive calls, should be left at default value; it controls various internal behaviors.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
120 static void g_process_path(const char * p_path,playlist_loader_callback::ptr p_callback, abort_callback & p_abort,playlist_loader_callback::t_entry_type p_type = playlist_loader_callback::entry_user_requested);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
121
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
122 //! Calls attempts to process specified path as a playlist; if that fails (i.e. not a playlist), calls g_process_path with same parameters. See g_process_path for parameter descriptions. \n
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
123 //! Warning: caller must handle exceptions which will occur in case of I/O failure or playlist parsing failure.
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
124 //! @returns True if specified path was processed as a playlist file, false otherwise (relevant in some scenarios where output is sorted after loading, playlist file contents should not be sorted).
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
125 static bool g_process_path_ex(const char * p_path,playlist_loader_callback::ptr p_callback, abort_callback & p_abort,playlist_loader_callback::t_entry_type p_type = playlist_loader_callback::entry_user_requested);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
126
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
127
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
128 static void g_path_to_handles_simple(const char* p_path, pfc::list_base_t<metadb_handle_ptr>& p_out, abort_callback& p_abort);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
129
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
130 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(playlist_loader);
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
131 };
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
132
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
133 template<typename t_myclass>
20d02a178406 *: check in everything else
Paper <paper@tflc.us>
parents:
diff changeset
134 class playlist_loader_factory_t : public service_factory_single_t<t_myclass> {};