aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_local/guess.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Plugins/Library/ml_local/guess.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/Plugins/Library/ml_local/guess.cpp')
-rw-r--r--Src/Plugins/Library/ml_local/guess.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/Src/Plugins/Library/ml_local/guess.cpp b/Src/Plugins/Library/ml_local/guess.cpp
new file mode 100644
index 00000000..24686ddc
--- /dev/null
+++ b/Src/Plugins/Library/ml_local/guess.cpp
@@ -0,0 +1,122 @@
+#include <string.h>
+#include <memory.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <windows.h>
+
+wchar_t *guessTitles(const wchar_t *filename,
+ int *tracknum,
+ wchar_t **artist,
+ wchar_t **album,
+ wchar_t **title) // should free the result of this function after using artist/album/title
+{
+ *tracknum=0;
+ *artist=0;
+ *album=0;
+ *title=0;
+
+ if (!filename[0]) return 0;
+
+ wchar_t *_artist=NULL;
+ wchar_t *_album=NULL;
+
+ const wchar_t *f=filename;
+ while (f && *f) f++;
+ while (f && (f > filename) && *f != L'/' && *f != L'\\') f--;
+
+ if (f == filename) return 0;
+
+ int dirlen = f-filename;
+
+ wchar_t *fullfn = (wchar_t*)_wcsdup(filename);
+ fullfn[dirlen]=0;
+
+ wchar_t *n=fullfn+dirlen;
+ while (n >= fullfn && *n != L'/' && *n != L'\\') n--;
+ n++;
+
+ // try to guess artist and album from the dirname
+ if (!wcsstr(n,L"-")) // assume dir name is album name, artist name unknown
+ {
+ *album=n;
+ _album=n;
+ }
+ else
+ {
+ *artist=_artist=n;
+ _album=wcsstr(n,L"-")+1;
+ wchar_t *t=_album-2;
+ while (t >= n && *t == L' ') t--;
+ t[1]=0;
+
+ while (_album && *_album == L' ') _album++;
+ *album=_album;
+ }
+
+ // get filename shizit
+ wcsncpy(fullfn+dirlen+1,filename+dirlen+1,wcslen(filename) - (dirlen + 1));
+
+ n=fullfn+dirlen+1;
+ while (n && *n) n++;
+ while (n > fullfn+dirlen+1 && *n != L'.') n--;
+ if (*n == L'.') *n=0;
+ n=fullfn+dirlen+1;
+
+ while (n && *n == L' ') n++;
+
+ // detect XX. filename
+ if (wcsstr(n,L".") && _wtoi(n) && _wtoi(n) < 130)
+ {
+ wchar_t *tmp=n;
+ while (tmp && *tmp >= L'0' && *tmp <= L'9') tmp++;
+ while (tmp && *tmp == L' ') tmp++;
+ if (tmp && *tmp == L'.')
+ {
+ *tracknum=_wtoi(n);
+ n=tmp+1;
+ while (n && *n == L'.') n++;
+ while (n && *n == L' ') n++;
+ }
+ }
+
+ // detect XX- filename
+ if (!*tracknum && wcsstr(n,L"-") && _wtoi(n) && _wtoi(n) < 130)
+ {
+ wchar_t *tmp=n;
+ while (tmp && *tmp >= L'0' && *tmp <= L'9') tmp++;
+ while (tmp && *tmp == L' ') tmp++;
+ if (tmp && *tmp == L'-')
+ {
+ *tracknum=_wtoi(n);
+ n=tmp+1;
+ while (n && *n == L'-') n++;
+ while (n && *n == L' ') n++;
+ }
+ }
+
+ while (wcsstr(n,L"-"))
+ {
+ wchar_t *a=n;
+ n=wcsstr(n,L"-");
+ {
+ wchar_t *t=n-1;
+ while (t >= a && *t == L' ') t--;
+ t[1]=0;
+ }
+ *n=0;
+ n++;
+ while (n && *n == L'-') n++;
+ while (n && *n == L' ') n++;
+
+ // a is the next token.
+ if (!*tracknum && !_wcsnicmp(a,L"Track ",6) && _wtoi(a+6)) *tracknum=_wtoi(a+6);
+ else if (*artist== _artist)
+ {
+ *artist=a;
+ }
+ if (*artist != _artist && *tracknum) break;
+ }
+ *title=n;
+
+ return fullfn;
+} \ No newline at end of file