-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVLC-Song-Tracker.lua
More file actions
200 lines (172 loc) · 5.67 KB
/
Copy pathVLC-Song-Tracker.lua
File metadata and controls
200 lines (172 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
--[[
VLC Song Tracker Extension for VLC media player
Copyright 2016 - 2017 Reiuiji
Authors: Reiuiji
Contact: reiuiji@gmail.com
Information:
Keeps track of which songs were played in VLC and saves the song information as well as the time played to a csv file which can be parsed by any spreadsheet application (LibreOffice Calc).
-------------------------
Installation Instructions
-------------------------
Place this file in the corresponding folder and restart vlc or reload plugin extensions.
Linux:
Current User: ~/.local/share/vlc/lua/extensions/
All Users: /usr/lib/vlc/lua/extensions/
Windows:
Current User: %APPDATA%\vlc\lua\extensions
All Users: %ProgramFiles%\VideoLAN\VLC\lua\extensions\
Mac OS X:
Current User: /Users/%your_name%/Library/Application Support/org.videolan.vlc/lua/extensions/
All Users: /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
The SongList.csv will be saved in the vlc user director which can be found in the following places
Linux: ~/.local/share/vlc/SongList.csv
Windows: %APPDATA%\vlc\SongList.csv
Mac OS X: /Users/%your_name%/Library/Application Support/org.videolan.vlc/SongList.csv
--]]
-- Global Variables
-- Name of the file to save the songs
FileName = "SongList.csv"
SongTrackerFile = ""
-- Default header for the csv file
FileHeader = "Date,Time,Title,Artist,Album,NowPlaying,Genre,Comments,Location\n"
-- CSV field separator
CSV_FS = ","--"|"
-- maintain lastsong played
lastsong = ""
-- Descriptor
function descriptor()
return {
title = "VLC Song Tracker 0.1.5",
version = "0.1.5",
author = "Reiuiji",
url = "https://github.com/Reiuiji/VLCAddons",
shortdesc = "VLC Song Tracker",
description = "Keeps track of what songs were played in VLC and saves the meta information and time played to SongList.csv which can be parsed by any spreadsheet application (LibreOffice Calc).",
capabilities = { "input-listener" }
}
end
-- Activate plugin
function activate()
vlc.msg.dbg("[VLC Song Tracker] Activate")
init()
update_song_Tracker()
end
-- Deactivate Plugin
function deactivate()
vlc.msg.dbg("[VLC Song Tracker] Deactivate")
end
-- Close Trigger
function close()
vlc.msg.dbg("[VLC Song Tracker] Close")
end
-- Triggers
function input_changed()
vlc.msg.dbg("[VLC Song Tracker] Input Changed")
update_song_Tracker()
end
function meta_changed()
vlc.msg.dbg("[VLC Song Tracker] Meta Changed")
update_song_Tracker()
end
-- First time init file
function init()
vlc.msg.dbg("[VLC Song Tracker] Initializing plugin")
local slash = "/"
--Determine which operating system
if string.match(vlc.config.datadir(), "^(%a:.+)$") then --Windows Detected
vlc.msg.dbg("[VLC Song Tracker] OS Detected: Windows")
slash = "\\"
elseif string.find(vlc.config.datadir(), 'MacOS') then -- Mac Detected
vlc.msg.dbg("[VLC Song Tracker] OS Detected: Mac OS X")
slash = "/"
else -- Linux/UNIX
vlc.msg.dbg("[VLC Song Tracker] OS Detected: Linux/Unix")
slash = "/"
end
SongTrackerFile = vlc.config.userdatadir() .. slash .. FileName
vlc.msg.dbg("[VLC Song Tracker] Song Tracker File: " .. SongTrackerFile)
-- Check if the file exist
local file = io.open(SongTrackerFile,"r")
if file ~= nil then
io.close(file)
else
vlc.msg.dbg("[VLC Song Tracker] File does not exist, Creating Header")
local file = io.open(SongTrackerFile, "w+")
file:write(FileHeader)
file:close()
end
end
-- Update Tracker
function update_song_Tracker()
vlc.msg.dbg("[VLC Song Tracker] Update Song Tracker!")
if vlc.input.is_playing() then
local item = vlc.item or vlc.input.item()
if item then
local meta = item:metas()
--Check Meta tags
if meta then
--Title
local title = meta["title"]
if title == nil then
title = ""
end
--Artist
local artist = meta["artist"]
if artist == nil then
artist = ""
end
--Album
local album = meta["album"]
if album == nil then
album = ""
end
--Now Playing
local now_playing = meta["now_playing"]
if now_playing == nil then
now_playing = ""
end
--Genre
local genre = meta["genre"]
if genre == nil then
genre = ""
end
--Description
local description = meta["description"]
if description == nil then
description = ""
end
--Clean up Description: Remove new lines (\n) and puts two spaces instead
description = string.gsub(description, "\n", " ")
--Remove carriage return
description = string.gsub(description, "\r", "")
-- uri information
local uri = item:uri()
-- Combine Song Info Together
local songinfo = title .. CSV_FS .. artist .. CSV_FS .. album .. CSV_FS .. now_playing .. CSV_FS .. genre .. CSV_FS .. description .. CSV_FS .. uri
-- Check if the song was previously played
if lastsong == songinfo then
vlc.msg.dbg("[VLC Song Tracker] Duplicate song info detected, Skipping")
return false
else
-- New Song Detected
-- Update last song captured
lastsong = songinfo
-- Date & Time
local date = os.date("%d/%m/%Y")
local time = os.date("%H:%M:%S")
-- Add time stamp with the song info
local info = date .. CSV_FS .. time .. CSV_FS .. songinfo
write_file(info)
return true
end
end
end
end
end
-- Write File
function write_file(info)
vlc.msg.dbg("[VLC Song Tracker] Write File!")
local file = io.open(SongTrackerFile, "a")
file:write(info .. "\n")
file:close()
end