data-mp3.c
author nathan
Sat, 29 Dec 2007 14:49:09 +0100
branchtrunk
changeset 2 4c1f7b705009
parent 0 474a1293c3c0
child 19 306cc35c7faa
permissions -rw-r--r--
release 0.10.1
nathan@0
     1
/*
nathan@0
     2
 * MP3/MPlayer plugin to VDR (C++)
nathan@0
     3
 *
nathan@0
     4
 * (C) 2001-2006 Stefan Huelswitt <s.huelswitt@gmx.de>
nathan@0
     5
 *
nathan@0
     6
 * This code is free software; you can redistribute it and/or
nathan@0
     7
 * modify it under the terms of the GNU General Public License
nathan@0
     8
 * as published by the Free Software Foundation; either version 2
nathan@0
     9
 * of the License, or (at your option) any later version.
nathan@0
    10
 *
nathan@0
    11
 * This code is distributed in the hope that it will be useful,
nathan@0
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nathan@0
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nathan@0
    14
 * GNU General Public License for more details.
nathan@0
    15
 *
nathan@0
    16
 * You should have received a copy of the GNU General Public License
nathan@0
    17
 * along with this program; if not, write to the Free Software
nathan@0
    18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
nathan@0
    19
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
nathan@0
    20
 */
nathan@0
    21
nathan@0
    22
#include <stdlib.h>
nathan@0
    23
#include <stdio.h>
nathan@0
    24
#include <unistd.h>
nathan@0
    25
nathan@0
    26
#include "common.h"
nathan@0
    27
#include "data-mp3.h"
nathan@0
    28
#include "data.h"
nathan@0
    29
#include "decoder.h"
nathan@0
    30
nathan@0
    31
#define DEBUG_IMAGE
nathan@0
    32
nathan@0
    33
#ifdef DEBUG_IMAGE
nathan@0
    34
#define di(x) { (x); }
nathan@0
    35
#else
nathan@0
    36
#define di(x) ; 
nathan@0
    37
#endif
nathan@0
    38
nathan@0
    39
const char *imagecache = "/var/cache/images/mp3";
nathan@0
    40
const char *imageconv  = "image_convert.sh";
nathan@0
    41
nathan@0
    42
// image suffixes to search
nathan@0
    43
const char *img_suff[] = { "jpg","png","gif",0 };
nathan@0
    44
// exclude list for instant playlist creation
nathan@0
    45
const char *excl_pl[] = { "*"PLAYLISTEXT,"*.jpg","*.gif","*.png",0 };
nathan@0
    46
// exclude list for song browser
nathan@0
    47
const char *excl_br[] = { ".*","*.jpg","*.gif","*.png",0 };
nathan@0
    48
nathan@0
    49
// --- cImageConvert -----------------------------------------------------------
nathan@0
    50
nathan@0
    51
class cImageConvert : private cThread {
nathan@0
    52
private:
nathan@0
    53
  char *image;
nathan@0
    54
  enum eStatus { stNone, stRun, stFin };
nathan@0
    55
  eStatus status;
nathan@0
    56
protected:
nathan@0
    57
  virtual void Action(void);
nathan@0
    58
public:
nathan@0
    59
  cImageConvert(void);
nathan@0
    60
  ~cImageConvert();
nathan@0
    61
  bool Convert(const char *Image);
nathan@0
    62
  bool Status(void);
nathan@0
    63
  };
nathan@0
    64
nathan@0
    65
cImageConvert::cImageConvert(void)
nathan@0
    66
{
nathan@0
    67
  image=0; status=stNone;
nathan@0
    68
}
nathan@0
    69
nathan@0
    70
cImageConvert::~cImageConvert()
nathan@0
    71
{
nathan@0
    72
  if(status==stRun) Cancel(10);
nathan@0
    73
  free(image);
nathan@0
    74
}
nathan@0
    75
nathan@0
    76
