Skip to content

Commit

Permalink
Merge pull request #8 from ducktordanny/fix/comma-breaking-track-list
Browse files Browse the repository at this point in the history
Fix: Broken list items by comma
  • Loading branch information
p5quared authored Jul 20, 2024
2 parents 07daeaa + 58b18ee commit deda524
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions lua/apple-music/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,15 @@ end
---Get a list of playlists from your Apple Music library
---@usage require('nvim-apple-music').get_playlists()
M.get_playlists = function()
local command = [[osascript -e 'tell application "Music" to get name of playlists']]
local command = [[osascript -e 'tell application "Music" to get name of playlists' -s s]]

local handle = io.popen(command)
local result = handle:read("*a")
handle:close()

-- Split the result into a table of playlist names
local playlists = {}
for playlist in result:gmatch("([^,]+)") do
playlist = playlist:match("^%s*(.-)%s*$")
table.insert(playlists, playlist)
end
-- Convert table string into table
local result_chunk = "return " .. result
local playlists = loadstring(result_chunk)()

return playlists
end
Expand Down Expand Up @@ -295,16 +292,14 @@ end
---Get a list of albums from your Apple Music library
---@usage require('nvim-apple-music').get_albums()
M.get_albums = function()
local command = [[osascript -e 'tell application "Music" to get album of every track']]
local command = [[osascript -e 'tell application "Music" to get album of every track' -s s]]
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
-- Split the result into a table of album names
local albums = {}
for album in result:gmatch("([^,]+)") do
album = album:match("^%s*(.-)%s*$")
table.insert(albums, album)
end

-- Convert table string into table
local result_chunk = "return " .. result
local albums = loadstring(result_chunk)()

local unique_albums = remove_duplicates(albums)

Expand Down Expand Up @@ -336,16 +331,15 @@ end
---Get a list of tracks from your Apple Music library
---@usage require('nvim-apple-music').get_tracks()
M.get_tracks = function()
local command = [[osascript -e 'tell application "Music" to get name of every track']]
local command = [[osascript -e 'tell application "Music" to get name of every track' -s s]]
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
-- Split the result into a table of album names
local tracks = {}
for track in result:gmatch("([^,]+)") do
track = track:match("^%s*(.-)%s*$")
table.insert(tracks, track)
end

-- Convert table string into table
local result_chunk = "return " .. result
local tracks = loadstring(result_chunk)()

return tracks
end

Expand Down

0 comments on commit deda524

Please sign in to comment.