libvalhalla
2.1.0
|
00001 /* 00002 * GeeXboX Valhalla: tiny media scanner API. 00003 * Copyright (C) 2009-2011 Mathieu Schroeter <mathieu@schroetersa.ch> 00004 * 00005 * This file is part of libvalhalla. 00006 * 00007 * libvalhalla is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * libvalhalla is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with libvalhalla; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #ifndef VALHALLA_H 00023 #define VALHALLA_H 00024 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif /* __cplusplus */ 00034 00035 #define VH_STRINGIFY(s) #s 00036 #define VH_TOSTRING(s) VH_STRINGIFY(s) 00037 00038 #define VH_VERSION_INT(a, b, c) (a << 16 | b << 8 | c) 00039 #define VH_VERSION_DOT(a, b, c) a ##.## b ##.## c 00040 #define VH_VERSION(a, b, c) VH_VERSION_DOT(a, b, c) 00041 00042 #define LIBVALHALLA_VERSION_MAJOR 2 00043 #define LIBVALHALLA_VERSION_MINOR 1 00044 #define LIBVALHALLA_VERSION_MICRO 0 00045 00046 #define LIBVALHALLA_DB_VERSION 2 00047 00048 #define LIBVALHALLA_VERSION_INT VH_VERSION_INT(LIBVALHALLA_VERSION_MAJOR, \ 00049 LIBVALHALLA_VERSION_MINOR, \ 00050 LIBVALHALLA_VERSION_MICRO) 00051 #define LIBVALHALLA_VERSION VH_VERSION(LIBVALHALLA_VERSION_MAJOR, \ 00052 LIBVALHALLA_VERSION_MINOR, \ 00053 LIBVALHALLA_VERSION_MICRO) 00054 #define LIBVALHALLA_VERSION_STR VH_TOSTRING(LIBVALHALLA_VERSION) 00055 #define LIBVALHALLA_BUILD LIBVALHALLA_VERSION_INT 00056 00057 #include <inttypes.h> 00058 #include <stdarg.h> 00059 00063 unsigned int libvalhalla_version (void); 00064 00066 typedef enum valhalla_lang { 00067 VALHALLA_LANG_ALL = -1, 00068 VALHALLA_LANG_UNDEF = 0, 00069 VALHALLA_LANG_DE, 00070 VALHALLA_LANG_EN, 00071 VALHALLA_LANG_ES, 00072 VALHALLA_LANG_FR, 00073 VALHALLA_LANG_IT, 00074 } valhalla_lang_t; 00075 00076 typedef enum valhalla_file_type { 00077 VALHALLA_FILE_TYPE_NULL = 0, 00078 VALHALLA_FILE_TYPE_AUDIO, 00079 VALHALLA_FILE_TYPE_IMAGE, 00080 VALHALLA_FILE_TYPE_PLAYLIST, 00081 VALHALLA_FILE_TYPE_VIDEO, 00082 } valhalla_file_type_t; 00083 00085 typedef enum valhalla_meta_grp { 00089 VALHALLA_META_GRP_NIL = 0, 00090 00095 VALHALLA_META_GRP_CLASSIFICATION, 00096 00101 VALHALLA_META_GRP_COMMERCIAL, 00102 00106 VALHALLA_META_GRP_CONTACT, 00107 00114 VALHALLA_META_GRP_ENTITIES, 00115 00119 VALHALLA_META_GRP_IDENTIFIER, 00120 00124 VALHALLA_META_GRP_LEGAL, 00125 00129 VALHALLA_META_GRP_MISCELLANEOUS, 00130 00134 VALHALLA_META_GRP_MUSICAL, 00135 00140 VALHALLA_META_GRP_ORGANIZATIONAL, 00141 00145 VALHALLA_META_GRP_PERSONAL, 00146 00150 VALHALLA_META_GRP_SPACIAL, 00151 00155 VALHALLA_META_GRP_TECHNICAL, 00156 00161 VALHALLA_META_GRP_TEMPORAL, 00162 00166 VALHALLA_META_GRP_TITLES, 00167 00168 } valhalla_meta_grp_t; 00169 00175 /* Classification */ 00176 #define VALHALLA_METADATA_CATEGORY "category" 00177 #define VALHALLA_METADATA_EPISODE "episode" 00178 #define VALHALLA_METADATA_GENRE "genre" 00179 #define VALHALLA_METADATA_MPAA "mpaa" 00180 #define VALHALLA_METADATA_RUNTIME "runtime" 00181 #define VALHALLA_METADATA_SEASON "season" 00182 #define VALHALLA_METADATA_SYNOPSIS "synopsis" 00183 #define VALHALLA_METADATA_SYNOPSIS_SHOW "synopsis_show" 00184 00185 /* Commercial */ 00186 #define VALHALLA_METADATA_BUDGET "budget" 00187 #define VALHALLA_METADATA_COUNTRY "country" 00188 #define VALHALLA_METADATA_REVENUE "revenue" 00189 #define VALHALLA_METADATA_STUDIO "studio" 00190 00191 /* Entities */ 00192 #define VALHALLA_METADATA_ACTOR "actor" 00193 #define VALHALLA_METADATA_ARTIST "artist" 00194 #define VALHALLA_METADATA_AUTHOR "author" 00195 #define VALHALLA_METADATA_CASTING "casting" 00196 #define VALHALLA_METADATA_COMPOSER "composer" 00197 #define VALHALLA_METADATA_CREDITS "credits" 00198 #define VALHALLA_METADATA_DIRECTOR "director" 00199 #define VALHALLA_METADATA_DIRECTOR_PHOTO "director_photo" 00200 #define VALHALLA_METADATA_EDITOR "editor" 00201 #define VALHALLA_METADATA_PRODUCER "producer" 00202 #define VALHALLA_METADATA_WRITER "writer" 00203 00204 /* Miscellaneous */ 00205 #define VALHALLA_METADATA_COVER "cover" 00206 #define VALHALLA_METADATA_COVER_SEASON "cover_season" 00207 #define VALHALLA_METADATA_COVER_SHOW "cover_show" 00208 #define VALHALLA_METADATA_COVER_SHOW_HEADER "cover_show_header" 00209 #define VALHALLA_METADATA_FAN_ART "fanart" 00210 #define VALHALLA_METADATA_LYRICS "lyrics" 00211 #define VALHALLA_METADATA_THUMBNAIL "thumbnail" 00212 00213 /* Organizational */ 00214 #define VALHALLA_METADATA_TRACK "track" 00215 00216 /* Personal */ 00217 #define VALHALLA_METADATA_PLAY_COUNT "playcount" 00218 #define VALHALLA_METADATA_RATING "rating" 00219 #define VALHALLA_METADATA_WATCHED "watched" 00220 00221 /* Technical */ 00222 #define VALHALLA_METADATA_AUDIO_BITRATE "audio_bitrate" 00223 #define VALHALLA_METADATA_AUDIO_CHANNELS "audio_channels" 00224 #define VALHALLA_METADATA_AUDIO_CODEC "audio_codec" 00225 #define VALHALLA_METADATA_AUDIO_LANG "audio_lang" 00226 #define VALHALLA_METADATA_AUDIO_STREAMS "audio_streams" 00227 #define VALHALLA_METADATA_DURATION "duration" 00228 #define VALHALLA_METADATA_FILESIZE "filesize" 00229 #define VALHALLA_METADATA_HEIGHT "height" 00230 #define VALHALLA_METADATA_PICTURE_ORIENTATION "picture_orientation" 00231 #define VALHALLA_METADATA_SUB_LANG "sub_lang" 00232 #define VALHALLA_METADATA_SUB_STREAMS "sub_streams" 00233 #define VALHALLA_METADATA_VIDEO_ASPECT "video_aspect" 00234 #define VALHALLA_METADATA_VIDEO_BITRATE "video_bitrate" 00235 #define VALHALLA_METADATA_VIDEO_CODEC "video_codec" 00236 #define VALHALLA_METADATA_VIDEO_STREAMS "video_streams" 00237 #define VALHALLA_METADATA_WIDTH "width" 00238 00239 /* Temporal */ 00240 #define VALHALLA_METADATA_DATE "date" 00241 #define VALHALLA_METADATA_PREMIERED "premiered" 00242 #define VALHALLA_METADATA_YEAR "year" 00243 00244 /* Titles */ 00245 #define VALHALLA_METADATA_ALBUM "album" 00246 #define VALHALLA_METADATA_TITLE "title" 00247 #define VALHALLA_METADATA_TITLE_ALTERNATIVE "title_alternative" 00248 #define VALHALLA_METADATA_TITLE_SHOW "title_show" 00249 #define VALHALLA_METADATA_TITLE_STREAM "title_stream" 00250 00255 /******************************************************************************/ 00256 /* */ 00257 /* Valhalla Handling */ 00258 /* */ 00259 /******************************************************************************/ 00260 00262 typedef struct valhalla_s valhalla_t; 00263 00265 enum valhalla_errno { 00266 VALHALLA_ERROR_DEAD = -4, 00267 VALHALLA_ERROR_PATH = -3, 00268 VALHALLA_ERROR_HANDLER = -2, 00269 VALHALLA_ERROR_THREAD = -1, 00270 VALHALLA_SUCCESS = 0, 00271 }; 00272 00274 typedef enum valhalla_verb { 00275 VALHALLA_MSG_NONE, 00276 VALHALLA_MSG_VERBOSE, 00277 VALHALLA_MSG_INFO, 00278 VALHALLA_MSG_WARNING, 00279 VALHALLA_MSG_ERROR, 00280 VALHALLA_MSG_CRITICAL, 00281 } valhalla_verb_t; 00282 00284 typedef enum valhalla_dl { 00285 VALHALLA_DL_DEFAULT = 0, 00286 VALHALLA_DL_COVER, 00287 VALHALLA_DL_THUMBNAIL, 00288 VALHALLA_DL_FAN_ART, 00289 VALHALLA_DL_LAST 00290 } valhalla_dl_t; 00291 00293 typedef enum valhalla_event_od { 00294 VALHALLA_EVENTOD_PARSED = 0, 00295 VALHALLA_EVENTOD_GRABBED, 00296 VALHALLA_EVENTOD_ENDED, 00297 } valhalla_event_od_t; 00298 00300 typedef enum valhalla_event_gl { 00301 VALHALLA_EVENTGL_SCANNER_BEGIN = 0, 00302 VALHALLA_EVENTGL_SCANNER_END, 00303 VALHALLA_EVENTGL_SCANNER_SLEEP, 00304 VALHALLA_EVENTGL_SCANNER_ACKS, 00305 VALHALLA_EVENTGL_SCANNER_EXIT, 00306 } valhalla_event_gl_t; 00307 00309 typedef enum valhalla_event_md { 00310 VALHALLA_EVENTMD_PARSER = 0, 00311 VALHALLA_EVENTMD_GRABBER, 00312 } valhalla_event_md_t; 00313 00315 typedef enum valhalla_stats_type { 00316 VALHALLA_STATS_TIMER = 0, 00317 VALHALLA_STATS_COUNTER, 00318 } valhalla_stats_type_t; 00319 00325 typedef enum valhalla_metadata_pl { 00326 VALHALLA_METADATA_PL_HIGHEST = -128, 00327 VALHALLA_METADATA_PL_HIGHER = -96, 00328 VALHALLA_METADATA_PL_HIGH = -64, 00329 VALHALLA_METADATA_PL_ABOVE = -32, 00330 VALHALLA_METADATA_PL_NORMAL = 0, 00331 VALHALLA_METADATA_PL_BELOW = 32, 00332 VALHALLA_METADATA_PL_LOW = 64, 00333 VALHALLA_METADATA_PL_LOWER = 96, 00334 VALHALLA_METADATA_PL_LOWEST = 128, 00335 } valhalla_metadata_pl_t; 00336 00338 typedef struct valhalla_metadata_s { 00339 const char *name; 00340 const char *value; 00341 valhalla_meta_grp_t group; 00342 valhalla_lang_t lang; 00343 } valhalla_metadata_t; 00344 00346 typedef struct valhalla_file_s { 00347 const char *path; 00348 int64_t mtime; 00349 int64_t size; 00350 valhalla_file_type_t type; 00351 } valhalla_file_t; 00352 00353 #define VH_CFG_RANGE 8 00355 #define VH_VOID_T (0 << VH_CFG_RANGE) 00356 #define VH_VOIDP_T (1 << VH_CFG_RANGE) 00357 #define VH_INT_T (2 << VH_CFG_RANGE) 00358 #define VH_VOIDP_2_T (4 << VH_CFG_RANGE) 00361 #define VH_CFG_INIT(name, type, num) VALHALLA_CFG_##name = ((type) + (num)) 00362 00383 typedef enum valhalla_cfg { 00394 VH_CFG_INIT (DOWNLOADER_DEST, VH_VOIDP_T | VH_INT_T, 2), 00395 00414 VH_CFG_INIT (GRABBER_PRIORITY, VH_VOIDP_T | VH_INT_T | VH_VOIDP_2_T, 0), 00415 00425 VH_CFG_INIT (GRABBER_STATE, VH_VOIDP_T | VH_INT_T, 0), 00426 00466 VH_CFG_INIT (PARSER_KEYWORD, VH_VOIDP_T, 0), 00467 00477 VH_CFG_INIT (SCANNER_PATH, VH_VOIDP_T | VH_INT_T, 1), 00478 00490 VH_CFG_INIT (SCANNER_SUFFIX, VH_VOIDP_T, 1), 00491 00492 } valhalla_cfg_t; 00493 00495 typedef struct valhalla_init_param_s { 00500 unsigned int parser_nb; 00510 unsigned int grabber_nb; 00516 unsigned int commit_int; 00524 unsigned int decrapifier : 1; 00529 unsigned int od_meta : 1; 00530 00542 void (*od_cb) (const char *file, valhalla_event_od_t e, 00543 const char *id, void *data); 00545 void *od_data; 00546 00551 void (*gl_cb) (valhalla_event_gl_t e, void *data); 00553 void *gl_data; 00554 00565 void (*md_cb) (valhalla_event_md_t e, const char *id, 00566 const valhalla_file_t *file, 00567 const valhalla_metadata_t *md, void *data); 00569 void *md_data; 00570 00571 } valhalla_init_param_t; 00572 00579 /* This function must not be used directly; refer to valhalla_config_set(). */ 00580 int valhalla_config_set_orig (valhalla_t *handle, valhalla_cfg_t conf, ...); 00605 #define valhalla_config_set(handle, conf, arg...) \ 00606 valhalla_config_set_orig (handle, VALHALLA_CFG_##conf, ##arg, ~0) 00607 00625 valhalla_t *valhalla_init (const char *db, valhalla_init_param_t *param); 00626 00635 void valhalla_uninit (valhalla_t *handle); 00636 00645 void valhalla_verbosity (valhalla_verb_t level); 00646 00656 const char *valhalla_metadata_group_str (valhalla_meta_grp_t group); 00657 00670 const char *valhalla_grabber_next (valhalla_t *handle, const char *id); 00671 00692 valhalla_metadata_pl_t valhalla_grabber_priority_read (valhalla_t *handle, 00693 const char *id, 00694 const char **meta); 00695 00707 const char *valhalla_stats_group_next (valhalla_t *handle, const char *id); 00708 00723 uint64_t valhalla_stats_read_next (valhalla_t *handle, const char *id, 00724 valhalla_stats_type_t type, 00725 const char **item); 00726 00746 int valhalla_run (valhalla_t *handle, 00747 int loop, uint16_t timeout, uint16_t delay, int priority); 00748 00764 void valhalla_wait (valhalla_t *handle); 00765 00777 void valhalla_scanner_wakeup (valhalla_t *handle); 00778 00790 void valhalla_ondemand (valhalla_t *handle, const char *file); 00791 00805 const char *valhalla_ondemand_cb_meta (valhalla_t *handle, const char *meta); 00806 00811 /******************************************************************************/ 00812 /* */ 00813 /* Database Selections */ 00814 /* */ 00815 /******************************************************************************/ 00816 00818 typedef struct valhalla_db_stmt_s valhalla_db_stmt_t; 00819 00821 typedef enum valhalla_db_type { 00822 VALHALLA_DB_TYPE_ID, 00823 VALHALLA_DB_TYPE_TEXT, 00824 VALHALLA_DB_TYPE_GROUP, 00825 } valhalla_db_type_t; 00826 00828 typedef enum valhalla_db_operator { 00829 VALHALLA_DB_OPERATOR_IN, 00830 VALHALLA_DB_OPERATOR_NOTIN, 00831 VALHALLA_DB_OPERATOR_EQUAL, 00832 } valhalla_db_operator_t; 00833 00835 typedef struct valhalla_db_item_s { 00836 valhalla_db_type_t type; 00837 int64_t id; 00838 const char *text; 00839 valhalla_meta_grp_t group; 00840 valhalla_lang_t lang; 00841 valhalla_metadata_pl_t priority; 00842 } valhalla_db_item_t; 00843 00845 typedef struct valhalla_db_metares_s { 00846 int64_t meta_id, data_id; 00847 const char *meta_name, *data_value; 00848 valhalla_meta_grp_t group; 00849 valhalla_lang_t lang; 00850 int external; 00851 } valhalla_db_metares_t; 00852 00854 typedef struct valhalla_db_fileres_s { 00855 int64_t id; 00856 const char *path; 00857 valhalla_file_type_t type; 00858 } valhalla_db_fileres_t; 00859 00861 typedef struct valhalla_db_restrict_s { 00862 struct valhalla_db_restrict_s *next; 00863 valhalla_db_operator_t op; 00864 valhalla_db_item_t meta; 00865 valhalla_db_item_t data; 00866 } valhalla_db_restrict_t; 00867 00868 00886 #define VALHALLA_DB_SEARCH(id, txt, g, t, l, p) \ 00887 { \ 00888 /* .type = */ VALHALLA_DB_TYPE_##t, \ 00889 /* .id = */ id, \ 00890 /* .text = */ txt, \ 00891 /* .group = */ VALHALLA_META_GRP_##g, \ 00892 /* .lang = */ l, \ 00893 /* .priority = */ p \ 00894 } 00895 00911 #define VALHALLA_DB_RESTRICT(op, m_id, d_id, m_txt, d_txt, m_t, d_t, l, p) \ 00912 { \ 00913 /* .next = */ NULL, \ 00914 /* .op = */ VALHALLA_DB_OPERATOR_##op, \ 00915 /* .meta = */ VALHALLA_DB_SEARCH (m_id, m_txt, NIL, m_t, l, p), \ 00916 /* .data = */ VALHALLA_DB_SEARCH (d_id, d_txt, NIL, d_t, l, p) \ 00917 } 00918 00920 #define VALHALLA_DB_SEARCH_ID(meta_id, group, l, p) \ 00921 VALHALLA_DB_SEARCH (meta_id, NULL, group, ID, l, p) 00922 00923 #define VALHALLA_DB_SEARCH_TEXT(meta_name, group, l, p) \ 00924 VALHALLA_DB_SEARCH (0, meta_name, group, TEXT, l, p) 00925 00926 #define VALHALLA_DB_SEARCH_GRP(group, l, p) \ 00927 VALHALLA_DB_SEARCH (0, NULL, group, GROUP, l, p) 00928 00930 #define VALHALLA_DB_RESTRICT_INT(op, meta, data, l, p) \ 00931 VALHALLA_DB_RESTRICT (op, meta, data, NULL, NULL, ID, ID, l, p) 00932 00933 #define VALHALLA_DB_RESTRICT_STR(op, meta, data, l, p) \ 00934 VALHALLA_DB_RESTRICT (op, 0, 0, meta, data, TEXT, TEXT, l, p) 00935 00936 #define VALHALLA_DB_RESTRICT_INTSTR(op, meta, data, l, p) \ 00937 VALHALLA_DB_RESTRICT (op, meta, 0, NULL, data, ID, TEXT, l, p) 00938 00939 #define VALHALLA_DB_RESTRICT_STRINT(op, meta, data, l, p) \ 00940 VALHALLA_DB_RESTRICT (op, 0, data, meta, NULL, TEXT, ID, l, p) 00941 00942 #define VALHALLA_DB_RESTRICT_LINK(from, to) \ 00943 do {(to).next = &(from);} while (0) 00944 00971 valhalla_db_stmt_t * 00972 valhalla_db_metalist_get (valhalla_t *handle, 00973 valhalla_db_item_t *search, 00974 valhalla_file_type_t filetype, 00975 valhalla_db_restrict_t *restriction); 00976 00988 const valhalla_db_metares_t * 00989 valhalla_db_metalist_read (valhalla_t *handle, valhalla_db_stmt_t *vhstmt); 00990 01011 valhalla_db_stmt_t * 01012 valhalla_db_filelist_get (valhalla_t *handle, 01013 valhalla_file_type_t filetype, 01014 valhalla_db_restrict_t *restriction); 01015 01027 const valhalla_db_fileres_t * 01028 valhalla_db_filelist_read (valhalla_t *handle, valhalla_db_stmt_t *vhstmt); 01029 01053 valhalla_db_stmt_t * 01054 valhalla_db_file_get (valhalla_t *handle, int64_t id, const char *path, 01055 valhalla_db_restrict_t *restriction); 01056 01068 const valhalla_db_metares_t * 01069 valhalla_db_file_read (valhalla_t *handle, valhalla_db_stmt_t *vhstmt); 01070 01141 int valhalla_db_metadata_insert (valhalla_t *handle, const char *path, 01142 const char *meta, const char *data, 01143 valhalla_lang_t lang, 01144 valhalla_meta_grp_t group); 01145 01165 int valhalla_db_metadata_update (valhalla_t *handle, const char *path, 01166 const char *meta, const char *data, 01167 const char *ndata, valhalla_lang_t lang); 01168 01183 int valhalla_db_metadata_delete (valhalla_t *handle, const char *path, 01184 const char *meta, const char *data); 01185 01204 int valhalla_db_metadata_priority (valhalla_t *handle, const char *path, 01205 const char *meta, const char *data, 01206 valhalla_metadata_pl_t p); 01207 01212 #ifdef __cplusplus 01213 } 01214 #endif /* __cplusplus */ 01215 01216 #endif /* VALHALLA_H */