diff options
author | Adam Boot <rotator@gmail.com> | 2007-03-03 06:08:28 +0000 |
---|---|---|
committer | Adam Boot <rotator@gmail.com> | 2007-03-03 06:08:28 +0000 |
commit | b9a71b305b98a87f747dc1e0cc91324b73693fd1 (patch) | |
tree | c6e033835b4fc63ad0955ea3124f4b699cc9fd69 /apps/metadata.c | |
parent | 411f8198b46764a7c29030f8da1da90dc332308c (diff) | |
download | rockbox-b9a71b305b98a87f747dc1e0cc91324b73693fd1.tar.gz rockbox-b9a71b305b98a87f747dc1e0cc91324b73693fd1.zip |
Add get_metadata() and year & comment tag support for SPC.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12563 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/metadata.c')
-rw-r--r-- | apps/metadata.c | 108 |
1 files changed, 106 insertions, 2 deletions
diff --git a/apps/metadata.c b/apps/metadata.c index 84ee37c2fe..42ae435aea 100644 --- a/apps/metadata.c +++ b/apps/metadata.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "system.h" | 33 | #include "system.h" |
34 | #include "cuesheet.h" | 34 | #include "cuesheet.h" |
35 | #include "structec.h" | 35 | #include "structec.h" |
36 | #include "settings.h" | ||
36 | 37 | ||
37 | enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS }; | 38 | enum tagtype { TAGTYPE_APE = 1, TAGTYPE_VORBIS }; |
38 | 39 | ||
@@ -1858,6 +1859,104 @@ static bool get_adx_metadata(int fd, struct mp3entry* id3) | |||
1858 | return true; | 1859 | return true; |
1859 | } | 1860 | } |
1860 | 1861 | ||
1862 | static bool get_spc_metadata(int fd, struct mp3entry* id3) | ||
1863 | { | ||
1864 | /* Use the trackname part of the id3 structure as a temporary buffer */ | ||
1865 | unsigned char * buf = (unsigned char *)id3->path; | ||
1866 | int read_bytes; | ||
1867 | char * p; | ||
1868 | |||
1869 | unsigned long length; | ||
1870 | unsigned long fade; | ||
1871 | bool isbinary = true; | ||
1872 | int i; | ||
1873 | |||
1874 | /* try to get the ID666 tag */ | ||
1875 | if ((lseek(fd, 0x2e, SEEK_SET) < 0) | ||
1876 | || ((read_bytes = read(fd, buf, 0xD2)) < 0xD2)) | ||
1877 | { | ||
1878 | DEBUGF("lseek or read failed\n"); | ||
1879 | return false; | ||
1880 | } | ||
1881 | |||
1882 | p = id3->id3v2buf; | ||
1883 | |||
1884 | id3->title = p; | ||
1885 | buf[31] = 0; | ||
1886 | p = iso_decode(buf, p, 0, 32); | ||
1887 | buf += 32; | ||
1888 | |||
1889 | id3->album = p; | ||
1890 | buf[31] = 0; | ||
1891 | p = iso_decode(buf, p, 0, 32); | ||
1892 | buf += 48; | ||
1893 | |||
1894 | id3->comment = p; | ||
1895 | buf[31] = 0; | ||
1896 | p = iso_decode(buf, p, 0, 32); | ||
1897 | buf += 32; | ||
1898 | |||
1899 | /* Date check */ | ||
1900 | if(buf[2] == '/' && buf[5] == '/') | ||
1901 | isbinary = false; | ||
1902 | |||
1903 | /* Reserved bytes check */ | ||
1904 | if(buf[0xD2 - 0x2E - 112] >= '0' && | ||
1905 | buf[0xD2 - 0x2E - 112] <= '9' && | ||
1906 | buf[0xD3 - 0x2E - 112] == 0x00) | ||
1907 | isbinary = false; | ||
1908 | |||
1909 | /* is length & fade only digits? */ | ||
1910 | for (i=0;i<8 && ( | ||
1911 | (buf[0xA9 - 0x2E - 112+i]>='0'&&buf[0xA9 - 0x2E - 112+i]<='9') || | ||
1912 | buf[0xA9 - 0x2E - 112+i]=='\0'); | ||
1913 | i++); | ||
1914 | if (i==8) isbinary = false; | ||
1915 | |||
1916 | if(isbinary) { | ||
1917 | unsigned char * tbuf = buf; | ||
1918 | |||
1919 | id3->year = tbuf[0] | (tbuf[1]<<8); | ||
1920 | buf += 11; | ||
1921 | |||
1922 | length = (buf[0] | (buf[1]<<8) | (buf[2]<<16)) * 1000; | ||
1923 | buf += 3; | ||
1924 | |||
1925 | fade = (buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24)); | ||
1926 | buf += 4; | ||
1927 | } else { | ||
1928 | char tbuf[6]; | ||
1929 | |||
1930 | buf += 6; | ||
1931 | buf[4] = 0; | ||
1932 | id3->year = atoi(buf); | ||
1933 | buf += 5; | ||
1934 | |||
1935 | memcpy(tbuf, buf, 3); | ||
1936 | tbuf[3] = 0; | ||
1937 | length = atoi(tbuf) * 1000; | ||
1938 | buf += 3; | ||
1939 | |||
1940 | memcpy(tbuf, buf, 5); | ||
1941 | tbuf[5] = 0; | ||
1942 | fade = atoi(tbuf); | ||
1943 | buf += 5; | ||
1944 | } | ||
1945 | |||
1946 | id3->artist = p; | ||
1947 | buf[31] = 0; | ||
1948 | p = iso_decode(buf, p, 0, 32); | ||
1949 | |||
1950 | if (global_settings.repeat_mode!=REPEAT_ONE && length==0) { | ||
1951 | length=3*60*1000; /* 3 minutes */ | ||
1952 | fade=5*1000; /* 5 seconds */ | ||
1953 | } | ||
1954 | |||
1955 | id3->length = length+fade; | ||
1956 | |||
1957 | return true; | ||
1958 | } | ||
1959 | |||
1861 | static bool get_aiff_metadata(int fd, struct mp3entry* id3) | 1960 | static bool get_aiff_metadata(int fd, struct mp3entry* id3) |
1862 | { | 1961 | { |
1863 | /* Use the trackname part of the id3 structure as a temporary buffer */ | 1962 | /* Use the trackname part of the id3 structure as a temporary buffer */ |
@@ -2173,6 +2272,11 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname, | |||
2173 | } | 2272 | } |
2174 | break; | 2273 | break; |
2175 | case AFMT_SPC: | 2274 | case AFMT_SPC: |
2275 | if(!get_spc_metadata(fd, &(track->id3))) | ||
2276 | { | ||
2277 | DEBUGF("get_spc_metadata error\n"); | ||
2278 | } | ||
2279 | |||
2176 | track->id3.filesize = filesize(fd); | 2280 | track->id3.filesize = filesize(fd); |
2177 | track->id3.genre_string = id3_get_num_genre(36); | 2281 | track->id3.genre_string = id3_get_num_genre(36); |
2178 | break; | 2282 | break; |
@@ -2182,7 +2286,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname, | |||
2182 | DEBUGF("get_adx_metadata error\n"); | 2286 | DEBUGF("get_adx_metadata error\n"); |
2183 | return false; | 2287 | return false; |
2184 | } | 2288 | } |
2185 | 2289 | ||
2186 | break; | 2290 | break; |
2187 | case AFMT_NSF: | 2291 | case AFMT_NSF: |
2188 | buf = (unsigned char *)track->id3.path; | 2292 | buf = (unsigned char *)track->id3.path; |
@@ -2194,7 +2298,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname, | |||
2194 | track->id3.vbr = false; | 2298 | track->id3.vbr = false; |
2195 | track->id3.filesize = filesize(fd); | 2299 | track->id3.filesize = filesize(fd); |
2196 | if (memcmp(buf,"NESM",4) && memcmp(buf,"NSFE",4)) return false; | 2300 | if (memcmp(buf,"NESM",4) && memcmp(buf,"NSFE",4)) return false; |
2197 | break; | 2301 | break; |
2198 | 2302 | ||
2199 | case AFMT_AIFF: | 2303 | case AFMT_AIFF: |
2200 | if (!get_aiff_metadata(fd, &(track->id3))) | 2304 | if (!get_aiff_metadata(fd, &(track->id3))) |