bool cImageConvert::Convert(const char *Image)
nathan@0
    77
{
nathan@0
    78
  if(status==stNone) {
nathan@0
    79
    image=strdup(Image);
nathan@0
    80
    status=stRun;
nathan@0
    81
    Start();
nathan@0
    82
    return true;
nathan@0
    83
    }
nathan@0
    84
  return false;
nathan@0
    85
}
nathan@0
    86
nathan@0
    87
bool cImageConvert::Status(void)
nathan@0
    88
{
nathan@0
    89
  if(status==stRun && !Active()) status=stFin;
nathan@0
    90
  return status==stFin;
nathan@0
    91
}
nathan@0
    92
nathan@0
    93
void cImageConvert::Action(void)
nathan@0
    94
{
nathan@0
    95
  nice(3);
nathan@0
    96
  char *m, *cmd, *qp, *qm;
nathan@0
    97
  asprintf(&m,"%s%s.mpg",imagecache,image);
nathan@0
    98
  di(printf("image: convert started %s -> %s\n",image,m))
nathan@0
    99
  asprintf(&cmd,"%s \"%s\" \"%s\"",imageconv,qp=Quote(image),qm=Quote(m));
nathan@0
   100
  int r=system(cmd);
nathan@0
   101
  if(r!=0) di(printf("image: convert returned with code %d. Failed?\n",r))
nathan@0
   102
  free(cmd); free(qp); free(qm); free(m);
nathan@0
   103
  di(printf("image: convert finished\n"))
nathan@0
   104
  status=stFin;
nathan@0
   105
}
nathan@0
   106
nathan@0
   107
// --- cSong -------------------------------------------------------------------
nathan@0
   108
nathan@0
   109
cSong::cSong(cFileObj *Obj)
nathan@0
   110
{
nathan@0
   111
  obj=new cFileObj(Obj);
nathan@0
   112
  Init();
nathan@0
   113
}
nathan@0
   114
nathan@0
   115
cSong::cSong(cFileSource *Source, const char *Subdir, const char *Name)
nathan@0
   116
{
nathan@0
   117
  obj=new cFileObj(Source,Subdir,Name,otFile);
nathan@0
   118
  Init();
nathan@0
   119
}
nathan@0
   120
nathan@0
   121
cSong::cSong(cSong *Song)
nathan@0
   122
{
nathan@0
   123
  obj=new cFileObj(Song->obj);
nathan@0
   124
  Init();
nathan@0
   125
}
nathan@0
   126
nathan@0
   127
cSong::~cSong()
nathan@0
   128
{
nathan@0
   129
  delete conv;
nathan@0
   130
  delete decoder;
nathan@0
   131
  obj->Source()->Unblock();
nathan@0
   132
  delete obj;
nathan@0
   133
  free((char *)image);
nathan@0
   134
}
nathan@0
   135
nathan@0
   136
void cSong::Init(void)
nathan@0
   137
{
nathan@0
   138
  decoder=0; user=0; image=0; conv=0; queueStat=0;
nathan@0
   139
  fromDOS=decoderFailed=false;
nathan@0
   140
  obj->Source()->Block();
nathan@0
   141
}
nathan@0
   142
nathan@0
   143
#if APIVERSNUM >= 10315
nathan@0
   144
int cSong::Compare(const cListObject &ListObject) const
nathan@0
   145
#else
nathan@0
   146
bool cSong::operator<(const cListObject &ListObject)
nathan@0
   147
#endif
nathan@0
   148
{
nathan@0
   149
  cSong *song=(cSong *)&ListObject;
nathan@0
   150
#if APIVERSNUM >= 10315
nathan@0
   151
  return strcasecmp(obj->Path(),song->obj->Path());
nathan@0
   152
#else
nathan@0
   153
  return strcasecmp(obj->Path(),song->obj->Path())<0;
nathan@0
   154
#endif
nathan@0
   155
}
nathan@0
   156
nathan@0
   157
cSongInfo *cSong::Info(bool get)
nathan@0
   158
{
nathan@0
   159
  Decoder();
nathan@0
   160
  cSongInfo *si=0;
nathan@0
   161
  if(decoder) si=decoder->SongInfo(get);
nathan@0
   162
  return si;
nathan@0
   163
}
nathan@0
   164
