From 89784435d0ca05bdf230407584ccb8e6dec40c15 Mon Sep 17 00:00:00 2001 From: Antoine Jacquet Date: Sun, 15 Jan 2023 12:25:18 +0100 Subject: [PATCH] version 0.44 (by Andreas Neuper) * add UTF-16 support --- ChangeLog | 3 +++ configure | 2 +- configure.in | 2 +- fapg.c | 32 +++++++++++++++++++++++++++----- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1380eb3..42f47a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ Change log file for FAPG +version 0.44 (2023-01-15) (by Andreas Neuper) + * add UTF-16 support + version 0.43 (2020-03-27) (by François Revol) * parse ID3v2.3 TLEN as a fallback for duration detection * don't skip printing EXTINF for unknown durations diff --git a/configure b/configure index 8b85125..f1b5912 100755 --- a/configure +++ b/configure @@ -2060,7 +2060,7 @@ fi # Define the identity of the package. PACKAGE=fapg - VERSION=0.43 + VERSION=0.44 cat >>confdefs.h <<_ACEOF diff --git a/configure.in b/configure.in index 647de5a..09bd51a 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) AC_INIT(fapg.c) -AM_INIT_AUTOMAKE(fapg, 0.43) +AM_INIT_AUTOMAKE(fapg, 0.44) AC_PROG_INSTALL AC_PROG_CC diff --git a/fapg.c b/fapg.c index bd2b3f0..e9d2b4d 100644 --- a/fapg.c +++ b/fapg.c @@ -44,8 +44,9 @@ #define MP3_BASE 1024 #define OGG_BASE 1024*10 #define MAX 1024*250 /* 250ko for ID3 with JPEG images in it */ +#define MAX_ITEM 1024 -#define FORMAT_M3U 0 +#define FORMAT_M3U 0 /* "0" is not a good choice for debugging, but OK for a default */ #define FORMAT_PLS 1 #define FORMAT_HTML 2 #define FORMAT_RSS 3 @@ -74,9 +75,9 @@ unsigned char buffer[MAX]; int counter = 0; -unsigned char artist[1024]; -unsigned char title[1024]; -unsigned char genrebuf[1024]; +unsigned char artist[MAX_ITEM]; +unsigned char title[MAX_ITEM]; +unsigned char genrebuf[MAX_ITEM]; unsigned char genre = 0; int duration; #define MP2ENC 1 @@ -259,6 +260,23 @@ void mywebputstr(const char *c) } } +void utf16toutf8(char *c,int n) +{ + /* check whether the we need to convert UTF-16 to UTF-8 strings */ + if ( ( c[0] != '\377' ) || ( c[1] != '\376' ) ) { return; } + /* only continue here, if the first 2 letters are 0xfffe * + * c references an UTF-16 input, where latin letters are * + * separated by zero bytes, which we need to eliminate */ + int i=0; --n; + for(int j=2; (j> parsing mp3 : %s\n", file); /* read header */ - if((fic = fopen(file, "r")) == NULL) { + if((fic = fopen(file, "rb")) == NULL) { fprintf(stderr, "Warning >> can't open file : %s\n", file); return; } @@ -732,10 +750,12 @@ void parse_mp3(unsigned char *file) if(*c == 0) break; if(strncmp(c, "TT2", 3) == 0) { + utf16toutf8(c+7,size); strncpy(title, c + 7, size - 1); title[size - 1] = '\0'; } if(strncmp(c, "TP1", 3) == 0) { + utf16toutf8(c+7,size); strncpy(artist, c + 7, size - 1); artist[size - 1] = '\0'; } @@ -755,10 +775,12 @@ void parse_mp3(unsigned char *file) if(*c == 0) break; if(strncmp(c, "TIT2", 4) == 0) { + utf16toutf8(c+11,size); strncpy(title, c + 11, size - 1); title[size - 1] = '\0'; } if(strncmp(c, "TPE1", 4) == 0) { + utf16toutf8(c+11,size); strncpy(artist, c + 11, size - 1); artist[size - 1] = '\0'; } -- 2.20.1