1 #include "stdafx.h" 2 #include "CoverDownloadCommon.h" 3 4 CCoverDownloadCommon()5CCoverDownloadCommon::CCoverDownloadCommon() 6 { 7 } 8 9 ~CCoverDownloadCommon()10CCoverDownloadCommon::~CCoverDownloadCommon() 11 { 12 } 13 GetAlbumCoverURL(const wstring & song_id)14wstring CCoverDownloadCommon::GetAlbumCoverURL(const wstring & song_id) 15 { 16 if(song_id.empty()) 17 return wstring(); 18 //获取专辑封面接口的URL 19 wchar_t buff[256]; 20 swprintf_s(buff, L"http://music.163.com/api/song/detail/?id=%s&ids=%%5B%s%%5D&csrf_token=", song_id.c_str(), song_id.c_str()); 21 wstring contents; 22 //将URL内容保存到内存 23 if(!CInternetCommon::GetURL(wstring(buff), contents)) 24 return wstring(); 25 #ifdef _DEBUG 26 ofstream out_put{ L".\\cover_down.log", std::ios::binary }; 27 out_put << CCommon::UnicodeToStr(contents, CodeType::UTF8); 28 out_put.close(); 29 #endif // _DEBUG 30 31 size_t index; 32 index = contents.find(L"\"album\""); 33 if (index == wstring::npos) 34 return wstring(); 35 index = contents.find(L"\"picUrl\"", index + 7); 36 if (index == wstring::npos) 37 return wstring(); 38 wstring url; 39 size_t index1; 40 index1 = contents.find(L'\"', index + 10); 41 url = contents.substr(index + 10, index1 - index - 10); 42 43 return url; 44 } 45