nathan@0
   165
cDecoder *cSong::Decoder(void)
nathan@0
   166
{
nathan@0
   167
  decLock.Lock();
nathan@0
   168
  if(!decoder && !decoderFailed) {
nathan@0
   169
    decoder=cDecoders::FindDecoder(obj);
nathan@0
   170
    if(!decoder) decoderFailed=true;
nathan@0
   171
    }
nathan@0
   172
  decLock.Unlock();
nathan@0
   173
  return decoder;
nathan@0
   174
}
nathan@0
   175
nathan@0
   176
void cSong::Convert(void)
nathan@0
   177
{
nathan@0
   178
  char *Name=Convert2Unix(obj->Name());
nathan@0
   179
  obj->SetName(Name);
nathan@0
   180
  fromDOS=true;
nathan@0
   181
  free(Name);
nathan@0
   182
}
nathan@0
   183
nathan@0
   184
char *cSong::Convert2Unix(const char *name) const
nathan@0
   185
{
nathan@0
   186
  char *Name=strdup(name);
nathan@0
   187
  char *p=Name;
nathan@0
   188
  while(*p) {
nathan@0
   189
    if(*p=='/') *p='?';
nathan@0
   190
    if(*p=='\\') *p='/';
nathan@0
   191
    p++;
nathan@0
   192
    }
nathan@0
   193
  return Name;
nathan@0
   194
}
nathan@0
   195
nathan@0
   196
/*
nathan@0
   197
char *cSong::Convert2Dos(const char *name)
nathan@0
   198
{
nathan@0
   199
  char *Name=strdup(name);
nathan@0
   200
  char *p=Name;
nathan@0
   201
  while(*p) {
nathan@0
   202
    if(*p=='\\') *p='?';
nathan@0
   203
    if(*p=='/') *p='\\';
nathan@0
   204
    p++;
nathan@0
   205
    }
nathan@0
   206
  return Name;
nathan@0
   207
}
nathan@0
   208
*/
nathan@0
   209
nathan@0
   210
bool cSong::Parse(char *s, const char *reldir) const
nathan@0
   211
{
nathan@0
   212
  s=skipspace(stripspace(s));
nathan@0
   213
  if(*s) {
nathan@0
   214
    if(s[0]=='/' || !reldir)
nathan@0
   215
      obj->SplitAndSet(s);
nathan@0
   216
    else {
nathan@0
   217
      s=AddPath(reldir,s);
nathan@0
   218
      obj->SplitAndSet(s);
nathan@0
   219
      free(s);
nathan@0
   220
      }
nathan@0
   221
    return true;
nathan@0
   222
    }
nathan@0
   223
  return false;
nathan@0
   224
}
nathan@0
   225
nathan@0
   226
bool cSong::Save(FILE *f, const char *reldir) const
nathan@0
   227
{
nathan@0
   228
  const char *path=obj->Path();
nathan@0
   229
  if(reldir) {
nathan@0
   230
    int l=strlen(reldir);
nathan@0
   231
    if(!strncasecmp(path,reldir,l)) path+=l+1;
nathan@0
   232
    }
nathan@0
   233
  return fprintf(f,"%s\n",path)>0;
nathan@0
   234
}
nathan@0
   235
nathan@0
   236
