mirror of
https://github.com/TangentFoxy/FindingMusic.git
synced 2024-11-25 10:24:21 +00:00
added name(), remove(), updated db, typos
This commit is contained in:
parent
aa3d0a8f21
commit
3702be34e7
@ -22,6 +22,10 @@ enforced by the library.
|
||||
- `buy`: (String or NULL) a URL where it can be bought (or where I bought it)
|
||||
- `favorite`: (TRUE or NULL) a favorite track
|
||||
- `genre`: (String or NULL) primary genre
|
||||
- `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)
|
||||
|
||||
(Note: I'm sure I've downloaded many tracks that aren't marked as downloaded.)
|
||||
|
||||
@ -36,6 +40,7 @@ A simple interface library to use in a Lua REPL.
|
||||
- `add(str)` adds a new track (checks for duplicates)
|
||||
- `add_file(file_name)` adds new tracks from the specified file (file must have
|
||||
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
|
||||
- `set(match, info)` match can be a list (as is returned by find) or a track
|
||||
@ -43,6 +48,7 @@ A simple interface library to use in a Lua REPL.
|
||||
these will be set on the matched tracks, overwriting existing values if a key
|
||||
is already in use
|
||||
- `normalize(str)` returns a normalized form of the input string
|
||||
- `name(name)` returns the first name of a track (input is normalized)
|
||||
|
||||
`music.random(count, match, include, exclude)` is a little more complicated.
|
||||
- `count` is the maximum number of returned names, and defaults to 1
|
||||
|
File diff suppressed because one or more lines are too long
18
music.lua
18
music.lua
@ -8,6 +8,15 @@ function music.normalize(str)
|
||||
return str:gsub("%W", ""):lower()
|
||||
end
|
||||
|
||||
function music.name(name)
|
||||
local entry = music.data[music.normalize(name)]
|
||||
if entry then
|
||||
return entry.names[1]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
function music.load(force, file_name)
|
||||
if music.data and not force then
|
||||
print("Music library was already loaded, use 'music.load(true)' to force load.")
|
||||
@ -149,6 +158,15 @@ function music.add_file(file_name)
|
||||
return true
|
||||
end
|
||||
|
||||
function music.remove(name)
|
||||
local normalized = music.normalize(name)
|
||||
if music.data[normalized] then
|
||||
music.data[normalized] = nil
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- match is a name or a list of names, info is a table of key-value pairs to be set
|
||||
function music.set(match, info)
|
||||
if type(match) == "table" then
|
||||
|
@ -6,7 +6,7 @@ if not success then
|
||||
print("Install 'urlencode' through LuaRocks for this script to function optimally.")
|
||||
end
|
||||
|
||||
local help == [[Usages:
|
||||
local help = [[Usage:
|
||||
|
||||
search-tracklist <file>
|
||||
|
||||
|
48
search.lua
Executable file
48
search.lua
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env lua
|
||||
|
||||
local success, urlencode = pcall(function() return require("urlencode") end)
|
||||
if not success then
|
||||
urlencode = nil
|
||||
print("Install 'urlencode' through LuaRocks for this script to function optimally.")
|
||||
end
|
||||
local success, music = pcall(function() return require("music") end)
|
||||
if not success then
|
||||
print("music.lua library (and its adjacent music.json database) must be installed.")
|
||||
return
|
||||
end
|
||||
|
||||
local help = [[Usage:
|
||||
|
||||
search <count> <funkwhale>
|
||||
|
||||
<count>: How many tracks to search for. Defaults to 10
|
||||
(Opens a new tab per track in your default browser searching Google.)
|
||||
<funkwhale>: Whether or not to search my FunkWhale instance for the track also.
|
||||
|
||||
Optionally requires urlencode to be installed from LuaRocks.
|
||||
Currently only tested on MacOS 11.4 (Big Sur).
|
||||
]]
|
||||
if arg[1]:find("h") then
|
||||
print(help)
|
||||
return false
|
||||
end
|
||||
|
||||
local count = tonumber(arg[1]) or 10
|
||||
local funkwhale = arg[2]
|
||||
|
||||
local results = music.random(count, nil, nil, {downloaded = true, searched = true})
|
||||
local track
|
||||
for _,v in ipairs(results) do
|
||||
track = music.data[v].names[1]
|
||||
if urlencode then
|
||||
track = urlencode.encode_url(track)
|
||||
else
|
||||
track = track:gsub("%s", "+"):gsub("&", "&")
|
||||
end
|
||||
os.execute("open \"https://google.com/search?q=" .. track .. "\"")
|
||||
if funkwhale then
|
||||
os.execute("open \"https://funkwhale.tangentfox.com/search?q=" .. track .. "&type=tracks\"")
|
||||
end
|
||||
end
|
||||
music.set(results, {searched = true})
|
||||
music.save()
|
Loading…
Reference in New Issue
Block a user