Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 243 lines (222 sloc) 6.875 kb
62fd704 initial 0.9 upload
Bart vd Ende authored
1 /*
2 * Copyright (C) 2005-2008 Team XBMC
3 * http://www.xbmc.org
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21
22 #include "MusicInfoTagLoaderSid.h"
23 #include "utils/RegExp.h"
24 #include "Util.h"
25 #include "MusicInfoTag.h"
26 #include "Settings.h"
27 #include "FileSystem/SpecialProtocol.h"
28
29 #include <cstring>
30
31 #include <fstream>
32
33 using namespace std;
34 using namespace MUSIC_INFO;
35
36 CMusicInfoTagLoaderSid::CMusicInfoTagLoaderSid(void)
37 {
38 }
39
40 CMusicInfoTagLoaderSid::~CMusicInfoTagLoaderSid()
41 {
42 }
43
44 bool CMusicInfoTagLoaderSid::Load(const CStdString& strFileName, CMusicInfoTag& tag)
45 {
46 CStdString strFileToLoad = strFileName;
47 int iTrack = 0;
48 CStdString strExtension;
49 CUtil::GetExtension(strFileName,strExtension);
50 strExtension.MakeLower();
51 if (strExtension==".sidstream")
52 {
53 // Extract the track to play
54 CStdString strFile=CUtil::GetFileName(strFileName);
55 int iStart=strFile.ReverseFind("-")+1;
56 iTrack = atoi(strFile.substr(iStart, strFile.size()-iStart-10).c_str());
57 // The directory we are in, is the file
58 // that contains the bitstream to play,
59 // so extract it
60 CStdString strPath=strFileName;
61 CUtil::GetDirectory(strPath, strFileToLoad);
62 CUtil::RemoveSlashAtEnd(strFileToLoad); // we want the filename
63 }
64 CStdString strFileNameLower(strFileToLoad);
65 strFileNameLower.MakeLower();
66 int iHVSC = strFileNameLower.find("hvsc"); // need hvsc in path name since our lookupfile is based on hvsc paths
67 if (iHVSC < 0)
68 {
69 iHVSC = strFileNameLower.find("c64music");
70 if (iHVSC >= 0)
71 iHVSC += 8;
72 }
73 else
74 iHVSC += 4;
75 if( iHVSC < 0 )
76 {
77 tag.SetLoaded(false);
78 return( false );
79 }
80
81 CStdString strHVSCpath = strFileToLoad.substr(iHVSC,strFileToLoad.length()-1);
82
83 strHVSCpath.Replace('\\','/'); // unix paths
84 strHVSCpath.MakeLower();
85
86 char temp[8192];
87 CRegExp reg;
88 if (!reg.RegComp("TITLE: ([^\r\n]*)\r?\n[^A]*ARTIST: ([^\r\n]*)\r?\n"))
89 {
90 CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..): failed to compile regular expression");
91 tag.SetLoaded(false);
92 return( false );
93 }
94
95 ifstream f(_P(CUtil::AddFileToFolder(g_settings.GetDatabaseFolder(), "stil.txt")).c_str()); // changeme?
96 if( !f.good() ) {
97 CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..) unable to locate stil.txt");
98 tag.SetLoaded(false);
99 return( false );
100 }
101
102 const char* szStart = NULL;
103 const char* szEnd = NULL;
104 char temp2[8191];
105 char* temp3 = temp2;
106 while( !f.eof() && !szEnd )
107 {
108 f.read(temp,8191);
109 CStdString strLower = temp;
110 strLower.MakeLower();
111
112 if (!szStart)
113 szStart= (char *)strstr(strLower.c_str(),strHVSCpath.c_str());
114 if (szStart)
115 {
116 szEnd = strstr(szStart+strHVSCpath.size(),".sid");
117 if (szEnd)
118 {
119 memcpy(temp3,temp+(szStart-strLower.c_str()),szEnd-szStart);
120 temp3 += szEnd-szStart;
121 }
122 else
123 {
124 memcpy(temp3,temp+(szStart-strLower.c_str()),strlen(szStart));
125 szStart = NULL;
126 temp3 += strlen(szStart);
127 }
128 }
129 }
130 f.close();
131
132 if (!f.eof() && szEnd)
133 {
134 temp2[temp3-temp2] = '\0';
135 temp3 = strstr(temp2,"TITLE:");
136 }
137 else
138 temp3 = NULL;
139 if (temp3)
140 {
141 for (int i=0;i<iTrack-1;++i) // skip tracks
142 {
143 int iStart = reg.RegFind(temp3);
144 if (!iStart)
145 {
146 tag.SetLoaded(false);
147 return false;
148 }
149 temp3 += iStart;
150 }
151 if(reg.RegFind(temp3) > -1)
152 {
153 char* szTitle = reg.GetReplaceString("\\1");
154 char* szArtist = reg.GetReplaceString("\\2");
155 char* szMins = NULL;
156 char* szSecs = NULL;
157 CRegExp reg2;
158 reg2.RegComp("(.*) \\(([0-9]*):([0-9]*)\\)");
159 if (reg2.RegFind(szTitle) > -1)
160 {
161 szMins = reg2.GetReplaceString("\\2");
162 szSecs = reg2.GetReplaceString("\\3");
163 char* szTemp = reg2.GetReplaceString("\\1");
164 free(szTitle);
165 szTitle = szTemp;
166 }
167 tag.SetLoaded(true);
168 tag.SetURL(strFileToLoad);
169 tag.SetTrackNumber(iTrack);
170 if (szMins && szSecs)
171 tag.SetDuration(atoi(szMins)*60+atoi(szSecs));
172
173 tag.SetTitle(szTitle);
174 tag.SetArtist(szArtist);
175 free(szTitle);
176 free(szArtist);
177 free(szMins);
178 free(szSecs);
179 }
180 }
181
182 ifstream f2(_P(CUtil::AddFileToFolder(g_settings.GetDatabaseFolder(),"sidlist.csv")).c_str()); // changeme?
183 if( !f2.good() ) {
184 CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..) unable to locate sidlist.csv");
185 tag.SetLoaded(false);
186 return( false );
187 }
188
189 while( !f2.eof() ) {
190 f2.getline(temp,8191);
191 CStdString strTemp(temp);
192 strTemp.MakeLower();
8326ead initial 1.5 upload
Bart vd Ende authored
193 size_t iFind = strTemp.find(strHVSCpath);
62fd704 initial 0.9 upload
Bart vd Ende authored
194 if (iFind == string::npos)
195 continue;
196
197 char temp2[1024];
198 char temp3[1024];
199 strncpy(temp3,temp+iFind,strlen(strHVSCpath));
200 temp3[strlen(strHVSCpath)] = '\0';
201 sprintf(temp2,"\"%s\",\"[^\"]*\",\"[^\"]*\",\"([^\"]*)\",\"([^\"]*)\",\"([0-9]*)[^\"]*\",\"[0-9]*\",\"[0-9]*\",\"",temp3);
202 for (int i=0;i<iTrack-1;++i)
203 strcat(temp2,"[0-9]*:[0-9]* ");
204 strcat(temp2,"([0-9]*):([0-9]*)");
205 if( !reg.RegComp(temp2) )
206 {
207 CLog::Log(LOGINFO,"MusicInfoTagLoaderSid::Load(..): failed to compile regular expression");
208 tag.SetLoaded(false);
209 return( false );
210 }
211 if( reg.RegFind(temp) >= 0 ) {
212 char* szTitle = reg.GetReplaceString("\\1");
213 char* szArtist = reg.GetReplaceString("\\2");
214 char* szYear = reg.GetReplaceString("\\3");
215 char* szMins = reg.GetReplaceString("\\4");
216 char* szSecs = reg.GetReplaceString("\\5");
217 tag.SetLoaded(true);
218 tag.SetTrackNumber(iTrack);
219 if (tag.GetDuration() == 0)
220 tag.SetDuration(atoi(szMins)*60+atoi(szSecs));
221 if (tag.GetTitle() == "")
222 tag.SetTitle(szTitle);
223 if (tag.GetArtist() == "")
224 tag.SetArtist(szArtist);
225 SYSTEMTIME dateTime;
226 dateTime.wYear = atoi(szYear);
227 tag.SetReleaseDate(dateTime);
228 free(szTitle);
229 free(szArtist);
230 free(szYear);
231 free(szMins);
232 free(szSecs);
233 f2.close();
234 return( true );
235 }
236 }
237
238 f2.close();
239 tag.SetLoaded(false);
240 return( false );
241 }
242
Something went wrong with that request. Please try again.