store fetched artist's info in ~/.ncmpcpp/artists instead of ~/.lyrics
This commit is contained in:
@@ -162,6 +162,22 @@ void WindowTitle(const string &status)
|
|||||||
printf("\033]0;%s\7",status.c_str());
|
printf("\033]0;%s\7",status.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EscapeUnallowedChars(string &s)
|
||||||
|
{
|
||||||
|
const string unallowed_chars = "\"*/:<>?\\|";
|
||||||
|
for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < s.length(); i++)
|
||||||
|
{
|
||||||
|
if (s[i] == *it)
|
||||||
|
{
|
||||||
|
s.erase(s.begin()+i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string FindSharedDir(const string &one, const string &two)
|
string FindSharedDir(const string &one, const string &two)
|
||||||
{
|
{
|
||||||
if (one == two)
|
if (one == two)
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ void UpdateSongList(Menu<Song> *);
|
|||||||
bool Keypressed(int, const int *);
|
bool Keypressed(int, const int *);
|
||||||
|
|
||||||
void WindowTitle(const string &);
|
void WindowTitle(const string &);
|
||||||
|
void EscapeUnallowedChars(string &);
|
||||||
|
|
||||||
string FindSharedDir(const string &, const string &);
|
string FindSharedDir(const string &, const string &);
|
||||||
string TotalPlaylistLength();
|
string TotalPlaylistLength();
|
||||||
|
|||||||
@@ -19,12 +19,14 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include "helpers.h"
|
||||||
#include "lyrics.h"
|
#include "lyrics.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
extern ncmpcpp_config Config;
|
extern ncmpcpp_config Config;
|
||||||
|
|
||||||
|
const string artists_folder = home_folder + "/" + ".ncmpcpp/artists";
|
||||||
const string lyrics_folder = home_folder + "/" + ".lyrics";
|
const string lyrics_folder = home_folder + "/" + ".lyrics";
|
||||||
|
|
||||||
#ifdef HAVE_CURL_CURL_H
|
#ifdef HAVE_CURL_CURL_H
|
||||||
@@ -68,9 +70,12 @@ void * GetArtistInfo(void *ptr)
|
|||||||
string artist = *strptr;
|
string artist = *strptr;
|
||||||
delete strptr;
|
delete strptr;
|
||||||
|
|
||||||
const string filename = artist + ".txt";
|
string filename = artist + ".txt";
|
||||||
const string fullpath = lyrics_folder + "/" + filename;
|
transform(filename.begin(), filename.end(), filename.begin(), tolower);
|
||||||
mkdir(lyrics_folder.c_str(), 0755);
|
EscapeUnallowedChars(filename);
|
||||||
|
|
||||||
|
const string fullpath = artists_folder + "/" + filename;
|
||||||
|
mkdir(artists_folder.c_str(), 0755);
|
||||||
|
|
||||||
string *result = new string();
|
string *result = new string();
|
||||||
std::ifstream input(fullpath.c_str());
|
std::ifstream input(fullpath.c_str());
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ const string message_part_of_songs_added = "Only part of requested songs' list a
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
CreateConfigDir();
|
||||||
DefaultConfiguration(Config);
|
DefaultConfiguration(Config);
|
||||||
DefaultKeys(Key);
|
DefaultKeys(Key);
|
||||||
ReadConfiguration(Config);
|
ReadConfiguration(Config);
|
||||||
|
|||||||
@@ -18,13 +18,19 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
const string config_file = home_folder + "/.ncmpcpp/config";
|
const string config_file = config_dir + "config";
|
||||||
const string keys_config_file = home_folder + "/.ncmpcpp/keys";
|
const string keys_config_file = config_dir + "keys";
|
||||||
|
|
||||||
using std::ifstream;
|
using std::ifstream;
|
||||||
|
|
||||||
|
void CreateConfigDir()
|
||||||
|
{
|
||||||
|
mkdir(config_dir.c_str(), 0755);
|
||||||
|
}
|
||||||
|
|
||||||
void DefaultKeys(ncmpcpp_keys &keys)
|
void DefaultKeys(ncmpcpp_keys &keys)
|
||||||
{
|
{
|
||||||
keys.Up[0] = KEY_UP;
|
keys.Up[0] = KEY_UP;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "ncmpcpp.h"
|
#include "ncmpcpp.h"
|
||||||
|
|
||||||
|
const string config_dir = home_folder + "/.ncmpcpp/";
|
||||||
const int null_key = 0x0fffffff;
|
const int null_key = 0x0fffffff;
|
||||||
|
|
||||||
struct ncmpcpp_keys
|
struct ncmpcpp_keys
|
||||||
@@ -146,6 +147,7 @@ struct ncmpcpp_config
|
|||||||
int message_delay_time;
|
int message_delay_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void CreateConfigDir();
|
||||||
void DefaultKeys(ncmpcpp_keys &);
|
void DefaultKeys(ncmpcpp_keys &);
|
||||||
void DefaultConfiguration(ncmpcpp_config &);
|
void DefaultConfiguration(ncmpcpp_config &);
|
||||||
void ReadKeys(ncmpcpp_keys &);
|
void ReadKeys(ncmpcpp_keys &);
|
||||||
|
|||||||
@@ -222,16 +222,8 @@ namespace
|
|||||||
|
|
||||||
string GenerateFilename(const Song &s, string &pattern)
|
string GenerateFilename(const Song &s, string &pattern)
|
||||||
{
|
{
|
||||||
const string unallowed_chars = "\"*/:<>?\\|";
|
|
||||||
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
|
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
|
||||||
for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
|
EscapeUnallowedChars(result);
|
||||||
{
|
|
||||||
for (int i = 0; i < result.length(); i++)
|
|
||||||
{
|
|
||||||
if (result[i] == *it)
|
|
||||||
result.erase(result.begin()+i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user