bool cSong::FindImage(void)
nathan@0
   237
{
nathan@0
   238
  if(image) return true;
nathan@0
   239
nathan@0
   240
  char base[strlen(obj->Path())+32];
nathan@0
   241
  strcpy(base,obj->Path());
nathan@0
   242
  di(printf("image: checking image for %s\n",obj->Path()))
nathan@0
   243
nathan@0
   244
  // song specific image
nathan@0
   245
  char *m=rindex(base,'.');
nathan@0
   246
  if(m) *m=0;
nathan@0
   247
  if((image=CheckImage(base))) return true;
nathan@0
   248
nathan@0
   249
  // album specific image in song directory
nathan@0
   250
  if(!(m=rindex(base,'/'))) m=base-1;
nathan@0
   251
  strcpy(m+1,"cover");
nathan@0
   252
  if((image=CheckImage(base))) return true;
nathan@0
   253
nathan@0
   254
  // artist specific image in parent directory
nathan@0
   255
  if((m=rindex(base,'/'))) {
nathan@0
   256
    *m=0;
nathan@0
   257
    if(!(m=rindex(base,'/'))) m=base-1;
nathan@0
   258
    strcpy(m+1,"artist");
nathan@0
   259
    if((image=CheckImage(base))) return true;
nathan@0
   260
    }
nathan@0
   261
nathan@0
   262
  // default image in source basedir
nathan@0
   263
  if((image=CheckImage("background"))) return true;
nathan@0
   264
nathan@0
   265
  di(printf("image: no image for %s\n",obj->Path()))
nathan@0
   266
  return false;
nathan@0
   267
}
nathan@0
   268
nathan@0
   269
const char *cSong::CheckImage(const char *base) const
nathan@0
   270
{
nathan@0
   271
  char *p;
nathan@0
   272
  int n;
nathan@0
   273
  asprintf(&p,"%s/%s.%n     ",obj->Source()->BaseDir(),base,&n);
nathan@0
   274
  for(const char **s=img_suff; *s; s++) {
nathan@0
   275
#ifdef DEBUG
nathan@0
   276
    if(strlen(*s)>5) printf("ERROR: buffer overflow in CheckImage ext=%s\n",*s);
nathan@0
   277
#endif
nathan@0
   278
    strcpy(&p[n],*s);
nathan@0
   279
    di(printf("image: check %s\n",p))
nathan@0
   280
    if(!access(p,R_OK)) {
nathan@0
   281
      di(printf("image: found\n"))
nathan@0
   282
      return p;
nathan@0
   283
      }
nathan@0
   284
    }
nathan@0
   285
  free(p);
nathan@0
   286
  return 0;
nathan@0
   287
}
nathan@0
   288
nathan@0
   289
#include "data-mp3-image.c"
nathan@0
   290
extern void PropagateImage(const char *image);
nathan@0
   291
nathan@0
   292
bool cSong::Image(unsigned char * &mem, int &len)
nathan@0
   293
{
nathan@0
   294
  mem=0;
nathan@0
   295
  if(queueStat>0) {
nathan@0
   296
    if(!conv->Status()) {
nathan@0
   297
      di(printf("image: still queued\n"))
nathan@0
   298
      return false;
nathan@0
   299
      }
nathan@0
   300
    queueStat=-1;
nathan@0
   301
    delete conv; conv=0;
nathan@0
   302
    }
nathan@0
   303
nathan@0
   304
  int res=0;
nathan@0
   305
  if(image || FindImage()) {
nathan@0
   306
    di(printf("image: loading image %s\n",image))
nathan@0
   307
    char *m;
nathan@0
   308
    asprintf(&m,"%s%s.mpg",imagecache,image);
nathan@0
   309
    if(access(m,R_OK)) {
nathan@0
   310
      di(printf("image: not cached\n"))
nathan@0
   311
      if(queueStat<0) {
nathan@0
   312
        di(printf("image: obviously convert failed...\n"))
nathan@0
   313
        }
nathan@0
   314
      else {
nathan@0
   315
        if(!conv) conv=new cImageConvert;
nathan@0
   316
        if(conv && conv->Convert(image)) {
nathan@0
   317
          di(printf("image: convert queued\n"))
nathan@0
   318
          queueStat=1;
nathan@0
   319
          res=-1;
nathan@0
   320
          }
nathan@0
   321
        else {
nathan@0
   322
          di(printf("image: queueing failed\n"))
nathan@0
   323
          queueStat=-1;
nathan@0
   324
          }
nathan@0
   325
        }
nathan@0
   326
      }
nathan@0
   327
    else {
nathan@0
   328
      di(printf("image: cached\n"))
nathan@0
   329
      int f=open(m,O_RDONLY);
nathan@0
   330
      if(f>=0) {
nathan@0
   331
        struct stat64 st;
nathan@0
   332
        fstat64(f,&st);
nathan@0
   333
        len=st.st_size;
nathan@0
   334
        mem=MALLOC(unsigned char,len);
nathan@0
   335
        if(mem) {
nathan@0
   336
          if(read(f,mem,len)==len) res=1;
nathan@0
   337
          else free(mem);
nathan@0
   338
          }
nathan@0
   339
        close(f);
nathan@0
   340
        }
nathan@0
   341
      }
nathan@0
   342
    free(m);
nathan@0
   343
    }
nathan@0
   344
nathan@0
   345
  PropagateImage(res==1 ? image : 0);
nathan@0
   346
nathan@0
   347
  if(res<=0) {
nathan@0
   348
    di(printf("image: using static default image\n"))
nathan@0
   349
    len=sizeof(defaultImage);
nathan@0
   350
    mem=MALLOC(unsigned char,len);
nathan@0
   351
    if(mem) {
nathan@0
   352
      memcpy(mem,defaultImage,len);
nathan@0
   353
      }
nathan@0
   354
    }
nathan@0
   355
  return res>=0;
nathan@0
   356
}
nathan@0
   357
