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
201
202
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "MusicInfoScraper.h"
#include "filesystem/CurlFile.h"
#include "utils/log.h"
using namespace MUSIC_GRABBER;
using namespace ADDON;
using namespace std::chrono_literals;
CMusicInfoScraper::CMusicInfoScraper(const ADDON::ScraperPtr& scraper)
: CThread("MusicInfoScraper"), m_scraper(scraper)
{
m_bSucceeded=false;
m_bCanceled=false;
m_iAlbum=-1;
m_iArtist=-1;
m_http = new XFILE::CCurlFile;
}
CMusicInfoScraper::~CMusicInfoScraper(void)
{
StopThread();
delete m_http;
}
int CMusicInfoScraper::GetAlbumCount() const
{
return (int)m_vecAlbums.size();
}
int CMusicInfoScraper::GetArtistCount() const
{
return (int)m_vecArtists.size();
}
CMusicAlbumInfo& CMusicInfoScraper::GetAlbum(int iAlbum)
{
return m_vecAlbums[iAlbum];
}
CMusicArtistInfo& CMusicInfoScraper::GetArtist(int iArtist)
{
return m_vecArtists[iArtist];
}
void CMusicInfoScraper::FindAlbumInfo(const std::string& strAlbum, const std::string& strArtist /* = "" */)
{
m_strAlbum=strAlbum;
m_strArtist=strArtist;
m_bSucceeded=false;
StopThread();
Create();
}
void CMusicInfoScraper::FindArtistInfo(const std::string& strArtist)
{
m_strArtist=strArtist;
m_bSucceeded=false;
StopThread();
Create();
}
void CMusicInfoScraper::FindAlbumInfo()
{
m_vecAlbums = m_scraper->FindAlbum(*m_http, m_strAlbum, m_strArtist);
m_bSucceeded = !m_vecAlbums.empty();
}
void CMusicInfoScraper::FindArtistInfo()
{
m_vecArtists = m_scraper->FindArtist(*m_http, m_strArtist);
m_bSucceeded = !m_vecArtists.empty();
}
void CMusicInfoScraper::LoadAlbumInfo(int iAlbum)
{
m_iAlbum=iAlbum;
m_iArtist=-1;
StopThread();
Create();
}
void CMusicInfoScraper::LoadArtistInfo(int iArtist, const std::string &strSearch)
{
m_iAlbum=-1;
m_iArtist=iArtist;
m_strSearch=strSearch;
StopThread();
Create();
}
void CMusicInfoScraper::LoadAlbumInfo()
{
if (m_iAlbum<0 || m_iAlbum>=(int)m_vecAlbums.size())
return;
CMusicAlbumInfo& album=m_vecAlbums[m_iAlbum];
// Clear album artist credits
album.GetAlbum().artistCredits.clear();
if (album.Load(*m_http,m_scraper))
m_bSucceeded=true;
}
void CMusicInfoScraper::LoadArtistInfo()
{
if (m_iArtist<0 || m_iArtist>=(int)m_vecArtists.size())
return;
CMusicArtistInfo& artist=m_vecArtists[m_iArtist];
artist.GetArtist().strArtist.clear();
if (artist.Load(*m_http,m_scraper,m_strSearch))
m_bSucceeded=true;
}
bool CMusicInfoScraper::Completed()
{
return Join(10ms);
}
bool CMusicInfoScraper::Succeeded()
{
return !m_bCanceled && m_bSucceeded;
}
void CMusicInfoScraper::Cancel()
{
m_http->Cancel();
m_bCanceled=true;
m_http->Reset();
}
bool CMusicInfoScraper::IsCanceled()
{
return m_bCanceled;
}
void CMusicInfoScraper::OnStartup()
{
m_bSucceeded=false;
m_bCanceled=false;
}
void CMusicInfoScraper::Process()
{
try
{
if (m_strAlbum.size())
{
FindAlbumInfo();
m_strAlbum.clear();
m_strArtist.clear();
}
else if (m_strArtist.size())
{
FindArtistInfo();
m_strArtist.clear();
}
if (m_iAlbum>-1)
{
LoadAlbumInfo();
m_iAlbum=-1;
}
if (m_iArtist>-1)
{
LoadArtistInfo();
m_iArtist=-1;
}
}
catch(...)
{
CLog::Log(LOGERROR, "Exception in CMusicInfoScraper::Process()");
}
}
bool CMusicInfoScraper::CheckValidOrFallback(const std::string &fallbackScraper)
{
return true;
//! @todo Handle fallback mechanism
/*
if (m_scraper->Path() != fallbackScraper &&
parser.Load("special://xbmc/system/scrapers/music/" + fallbackScraper))
{
CLog::Log(LOGWARNING, "{} - scraper {} fails to load, falling back to {}", __FUNCTION__, m_info.strPath, fallbackScraper);
m_info.strPath = fallbackScraper;
m_info.strContent = "albums";
m_info.strTitle = parser.GetName();
m_info.strDate = parser.GetDate();
m_info.strFramework = parser.GetFramework();
m_info.strLanguage = parser.GetLanguage();
m_info.settings.LoadSettingsXML("special://xbmc/system/scrapers/music/" + m_info.strPath);
return true;
}
return false; */
}
|