blob: 9207a14048f98110cf1827aea1448eaedc4bafe1 [file] [log] [blame]
Michael Giacomellif701fc52009-08-30 03:15:43 +00001#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <ctype.h>
5#include <inttypes.h>
6
7#include "system.h"
8#include "metadata.h"
9#include "metadata_common.h"
10#include "metadata_parsers.h"
11#include "rbunicode.h"
12
13bool get_nsf_metadata(int fd, struct mp3entry* id3)
14{
15 /* Use the trackname part of the id3 structure as a temporary buffer */
16 unsigned char* buf = (unsigned char *)id3->path;
Michael Giacomellif701fc52009-08-30 03:15:43 +000017 char *p;
18
Michael Giacomellif701fc52009-08-30 03:15:43 +000019 if ((lseek(fd, 0, SEEK_SET) < 0)
Björn Stenberg2d00f0c2011-04-06 21:08:31 +000020 || (read(fd, buf, 110) < 110))
Michael Giacomellif701fc52009-08-30 03:15:43 +000021 {
22 return false;
23 }
24
25 id3->length = 120*1000;
26 id3->vbr = false;
27 id3->filesize = filesize(fd);
28
Michael Giacomelliad9835c2009-08-30 03:52:11 +000029 if (memcmp(buf,"NSFE",4) == 0) /* only NESM contain metadata */
Michael Giacomellif701fc52009-08-30 03:15:43 +000030 {
31 return true;
32 }
Michael Giacomelliad9835c2009-08-30 03:52:11 +000033 else
34 {
35 if (memcmp(buf, "NESM",4) != 0) /* not a valid format*/
36 {
37 return false;
38 }
39 }
Michael Giacomellif701fc52009-08-30 03:15:43 +000040
41 p = id3->id3v2buf;
42
Michael Sevakisc537d592011-04-27 03:08:23 +000043 /* Length */
44 id3->length = buf[6]*1000;
45
Michael Giacomellif701fc52009-08-30 03:15:43 +000046 /* Title */
47 memcpy(p, &buf[14], 32);
48 id3->title = p;
49 p += strlen(p)+1;
50
51 /* Artist */
52 memcpy(p, &buf[46], 32);
53 id3->artist = p;
54 p += strlen(p)+1;
55
56 /* Copyright (per codec) */
57 memcpy(p, &buf[78], 32);
58 id3->album = p;
Michael Giacomellif701fc52009-08-30 03:15:43 +000059
60 return true;
61}
62