]> git.sesse.net Git - vlc/blobdiff - src/input/meta.c
Clear confusion about --started-from-file-and-one-instance-when-sunset-is-beautiful
[vlc] / src / input / meta.c
index bff1b7d2eb7bce2b55397e9814059ddc06cc389f..aeda5d40e5a8f877399fc28ef9c62b62dfebfccb 100644 (file)
@@ -1,36 +1,39 @@
 /*****************************************************************************
  * meta.c : Metadata handling
  *****************************************************************************
- * Copyright (C) 1998-2004 the VideoLAN team
+ * Copyright (C) 1998-2004 VLC authors and VideoLAN
  * $Id$
  *
  * 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
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser 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.
+ * You should have received a copy of the GNU Lesser 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 <assert.h>
+
 #include <vlc_common.h>
 #include <vlc_playlist.h>
 #include <vlc_url.h>
 #include <vlc_arrays.h>
 #include <vlc_modules.h>
+#include <vlc_charset.h>
 
 #include "input_internal.h"
 #include "../playlist/art.h"
 struct vlc_meta_t
 {
     char * ppsz_meta[VLC_META_TYPE_COUNT];
-    
+
     vlc_dictionary_t extra_tags;
-    
+
     int i_status;
 };
 
 /* FIXME bad name convention */
 const char * vlc_meta_TypeToLocalizedString( vlc_meta_type_t meta_type )
 {
-    switch( meta_type )
+    static const char posix_names[][16] =
     {
-    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();
-    }
+        [vlc_meta_Title]       = N_("Title"),
+        [vlc_meta_Artist]      = N_("Artist"),
+        [vlc_meta_Genre]       = N_("Genre"),
+        [vlc_meta_Copyright]   = N_("Copyright"),
+        [vlc_meta_Album]       = N_("Album"),
+        [vlc_meta_TrackNumber] = N_("Track number"),
+        [vlc_meta_Description] = N_("Description"),
+        [vlc_meta_Rating]      = N_("Rating"),
+        [vlc_meta_Date]        = N_("Date"),
+        [vlc_meta_Setting]     = N_("Setting"),
+        [vlc_meta_URL]         = N_("URL"),
+        [vlc_meta_Language]    = N_("Language"),
+        [vlc_meta_NowPlaying]  = N_("Now Playing"),
+        [vlc_meta_Publisher]   = N_("Publisher"),
+        [vlc_meta_EncodedBy]   = N_("Encoded by"),
+        [vlc_meta_ArtworkURL]  = N_("Artwork URL"),
+        [vlc_meta_TrackID]     = N_("Track ID"),
+    };
+
+    assert (meta_type < (sizeof(posix_names) / sizeof(posix_names[0])));
+    return vlc_gettext (posix_names[meta_type]);
 };
 
 
 /**
  * vlc_meta contructor.
  * vlc_meta_Delete() will free the returned pointer.
- */ 
+ */
 vlc_meta_t *vlc_meta_New( void )
 {
     vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof(*m) );
@@ -107,7 +111,7 @@ void vlc_meta_Delete( vlc_meta_t *m )
  * vlc_meta has two kinds of meta, the one in a table, and the one in a
  * dictionary.
  * FIXME - Why don't we merge those two?
- */ 
+ */
 
 void vlc_meta_Set( vlc_meta_t *p_meta, vlc_meta_type_t meta_type, const char *psz_val )
 {
@@ -165,10 +169,10 @@ void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
 {
     char **ppsz_all_keys;
     int i;
-    
+
     if( !dst || !src )
         return;
-    
+
     for( i = 0; i < VLC_META_TYPE_COUNT; i++ )
     {
         if( src->ppsz_meta[i] )
@@ -177,14 +181,14 @@ void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
             dst->ppsz_meta[i] = strdup( src->ppsz_meta[i] );
         }
     }
-    
+
     /* XXX: If speed up are needed, it is possible */
     ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags );
     for( i = 0; ppsz_all_keys && ppsz_all_keys[i]; i++ )
     {
         /* Always try to remove the previous value */
         vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i], vlc_meta_FreeExtraKey, NULL );
-        
+
         void *p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] );
         vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], strdup( (const char*)p_value ) );
         free( ppsz_all_keys[i] );
@@ -206,8 +210,6 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
         return;
     }
 
-    playlist_t *p_playlist = pl_Get( p_input );
-
     if( input_item_IsArtFetched( p_item ) )
     {
         /* XXX Weird, we should not have end up with attachment:// art url unless there is a race
@@ -248,7 +250,7 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
         psz_type = ".png";
 
     /* */
-    playlist_SaveArt( p_playlist, p_item,
+    playlist_SaveArt( VLC_OBJECT(p_input), p_item,
                       p_attachment->p_data, p_attachment->i_data, psz_type );
 
     vlc_input_attachment_Delete( p_attachment );
@@ -260,11 +262,9 @@ exit:
 int input_item_WriteMeta( vlc_object_t *obj, input_item_t *p_item )
 {
     meta_export_t *p_export =
-        vlc_custom_create( obj, sizeof( *p_export ), VLC_OBJECT_GENERIC,
-                           "meta writer" );
+        vlc_custom_create( obj, sizeof( *p_export ), "meta writer" );
     if( p_export == NULL )
         return VLC_ENOMEM;
-    vlc_object_attach( p_export, obj );
     p_export->p_item = p_item;
 
     int type;
@@ -292,3 +292,39 @@ error:
     vlc_object_release( p_export );
     return VLC_EGENERIC;
 }
+
+void vlc_audio_replay_gain_MergeFromMeta( audio_replay_gain_t *p_dst,
+                                          const vlc_meta_t *p_meta )
+{
+    const char * psz_value;
+
+    if( !p_meta )
+        return;
+
+    if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_TRACK_GAIN")) ||
+        (psz_value = vlc_meta_GetExtra(p_meta, "RG_RADIO")) )
+    {
+        p_dst->pb_gain[AUDIO_REPLAY_GAIN_TRACK] = true;
+        p_dst->pf_gain[AUDIO_REPLAY_GAIN_TRACK] = us_atof( psz_value );
+    }
+
+    if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_TRACK_PEAK" )) ||
+             (psz_value = vlc_meta_GetExtra(p_meta, "RG_PEAK" )) )
+    {
+        p_dst->pb_peak[AUDIO_REPLAY_GAIN_TRACK] = true;
+        p_dst->pf_peak[AUDIO_REPLAY_GAIN_TRACK] = us_atof( psz_value );
+    }
+
+    if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_ALBUM_GAIN" )) ||
+             (psz_value = vlc_meta_GetExtra(p_meta, "RG_AUDIOPHILE" )) )
+    {
+        p_dst->pb_gain[AUDIO_REPLAY_GAIN_ALBUM] = true;
+        p_dst->pf_gain[AUDIO_REPLAY_GAIN_ALBUM] = us_atof( psz_value );
+    }
+
+    if( (psz_value = vlc_meta_GetExtra(p_meta, "REPLAYGAIN_ALBUM_PEAK" )) )
+    {
+        p_dst->pb_peak[AUDIO_REPLAY_GAIN_ALBUM] = true;
+        p_dst->pf_peak[AUDIO_REPLAY_GAIN_ALBUM] = us_atof( psz_value );
+    }
+}