folder.c 3.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*****************************************************************************
 * folder.c
 *****************************************************************************
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
 *
 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

28
29
30
31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include <vlc_common.h>
33
#include <vlc_plugin.h>
zorglub's avatar
zorglub committed
34
35
#include <vlc_playlist.h>
#include <vlc_charset.h>
ivoire's avatar
ivoire committed
36
#include <vlc_url.h>
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#ifdef HAVE_SYS_STAT_H
#   include <sys/stat.h>
#endif

#ifndef MAX_PATH
#   define MAX_PATH 250
#endif

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int FindMeta( vlc_object_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/

55
56
57
vlc_module_begin ()
    set_shortname( N_( "Folder" ) )
    set_description( N_("Folder meta data") )
58

59
60
61
    set_capability( "art finder", 90 )
    set_callbacks( FindMeta, NULL )
vlc_module_end ()
62
63
64
65
66

/*****************************************************************************
 *****************************************************************************/
static int FindMeta( vlc_object_t *p_this )
{
67
    input_item_t *p_item = (input_item_t *)p_this->p_private;
68
    bool b_have_art = false;
69

70
71
72
    int i = 0;
    struct stat a;
    char psz_filename[MAX_PATH];
73
74
75
    if( !p_item )
        return VLC_EGENERIC;

76
    char *psz_dir = input_item_GetURI( p_item );
77
78
    if( !psz_dir )
        return VLC_EGENERIC;
79

80
    char *psz_buf = strrchr( psz_dir, '/' );
81
    if( psz_buf )
82
    {
83
84
85
86
87
88
89
        psz_buf++;
        *psz_buf = '\0';
    }
    else
    {
        *psz_dir = '\0';
    }
90

91
92
93
    char *psz_path = psz_dir;
    if( !strncmp( psz_path, "file://", 7 ) )
        psz_path += 7;
94

95
    for( i = 0; b_have_art == false && i < 3; i++ )
96
97
    {
        switch( i )
98
        {
99
100
101
            case 0:
            /* Windows Folder.jpg */
            snprintf( psz_filename, MAX_PATH,
Rafaël Carré's avatar
Rafaël Carré committed
102
                      "%sFolder.jpg", psz_path );
103
104
105
106
107
            break;

            case 1:
            /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
            snprintf( psz_filename, MAX_PATH,
Rafaël Carré's avatar
Rafaël Carré committed
108
                  "%sAlbumArtSmall.jpg", psz_path );
109
110
111
112
113
            break;

            case 2:
            /* KDE (?) .folder.png */
            snprintf( psz_filename, MAX_PATH,
Rafaël Carré's avatar
Rafaël Carré committed
114
                  "%s.folder.png", psz_path );
115
            break;
116
117
        }

Rafaël Carré's avatar
Rafaël Carré committed
118
        if( utf8_stat( psz_filename, &a ) != -1 )
119
        {
Rafaël Carré's avatar
Rafaël Carré committed
120
121
122
123
124
125
126
            char *psz_uri = make_URI( psz_filename );
            if( psz_uri )
            {
                input_item_SetArtURL( p_item, psz_uri );
                free( psz_uri );
                b_have_art = true;
            }
127
128
129
        }
    }

130
131
132
    free( psz_dir );

    return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
133
}