command getDownloadedAudio
local tList, tSearchA, tURL, tFolder, tTitle, tTitles, tDataA
put empty into sDownloadedAudioA
# do directory walk of the media/audio folder
put (path_Documents() & "media/audio") into tFolder
put listFilesWithPaths(tFolder, "true") into tList
repeat with x = 1 to (the number of lines of tList)
put line x of tList into tURL
put tURL into sDownloadedAudioA[x]["localURL"]
set the itemdel to "/"
put item -2 of tURL into sDownloadedAudioA[x]["file_id"]
end repeat
repeat for each line tKey in the keys of sDownloadedAudioA
put sDownloadedAudioA[tKey]["file_id"] into tSearchA["file_id"]
## This fetchMediaItems funciton loads data from local copy of
## JNANAM SQLite file which might be outdated.
put fetchMediaItems(tSearchA) into tDataA
-- BR: this return an error
-- going to server, 4/5/2021 was an update
-- installing it, it worked
-- we should talk about together on Skype
if tDataA[1]["file_id"] is empty then
throw "jnanam.sqlite is not up to date"
exit getDownloadedAudio
end if
put tDataA into sDownloadedAudioA[tKey]["metadata"]
end repeat
# first look in the dates base
repeat with x = 1 to (the number lines of keys of sDownloadedAudioA)
if sDownloadedAudioA[x]["file_id"] contains "-audiobook" then
# get in from file names
set the itemdel to "/"
put item -1 of sDownloadedAudioA[x]["localURL"] into tTitle
put normalizeFileToTitle(tTitle) after tTitles
put cr & cr after tTitles
next repeat
end if
put sDownloadedAudioA[x]["metadata"][1]["title"] into tTitle
if tTitle is empty then
put sDownloadedAudioA[x]["file_id"] into tTitle
put normalizeFileToTitle(tTitle) after tTitles
else
put tTitle after tTitles
end if
put cr after tTitles
if sDownloadedAudioA[x]["metadata"][1]["media_type"] ="audio/song" then
put sDownloadedAudioA[x]["metadata"][1]["artists"] after tTitles
end if
put cr after tTitles
end repeat
# getting the final cr out
delete char -1 of tTitles
loadTitles tTitles
return sDownloadedAudioA
end getDownloadedAudio