nathan@0
   358
// -- cPlayList --------------------------------------------------------------
nathan@0
   359
nathan@0
   360
cPlayList::cPlayList(cFileObj *Obj)
nathan@0
   361
{
nathan@0
   362
  obj=new cFileObj(Obj);
nathan@0
   363
  Init();
nathan@0
   364
}
nathan@0
   365
nathan@0
   366
cPlayList::cPlayList(cFileSource *Source, const char *Subdir, const char *Name)
nathan@0
   367
{
nathan@0
   368
  obj=new cFileObj(Source,Subdir,Name,otFile);
nathan@0
   369
  Init();
nathan@0
   370
}
nathan@0
   371
nathan@0
   372
cPlayList::cPlayList(cPlayList *List)
nathan@0
   373
{
nathan@0
   374
  obj=new cFileObj(List->obj);
nathan@0
   375
  Init();
nathan@0
   376
}
nathan@0
   377
nathan@0
   378
cPlayList::~cPlayList()
nathan@0
   379
{
nathan@0
   380
  free(basename);
nathan@0
   381
  free(extbuffer);
nathan@0
   382
  obj->Source()->Unblock();
nathan@0
   383
  delete obj;
nathan@0
   384
}
nathan@0
   385
nathan@0
   386
void cPlayList::Init(void)
nathan@0
   387
{
nathan@0
   388
  extbuffer=basename=0;
nathan@0
   389
  isWinAmp=false;
nathan@0
   390
  obj->Source()->Block();
nathan@0
   391
  Set();
nathan@0
   392
}
nathan@0
   393
nathan@0
   394
void cPlayList::Set(void)
nathan@0
   395
{
nathan@0
   396
  free(basename); basename=0;
nathan@0
   397
  if(obj->Name()) {
nathan@0
   398
    basename=strdup(obj->Name());
nathan@0
   399
    int l=strlen(basename)-strlen(PLAYLISTEXT);
nathan@0
   400
    if(l>0 && !strcasecmp(basename+l,PLAYLISTEXT)) basename[l]=0;
nathan@0
   401
    }
nathan@0
   402
}
nathan@0
   403
nathan@0
   404
#if APIVERSNUM >= 10315
nathan@0
   405
int cPlayList::Compare(const cListObject &ListObject) const
nathan@0
   406
#else
nathan@0
   407
bool cPlayList::operator<(const cListObject &ListObject)
nathan@0
   408
