-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilaudio.bas
More file actions
408 lines (369 loc) · 15.3 KB
/
Copy pathutilaudio.bas
File metadata and controls
408 lines (369 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
' file type specific functions
' ______________________________________________________________________________'
' code by squall4226
' see https://www.freebasic.net/forum/viewtopic.php?p=149207&hilit=user+need+TALB+for+album#p149207
' april 2026 tweaked to deal with both 64 and 32 bit
Function getmp3tag(searchtag As String, fn As String) As String
Dim As Long skip, offset
Dim As LongInt count, maxcheck = 3000
Dim As Long fnum
Dim As UInteger tag_length
Dim As String tagdata, searchSig, sig_str
Dim As Long i
Dim As Byte b1, b2, b3, b4, textEnc
' Tag normalization
Select Case UCase(searchtag)
Case "HEADER", "ID3"
searchSig = "ID3" & Chr(&h03)
Case "TITLE", "TIT2"
searchSig = "TIT2"
Case "ARTIST", "TPE1"
searchSig = "TPE1"
Case "ALBUM", "TALB"
searchSig = "TALB"
Case "COMMENT", "COMM"
searchSig = "COMM"
Case "COPYRIGHT", "TCOP"
searchSig = "TCOP"
Case "COMPOSER", "TCOM"
searchSig = "TCOM"
Case "BEATS PER MINUTE", "BPM", "TBPM"
searchSig = "TBPM"
Case "PUBLISHER", "TPUB"
searchSig = "TPUB"
Case "URL", "WXXX"
searchSig = "WXXX"
Case "PLAY COUNT", "PCNT"
searchSig = "PCNT"
Case "GENRE", "TCON"
searchSig = "TCON"
Case "ENCODER", "TENC"
searchSig = "TENC"
Case "TRACK", "TRACK NUMBER", "TRCK"
searchSig = "TRCK"
Case "YEAR", "TYER"
searchSig = "TYER"
Case "PICTURE", "APIC"
searchSig = "APIC"
Case Else
Return "----"
End Select
fnum = FreeFile
Open fn For Binary Access Read As #fnum
If Lof(fnum) < maxcheck Then maxcheck = Lof(fnum)
For count = 1 To maxcheck - 10 Step 1
' Read 4 bytes for tag ID
Get #fnum, count, b1
Get #fnum, count + 1, b2
Get #fnum, count + 2, b3
Get #fnum, count + 3, b4
' Reconstruct as string
sig_str = Chr(b1) & Chr(b2) & Chr(b3) & Chr(b4)
If sig_str = Left(searchSig, 4) Then
If searchSig = "ID3" & Chr(&h03) Then
Close #fnum
Return "1"
EndIf
' Read syncsafe size (4 bytes at offset 4)
Get #fnum, count + 4, b1
Get #fnum, count + 5, b2
Get #fnum, count + 6, b3
Get #fnum, count + 7, b4
tag_length = (CLng(b1) Shl 24) Or (CLng(b2) Shl 16) Or (CLng(b3) Shl 8) Or CLng(b4)
' Decode syncsafe integer
tag_length = ((tag_length And &h7F000000) Shr 24) Or _
((tag_length And &h007F0000) Shr 16) Or _
((tag_length And &h00007F00) Shr 8) Or _
(tag_length And &h0000007F)
If tag_length < 2 Then
Close #fnum
Return "ERROR"
EndIf
' Frame data starts at count + 10
Dim As Byte dataget(1 To tag_length)
Get #fnum, count + 10, dataget()
' Get encoding byte (byte 1)
textEnc = dataget(1)
' Handle different text encodings
Select Case textEnc
Case 0
' ISO-8859-1 (single byte)
For i = 2 To tag_length
If dataget(i) = 0 Then Exit For
If dataget(i) >= 32 Then
tagdata = tagdata & Chr(dataget(i))
EndIf
Next
Case 1
' UTF-16 with BOM (2 bytes per character)
i = 2
' Skip BOM if present (bytes -1, -2 = 0xFF, 0xFE in two's complement)
If dataget(2) = 255 And dataget(3) = 254 Then
i = 4
EndIf
' Read UTF-16LE (little-endian)
While i < tag_length
If dataget(i) = 0 And dataget(i + 1) = 0 Then Exit While
If dataget(i) >= 32 And dataget(i) <> 0 Then
tagdata = tagdata & Chr(dataget(i))
EndIf
i = i + 2
Wend
Case 2
' UTF-16BE (big-endian)
For i = 2 To tag_length Step 2
If dataget(i) = 0 And dataget(i + 1) = 0 Then Exit For
If dataget(i + 1) >= 32 Then
tagdata = tagdata & Chr(dataget(i + 1))
EndIf
Next
Case 3
' UTF-8
For i = 2 To tag_length
If dataget(i) = 0 Then Exit For
If dataget(i) >= 32 Then
tagdata = tagdata & Chr(dataget(i))
EndIf
Next
End Select
Exit For
End If
Next
Close #fnum
If Len(tagdata) = 0 Then
tagdata = "----"
EndIf
Return tagdata
End Function
' get base mp3 info
function getmp3baseinfo(fx1File as string) as boolean
taginfo(1) = getmp3tag("artist",fx1File)
taginfo(2) = getmp3tag("title", fx1File)
taginfo(3) = getmp3tag("album", fx1File)
taginfo(4) = getmp3tag("year", fx1File)
taginfo(5) = getmp3tag("genre", fx1File)
' use last part path as theme
ReDim As String ordinance(0)
explode(fx1File, "\", ordinance())
taginfo(6) = ordinance(UBound(ordinance) -1)
if taginfo(1) <> "----" and taginfo(2) <> "----" then
'nop
else
taginfo(1) = mid(left(fx1File, len(fx1File) - instr(fx1File, pathchar) -1), InStrRev(fx1File, pathchar) + 1, len(fx1File))
taginfo(2) = ""
end if
return true
end function
/' get http stream info
function gethttpstreaminfo(fx1Handle as HSTREAM) as boolean
dim as const zstring ptr meta
dim as string artist,title
' shoutcast
meta = BASS_ChannelGetTags(fx1Handle, BASS_TAG_META)
' icecast
if meta = 0 then
meta = BASS_ChannelGetTags(fx1Handle, BASS_TAG_OGG)
end if
if meta <> 0 then
dim as string raw = *meta
dim as integer start = instr(raw, "'") + 1
dim as integer endpos = instr(start, raw, "';")
title = mid(raw, start, endpos - start)
dim as integer dashpos = instr(title, " - ")
if dashpos > 0 then
artist = left(title, dashpos - 1)
title = mid(title, dashpos + 3)
else
artist = title ' artist and title
end if
' print *meta
end if
taginfo(1) = artist
taginfo(2) = title
taginfo(3) = "----"
taginfo(4) = "----"
taginfo(5) = "----"
return true
end function
'/
function getmp3playlist(filename as string, listtype as string) as integer
dim as long f
dim itemnr as integer = 1
dim listitem as string
dim mp3listtype as string = ""
dim temptitle as string = ""
select case true
case instr(lcase(filename), ".pls") > 0
mp3listtype = "pls"
case instr(lcase(filename), ".m3u") > 0
mp3listtype = "m3u"
case else
return 0
end select
if len(filename) = 0 then
logentry("warning", filename + " path or file not found.")
else
logentry("notice", "parsing and playing plylist " + filename)
end if
f = freefile
Open filename For input As #f
itemnr = 0
do until eof(f)
line input #f, listitem
listitem = trim(listitem)
if mp3listtype = "pls" then
if instr(listitem, "=") > 0 then
select case true
case instr(lcase(listitem), "file") = 1
itemnr += 1
redim preserve listrec.listname(0 to itemnr)
redim preserve listrec.listfile(0 to itemnr)
redim preserve listrec.listtype(0 to itemnr)
redim preserve listrec.listseqh(0 to itemnr)
listrec.listfile(itemnr) = trim( mid(listitem, instr(listitem, "=") + 1) )
listrec.listname(itemnr) = ""
listrec.listtype(itemnr) = listtype
listrec.listseqh(itemnr) = 0
case instr(lcase(listitem), "title") = 1
if itemnr >= 0 then
listrec.listname(itemnr) = trim( mid(listitem, instr(listitem, "=") + 1) )
end if
case else
' nop
end select
end if
end if
if mp3listtype = "m3u" then
if len(listitem) > 0 then
select case true
case left(listitem, 7) = "#EXTINF"
dim as integer p = instr(listitem, ",")
if p > 0 then
temptitle = trim( mid(listitem, p + 1) )
else
temptitle = ""
end if
case left(listitem, 1) <> "#"
' file/url line (after EXTINF or plain entry)
itemnr += 1
redim preserve listrec.listname(0 to itemnr)
redim preserve listrec.listfile(0 to itemnr)
redim preserve listrec.listtype(0 to itemnr)
redim preserve listrec.listseqh(0 to itemnr)
listrec.listfile(itemnr) = listitem
listrec.listname(itemnr) = temptitle
listrec.listtype(itemnr) = listtype
listrec.listseqh(itemnr) = 0
temptitle = ""
case else
' nop
end select
end if
end if
loop
close f
'for i as integer = 0 to ubound(listrec.listname)
' with listrec
' print listrec.listname(i)
' print listrec.listfile(i)
' print listrec.listtype(i)
' print listrec.listseqh(i)
' end with
'next i
'maxmusicitems = itemnr
return itemnr
end function
' export m3u
' based on recursive dir code of coderjeff https://www.freebasic.net/forum/viewtopic.php?t=5758
function exportm3u(folder as string, filterext as string, listtype as string = "m3u", htmloutput as string = "default", tag as string = "", tagquery as string = "") as integer
' setup filelist
dim as integer i = 1, j=1, n = 1, attrib, itemnr, maxfiles
dim dummy as string
dim dummy2 as string
dim tbname as string
dim file as string
dim fileext as string
dim fsize as long
dim fdate as string
dim fattr as string
dim argc(0 to 5) as string
dim argv(0 to 5) as string
redim path(1 to 1) As string
'export to m3u
Open exepath + pathchar + tagquery + ".m3u" For output As #20
print #20, "#EXTM3U"
print "exporting result to " & exepath + pathchar + tagquery + ".m3u" & " ..."
' read dir recursive starting directory
path(1) = folder
if( right(path(1), 1) <> pathchar) then
file = dir(path(1), fbNormal or fbDirectory, @attrib)
if( attrib and fbDirectory ) then
path(1) += pathchar
end if
end if
itemnr = 0
cls
while i <= n
file = dir(path(i) + "*" , fbNormal or fbDirectory, @attrib)
while file > ""
if (attrib and fbDirectory) then
if file <> "." and file <> ".." then
n += 1
redim preserve path(1 to n)
path(n) = path(i) + file + pathchar
end if
else
fileext = lcase(mid(file, instrrev(file, ".")))
if instr(1, filterext, fileext) > 0 and len(fileext) > 3 then
' get specific file information
fsize = filelen(path(i) + file)
fdate = Format(FileDateTime(path(i) + file), "yyyy-mm-dd hh:mm:ss" )
If (attrib And fbReadOnly) <> 0 Then fattr = "read-only"
If (attrib And fbHidden ) <> 0 Then fattr = "hidden"
If (attrib And fbSystem ) <> 0 Then fattr = "system"
If (attrib And fbArchive ) <> 0 Then fattr = "archived"
select case listtype
case "m3u"
if instr(filterext, ".mp3") > 0 and htmloutput = "exif" then
Locate 1, 1
print "scanning " & folder + " with filespec " + filterext + " with tag " & tag & " contains " & tagquery
print str(itemnr)
itemnr += 1
' path(i) folder and drive
getmp3baseinfo(path(i) + file)
argc(0) = "artist"
argc(1) = "title"
argc(2) = "album"
argc(3) = "year"
argc(4) = "genre"
argc(5) = "nop"
argv(0) = taginfo(1)
argv(1) = taginfo(2)
argv(2) = taginfo(3)
argv(3) = taginfo(4)
argv(4) = taginfo(5)
argv(5) = "nop"
end if
For j As Integer = 0 To 5
'export to m3u
if argc(j) = tag and instr(lcase(argv(j)), lcase(tagquery)) > 0 then
print #20, "#EXTINF:134," & argv(0) & " - " & argv(1)
print #20, path(i) & file
maxfiles += 1
end if
Next j
end select
else
'logentry("warning", "file format not supported - " + path(i) & file)
end if
end if
file = dir(@attrib)
wend
i += 1
wend
itemnr = itemnr - 1
print "scanned " & itemnr & " files in " + folder + " with filespec " + filterext + " " & maxfiles & " file(s) found with " & tag & " " & tagquery
logentry("notice", "scanned and exported m3u")
close(20)
return maxfiles
end function