[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

tips for managing mp3 playlists



[ please cc: me! i'm not on the list now. thanks! ]

hi,

my favorite mp3 player (alsaplayer) does not have satisfying
functionality for managing playlists. and i don't think winamp is much
better on this either. so below is an invitation for tips managing mp3
playlists. i find for now the old unix way doing things is pretty
satisfying. ;)

i use this command line for playing a sigle mp3:

$ alsaplayer-text -l 100 -n some.mp3 > /dev/null

i will write the above line simply as ``playmp3 some.mp3'' below.

1) to play all the mp3s in the archive in a random order. rand is a
   small c program i wrote to randomize lines. (src attached
   below. it's pretty amazing there is no standard tools to do this?)

$ find . -name '*.mp3' | rand | awk '/^.*$/ { system("playmp3 \"" $0 "\"") }'

2) to get rid of .m3u files, i just have to arrange my mp3 in
   different directories. and use hardlinks if i want to listen a song
   in different collections. i.e. in different .m3u files. using
   hardlinks and directories, i find this is way better than messing
   with .m3u files. what do you feel? (i understand windoze guys
   cannot play this way. ;)

3) to cycling around a .m3u is pretty obvious for you unix guys
   there now, isn't it. ;)

cheers,

/* This is rand version 0.1 GNU GPL protected. Report bugs and
   suggestions to zhaoway <zw@debian.org> */

#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct item {
  char *str;
  struct item *next;
  struct item *prev;
} *first;

/* count the lines */
int lines;

void die(char *str)
{
  fprintf(stderr, "rand: die! %s\n", str);
  exit(1);
}

void read_items(void)
{
  struct item *last, *this;
  size_t zero = 0;

  lines = 0;
  first = (struct item *) malloc(sizeof(struct item));
  if (first == NULL) die("not enough memory!");
  first->str = NULL;
  first->next = first;
  first->prev = first;
  this = first;
  last = NULL;

  /* getline() is _GNU_SOURCE */
  while (getline(&(this->str), &zero, stdin) != -1)
    {
      if (last != NULL) last->next = this;
      last = this;
      this = (struct item *) malloc(sizeof(struct item));
      if (this == NULL) die("not enough memory!");
      this->str = NULL;
      this->next = first;
      this->prev = last;
      lines++;
    }

  first->prev = last;
  free(this);
}

void disp_items(void)
{
  struct item *this;
  int count = lines;

  if (first == NULL) return;
  else this = first;

  while (count-- > 0)
    {
      printf("%s", this->str);
      this = this->next;
    }
}

void rand_items(void)
{
  int num, count = lines;
  struct item *this, *last = NULL;

  if (first == NULL) return;
  else this = first;
  srand(time(0));

  while (count > 0)
    {
      num = rand() % count--;
      while (num-- > 0) this = this->next;
      this->prev->next = this->next;
      this->next->prev = this->prev;

      if (last != NULL)
	{
	  last->next = this;
	  this->prev = last;
	}
      else first = this;

      last = this;
      this = this->next;
    }

  first->prev = last;
  if (last != NULL) last->next = first;
}

int main(int argc, char *argv[])
{
  read_items();
  rand_items();
  disp_items();
  return(0);
}

Reply to: