bug fixes, db updates, readme updated

This commit is contained in:
Rose Liverman 2021-09-29 23:17:08 -06:00
parent 08372b05d7
commit f17a44e91f
4 changed files with 29 additions and 11 deletions

View File

@ -25,7 +25,8 @@ enforced by the library.
- `invalid`: (TRUE or NULL) whether or not this is actually a track (whoops!)
- `searched`: (TRUE or NULL) whether or not a track has been searched for using
`search.lua` (I'm being lazy, and obtaining music this way without fully
updating the database, sue me)
updating the database, sue me) (note: this script has an issue with tracks
with special characters in their names, I am not sure of the cause)
(Note: I'm sure I've downloaded many tracks that aren't marked as downloaded.)
@ -42,7 +43,8 @@ A simple interface library to use in a Lua REPL.
one track per line, ignores empty lines)
- `remove(name)` removes a track, if it exists (input is normalized)
- `find(str)` finds possible track matches by normalizing the input string,
returns them as a list of normalized names
returns them as a list of normalized names (cannot handle already normalized
input in my db because of a bug)
- `set(match, info)` match can be a list (as is returned by find) or a track
name (either will be normalized), info must be a table of key-value pairs,
these will be set on the matched tracks, overwriting existing values if a key

File diff suppressed because one or more lines are too long

View File

@ -10,6 +10,7 @@ end
function music.name(name)
local entry = music.data[music.normalize(name)]
if not entry then entry = music.data[name] end -- some normalized names have extra characters somehow
if entry then
return entry.names[1]
else
@ -102,10 +103,15 @@ function music.random(count, match, include, exclude)
end
if type(match) == "table" then
for _, v in ipairs(match) do
table.insert(matches, music.normalize(v))
table.insert(matches, v) -- should be normalized already
end
elseif type(match) == "string" then
-- compensating for db bug...
if music.data[music.normalize(match)] then
matches[1] = music.normalize(match)
else
matches[1] = match
end
else
for k in pairs(music.data) do
table.insert(matches, k)
@ -126,7 +132,7 @@ function music.random(count, match, include, exclude)
return results
end
function music.add(name)
function music.add(name) -- input should never be normalized
local normalized = music.normalize(name)
local entry = music.data[normalized]
if entry then
@ -160,6 +166,7 @@ end
function music.remove(name)
local normalized = music.normalize(name)
if not music.data[normalized] then normalized = name end -- handling db bug
if music.data[normalized] then
music.data[normalized] = nil
return true
@ -177,8 +184,9 @@ function music.set(match, info)
end
tab = music.data[music.normalize(match)]
if not tab then tab = music.data[match] end -- compensating for database bug
if not tab then
print("'" .. tab .. "' does not exist!")
print("'" .. match .. "' does not exist!")
return false
end
for key, value in pairs(info) do

View File

@ -31,10 +31,14 @@ local count = tonumber(arg[1]) or 10
local funkwhale = arg[2]
local results = music.random(count, nil, nil, {downloaded = true, searched = true})
local track
local errors_occurred, track = false
for _,v in ipairs(results) do
track = music.name(v) -- music.data[v].names[1]
if not track then print("Track '" .. v .. "' does not exist?") end -- shouldn't happen
if not track then
print("Track '" .. v .. "' does not exist?")
errors_occurred = true
break
end
if urlencode then
track = urlencode.encode_url(track)
else
@ -45,5 +49,9 @@ for _,v in ipairs(results) do
end
os.execute("open \"https://google.com/search?q=" .. track .. "\"")
end
if errors_occurred then
print("Database not saved because errors occurred.")
else
music.set(results, {searched = true})
music.save()
end