/* * xmmsr -- (C) Copyright 2001,2007 ccr/TNSP * * COMPILE: * gcc -g -O -o xmmsr xmmsr.c `xmms-config --cflags --libs` * */ #include #include #include #include #include gchar *getfext(gchar *filename) { gchar *ptr, *ext; if (!filename || !filename[0]) return NULL; /* Find the extension */ ext = NULL; ptr = filename; while (*ptr != 0) { if (*ptr == '/') ext = NULL; else if (*ptr == '.') ext = ptr+1; ptr++; } /* Check if found */ if (ext) { ptr = ext; while (*ptr != '/' && ptr != filename) { if (*ptr == '.') ext = ptr+1; ptr--; } return g_strdup(ext); } else return g_strdup_printf(""); } int main(void) { const gint session = 0; gint pos, length; gchar *tmps, *title, *filename, *fext, *p; /* Check if XMMS is running */ if (!xmms_remote_is_running(session)) { fprintf(stderr, "Error: No XMMS session running.\n"); return 0; } /* Get the information ! */ pos = xmms_remote_get_playlist_pos(session); title = xmms_remote_get_playlist_title(session, pos); filename = xmms_remote_get_playlist_file(session, pos); length = xmms_remote_get_playlist_time(session, pos) / 1000; fext = getfext(filename); /* Print information into one string */ tmps = g_strdup_printf("(#%d) %s [%s] [%d:%-2.2d]", (pos + 1), title, fext, (length / 60), (length % 60)); /* Change non-alphanumeric chars into spaces */ p = tmps; while (*p) { if (!isascii(*p)) { switch (*p) { case 'ä': case 'Ä': case 'ö': case 'Ö': case 'å': case 'Å': break; default: *p = '?'; } } p++; } /* Print out the string */ printf("%s\n", tmps); g_free(title); g_free(filename); g_free(fext); g_free(tmps); return 0; }