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
|
#include <string.h>
#include <fstream>
#include <vdr/interface.h>
#include <vdr/menu.h>
#include <vdr/plugin.h>
#include "lyrics.h"
#include "mg_item_gd.h"
#include "vdr_actions.h"
#include "mg_setup.h"
#include "vdr_player.h"
int mgLyrics::RunCommand(const string cmd) {
int res=-1;
if (access(cmd.c_str(),R_OK|X_OK)) return res;
char *tmp;
msprintf(&tmp,"%s \"%s\" \"%s\" \"%s\"",cmd.c_str(),
playItem->getArtist().c_str(),
playItem->getTitle().c_str(),
playItem->getCachedFilename("lyrics.tmp").c_str());
mgDebug(1,"muggle[%d]: lyrics: executing '%s'\n",getpid (), tmp);
#if VDRVERSNUM >= 10504
res=SystemExec(tmp,true); // run detached
#else
res=SystemExec(tmp);
#endif
free(tmp);
return res;
}
void
mgLyrics::LoadExternal() {
mgLog("LoadExternal");
osd()->Message1(tr("Loading lyrics from internet..."));
string script=the_setup.ConfigDirectory + "/scripts/muggle_getlyrics";
if (RunCommand(script)==0) {
state=lyricsLoading;
playItem->setCheckedForTmpLyrics(time(0));
}
}
void
mgLyrics::SaveExternal() {
const mgItemGd *item = PlayingItem();
if (!item) return;
string local=item->getCachedFilename("lyrics");
string tmp=item->getCachedFilename("lyrics.tmp");
PlayerControl()->CurrentItem()->resetHasLyricsFile();
char *cmd;
msprintf(&cmd, "mv \"%s\" \"%s\"", tmp.c_str(), local.c_str());
mgDebug(1,"muggle[%d]: lyrics: Executing %s\n",getpid(), cmd);
if (!SystemExec(cmd)) {
BlueAction=actLoadExternalLyrics;
SetHelpKeys();
}
free(cmd);
}
eOSState
mgLyrics::Process(eKeys key) {
playItem=mutPlayingItem();
LyricsState prevstate=state;
if (displayItem!=playItem && prevstate==lyricsLoaded) {
char *cmd;
msprintf(&cmd,"rm -f \"%s\"",displayItem->getCachedFilename("lyrics.tmp").c_str());
SystemExec(cmd);
free(cmd);
state=lyricsSaved;
}
long cl=playItem->getCheckedForTmpLyrics();
if (displayItem!=playItem || cl>0 && cl<time(0)) {
if (!access(playItem->getCachedFilename("lyrics.tmp.loading").c_str(),R_OK)) {
state=lyricsLoading;
playItem->setCheckedForTmpLyrics(time(0));
} else {
bool normfound=!access(playItem->getCachedFilename("lyrics").c_str(),R_OK);
if (!access(playItem->getCachedFilename("lyrics.tmp").c_str(),R_OK)) {
playItem->setCheckedForTmpLyrics(0);
state=lyricsLoaded;
if (!normfound) {
SaveExternal();
state=lyricsSaved;
}
} else if (displayItem!=playItem) {
if (normfound) {
state=lyricsSaved;
playItem->setCheckedForTmpLyrics(0);
} else {
LoadExternal();
}
} else {
state=lyricsSaved;
playItem->setCheckedForTmpLyrics(0);
}
}
}
if (displayItem!=playItem || state!=prevstate) {
BuildOsd();
osd()->Display();
}
eOSState result = osContinue;
switch (key) {
case kBlue:
if (BlueAction==actSaveExternalLyrics)
SaveExternal();
else if (BlueAction==actLoadExternalLyrics) {
LoadExternal();
BuildOsd();
osd()->Display();
}
break;
default:
result = mgMenu::Process(key);
break;
}
return result;
}
mgLyrics::mgLyrics() {
playItem=0;
displayItem=0;
state=lyricsSaved;
}
string
mgLyrics::Title() const
{
const mgItemGd *item = PlayingItem();
if (!item) return "";
return item->getArtist() + ":" + item->getTitle();
}
void
mgLyrics::BuildOsd () {
playItem = mutPlayingItem();
if (!playItem) return;
RedAction=actBack2;
GreenAction=actPrevTrack;
YellowAction=actNextTrack;
string loadfile="";
switch (state) {
case lyricsLoading:
BlueAction=actNone;
break;
case lyricsLoaded:
BlueAction=actSaveExternalLyrics;
loadfile=playItem->getCachedFilename("lyrics.tmp");
break;
default:
BlueAction=actLoadExternalLyrics;
loadfile=playItem->getCachedFilename("lyrics");
break;
}
InitOsd();
if (!access(loadfile.c_str(),R_OK))
osd()->AddFile(loadfile);
displayItem=playItem;
}
|