#endif
nathan@0
   409
{
nathan@0
   410
  cPlayList *list=(cPlayList *)&ListObject;
nathan@0
   411
#if APIVERSNUM >= 10315
nathan@0
   412
  return strcasecmp(obj->Name(),list->obj->Name());
nathan@0
   413
#else
nathan@0
   414
  return strcasecmp(obj->Name(),list->obj->Name())<0;
nathan@0
   415
#endif
nathan@0
   416
}
nathan@0
   417
nathan@0
   418
bool cPlayList::Load(void)
nathan@0
   419
{
nathan@0
   420
  Clear();
nathan@0
   421
  bool result=false;
nathan@0
   422
  FILE *f=fopen(obj->FullPath(),"r");
nathan@0
   423
  if(f) {
nathan@0
   424
    char buffer[512];
nathan@0
   425
    result=true;
nathan@0
   426
    while(fgets(buffer,sizeof(buffer),f)>0) {
nathan@0
   427
      if(buffer[0]=='#') {
nathan@0
   428
        if(!strncmp(buffer,WINAMPEXT,strlen(WINAMPEXT))) {
nathan@0
   429
          d(printf("mp3: detected WinAmp style playlist\n"))
nathan@0
   430
          isWinAmp=true;
nathan@0
   431
          }
nathan@0
   432
        continue;
nathan@0
   433
        }
nathan@0
   434
      if(!isempty(buffer)) {
nathan@0
   435
        cSong *song=new cSong(obj->Source(),0,0);
nathan@0
   436
        if(song->Parse(buffer,obj->Subdir())) Add(song);
nathan@0
   437
        else {
nathan@0
   438
          esyslog("error loading playlist %s\n",obj->FullPath());
nathan@0
   439
          delete song;
nathan@0
   440
          result=false;
nathan@0
   441
          break;
nathan@0
   442
          }
nathan@0
   443
        }
nathan@0
   444
      }
nathan@0
   445
    fclose(f);
nathan@0
   446
    }
nathan@0
   447
  else LOG_ERROR_STR(obj->FullPath());
nathan@0
   448
nathan@0
   449
  if(result && isWinAmp) {
nathan@0
   450
    cSong *song=First();
nathan@0
   451
    while(song) {   // if this is a WinAmp playlist, convert \ to /
nathan@0
   452
      song->Convert();
nathan@0
   453
      song=cList<cSong>::Next(song);
nathan@0
   454
      }
nathan@0
   455
    }
nathan@0
   456
  return result;
nathan@0
   457
}
nathan@0
   458
nathan@0
   459
bool cPlayList::Save(void)
nathan@0
   460
{
nathan@0
   461
  bool result=true;
nathan@0
   462
  cSafeFile f(obj->FullPath());
nathan@0
   463
  if(f.Open()) {
nathan@0
   464
    cSong *song=First();
nathan@0
   465
    while(song) {
nathan@0
   466
      if(!song->Save(f,obj->Subdir())) {
nathan@0
   467
         result=false;
nathan@0
   468
         break;
nathan@0
   469
         }
nathan@0
   470
      song=cList<cSong>::Next(song);
nathan@0
   471
      }
nathan@0
   472
    if(!f.Close()) result=false;
nathan@0
   473
    }
nathan@0
   474
  else result=false;
nathan@0
   475
  return result;
nathan@0
   476
}
nathan@0
   477
 
nathan@0
   478
bool cPlayList::Exists(void)
nathan@0
   479
{
nathan@0
   480
  return obj->Exists();
nathan@0
   481
}
nathan@0
   482
nathan@0
   483
bool cPlayList::TestName(const char *newName)
nathan@0
   484
{
nathan@0
   485
  return obj->TestName(AddExt(newName,PLAYLISTEXT));
nathan@0
   486
}
nathan@0
   487
nathan@0
   488
bool cPlayList::Rename(const char *newName)
nathan@0
   489
{
nathan@0
   490
  bool r=obj->Rename(AddExt(newName,PLAYLISTEXT));
nathan@0
   491
  if(r) Set();
nathan@0
   492
  return r;
nathan@0
   493
}
nathan@0
   494
nathan@0
   495
