⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 meta.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * meta.c : Metadata handling ***************************************************************************** * Copyright (C) 1998-2004 the VideoLAN team * $Id: 402c9919ea47577b26d663e6678db48be32524d6 $ * * Authors: Antoine Cellerier <dionoea@videolan.org> *          Clément Stenac <zorglub@videolan.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. *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_input.h>#include <vlc_stream.h>#include <vlc_meta.h>#include <vlc_playlist.h>#include <vlc_charset.h>#include <vlc_strings.h>#include "../playlist/playlist_internal.h"#include <errno.h>#include <limits.h>                                             /* PATH_MAX */#include <assert.h>#ifdef HAVE_SYS_STAT_H#   include <sys/stat.h>#endif#include "../libvlc.h"const char *input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type ){    switch( meta_type )    {    case vlc_meta_Title:        return _("Title");    case vlc_meta_Artist:       return _("Artist");    case vlc_meta_Genre:        return _("Genre");    case vlc_meta_Copyright:    return _("Copyright");    case vlc_meta_Album:        return _("Album");    case vlc_meta_TrackNumber:  return _("Track number");    case vlc_meta_Description:  return _("Description");    case vlc_meta_Rating:       return _("Rating");    case vlc_meta_Date:         return _("Date");    case vlc_meta_Setting:      return _("Setting");    case vlc_meta_URL:          return _("URL");    case vlc_meta_Language:     return _("Language");    case vlc_meta_NowPlaying:   return _("Now Playing");    case vlc_meta_Publisher:    return _("Publisher");    case vlc_meta_EncodedBy:    return _("Encoded by");    case vlc_meta_ArtworkURL:   return _("Artwork URL");    case vlc_meta_TrackID:      return _("Track ID");    default: abort();    }};#define input_FindArtInCache(a,b) __input_FindArtInCache(VLC_OBJECT(a),b)static int __input_FindArtInCache( vlc_object_t *, input_item_t *p_item );/* Return codes: *   0 : Art is in cache or is a local file *   1 : Art found, need to download *  -X : Error/not found */int input_ArtFind( playlist_t *p_playlist, input_item_t *p_item ){    int i_ret = VLC_EGENERIC;    module_t *p_module;    char *psz_title, *psz_artist, *psz_album;    psz_artist = input_item_GetArtist( p_item );    psz_album = input_item_GetAlbum( p_item );    psz_title = input_item_GetTitle( p_item );    if(!psz_title)        psz_title = input_item_GetName( p_item );    if( !psz_title && !psz_artist && !psz_album )        return VLC_EGENERIC;    free( psz_title );    /* If we already checked this album in this session, skip */    if( psz_artist && psz_album )    {        FOREACH_ARRAY( playlist_album_t album, p_playlist->p_fetcher->albums )            if( !strcmp( album.psz_artist, psz_artist ) &&                !strcmp( album.psz_album, psz_album ) )            {                msg_Dbg( p_playlist, " %s - %s has already been searched",                         psz_artist, psz_album );        /* TODO-fenrir if we cache art filename too, we can go faster */                free( psz_artist );                free( psz_album );                if( album.b_found )                {                    if( !strncmp( album.psz_arturl, "file://", 7 ) )                        input_item_SetArtURL( p_item, album.psz_arturl );                    else /* Actually get URL from cache */                        input_FindArtInCache( p_playlist, p_item );                    return 0;                }                else                {                    return VLC_EGENERIC;                }            }        FOREACH_END();    }    free( psz_artist );    free( psz_album );    input_FindArtInCache( p_playlist, p_item );    char *psz_arturl = input_item_GetArtURL( p_item );    if( psz_arturl )    {        /* We already have an URL */        if( !strncmp( psz_arturl, "file://", strlen( "file://" ) ) )        {            free( psz_arturl );            return 0; /* Art is in cache, no need to go further */        }        free( psz_arturl );                /* Art need to be put in cache */        return 1;    }    PL_LOCK;    p_playlist->p_private = p_item;    psz_album = input_item_GetAlbum( p_item );    psz_artist = input_item_GetArtist( p_item );    psz_title = input_item_GetTitle( p_item );    if( !psz_title )        psz_title = input_item_GetName( p_item );    if( psz_album && psz_artist )    {        msg_Dbg( p_playlist, "searching art for %s - %s",             psz_artist, psz_album );    }    else    {        msg_Dbg( p_playlist, "searching art for %s",             psz_title );    }    free( psz_title );    p_module = module_Need( p_playlist, "art finder", 0, false );    if( p_module )        i_ret = 1;    else        msg_Dbg( p_playlist, "unable to find art" );    /* Record this album */    if( psz_artist && psz_album )    {        playlist_album_t a;        a.psz_artist = psz_artist;        a.psz_album = psz_album;        a.psz_arturl = input_item_GetArtURL( p_item );        a.b_found = (i_ret == VLC_EGENERIC ? false : true );        ARRAY_APPEND( p_playlist->p_fetcher->albums, a );    }    else    {        free( psz_artist );        free( psz_album );    }    if( p_module )        module_Unneed( p_playlist, p_module );    p_playlist->p_private = NULL;    PL_UNLOCK;    return i_ret;}static void ArtCacheCreateDir( const char *psz_dir ){    char newdir[strlen( psz_dir ) + 1];    strcpy( newdir, psz_dir );    char * psz_newdir = newdir;    char * psz = psz_newdir;    while( *psz )    {        while( *psz && *psz != DIR_SEP_CHAR) psz++;        if( !*psz ) break;        *psz = 0;        if( !EMPTY_STR( psz_newdir ) )            utf8_mkdir( psz_newdir, 0700 );        *psz = DIR_SEP_CHAR;        psz++;    }    utf8_mkdir( psz_dir, 0700 );}static char * ArtCacheGetSanitizedFileName( const char *psz ){    char *dup = strdup(psz);    int i;    filename_sanitize( dup );    /* Doesn't create a filename with invalid characters     * TODO: several filesystems forbid several characters: list them all     */    for( i = 0; dup[i] != '\0'; i++ )    {        if( dup[i] == DIR_SEP_CHAR )            dup[i] = ' ';    }    return dup;}#define ArtCacheGetDirPath(a,b,c,d,e) __ArtCacheGetDirPath(VLC_OBJECT(a),b,c,d,e)static void __ArtCacheGetDirPath( vlc_object_t *p_obj,                                  char *psz_dir,                                  const char *psz_title,                                  const char *psz_artist, const char *psz_album ){    (void)p_obj;    char *psz_cachedir = config_GetCacheDir();    if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )    {        char * psz_album_sanitized = ArtCacheGetSanitizedFileName( psz_album );        char * psz_artist_sanitized = ArtCacheGetSanitizedFileName( psz_artist );        snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP                  "art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",                  psz_cachedir, psz_artist_sanitized, psz_album_sanitized );        free( psz_album_sanitized );        free( psz_artist_sanitized );    }    else    {        char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title );        snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP                  "art" DIR_SEP "title" DIR_SEP "%s",                  psz_cachedir, psz_title_sanitized );        free( psz_title_sanitized );    }    free( psz_cachedir );}#define ArtCacheGetFilePath(a,b,c,d,e,f) __ArtCacheGetFilePath(VLC_OBJECT(a),b,c,d,e,f)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -