Michael Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 1 | #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 | |
| 13 | bool 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 Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 17 | char *p; |
| 18 | |
Michael Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 19 | if ((lseek(fd, 0, SEEK_SET) < 0) |
Björn Stenberg | 2d00f0c | 2011-04-06 21:08:31 +0000 | [diff] [blame] | 20 | || (read(fd, buf, 110) < 110)) |
Michael Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 21 | { |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | id3->length = 120*1000; |
| 26 | id3->vbr = false; |
| 27 | id3->filesize = filesize(fd); |
| 28 | |
Michael Giacomelli | ad9835c | 2009-08-30 03:52:11 +0000 | [diff] [blame] | 29 | if (memcmp(buf,"NSFE",4) == 0) /* only NESM contain metadata */ |
Michael Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 30 | { |
| 31 | return true; |
| 32 | } |
Michael Giacomelli | ad9835c | 2009-08-30 03:52:11 +0000 | [diff] [blame] | 33 | else |
| 34 | { |
| 35 | if (memcmp(buf, "NESM",4) != 0) /* not a valid format*/ |
| 36 | { |
| 37 | return false; |
| 38 | } |
| 39 | } |
Michael Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 40 | |
| 41 | p = id3->id3v2buf; |
| 42 | |
Michael Sevakis | c537d59 | 2011-04-27 03:08:23 +0000 | [diff] [blame^] | 43 | /* Length */ |
| 44 | id3->length = buf[6]*1000; |
| 45 | |
Michael Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 46 | /* 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 Giacomelli | f701fc5 | 2009-08-30 03:15:43 +0000 | [diff] [blame] | 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |