Commit e41c90dd authored by Rocky Bernstein's avatar Rocky Bernstein

Customizable playlist title.

parent 7614ebe6
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* cddax.c : CD digital audio input module for vlc using libcdio * cddax.c : CD digital audio input module for vlc using libcdio
***************************************************************************** *****************************************************************************
* Copyright (C) 2000,2003 VideoLAN * Copyright (C) 2000,2003 VideoLAN
* $Id: access.c,v 1.4 2003/11/30 18:14:20 rocky Exp $ * $Id: access.c,v 1.5 2003/11/30 22:26:48 rocky Exp $
* *
* Authors: Rocky Bernstein <rocky@panix.com> * Authors: Rocky Bernstein <rocky@panix.com>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -66,7 +66,7 @@ static int CDDASetProgram ( input_thread_t *, pgrm_descriptor_t * ); ...@@ -66,7 +66,7 @@ static int CDDASetProgram ( input_thread_t *, pgrm_descriptor_t * );
static int CDDAFixupPlayList(const input_thread_t *p_input, static int CDDAFixupPlayList(const input_thread_t *p_input,
cdda_data_t *p_cdda, const char *psz_source, cdda_data_t *p_cdda, const char *psz_source,
bool play_single_track, unsigned int i_track); bool play_single_track);
/**************************************************************************** /****************************************************************************
* Private functions * Private functions
...@@ -312,10 +312,10 @@ E_(Open)( vlc_object_t *p_this ) ...@@ -312,10 +312,10 @@ E_(Open)( vlc_object_t *p_this )
} }
#undef area #undef area
CDDAFixupPlayList(p_input, p_cdda, psz_source, play_single_track, i_track);
CDDAPlay( p_input, i_track); CDDAPlay( p_input, i_track);
CDDAFixupPlayList(p_input, p_cdda, psz_source, play_single_track);
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
if( !p_input->psz_demux || !*p_input->psz_demux ) if( !p_input->psz_demux || !*p_input->psz_demux )
...@@ -518,6 +518,12 @@ static void CDDASeek( input_thread_t * p_input, off_t i_off ) ...@@ -518,6 +518,12 @@ static void CDDASeek( input_thread_t * p_input, off_t i_off )
} }
#ifdef HAVE_LIBCDDB #ifdef HAVE_LIBCDDB
#define free_and_dup(var, val) \
if (var) free(var); \
if (val) var=strdup(val);
static void static void
GetCDDBInfo( const input_thread_t *p_input, cdda_data_t *p_cdda ) GetCDDBInfo( const input_thread_t *p_input, cdda_data_t *p_cdda )
{ {
...@@ -600,10 +606,6 @@ GetCDDBInfo( const input_thread_t *p_input, cdda_data_t *p_cdda ) ...@@ -600,10 +606,6 @@ GetCDDBInfo( const input_thread_t *p_input, cdda_data_t *p_cdda )
if (p_cdda->i_debug & INPUT_DBG_CDDB) if (p_cdda->i_debug & INPUT_DBG_CDDB)
cddb_disc_print(p_cdda->cddb.disc); cddb_disc_print(p_cdda->cddb.disc);
#if FIXED
if ((_cdda_is_cd_changed(this) == 1))
#endif
/**** _cdda_cddb_set_info(this, this->cddb.disc); ***/
} else { } else {
msg_Warn( p_input, "CDDB error: %s", cddb_error_str(errno)); msg_Warn( p_input, "CDDB error: %s", cddb_error_str(errno));
} }
...@@ -615,47 +617,178 @@ GetCDDBInfo( const input_thread_t *p_input, cdda_data_t *p_cdda ) ...@@ -615,47 +617,178 @@ GetCDDBInfo( const input_thread_t *p_input, cdda_data_t *p_cdda )
} }
#endif /*HAVE_LIBCDDB*/ #endif /*HAVE_LIBCDDB*/
#define add_format_str_info(val) \
{ \
const char *str = val; \
unsigned int len; \
if (val != NULL) { \
len=strlen(str); \
if (len != 0) { \
strncat(tp, str, TEMP_STR_LEN-(tp-temp_str)); \
tp += len; \
} \
saw_control_prefix = false; \
} \
}
#define add_format_num_info(val, fmt) \
{ \
char num_str[10]; \
unsigned int len; \
sprintf(num_str, fmt, val); \
len=strlen(num_str); \
if (len != 0) { \
strncat(tp, num_str, TEMP_STR_LEN-(tp-temp_str)); \
tp += len; \
} \
saw_control_prefix = false; \
}
/*!
Take a format string and expand escape sequences, that is sequences that
begin with %, with information from the current CD.
The expanded string is returned. Here is a list of escape sequences:
%a : The artist
%A : The album information
%C : Category
%I : CDDB disk ID
%G : Genre
%M : The current MRL
%m : The CD-DA Media Catalog Number (MCN)
%T : The track number
%t : The name
%Y : The year 19xx or 20xx
%% : a %
*/
static char *
CDDAFormatStr(const input_thread_t *p_input, cdda_data_t *p_cdda,
const char format_str[], const char *mrl, int i_track)
{
#define TEMP_STR_SIZE 256
#define TEMP_STR_LEN (TEMP_STR_SIZE-1)
static char temp_str[TEMP_STR_SIZE];
size_t i;
char * tp = temp_str;
bool saw_control_prefix = false;
size_t format_len = strlen(format_str);
bzero(temp_str, TEMP_STR_SIZE);
for (i=0; i<format_len; i++) {
if (!saw_control_prefix && format_str[i] != '%') {
*tp++ = format_str[i];
saw_control_prefix = false;
continue;
}
switch(format_str[i]) {
case '%':
if (saw_control_prefix) {
*tp++ = '%';
}
saw_control_prefix = !saw_control_prefix;
break;
#ifdef HAVE_LIBCDDB
case 'a':
if (!p_cdda->i_cddb_enabled) goto not_special;
add_format_str_info(p_cdda->cddb.disc->artist);
break;
case 'A':
if (!p_cdda->i_cddb_enabled) goto not_special;
add_format_str_info(p_cdda->cddb.disc->title);
break;
case 'C':
if (!p_cdda->i_cddb_enabled) goto not_special;
add_format_str_info(CDDB_CATEGORY[p_cdda->cddb.disc->category]);
break;
case 'G':
if (!p_cdda->i_cddb_enabled) goto not_special;
add_format_str_info(p_cdda->cddb.disc->genre);
break;
case 'I':
if (!p_cdda->i_cddb_enabled) goto not_special;
add_format_num_info(p_cdda->cddb.disc->discid, "%x");
break;
case 'Y':
if (!p_cdda->i_cddb_enabled) goto not_special;
add_format_num_info(p_cdda->cddb.disc->year, "%5d");
break;
case 't':
if (p_cdda->i_cddb_enabled) {
cddb_track_t *t=cddb_disc_get_track(p_cdda->cddb.disc,
i_track-1);
if (t != NULL && t->title != NULL)
add_format_str_info(t->title);
} else goto not_special;
break;
#endif
case 'M':
add_format_str_info(mrl);
break;
#if FINISHED
case 'm':
add_format_str_info(p_cdda->mcn);
break;
#endif
case 'T':
add_format_num_info(i_track, "%d");
break;
#ifdef HAVE_LIBCDDB
not_special:
#endif
default:
*tp++ = '%';
*tp++ = format_str[i];
saw_control_prefix = false;
}
}
return strdup(temp_str);
}
static void static void
CDDACreatePlayListItem(const input_thread_t *p_input, cdda_data_t *p_cdda, CDDACreatePlayListItem(const input_thread_t *p_input, cdda_data_t *p_cdda,
playlist_t *p_playlist, unsigned int i_track, playlist_t *p_playlist, unsigned int i_track,
char *psz_mrl, int psz_mrl_max, char *psz_mrl, int psz_mrl_max,
const char *psz_source, int i_cddb_enabled, const char *psz_source, int playlist_operation,
int playlist_operation, unsigned int i_pos) unsigned int i_pos)
{ {
mtime_t i_duration = mtime_t i_duration =
(p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1]) (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])
* 1000 / CDIO_CD_FRAMES_PER_SEC; * 1000 / CDIO_CD_FRAMES_PER_SEC;
char *p_title = psz_mrl; char *p_title;
snprintf(psz_mrl, psz_mrl_max, "%s%s@T%u", snprintf(psz_mrl, psz_mrl_max, "%s%s@T%u",
CDDA_MRL_PREFIX, psz_source, i_track); CDDA_MRL_PREFIX, psz_source, i_track);
if (i_cddb_enabled) {
cddb_track_t *t=cddb_disc_get_track(p_cdda->cddb.disc, i_track-1); p_title = CDDAFormatStr(p_input, p_cdda,
if (t != NULL && t->title != NULL) config_GetPsz( p_input,
p_title = t->title; MODULE_STRING "-title-format" ),
} psz_mrl, i_track);
playlist_AddExt( p_playlist, psz_mrl, p_title, i_duration, playlist_AddExt( p_playlist, psz_mrl, p_title, i_duration,
0, 0, playlist_operation, i_pos ); 0, 0, playlist_operation, i_pos );
} }
static int static int
CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda, CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda,
const char *psz_source, bool play_single_track, const char *psz_source, bool play_single_track)
unsigned int i_track)
{ {
int i; int i;
playlist_t * p_playlist; playlist_t * p_playlist;
char * psz_mrl; char * psz_mrl;
unsigned int psz_mrl_max = strlen(CDDA_MRL_PREFIX) + strlen(psz_source) + unsigned int psz_mrl_max = strlen(CDDA_MRL_PREFIX) + strlen(psz_source) +
strlen("@T") + strlen("100") + 1; strlen("@T") + strlen("100") + 1;
int i_cddb_enabled =
#ifdef HAVE_LIBCDDB #ifdef HAVE_LIBCDDB
p_cdda->i_cddb_enabled =
config_GetInt( p_input, MODULE_STRING "-cddb-enabled" ); config_GetInt( p_input, MODULE_STRING "-cddb-enabled" );
#else
0
#endif #endif
if (play_single_track && !i_cddb_enabled) return 0; if (play_single_track && !p_cdda->i_cddb_enabled) return 0;
psz_mrl = malloc( psz_mrl_max ); psz_mrl = malloc( psz_mrl_max );
...@@ -675,7 +808,7 @@ CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda, ...@@ -675,7 +808,7 @@ CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda,
} }
#ifdef HAVE_LIBCDDB #ifdef HAVE_LIBCDDB
if (i_cddb_enabled) if (p_cdda->i_cddb_enabled)
GetCDDBInfo(p_input, p_cdda); GetCDDBInfo(p_input, p_cdda);
#endif #endif
...@@ -683,10 +816,9 @@ CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda, ...@@ -683,10 +816,9 @@ CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda,
/* May fill out more information when the playlist user interface becomes /* May fill out more information when the playlist user interface becomes
more mature. more mature.
*/ */
CDDACreatePlayListItem(p_input, p_cdda, p_playlist, i_track, CDDACreatePlayListItem(p_input, p_cdda, p_playlist, p_cdda->i_track+1,
psz_mrl, psz_mrl_max, psz_mrl, psz_mrl_max, psz_source, PLAYLIST_REPLACE,
psz_source, i_cddb_enabled, p_playlist->i_index);
PLAYLIST_REPLACE, p_playlist->i_index);
} else { } else {
playlist_Delete( p_playlist, p_playlist->i_index); playlist_Delete( p_playlist, p_playlist->i_index);
...@@ -694,8 +826,8 @@ CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda, ...@@ -694,8 +826,8 @@ CDDAFixupPlayList(const input_thread_t *p_input, cdda_data_t *p_cdda,
for( i = 1 ; i <= p_cdda->i_nb_tracks ; i++ ) for( i = 1 ; i <= p_cdda->i_nb_tracks ; i++ )
{ {
CDDACreatePlayListItem(p_input, p_cdda, p_playlist, i, psz_mrl, CDDACreatePlayListItem(p_input, p_cdda, p_playlist, i, psz_mrl,
psz_mrl_max, psz_source, i_cddb_enabled, psz_mrl_max, psz_source, PLAYLIST_APPEND,
PLAYLIST_APPEND, PLAYLIST_END); PLAYLIST_END);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* cddax.c : CD digital audio input module for vlc using libcdio * cddax.c : CD digital audio input module for vlc using libcdio
***************************************************************************** *****************************************************************************
* Copyright (C) 2000,2003 VideoLAN * Copyright (C) 2000,2003 VideoLAN
* $Id: cdda.c,v 1.3 2003/11/30 18:14:20 rocky Exp $ * $Id: cdda.c,v 1.4 2003/11/30 22:26:48 rocky Exp $
* *
* Authors: Rocky Bernstein <rocky@panix.com> * Authors: Rocky Bernstein <rocky@panix.com>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -73,6 +73,27 @@ int E_(DebugCallback) ( vlc_object_t *p_this, const char *psz_name, ...@@ -73,6 +73,27 @@ int E_(DebugCallback) ( vlc_object_t *p_this, const char *psz_name,
"Allows you to modify the default caching value for cdda streams. This " \ "Allows you to modify the default caching value for cdda streams. This " \
"value should be set in millisecond units." ) "value should be set in millisecond units." )
#define TITLE_FMT_LONGTEXT N_( \
"Format used in the GUI Playlist Title. Similar to the Unix date \n" \
"Format specifiers that start with a percent sign. Specifiers are: \n" \
" %a : The artist\n" \
" %A : The album information \n" \
" %C : Category\n" \
" %I : CDDB disk ID\n" \
" %G : Genre\n" \
" %M : The current MRL\n" \
" %m : The CD-DA Media Catalog Number (MCN)\n" \
" %T : The track number\n" \
" %t : The name\n" \
" %Y : The year 19xx or 20xx\n" \
" %% : a %\n")
#ifdef HAVE_LIBCDDB
#define DEFAULT_TITLE_FORMAT "%T %t",
#else
#define DEFAULT_TILTE_FORMAT "%T %M",
#endif
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
*****************************************************************************/ *****************************************************************************/
...@@ -101,6 +122,10 @@ vlc_module_begin(); ...@@ -101,6 +122,10 @@ vlc_module_begin();
N_("CD-ROM device name"), N_("CD-ROM device name"),
DEV_LONGTEXT, VLC_FALSE ); DEV_LONGTEXT, VLC_FALSE );
add_string( MODULE_STRING "-title-format", DEFAULT_TITLE_FORMAT, NULL,
N_("Format to use in playlist 'title' field"),
TITLE_FMT_LONGTEXT, VLC_TRUE );
#ifdef HAVE_LIBCDDB #ifdef HAVE_LIBCDDB
add_bool( MODULE_STRING "-cddb-enabled", 1, NULL, add_bool( MODULE_STRING "-cddb-enabled", 1, NULL,
N_("Do CDDB lookups?"), N_("Do CDDB lookups?"),
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* using libcdio, libvcd and libvcdinfo * using libcdio, libvcd and libvcdinfo
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: cdda.h,v 1.2 2003/11/30 18:14:20 rocky Exp $ * $Id: cdda.h,v 1.3 2003/11/30 22:26:49 rocky Exp $
* *
* Authors: Rocky Bernstein <rocky@panix.com> * Authors: Rocky Bernstein <rocky@panix.com>
* *
...@@ -62,28 +62,16 @@ typedef struct cdda_data_s ...@@ -62,28 +62,16 @@ typedef struct cdda_data_s
lsn_t * p_sectors; /* Track sectors */ lsn_t * p_sectors; /* Track sectors */
vlc_bool_t b_end_of_track; /* If the end of track was reached */ vlc_bool_t b_end_of_track; /* If the end of track was reached */
int i_debug; /* Debugging mask */ int i_debug; /* Debugging mask */
char * mcn; /* Media Catalog Number */
intf_thread_t *p_intf; intf_thread_t *p_intf;
#ifdef HAVE_LIBCDDB #ifdef HAVE_LIBCDDB
int i_cddb_enabled;
struct { struct {
bool have_info; /* True if we have any info */ bool have_info; /* True if we have any info */
cddb_disc_t *disc; /* libcdio uses this to get disc info */ cddb_disc_t *disc; /* libcdio uses this to get disc info */
char *cdiscid;
char *disc_title;
char disc_year[5]; /* Year. Probably 19XX or 20XX */
char *disc_artist;
char *disc_genre;
cddb_cat_t disc_category; /* CDDB category */
int disc_seconds; /* Length in seconds listed in CDDB
catalog. May or may not match
length below.
*/
int disc_length; /* Length in frames of cd. Used in int disc_length; /* Length in frames of cd. Used in
CDDB lookups */ CDDB lookups */
unsigned int disc_id; /* This along with the length and
num_tracks below is what CDDB uses
to look up CD info */
} cddb; } cddb;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment