root/modules/meta_engine/folder.c
| Revision c4afdf592d3f4261bf05aabefab0b1d3bbf0dd28, 3.8 kB (checked in by Derk-Jan Hartman <hartman@videolan.org>, 4 months ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /***************************************************************************** |
| 2 | * folder.c |
| 3 | ***************************************************************************** |
| 4 | * Copyright (C) 2006 the VideoLAN team |
| 5 | * $Id$ |
| 6 | * |
| 7 | * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
| 22 | *****************************************************************************/ |
| 23 | |
| 24 | /***************************************************************************** |
| 25 | * Preamble |
| 26 | *****************************************************************************/ |
| 27 | |
| 28 | #ifdef HAVE_CONFIG_H |
| 29 | # include "config.h" |
| 30 | #endif |
| 31 | |
| 32 | #include <vlc_common.h> |
| 33 | #include <vlc_plugin.h> |
| 34 | #include <vlc_interface.h> |
| 35 | #include <vlc_meta.h> |
| 36 | #include <vlc_playlist.h> |
| 37 | #include <vlc_input.h> |
| 38 | #include <vlc_charset.h> |
| 39 | |
| 40 | #ifdef HAVE_SYS_STAT_H |
| 41 | # include <sys/stat.h> |
| 42 | #endif |
| 43 | |
| 44 | #ifndef MAX_PATH |
| 45 | # define MAX_PATH 250 |
| 46 | #endif |
| 47 | |
| 48 | /***************************************************************************** |
| 49 | * Local prototypes |
| 50 | *****************************************************************************/ |
| 51 | static int FindMeta( vlc_object_t * ); |
| 52 | |
| 53 | /***************************************************************************** |
| 54 | * Module descriptor |
| 55 | *****************************************************************************/ |
| 56 | |
| 57 | vlc_module_begin(); |
| 58 | set_shortname( N_( "Folder" ) ); |
| 59 | set_description( N_("Folder meta data") ); |
| 60 | |
| 61 | set_capability( "art finder", 90 ); |
| 62 | set_callbacks( FindMeta, NULL ); |
| 63 | vlc_module_end(); |
| 64 | |
| 65 | /***************************************************************************** |
| 66 | *****************************************************************************/ |
| 67 | static int FindMeta( vlc_object_t *p_this ) |
| 68 | { |
| 69 | playlist_t *p_playlist = (playlist_t *)p_this; |
| 70 | input_item_t *p_item = (input_item_t *)(p_playlist->p_private); |
| 71 | bool b_have_art = false; |
| 72 | |
| 73 | int i = 0; |
| 74 | struct stat a; |
| 75 | char psz_filename[MAX_PATH]; |
| 76 | if( !p_item ) |
| 77 | return VLC_EGENERIC; |
| 78 | |
| 79 | char *psz_dir = input_item_GetURI( p_item ); |
| 80 | if( !psz_dir ) |
| 81 | return VLC_EGENERIC; |
| 82 | |
| 83 | char *psz_buf = strrchr( psz_dir, '/' ); |
| 84 | if( psz_buf ) |
| 85 | { |
| 86 | psz_buf++; |
| 87 | *psz_buf = '\0'; |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | *psz_dir = '\0'; |
| 92 | } |
| 93 | |
| 94 | char *psz_path = psz_dir; |
| 95 | if( !strncmp( psz_path, "file://", 7 ) ) |
| 96 | psz_path += 7; |
| 97 | |
| 98 | for( i = 0; b_have_art == false && i < 3; i++ ) |
| 99 | { |
| 100 | switch( i ) |
| 101 | { |
| 102 | case 0: |
| 103 | /* Windows Folder.jpg */ |
| 104 | snprintf( psz_filename, MAX_PATH, |
| 105 | "file://%sFolder.jpg", psz_path ); |
| 106 | break; |
| 107 | |
| 108 | case 1: |
| 109 | /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */ |
| 110 | snprintf( psz_filename, MAX_PATH, |
| 111 | "file://%sAlbumArtSmall.jpg", psz_path ); |
| 112 | break; |
| 113 | |
| 114 | case 2: |
| 115 | /* KDE (?) .folder.png */ |
| 116 | snprintf( psz_filename, MAX_PATH, |
| 117 | "file://%s.folder.png", psz_path ); |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | if( utf8_stat( psz_filename+7, &a ) != -1 ) |
| 122 | { |
| 123 | input_item_SetArtURL( p_item, psz_filename ); |
| 124 | b_have_art = true; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | free( psz_dir ); |
| 129 | |
| 130 | return b_have_art ? VLC_SUCCESS : VLC_EGENERIC; |
| 131 | } |
Note: See TracBrowser for help on using the browser.
