1 /*
2  * Copyright (c) 2010, 2011 Ryan Flannery <ryan.flannery@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /*
18  * TODO Maintain an index of the filenames of each meta_info in the db
19  * and provide ability to bin-search against that when loading
20  * playlists from file.  As-is, really large playlists can take a
21  * while.  Also could be used in medialib_scan_dirs when checking if file
22  * already exists in database.  Possibly elsewhere too.
23  */
24 
25 #ifndef MEDIALIB_H
26 #define MEDIALIB_H
27 
28 #include <sys/errno.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 
32 #include <fts.h>
33 #include <limits.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 
37 #include "debug.h"
38 #include "meta_info.h"
39 #include "playlist.h"
40 
41 #include "compat.h"
42 
43 #define MEDIALIB_PLAYLISTS_CHUNK_SIZE  100
44 
45 /* current database file-format version */
46 #define DB_VERSION_MAJOR   2
47 #define DB_VERSION_MINOR   1
48 #define DB_VERSION_OTHER   0
49 
50 typedef struct {
51    /* some locations of where things are loaded/saved */
52    char     *db_file;      /* file containing the database */
53    char     *playlist_dir; /* directory where playlists are stored */
54 
55    /* psuedo-playlists */
56    playlist *library;         /* playlist representing the database */
57    playlist *filter_results;  /* playlist representing results of a filter */
58       /*
59        * NOTE: these also exist as the first two members of the playlists
60        * array below (this makes searching playlists, displaying, etc.
61        * easier)
62        */
63 
64    /* the playlists */
65    playlist **playlists;            /* array of all playlists */
66    int        nplaylists;           /* num playlists in array */
67    int        playlists_capacity;   /* total size of playlists array */
68 
69 } medialib;
70 
71 
72 /* the global medialib object used throughout vitunes */
73 extern medialib mdb;
74 
75 
76 /* load/free the global media library */
77 void medialib_load(const char *db_file, const char *playlist_dir);
78 void medialib_destroy();
79 
80 /* add/remove playlists to/from the global media library */
81 void medialib_playlist_add(playlist *p);
82 void medialib_playlist_remove(int pindex);
83 
84 /* create all the necessary files/directories for vitunes medialib */
85 void medialib_setup_files(const char *vitunes_dir, const char *db_file,
86    const char *playlist_dir);
87 
88 /* load/save the core database from/to disk */
89 void medialib_db_load(const char *db_file);
90 void medialib_db_save(const char *db_file);
91 
92 /* update/add files to the database */
93 void medialib_db_update(bool show_skipped);
94 void medialib_db_scan_dirs(char *dirlist[]);
95 
96 /* debug routine for dumping db contents to stdout */
97 void medialib_db_flush(FILE *f, const char *time_fmt);
98 
99 #endif
100