foobar2000 SDK  2015-08-03
Public Member Functions | Static Public Member Functions
playlist_loaderabstract

#include <playlist_loader.h>

+ Inheritance diagram for playlist_loader:

Public Member Functions

virtual bool can_write ()=0
 
 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT (playlist_loader)
 
virtual const char * get_extension ()=0
 
virtual bool is_associatable ()=0
 
virtual bool is_our_content_type (const char *p_content_type)=0
 
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
 
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
 
- Public Member Functions inherited from service_base
template<typename outPtr_t >
bool cast (outPtr_t &outPtr)
 
virtual int service_add_ref ()=0 throw ()
 
virtual bool service_query (service_ptr_t< service_base > &p_out, const GUID &p_guid)
 
template<class T >
bool service_query_t (service_ptr_t< T > &p_out)
 
virtual int service_release ()=0 throw ()
 

Static Public Member Functions

static void g_load_playlist (const char *p_path, playlist_loader_callback::ptr p_callback, abort_callback &p_abort)
 
static void g_load_playlist_filehint (file::ptr fileHint, const char *p_path, playlist_loader_callback::ptr p_callback, abort_callback &p_abort)
 
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)
 
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)
 
static void g_save_playlist (const char *p_path, metadb_handle_list_cref p_data, abort_callback &p_abort)
 
static bool g_try_load_playlist (file::ptr fileHint, const char *p_path, playlist_loader_callback::ptr p_callback, abort_callback &p_abort)
 

Additional Inherited Members

- Public Types inherited from service_base
typedef service_base t_interface
 
- Protected Member Functions inherited from service_base
 service_base ()
 
 ~service_base ()
 

Detailed Description

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.
Also provides static helper functions for turning a filesystem path into a list of playable item locations.
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.
To register your own implementation, use playlist_loader_factory_t template.
To call existing implementations, use static helper methods of playlist_loader class.

Definition at line 66 of file playlist_loader.h.

Member Function Documentation

virtual bool playlist_loader::can_write ( )
pure virtual

Returns whether this playlist_loader implementation supports writing. If can_write() returns false, all write() calls will fail.

playlist_loader::FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT ( playlist_loader  )
void playlist_loader::g_load_playlist ( const char *  p_path,
playlist_loader_callback::ptr  p_callback,
abort_callback p_abort 
)
static

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.
Equivalent to g_load_playlist_filehint(NULL,p_path,p_callback).

Parameters
p_pathFilesystem path to load playlist from, a UTF-8 encoded null-terminated string.
p_callbackCallback object receiving enumerated playable item locations as well as signaling user aborting the operation.

Definition at line 84 of file playlist_loader.cpp.

84  {
85  g_load_playlist_filehint(NULL,p_path,callback,abort);
86 }
static void g_load_playlist_filehint(file::ptr fileHint, const char *p_path, playlist_loader_callback::ptr p_callback, abort_callback &p_abort)
Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives o...
void playlist_loader::g_load_playlist_filehint ( file::ptr  fileHint,
const char *  p_path,
playlist_loader_callback::ptr  p_callback,
abort_callback p_abort 
)
static

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.

Parameters
p_pathFilesystem path to load playlist from, a UTF-8 encoded null-terminated string.
p_callbackCallback object receiving enumerated playable item locations as well as signaling user aborting the operation.
fileHintFile object to read from, can be NULL if not available.

Definition at line 80 of file playlist_loader.cpp.

80  {
81  if (!g_try_load_playlist(fileHint, p_path, p_callback, p_abort)) throw exception_io_unsupported_format();
82 }
static bool g_try_load_playlist(file::ptr fileHint, const char *p_path, playlist_loader_callback::ptr p_callback, abort_callback &p_abort)
Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives o...
void playlist_loader::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 
)
static

Processes specified path to generate list of playable items. Includes recursive directory/archive enumeration.
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.
Warning: caller must handle exceptions which will occur in case of I/O failure.

Parameters
p_pathFilesystem path to process; a UTF-8 encoded null-terminated string.
p_callbackCallback object receiving enumerated playable item locations as well as signaling user aborting the operation.
p_typeOrigin of p_path string. Reserved for internal use in recursive calls, should be left at default value; it controls various internal behaviors.

Definition at line 270 of file playlist_loader.cpp.

271 {
272  TRACK_CALL_TEXT("playlist_loader::g_process_path");
273 
274  file_path_canonical filename(p_filename);
275 
276  process_path_internal(filename,0,callback,abort, type,filestats_invalid);
277 }
static const t_filestats filestats_invalid
Invalid/unknown file stats constant. See: t_filestats.
Definition: filesystem.h:80
static void process_path_internal(const char *p_path, const service_ptr_t< file > &p_reader, playlist_loader_callback::ptr callback, abort_callback &abort, playlist_loader_callback::t_entry_type type, const t_filestats &p_stats)
bool playlist_loader::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 
)
static

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.
Warning: caller must handle exceptions which will occur in case of I/O failure or playlist parsing failure.

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).

Definition at line 308 of file playlist_loader.cpp.

309 {
310  if (g_try_load_playlist(NULL, filename, callback, abort)) return true;
311  //not a playlist format
312  g_process_path(filename,callback,abort,type);
313  return false;
314 }
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)
Processes specified path to generate list of playable items. Includes recursive directory/archive enu...
static bool g_try_load_playlist(file::ptr fileHint, const char *p_path, playlist_loader_callback::ptr p_callback, abort_callback &p_abort)
Attempts to load a playlist file from specified filesystem path. Throws exception_io or derivatives o...
void playlist_loader::g_save_playlist ( const char *  p_path,
metadb_handle_list_cref  p_data,
abort_callback p_abort 
)
static

