~ubuntu-branches/ubuntu/hardy/gnomad2/hardy

« back to all changes in this revision

Viewing changes to src/filenaming.c

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2005-09-17 20:50:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050917205020-w5j2zngvh2czg0i1
Tags: 2.8.1-1
* New upstream release.
* Fix bug affecting file names starting with numbers. Closes: #324865.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "filenaming.h"
29
29
#include "prefs.h"
30
30
#include "util.h"
 
31
#include "metadata.h"
31
32
 
32
33
gchar *chomp_strings[] =
33
34
{
130
131
  return returnname;
131
132
}
132
133
 
133
 
static gint number_of_dashes(gchar *string)
 
134
static gint number_of_dashes(const gchar *string)
134
135
{
135
 
  gchar *tmp;
 
136
  const gchar *tmp;
136
137
  gint no = 0;
137
138
  
138
139
  tmp = string;
145
146
  return no;
146
147
}
147
148
 
148
 
static gchar *kill_tracknumber(gchar *string)
 
149
static gchar *kill_tracknumber(const gchar *string)
149
150
{
150
151
  /* If something beginning with two figures is followed
151
152
   * by something that is not a figure, we assume it is
155
156
 
156
157
  if (strlen(string) < 4)
157
158
    return g_strdup(string);
158
 
  test[0] = string[0];
159
 
  test[1] = string[1];
160
 
  test[2] = '\0';
161
 
  if (is_a_number(test)) {
162
 
    test[0] = string[2];
163
 
    test[1] = '\0';
164
 
    if (!is_a_number(test)) {
165
 
      tmp = g_strdup(string+2);
166
 
      g_strstrip(tmp);
167
 
      g_free(string);
168
 
      return tmp;
169
 
    }
 
159
  if (g_ascii_isdigit(string[0]) &&
 
160
      g_ascii_isdigit(string[1]) &&
 
161
      !g_ascii_isdigit(string[2]) &&
 
162
      string[2] != '\'') { // This last condition is for year albums like "70's".
 
163
    tmp = g_strdup(string+2);
 
164
    g_strstrip(tmp);
 
165
    return tmp;
170
166
  }
171
167
  return g_strdup(string);
172
168
}
417
413
  gchar **tmp;
418
414
  gchar *artist = NULL;
419
415
 
 
416
  if (gnomad_debug != 0) {
 
417
    g_print("get_artist()\n");
 
418
  }
420
419
  tmp = g_strsplit(dir, " - ", 0);
421
420
  /* If the directory is named "Foo - Bar", we presume
422
421
   * Foo is the artist, and Bar is the album title */
456
455
{
457
456
  gchar **tmp;
458
457
  gchar *title = NULL;
459
 
 
460
 
  gchar *file2 = kill_tracknumber(file);
 
458
  gchar *file2;
 
459
 
 
460
  if (gnomad_debug != 0) {
 
461
    g_print("get_title()\n");
 
462
  }
 
463
 
 
464
  file2 = kill_tracknumber(file);
 
465
  if (file2 == NULL) {
 
466
    return NULL;
 
467
  }
 
468
  tmp = g_strsplit(file, " - ", 0);
 
469
  g_free(file2);
 
470
 
 
471
  if (vectorlength(tmp) > 1) {
 
472
    gchar **tmp2 = tmp;
 
473
    gchar *tmp3;
 
474
 
 
475
    while(*tmp2 != NULL) {
 
476
      tmp3 = *tmp2;
 
477
      tmp2++;
 
478
    }
 
479
    g_print("%s\n", tmp3);
 
480
  }
 
481
  g_strfreev(tmp);
 
482
  return g_strdup(file);
 
483
 
461
484
  tmp = g_strsplit(file2, " - ", 0);
462
 
  /* If the file is named "F - oo - Bar", we assume
463
 
   * Bar is the title */
464
 
  if (vectorlength(tmp) > 2) {
465
 
    title = g_strdup(*(tmp+2));
466
 
  /* Else if the file is named "Foo - Bar", we assume
467
 
   * Bar is the title */
468
 
  } else if (vectorlength(tmp) > 1) {
469
 
    title = g_strdup(*(tmp+1));
 
485
  g_free(file2);
 
486
  if (vectorlength(tmp) > 1) {
 
487
    gchar **tmp2 = tmp;
 
488
    gchar *tmp3;
 
489
 
 
490
    while(*tmp2 != NULL) {
 
491
      tmp3 = *tmp2;
 
492
      tmp2++;
 
493
    }
 
494
    title = g_strdup(tmp3);
470
495
  } else {
471
496
    /* Otherwise we will use the file name as it is,
472
497
     * assuming this is the title is the best we can do... */
473
498
    title = g_strdup(file);
474
499
  }
 
500
  // This is the culprit
475
501
  g_strfreev(tmp);
476
 
  g_free(file2);
 
502
  if (gnomad_debug != 0) {
 
503
    if (title != NULL) {
 
504
      g_print("Found title \"%s\"...\n", title);
 
505
    } else {
 
506
      g_print("Didn't find any title.\n");
 
507
    }
 
508
  }
477
509
  return title;
478
510
}
479
511
 
482
514
  gchar **tmp;
483
515
  gchar *album = NULL;
484
516
 
 
517
  if (gnomad_debug != 0) {
 
518
    g_print("get_album()\n");
 
519
  }
485
520
  tmp = g_strsplit(dir, " - ", 0);
486
521
  /* If the directory is named "Foo - Bar", we presume
487
522
   * Foo is the artist, and Bar is the album title */
496
531
  /* If something beginning with two figures is followed
497
532
   * by something that is not a figure, we assume it is
498
533
   * a track number. */
499
 
  gchar *p;
500
534
  gchar test[3];
501
 
  gint found=0;
502
 
 
503
 
  memset(test, 0, sizeof(test));
504
 
 
505
 
  for (p=file; *p; ++p)
506
 
    if (g_ascii_isdigit(*p)) {
507
 
      if (found < 2)
508
 
        test[found]=*p;
509
 
      ++found;
510
 
      if (found==2) {
511
 
        if (!isdigit(p[1]))
512
 
          return string_to_guint(test);
 
535
  guint i;
 
536
 
 
537
  if (gnomad_debug != 0) {
 
538
    g_print("get_trackno()\n");
 
539
  }
 
540
 
 
541
  if (strlen(file) < 3) {
 
542
    return 0;
 
543
  }
 
544
  for (i = 0; i < (strlen(file) - 2); i++) {
 
545
    if (g_ascii_isdigit(file[i]) &&
 
546
        g_ascii_isdigit(file[i+1]) &&
 
547
        !g_ascii_isdigit(file[i+2])) {
 
548
      test[0] = file[i];
 
549
      test[1] = file[i+1];
 
550
      test[2] = '\0';
 
551
      if (gnomad_debug != 0) {
 
552
        g_print("Found track number: %s\n", test);
513
553
      }
514
 
    } else
515
 
      found=0;
516
 
 
 
554
      return string_to_guint(test);
 
555
    }
 
556
  }
517
557
  return 0;
518
558
}
519
559
 
530
570
  guint track = 0;
531
571
  int i;
532
572
 
533
 
  /* g_print("Getting info from path...\n"); */
 
573
  if (gnomad_debug != 0) {
 
574
    g_print("Getting info from path...\n");
 
575
  }
534
576
  /* If ID3lib has already set seriously acceptable tags,
535
577
   * use them and return */
536
578
  if (meta->artist != NULL &&
537
579
      meta->title != NULL &&
538
580
      meta->album != NULL &&
539
581
      meta->trackno > 0) {
540
 
    /* g_print("All metadata already set.\n"); */
 
582
    if (gnomad_debug != 0) {
 
583
      g_print("All metadata already set.\n");
 
584
    }
541
585
    return;
542
586
  }
543
587
  /* It's not much use trying to determine something
550
594
   * cook up Artist / Title / Album fields from the path.
551
595
   */
552
596
  path = g_strdup(meta->path);
553
 
  //g_print("Processing path: %s\n", path);
 
597
  if (gnomad_debug != 0) {
 
598
    g_print("Processing path: %s\n", path);
 
599
  }
554
600
  /* Chop off the file extension */
555
601
  if (path[strlen(path)-3] == '.')
556
602
    path[strlen(path)-3] = '\0';
576
622
    tmpdir = beautify_string(tmpdir);
577
623
    tmpfile = beautify_string(tmpfile);
578
624
  }
579
 
  //g_print("Dir: %s\n", tmpdir);
580
 
  //g_print("File: %s\n", tmpfile);
 
625
  if (gnomad_debug != 0) {
 
626
    g_print("Dir: %s\n", tmpdir);
 
627
    g_print("File: %s\n", tmpfile);
 
628
  }
581
629
  // If we're not being too clever, do as mediasource do.
582
630
  if (!be_clever) {
583
631
    if ((meta->title == NULL) && (tmpfile != NULL)) {
600
648
    meta->trackno = get_trackno(tmpfile);
601
649
  g_free(tmpdir);
602
650
  g_free(tmpfile);
 
651
  if (gnomad_debug != 0) {
 
652
    g_print("Got all info from path...\n");
 
653
    dump_metadata_t(meta);
 
654
  }
603
655
}