Skip to content

Commit 8990044

Browse files
committed
adding text modules for translation on first plugin, deploy script modified
1 parent 72f6023 commit 8990044

File tree

3 files changed

+104
-107
lines changed

3 files changed

+104
-107
lines changed

deploy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
# later you will be ask for each plugin
33
cp -f ./helpers/* /home/botmaster/src/mumble-ruby-pluginbot/helpers/
44
cp -f ./plugins/* /home/botmaster/src/mumble-ruby-pluginbot/plugins/
5+
cp -f ./i18n/en/* /home/botmaster/src/mumble-ruby-pluginbot/i18n/en/
6+
cp -f ./i18n/de/* /home/botmaster/src/mumble-ruby-pluginbot/i18n/de/
57
sudo chown -R botmaster:botmaster /home/botmaster/src/mumble-ruby-pluginbot/
68
exit

i18n/en/plugin_metadata.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
en:
2+
plugin_metadata:
3+
4+
mlist: "List of all songs with meta tags including search pattern"
5+
6+
mtags:
7+
title: "Title"
8+
artist: "Artist"
9+
album: "Album"
10+
genre: "Genre"
11+
date: "Date"
12+
file: "File"
13+
length: "Length"
14+
15+
fnferr: "No file found with pattern"
16+
17+
help:
18+
meta: "[pattern] [value] - add/change metadata offirst file with search pattern"
19+
mall: " [pattern] [value] - add/change metadata \
20+
for all files with same search pattern"
21+
mdata: "[pattern] - show metadata from first audiofile with search pattern"
22+
mlist: "[pattern] - list all files with same pattern"
23+
mp3info: "command works only with mp3 files"
24+
25+
error:
26+
parameter: "Wrong number of paramter!"
27+
fnferr: "File not found!"
28+
29+
30+
31+

plugins/metadata.rb

Lines changed: 71 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -6,99 +6,22 @@
66
class Metadata < Plugin
77
include IMpd
88

9-
private
10-
11-
def getTableRow(col1, col2)
12-
row = "<tr>"
13-
row += "<td style=\"color:lightseagreen;\"><b>#{col1}</b></td>"
14-
row += "<td>#{col2}</td>"
15-
row += "</tr>"
16-
return row
17-
end
18-
19-
def getListRow(val)
20-
row = "<style=\"padding: 0 10px 0 10px\";><td>#{val}</td></style>"
21-
return row
22-
end
23-
24-
def getTableHeadCol(name)
25-
col = "<td style=\"color:lightseagreen;\"><b>#{name}</b></td>"
26-
return col
27-
end
28-
29-
@@tab = "&#160;&#160;&#160;"
30-
31-
@@id3 = ID3v2.new
32-
33-
def getSongs(search)
34-
songs = []
35-
for song in @@bot[:mpd].songs
36-
if song.title.to_s.downcase.include? search.to_s.downcase
37-
songs.push(song); next
38-
end
39-
if song.artist.to_s.downcase.include? search.to_s.downcase
40-
songs.push(song); next
41-
end
42-
if song.album.to_s.downcase.include? search.to_s.downcase
43-
songs.push(song); next
44-
end
45-
if song.genre.to_s.downcase.include? search.to_s.downcase
46-
songs.push(song); next
47-
end
48-
if song.file.to_s.downcase.include? search.to_s.downcase
49-
songs.push(song)
50-
end
51-
end
52-
return songs
53-
end
54-
55-
def getSong(search)
56-
song = @@bot[:mpd].songs.select { |s|
57-
s.title.to_s.downcase.include? search.to_s.downcase
58-
}.first
59-
if song.nil?
60-
song = @@bot[:mpd].songs.select { |s|
61-
s.artist.to_s.downcase.include? search.to_s.downcase
62-
}.first
63-
end
64-
if song.nil?
65-
song = @@bot[:mpd].songs.select { |s|
66-
s.album.to_s.downcase.include? search.to_s.downcase
67-
}.first
68-
end
69-
if song.nil?
70-
song = @@bot[:mpd].songs.select { |s|
71-
s.file.to_s.downcase.include? search.to_s.downcase
72-
}.first
73-
end
74-
return song
75-
end
76-
77-
def getTags(search)
78-
song = getSong(search)
79-
if !song.nil?
80-
meta = "<table>"
81-
meta += getTableRow("Title:", song.title) if !song.title.nil?
82-
meta += getTableRow("Artist:", song.artist) if !song.artist.nil?
83-
meta += getTableRow("Album:", song.album) if !song.album.nil?
84-
meta += getTableRow("Genre:", song.genre) if !song.genre.nil?
85-
meta += getTableRow("Date:", song.date) if !song.date.nil?
86-
meta += getTableRow("File:", song.file) if !song.file.nil?
87-
meta += getTableRow("Length:#{@@tab}", song.length) if !song.length.nil?
88-
meta += "</table>"
89-
90-
privatemessage(meta)
91-
else
92-
privatemessage("No file with pattern #{file} found")
93-
end
94-
end
95-
969
public
9710

9811
def init(init)
9912
super
10013
logger("INFO: INIT plugin #{self.class.name}.")
10114
@@bot[:meta] = self
15+
16+
# put translations into member variables to space in code
17+
@title = I18n.t('plugin_metadata.mtags.title')
18+
@artist = I18n.t('plugin_metadata.mtags.artist')
19+
@album = I18n.t('plugin_metadata.mtags.album')
20+
@genre = I18n.t('plugin_metadata.mtags.genre')
21+
@date = I18n.t('plugin_metadata.mtags.date')
22+
@file = I18n.t('plugin_metadata.mtags.file')
23+
@length = I18n.t('plugin_metadata.mtags.length')
24+
10225
return @@bot
10326
end
10427

@@ -108,18 +31,16 @@ def name
10831

10932
def help(h)
11033
h << "<hr><span style='color:red;'>Plugin #{self.class.name}</span><br>"
111-
h << "<b>#{Conf.gvalue("main:control:string")}meta [title|artist|album" \
112-
"|genre|year] [pattern] [value] - add/change metadata of " \
113-
"first file with search pattern<br>"
114-
h << "<b>#{Conf.gvalue("main:control:string")}metaall|mall [title| " \
115-
"artist|album|genre|year] [pattern] [value] - add/change metadata " \
116-
"for all files with same search pattern<br>"
117-
h << "<b>#{Conf.gvalue("main:control:string")}metadata|mdata [pattern] - " \
118-
"show metadata from first audiofile with search pattern<br>"
119-
h << "<b>#{Conf.gvalue("main:control:string")}metalist|mlist [pattern] - " \
120-
"list all files with same pattern<br>"
34+
h << "<b>#{Conf.gvalue("main:control:string")}meta " \
35+
"[title|artist|album|genre|year] #{I18n.t('plugin_metadata.help.meta')}<br>"
36+
h << "<b>#{Conf.gvalue("main:control:string")}metaall|mall " \
37+
"[title|artist|album|genre|year] #{I18n.t('plugin_metadata.help.mall')}<br>"
38+
h << "<b>#{Conf.gvalue("main:control:string")}metadata|mdata " \
39+
"#{I18n.t('plugin_metadata.help.mdata')}<br>"
40+
h << "<b>#{Conf.gvalue("main:control:string")}metalist|mlist " \
41+
"#{I18n.t('plugin_metadata.help.mlist')}<br>"
12142
h << "<b>Information:</b> #{Conf.gvalue("main:control:string")}meta " \
122-
"command works only with mp3 files<br>"
43+
"#{I18n.t('plugin_metadata.help.mp3info')}<br>"
12344
h
12445
end
12546

@@ -139,16 +60,16 @@ def handle_chat(msg, message)
13960
if parts[0] == "metalist" || parts[0] == "mlist"
14061
if !parts[1].nil?
14162
pattern = parts[1..parts.length - 1].join(" ").to_s
142-
songs = getSongs(pattern)
63+
songs = getSongs(@@bot, pattern)
14364
if !songs.nil?
144-
text = "All songs with meta tags including search pattern #{pattern}<br>"
65+
text = "#{I18n.t('plugin_metadata.mlist')} #{pattern}<br>"
14566
text += "<table cellspacing=\"5\">"
14667
text += "<tr>"
147-
text += getTableHeadCol("File:")
148-
text += getTableHeadCol("Title:")
149-
text += getTableHeadCol("Artist:")
150-
text += getTableHeadCol("Album:")
151-
text += getTableHeadCol("Genre:")
68+
text += getTableHeadCol("#{@file}:")
69+
text += getTableHeadCol("#{@title}:")
70+
text += getTableHeadCol("#{@artist}:")
71+
text += getTableHeadCol("#{@album}:")
72+
text += getTableHeadCol("#{@genre}:")
15273
text += "</tr>"
15374
for song in songs
15475
text += "<tr>"
@@ -198,7 +119,7 @@ def handle_chat(msg, message)
198119
search = parts[2].to_s
199120
val = parts[3..parts.length - 1].join(" ").to_s
200121
if !tag.empty? && !file.empty? && !val.empty?
201-
songs = getSongs(search)
122+
songs = getSongs(@@bot, search)
202123
if !songs.nil?
203124
for song in songs
204125
text = @@id3.setTitle(song.file, val) if tag == "title"
@@ -208,7 +129,7 @@ def handle_chat(msg, message)
208129
text = @@id3.setYear(song.file, val) if tag == "year"
209130
end
210131
else
211-
text = "No file found"
132+
text = "file not found"
212133
end
213134
privatemessage(text)
214135
updateBot(@@bot)
@@ -220,4 +141,47 @@ def handle_chat(msg, message)
220141
privatemessage("Metadata Error: #{ex.message}")
221142
end
222143
end
144+
145+
private
146+
147+
def getTableRow(col1, col2)
148+
row = "<tr>"
149+
row += "<td style=\"color:lightseagreen;\"><b>#{col1}</b></td>"
150+
row += "<td>#{col2}</td>"
151+
row += "</tr>"
152+
return row
153+
end
154+
155+
def getListRow(val)
156+
row = "<style=\"padding: 0 10px 0 10px\";><td>#{val}</td></style>"
157+
return row
158+
end
159+
160+
def getTableHeadCol(name)
161+
col = "<td style=\"color:lightseagreen;\"><b>#{name}</b></td>"
162+
return col
163+
end
164+
165+
@@tab = "&#160;&#160;&#160;"
166+
167+
@@id3 = ID3v2.new
168+
169+
def getTags(search)
170+
song = getFirstSong(@@bot, search)
171+
if !song.nil?
172+
meta = "<table>"
173+
meta += getTableRow("#{@title}:", song.title) if !song.title.nil?
174+
meta += getTableRow("#{@artist}:", song.artist) if !song.artist.nil?
175+
meta += getTableRow("#{@album}:", song.album) if !song.album.nil?
176+
meta += getTableRow("#{@genre}:", song.genre) if !song.genre.nil?
177+
meta += getTableRow("#{@date}:", song.date) if !song.date.nil?
178+
meta += getTableRow("#{@file}:", song.file) if !song.file.nil?
179+
meta += getTableRow("#{@length}: #{@@tab}", song.length) if !song.length.nil?
180+
meta += "</table>"
181+
182+
privatemessage(meta)
183+
else
184+
privatemessage("#{I18n.t('plugin_metadata.mtags.fnferr')}: #{file}")
185+
end
186+
end
223187
end

0 commit comments

Comments
 (0)