View | Details | Raw Unified | Return to bug 64337
Collapse All | Expand All

(-)file_not_specified_in_diff (-12 / +34 lines)
Line  Link Here
0
-- src/id3tag.c
0
++ src/id3tag.c
Lines 389-400 Link Here
389
  return(1);
389
  return(1);
390
}
390
}
391
391
392
static void id3tag_sanitize (char *string)
393
{
394
    while ((string = strchr (string, '/')))
395
    {
396
      *string = '_';
397
    }
398
}
399
392
/* This function renames a file based on its tag in the given format */
400
/* This function renames a file based on its tag in the given format */
393
int id3tag_rename( char *filename, char *format )
401
int id3tag_rename( char *filename, char *format )
394
{
402
{
395
  struct id3tag tag;
403
  struct id3tag tag;
396
  struct stat stbuf;
404
  struct stat stbuf;
397
  char target_filename[80]="";
405
  char target_filename[PATH_MAX]="";
398
  char buffer[10]="";
406
  char buffer[10]="";
399
  char *tmp;
407
  char *tmp;
400
  int i;
408
  int i;
Lines 425-460 Link Here
425
	    {
433
	    {
426
	    case 't':
434
	    case 't':
427
	      strcat( target_filename, tag.title);
435
	      strcat( target_filename, tag.title);
436
	      id3tag_sanitize (target_filename+i2);
428
	      i2=i2+strlen(tag.title);
437
	      i2=i2+strlen(tag.title);
429
	      i++;
438
	      i++;
430
	      break;
439
	      break;
431
	      
440
	      
432
	    case 'a':
441
	    case 'a':
433
	      strcat( target_filename, tag.artist);
442
	      strcat( target_filename, tag.artist);
443
	      id3tag_sanitize (target_filename+i2);
434
	      i2=i2+strlen(tag.artist);
444
	      i2=i2+strlen(tag.artist);
435
	      i++;	      
445
	      i++;	      
436
	      break;
446
	      break;
437
447
438
	    case 'b':
448
	    case 'b':
439
	      strcat( target_filename, tag.album);
449
	      strcat( target_filename, tag.album);
450
	      id3tag_sanitize (target_filename+i2);
440
	      i2=i2+strlen(tag.album);
451
	      i2=i2+strlen(tag.album);
441
	      i++;	      
452
	      i++;	      
442
	      break;
453
	      break;
443
454
444
	    case 'c':
455
	    case 'c':
445
	      strcat( target_filename, tag.comment);
456
	      strcat( target_filename, tag.comment);
457
	      id3tag_sanitize (target_filename+i2);
446
	      i2=i2+strlen(tag.comment);
458
	      i2=i2+strlen(tag.comment);
447
	      i++;	      
459
	      i++;	      
448
	      break;
460
	      break;
449
		
461
		
450
	    case 'y':
462
	    case 'y':
451
	      strcat( target_filename, tag.year);
463
	      strcat( target_filename, tag.year);
464
	      id3tag_sanitize (target_filename+i2);
452
	      i2=i2+strlen(tag.year);
465
	      i2=i2+strlen(tag.year);
453
	      i++;	      
466
	      i++;	      
454
	      break;
467
	      break;
455
468
456
	    case 'g':
469
	    case 'g':
457
	      strcat( target_filename, id3tag_get_genre(tag.genre));
470
	      strcat( target_filename, id3tag_get_genre(tag.genre));
471
	      id3tag_sanitize (target_filename+i2);
458
	      i2=i2+strlen(id3tag_get_genre(tag.genre));	      
472
	      i2=i2+strlen(id3tag_get_genre(tag.genre));	      
459
	      i++;
473
	      i++;
460
	      break;
474
	      break;
Lines 521-529 Link Here
521
int id3tag_sort( char *filename, char *rootdir, char *format_level1, char *format_level2 )
535
int id3tag_sort( char *filename, char *rootdir, char *format_level1, char *format_level2 )
522
{
536
{
523
  struct id3tag tag;
537
  struct id3tag tag;
524
  char *dir_level1=NULL;
538
  char *dir_level1=NULL, *dir_level1_sanitized;
525
  char *dir_level2=NULL;
539
  char *dir_level2=NULL, *dir_level2_sanitized;
526
  char target_filename[80];
540
  char source_filename[PATH_MAX], target_filename[PATH_MAX];
527
  char dir_cur[80];
541
  char dir_cur[80];
528
542
529
  
543
  
Lines 554-561 Link Here
554
  chdir(rootdir);
568
  chdir(rootdir);
555
  if( dir_level1[0] == '\0' )
569
  if( dir_level1[0] == '\0' )
556
    dir_level1 = "Unknown";
570
    dir_level1 = "Unknown";
557
  yamtlog("%s %s", "New directory: ", dir_level1);
571
  dir_level1_sanitized = strdup (dir_level1);
558
  mkdir( dir_level1, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH );
572
  id3tag_sanitize (dir_level1_sanitized);
573
  yamtlog("%s %s", "New directory: ", dir_level1_sanitized);
574
  mkdir( dir_level1_sanitized, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH );
559
	  
575
	  
560
  /* Level 2 */
576
  /* Level 2 */
561
  if( strcmp( format_level2, "Album") == 0 )
577
  if( strcmp( format_level2, "Album") == 0 )
Lines 573-590 Link Here
573
  
589
  
574
  if( dir_level2[0] == '\0' )
590
  if( dir_level2[0] == '\0' )
575
    dir_level2 = "Unknown";
591
    dir_level2 = "Unknown";
576
  yamtlog("%s %s", "New directory: ", dir_level2);
592
  dir_level2_sanitized = strdup (dir_level2);
593
  id3tag_sanitize (dir_level2_sanitized);
594
  yamtlog("%s %s", "New directory: ", dir_level2_sanitized);
577
595
578
  /* Go into the previously created directory */
596
  /* Go into the previously created directory */
579
  chdir( dir_level1 );
597
  chdir( dir_level1_sanitized );
580
  mkdir( dir_level2, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH );
598
  mkdir( dir_level2_sanitized, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH );
581
  /* Move the file into the new (?) directory */
599
  /* Move the file into the new (?) directory */
582
600
583
  sprintf( target_filename, "mv \"%s/%s\" \"%s%s/%s/%s\"", dir_cur, filename, rootdir, dir_level1, dir_level2, filename ); 
601
  snprintf( source_filename, PATH_MAX, "%s/%s", dir_cur, filename );
602
  snprintf( target_filename, PATH_MAX, "%s%s/%s/%s", rootdir, dir_level1_sanitized, dir_level2_sanitized, filename );
603
604
  free (dir_level1_sanitized);
605
  free (dir_level2_sanitized);
584
606
585
  yamtlog("%s %s", "Sorted ", filename );
607
  yamtlog("%s %s", "Sorted ", filename );
586
608
587
  system( target_filename ); 
609
  rename( source_filename, target_filename ); 
588
  
610
  
589
/*   if( (rename( filename, target_filename )) )   */
611
/*   if( (rename( filename, target_filename )) )   */
590
/*     {   */
612
/*     {   */

Return to bug 64337