Saves specified list of locations into a playlist file. Throws exception_io or derivatives on failure, exception_aborted on abort.

Parameters
p_pathFilesystem path to save playlist to, a UTF-8 encoded null-terminated string.
p_dataList of items to save to playlist file.
p_abortabort_callback object signaling user aborting the operation. Note that aborting a save playlist operation will most likely leave user with corrupted/incomplete file.

Definition at line 279 of file playlist_loader.cpp.

280 {
281  TRACK_CALL_TEXT("playlist_loader::g_save_playlist");
282  pfc::string8 filename;
283  filesystem::g_get_canonical_path(p_filename,filename);
284  try {
286  filesystem::g_open(r,filename,filesystem::open_mode_write_new,p_abort);
287 
288  pfc::string_extension ext(filename);
289 
292  if (e.first(l)) do {
293  if (l->can_write() && !stricmp_utf8(ext,l->get_extension())) {
294  try {
295  TRACK_CODE("playlist_loader::write",l->write(filename,r,data,p_abort));
296  return;
297  } catch(exception_io_data) {}
298  }
299  } while(e.next(l));
300  throw exception_io_data();
301  } catch(...) {
302  try {filesystem::g_remove(filename,p_abort);} catch(...) {}
303  throw;
304  }
305 }
bool first(service_ptr_t< t_query > &p_out)
Definition: service.h:581
int SHARED_EXPORT stricmp_utf8(const char *p1, const char *p2)
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
bool playlist_loader::g_try_load_playlist ( file::ptr  fileHint,
const char *  p_path,
playlist_loader_callback::ptr  p_callback,
abort_callback p_abort 
)
static

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.

Parameters
p_pathFilesystem path to load playlist from, a UTF-8 encoded null-terminated string.
p_callbackCallback object receiving enumerated playable item locations as well as signaling user aborting the operation.
fileHintFile object to read from, can be NULL if not available.

Definition at line 23 of file playlist_loader.cpp.

23  {
24  pfc::string8 filepath;
25 
26  filesystem::g_get_canonical_path(p_path,filepath);
27 
28  pfc::string_extension extension(filepath);
29 
30  service_ptr_t<file> l_file = fileHint;
31 
32  if (l_file.is_empty()) {
33  filesystem::ptr fs;
34  if (filesystem::g_get_interface(fs,filepath)) {
35  if (fs->supports_content_types()) {
36  fs->open(l_file,filepath,filesystem::open_mode_read,p_abort);
37  }
38  }
39  }
40 
41  {
43 
44  if (l_file.is_valid()) {
45  pfc::string8 content_type;
46  if (l_file->get_content_type(content_type)) {
48  e.reset(); while(e.next(l)) {
49  if (l->is_our_content_type(content_type)) {
50  try {
51  TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback, p_abort));
52  return true;
53  } catch(exception_io_unsupported_format) {
54  l_file->reopen(p_abort);
55  }
56  }
57  }
58  }
59  }
60 
61  if (extension.length()>0) {
62  playlist_loader::ptr l;
63  e.reset(); while(e.next(l)) {
64  if (stricmp_utf8(l->get_extension(),extension) == 0) {
65  if (l_file.is_empty()) filesystem::g_open_read(l_file,filepath,p_abort);
66  try {
67  TRACK_CODE("playlist_loader::open",l->open(filepath,l_file,p_callback,p_abort));
68  return true;
69  } catch(exception_io_unsupported_format) {
70  l_file->reopen(p_abort);
71  }
72  }
73  }
74  }
75  }
76 
77  return false;
78 }
void reset()
Definition: service.h:578
bool is_empty() const
Definition: service.h:120
int SHARED_EXPORT stricmp_utf8(const char *p1, const char *p2)
bool is_valid() const
Definition: service.h:119
bool next(service_ptr_t< t_query > &p_out)
Definition: service.h:587
virtual const char* playlist_loader::get_extension ( )
pure virtual

Returns extension of file format handled by this playlist_loader implementation (a UTF-8 encoded null-terminated string).

virtual bool playlist_loader::is_associatable ( )
pure virtual

Returns whether playlist format extension supported by this implementation should be listed on file types associations page.

virtual bool playlist_loader::is_our_content_type ( const char *  p_content_type)
pure virtual

Returns whether specified content type is one of playlist types supported by this playlist_loader implementation or not.

Parameters
p_content_typeContent type to query, a UTF-8 encoded null-terminated string.
virtual void playlist_loader::open ( const char *  p_path,
const service_ptr_t< file > &  p_file,
playlist_loader_callback::ptr  p_callback,
abort_callback p_abort 
)
pure virtual

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.

Parameters
p_pathPath of playlist file to parse. Used for relative path handling purposes (p_file parameter is used for actual file access).
p_fileFile interface to use for reading. Read/write pointer must be set to beginning by caller before calling.
p_callbackCallback object receiving enumerated playable item locations.
virtual void playlist_loader::write ( const char *  p_path,
const service_ptr_t< file > &  p_file,
metadb_handle_list_cref  p_data,
abort_callback p_abort 
)
pure virtual

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).

Parameters
p_pathPath of playlist file to write. Used for relative path handling purposes (p_file parameter is used for actual file access).
p_fileFile interface to use for writing. Caller should ensure that the file is empty (0 bytes long) before calling.
p_dataList of items to save to playlist file.
p_abortabort_callback object signaling user aborting the operation. Note that aborting a save playlist operation will most likely leave user with corrupted/incomplete file.

The documentation for this class was generated from the following files: