Esempio n. 1
0
        public List <QabuzeAlbum> search(string query, int offset = 0, int credIndex = 0)
        {
            List <KeyValuePair <string, string> > data = new List <KeyValuePair <string, string> >();

            data.Add(new KeyValuePair <string, string>("query", query));
            data.Add(new KeyValuePair <string, string>("type", "albums"));
            data.Add(new KeyValuePair <string, string>("limit", (50 + offset).ToString()));
            data.Add(new KeyValuePair <string, string>("offset", offset.ToString()));
            return((List <QabuzeAlbum>)QabuzeAPI.PerformRequest(QabuzeAPI.instance.BuildRequest("catalog/search", data, false, credIndex)));
        }
Esempio n. 2
0
        public static QabuzeAlbum QueryAlbumById(string id)
        {
            List <KeyValuePair <string, string> > data = new List <KeyValuePair <string, string> >();

            data.Add(new KeyValuePair <string, string>("album_id", id));
            for (int credIndex = 0; credIndex < QabuzeAPI.Config.getInstance().accounts.Count; credIndex++)
            {
                QabuzeAlbum tmp = (QabuzeAlbum)QabuzeAPI.PerformRequest(QabuzeAPI.instance.BuildRequest("album/get", data, false, credIndex));
                if (tmp != null)
                {
                    return(tmp);
                }
            }
            return(null);
        }
Esempio n. 3
0
 public static void init()
 {
     QabuzeAPI.instance = new QabuzeAPI();
 }
Esempio n. 4
0
        public QabuzeAPI()
        {
            string  json = "";
            JObject obj  = null;

            if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\qabuze.json"))
            {
                json = System.IO.File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\qabuze.json");
            }
            else
            {
                try {
                    json = System.IO.File.ReadAllText("config.json");
                } catch (Exception) {
                    Console.WriteLine("No valid configfile found!");
                    return;
                }
            }
            try {
                obj = JObject.Parse(json);
                JObject config = (JObject)obj["qabuze"];
                if (config == null)
                {
                    throw new Exception();
                }

                QabuzeAPI.Config.getInstance().appId        = (string)config["appId"];
                QabuzeAPI.Config.getInstance().appSecret    = (string)config["appSecret"];
                QabuzeAPI.Config.getInstance().apiURL       = (string)config["apiURL"];
                QabuzeAPI.Config.getInstance().fileScheme   = (string)config["fileScheme"];
                QabuzeAPI.Config.getInstance().folderScheme = (string)config["folderScheme"];
                QabuzeAPI.Config.getInstance().outputFolder = (string)config["outputFolder"];

                #if DEBUG
                Console.WriteLine("appId: " + QabuzeAPI.Config.getInstance().appId);
                Console.WriteLine("appSecret: " + QabuzeAPI.Config.getInstance().appSecret);
                Console.WriteLine("apiURL: " + QabuzeAPI.Config.getInstance().apiURL);
                Console.WriteLine("fileScheme: " + QabuzeAPI.Config.getInstance().fileScheme);
                Console.WriteLine("folderScheme: " + QabuzeAPI.Config.getInstance().folderScheme);
                Console.WriteLine("outputFolder: " + QabuzeAPI.Config.getInstance().outputFolder);
                Console.WriteLine("\n");
                #endif

                Console.WriteLine("=== Accounts ===");
                foreach (JObject acc in config["accounts"])
                {
                    Console.WriteLine("Name: " + acc["name"]);
                    if ((string)acc["token"] == "LOGIN")
                    {
                        Console.WriteLine("Aquiring Usertoken...");
                        List <KeyValuePair <string, string> > data = new List <KeyValuePair <string, string> >();

                        acc["password"] = Utils.GetMd5Hash((string)acc["password"]);

                        data.Add(new KeyValuePair <string, string>("username", (string)acc["name"]));
                        data.Add(new KeyValuePair <string, string>("password", (string)acc["password"]));

                        string response = (new WebClient()).DownloadString(BuildRequest("user/login", data, true));

                        JObject resp = JObject.Parse(response);
#if DEBUG
                        System.IO.File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\qabuze_account_" + (string)acc["name"] + ".json", resp.ToString());
#endif
                        acc["token"] = (string)resp["user_auth_token"];
                        Console.WriteLine((string)acc["token"]);
                        acc["password"] = null;
                        QabuzeAPI.Config.getInstance().accounts.Add(new QabuzeAPI.Account((string)acc["name"], (string)acc["token"]));
                    }
                    else
                    {
                        QabuzeAPI.Config.getInstance().accounts.Add(new QabuzeAPI.Account((string)acc["name"], (string)acc["token"]));
                        //Console.WriteLine(acc["token"]);
                    }
                }
                Console.WriteLine("=== Accounts ===\n");

                #if DEBUG
                foreach (QabuzeAPI.Account acc in QabuzeAPI.Config.getInstance().accounts)
                {
                    Console.WriteLine(acc.getName() + ": " + acc.getToken());
                }
                #endif

                if (QabuzeAPI.Config.getInstance().accounts.Count == 0)
                {
                    MessageBox.Show("Please add an account to the config file!", "No account configured");
                    frmMain.instance.Close();
                }

                #if DEBUG
                Console.WriteLine(obj.ToString());
                #endif
                System.IO.File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\qabuze.json", obj.ToString());
            } catch (Exception) {
                Console.WriteLine("Configfile invalid!");
                Console.WriteLine(obj.ToString());
            }
            instance = this;

            /*#if WITHDOWNLOAD
             * if (!System.IO.File.Exists("metaflac.exe"))
             * {
             *  MessageBox.Show("Metaflac could not be found. Files will NOT be tagged!", "Metaflac not found");
             * }
             #endif*/
        }
Esempio n. 5
0
 public frmMain()
 {
     InitializeComponent();
     instance = this;
     QabuzeAPI.init();
 }