Skip to content

Commit

Permalink
Test for filenames for cover images other than cover.jpg
Browse files Browse the repository at this point in the history
Also, move static variables to the beginning of the file
  • Loading branch information
antlarr committed Aug 20, 2017
1 parent b4956b3 commit 1f2b53f
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions mpv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ local mputils = require 'mp.utils'
local pid = tostring(mp):match(': (%w+)$') -- FIXME
local mpris = Applet:new({ name = "mpv", id = 'instance' .. pid })

local assignments = {{'xesam:album', 'metadata/by-key/album'},
{'xesam:albumArtist','metadata/by-key/album_artist'},
{'xesam:artist','metadata/by-key/artist'},
{'xesam:trackNumber','metadata/by-key/track'},
{'xesam:genre','metadata/by-key/genre'},
{'xesam:lyricist','metadata/by-key/lyricist'},
{'xesam:discNumber','metadata/by-key/disc'}}

local cover_filenames = {'cover.jpg', 'cover.png', 'folder.jpg', 'folder.png', 'front.jpg', 'front.png'}

--- sync

mp.add_periodic_timer(0.1, function () mpris.dbus.poll() end)
Expand Down Expand Up @@ -114,20 +124,21 @@ local function update_idle(name, idle)
end
end

local function table_contains(table, item)
for key, value in pairs(table) do
if value == item then return key end
end
return false
end


local function update_title(name, title)
local meta = mpris.property:get('metadata')
if title or title ~= '' then
meta['xesam:title'] = title
else
meta['xesam:title'] = nil
end
assignments = {{'xesam:album', 'metadata/by-key/album'},
{'xesam:albumArtist','metadata/by-key/album_artist'},
{'xesam:artist','metadata/by-key/artist'},
{'xesam:trackNumber','metadata/by-key/track'},
{'xesam:genre','metadata/by-key/genre'},
{'xesam:lyricist','metadata/by-key/lyricist'},
{'xesam:discNumber','metadata/by-key/disc'}}
for k,assignment in pairs(assignments) do
value = mp.get_property(assignment[2])
if value or value ~= '' then
Expand All @@ -141,9 +152,15 @@ local function update_title(name, title)
path = mp.get_property('path')
if path or path ~= '' then
cwd = mputils.getcwd()
local dir, fname = mputils.split_path(path)
meta['mpris:artUrl'] = mputils.join_path(mputils.join_path(cwd, dir), 'cover.jpg')
meta['xesam:url'] = mputils.join_path(cwd, path)
local dir, fname = mputils.split_path(path)
files = mputils.readdir(dir)
for _ , cover_filename in pairs(cover_filenames) do
if table_contains(files, cover_filename) then
meta['mpris:artUrl'] = mputils.join_path(mputils.join_path(cwd, dir), cover_filename)
break;
end
end
end
mpris.property:set('metadata', meta)
end
Expand Down

0 comments on commit 1f2b53f

Please sign in to comment.