extractors/extractor-taglib.cxx
author Stiletto <blasux@blasux.ru>
Thu, 22 Sep 2011 13:27:23 +0400
changeset 9 ae87469781f2
parent 6 f0c87fb62b66
permissions -rw-r--r--
CUE extractor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     1
/* Copyright (C) 2003 Scott Wheeler <wheeler@kde.org>
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     2
 *
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     3
 * Redistribution and use in source and binary forms, with or without
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     4
 * modification, are permitted provided that the following conditions
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     5
 * are met:
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     6
 *
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     7
 * 1. Redistributions of source code must retain the above copyright
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     8
 *    notice, this list of conditions and the following disclaimer.
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
     9
 * 2. Redistributions in binary form must reproduce the above copyright
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    10
 *    notice, this list of conditions and the following disclaimer in the
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    11
 *    documentation and/or other materials provided with the distribution.
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    12
 *
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    13
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    14
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    15
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    16
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    17
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    18
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    19
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    20
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    21
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    22
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    23
 */
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    24
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    25
#include <iostream>
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    26
#include <stdio.h>
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    27
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    28
#include <fileref.h>
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    29
#include <tag.h>
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    30
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    31
using namespace std;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    32
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    33
TagLib::String formatSeconds(int seconds)
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    34
{
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    35
  char secondsString[3];
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    36
  sprintf(secondsString, "%02i", seconds);
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    37
  return secondsString;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    38
}
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    39
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    40
int main(int argc, char *argv[])
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    41
{
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    42
  for(int i = 1; i < argc; i++) {
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    43
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    44
    cout << argv[i] << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    45
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    46
    TagLib::FileRef f(argv[i]);
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    47
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    48
    if(!f.isNull() && f.tag()) {
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    49
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    50
      TagLib::Tag *tag = f.tag();
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    51
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    52
      cout << "TITLE:" << tag->title() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    53
      cout << "ARTIST:" << tag->artist() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    54
      cout << "ALBUM:" << tag->album() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    55
      cout << "YEAR:" << tag->year() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    56
      cout << "COMMENT:" << tag->comment() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    57
      cout << "TRACK:" << tag->track() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    58
      cout << "GENRE:" << tag->genre() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    59
    }
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    60
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    61
    if(!f.isNull() && f.audioProperties()) {
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    62
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    63
      TagLib::AudioProperties *properties = f.audioProperties();
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    64
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    65
      int seconds = properties->length() % 60;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    66
      int minutes = (properties->length() - seconds) / 60;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    67
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    68
      cout << "BITRATE:" << properties->bitrate() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    69
      cout << "SAMPLERATE:" << properties->sampleRate() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    70
      cout << "CHANNELS:" << properties->channels() << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    71
      cout << "LENGTH:" << minutes << ":" << formatSeconds(seconds) << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    72
    }
9
ae87469781f2 CUE extractor
Stiletto <blasux@blasux.ru>
parents: 6
diff changeset
    73
    cout << "EXTRACTOR: taglib" << endl;
6
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    74
    cout << endl;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    75
  }
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    76
  return 0;
f0c87fb62b66 example updater, two metadata extractors
Stiletto <blasux@blasux.ru>
parents:
diff changeset
    77
}