bool cPlayList::Create(const char *newName)
nathan@0
   496
{
nathan@0
   497
  bool r=obj->Create(AddExt(newName,PLAYLISTEXT));
nathan@0
   498
  if(r) {
nathan@0
   499
    Set();
nathan@0
   500
    r=Load();
nathan@0
   501
    }
nathan@0
   502
  return r;
nathan@0
   503
}
nathan@0
   504
nathan@0
   505
bool cPlayList::Delete(void)
nathan@0
   506
{
nathan@0
   507
  return obj->Delete();
nathan@0
   508
}
nathan@0
   509
nathan@0
   510
const char *cPlayList::AddExt(const char *FileName, const char *Ext)
nathan@0
   511
{
nathan@0
   512
  free(extbuffer); extbuffer=0;
nathan@0
   513
  asprintf(&extbuffer,"%s%s",FileName,Ext);
nathan@0
   514
  return extbuffer;
nathan@0
   515
}
nathan@0
   516
nathan@0
   517
// -- cInstantPlayList ------------------------------------------------------
nathan@0
   518
nathan@0
   519
cInstantPlayList::cInstantPlayList(cFileObj *Obj)
nathan@0
   520
:cPlayList(Obj)
nathan@0
   521
{
nathan@0
   522
  if(!Obj->Name()) Obj->SetName("instant");
nathan@0
   523
}
nathan@0
   524
nathan@0
   525
bool cInstantPlayList::Load(void)
nathan@0
   526
{
nathan@0
   527
  bool res=false;
nathan@0
   528
  Clear();
nathan@0
   529
  switch(obj->Type()) {
nathan@0
   530
    case otFile:
nathan@0
   531
      d(printf("instant: file %s\n",obj->Name()))
nathan@0
   532
      if(strcasecmp(obj->Name(),basename)) {
nathan@0
   533
        d(printf("instant: detected as playlist\n"))
nathan@0
   534
        res=cPlayList::Load();
nathan@0
   535
        }
nathan@0
   536
      else {
nathan@0
   537
        Add(new cSong(obj));
nathan@0
   538
        res=true;
nathan@0
   539
        }
nathan@0
   540
      break;
nathan@0
   541
    case otDir:
nathan@0
   542
      {
nathan@0
   543
      d(printf("instant: dir %s\n",obj->Name()))
nathan@0
   544
      res=ScanDir(obj->Source(),obj->Path(),stFile,obj->Source()->Include(),excl_pl,true);
nathan@0
   545
      Sort();
nathan@0
   546
      break;
nathan@0
   547
      }
nathan@0
   548
    case otBase:
nathan@0
   549
      d(printf("instant: base\n"))
nathan@0
   550
      res=ScanDir(obj->Source(),0,stFile,obj->Source()->Include(),excl_pl,true);
nathan@0
   551
      Sort();
nathan@0
   552
      break;
nathan@0
   553
    default: break;
nathan@0
   554
    }
nathan@0
   555
  return res;
nathan@0
   556
}
nathan@0
   557
nathan@0
   558
void cInstantPlayList::DoItem(cFileSource *src, const char *subdir, const char *name)
nathan@0
   559
{
nathan@0
   560
  Add(new cSong(src,subdir,name));
nathan@0
   561
}
nathan@0
   562
nathan@0
   563
// -- cPlayLists --------------------------------------------------------------
nathan@0
   564
nathan@0
   565
bool cPlayLists::Load(cFileSource *Source)
nathan@0
   566
{
nathan@0
   567
  static const char *spec[] = { "*"PLAYLISTEXT,0 };
nathan@0
   568
  Clear();
nathan@0
   569
  bool res=ScanDir(Source,0,stFile,spec,0,false);
nathan@0
   570
  Sort();
nathan@0
   571
  return res;
nathan@0
   572
}
nathan@0
   573
nathan@0
   574
void cPlayLists::DoItem(cFileSource *src, const char *subdir, const char *name)
nathan@0
   575
{
nathan@0
   576
  Add(new cPlayList(src,subdir,name));
nathan@0
   577
}