Ejemplo n.º 1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            album = QabuzeAlbum.queryAlbum(txtAlbumId.Text);
            if (album != null)
            {
                TimeSpan t        = TimeSpan.FromSeconds((int)album.duration);
                string   duration = string.Format("{0:D2}:{1:D2}:{2:D2}",
                                                  t.Hours,
                                                  t.Minutes,
                                                  t.Seconds);

                pbArtwork.ImageLocation = album.coverURL;
                lblArtist.Text          = album.artist;
                lblAlbum.Text           = album.title;
                lblGenre.Text           = album.genre;
                lblLabel.Text           = album.label;
                lblDuration.Text        = duration;
                lblEstSize.Text         = "< " + (((t.Hours * 60) + t.Minutes) * 11) + " MiB *"; //Estimate uses 16 bit 44.1 KHz PCM. FLAC size WILL be lower!
                if (album.release_timestamp == null)
                {
                    lblRelease.Text = "no date";
                }
                else
                {
                    lblRelease.Text = Utils.UnixTimeStampToDateTime((int)album.release_timestamp).ToShortDateString();
                }
                lblTracks.Text       = album.track_count.ToString();
                lblAvailability.Text = (album.availableForStreaming ? "Yes (until " : "No (available ");
                string   until = album.availableUntil.ToShortDateString(), from = album.availableFrom.ToShortDateString();
                DateTime dateToDisplay = new DateTime(9999, 12, 30, 0, 0, 0); //Use this to accomodate for Localization-issues regarding date-format
                until = until.Replace(dateToDisplay.ToShortDateString(), "forever");
                from  = from.Replace(dateToDisplay.ToShortDateString(), "at no time");
                lblAvailability.Text     += (album.availableForStreaming ? until : from) + ")";
                lblAvailability.ForeColor = (album.availableForStreaming ? Color.DarkGreen : Color.DarkRed);
                #if (WITHDOWNLOAD)
                button2.Enabled = album.availableForStreaming;
                #endif

                artist = QabuzeArtist.queryArtist(album.artistID.ToString());
                if (artist != null)
                {
                    txtArtist_Bio.Text     = artist.biography;
                    pbArtist.ImageLocation = artist.imageURL;
                    Console.WriteLine(artist.biography);
                }

                //Console.WriteLine(album.songs[1].Value.getDownloadLink(true));
            }
        }
Ejemplo n.º 2
0
        public static QabuzeArtist queryArtist(string id)
        {
            List <KeyValuePair <string, string> > data = new List <KeyValuePair <string, string> >();

            data.Add(new KeyValuePair <string, string>("artist_id", id));
            for (int credIndex = 0; credIndex < QabuzeAPI.Config.getInstance().accounts.Count; credIndex++)
            {
                QabuzeArtist tmp = (QabuzeArtist)QabuzeAPI.PerformRequest(QabuzeAPI.instance.BuildRequest("artist/get", data, false, credIndex));
                if (tmp != null)
                {
                    return(tmp);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static Object PerformRequest(string url)
        {
            string response;

            try
            {
                response = (new WebClient()).DownloadString(url);
            }
            catch (WebException e) {
                HttpWebResponse _response = (System.Net.HttpWebResponse)e.Response;
                Console.WriteLine("URL \"" + url + "\" has come back with the following error: " + _response.StatusCode);
                return(null);
            }
            JObject obj = JObject.Parse(response);

            #region Album
            if (obj["tracks_count"] != null)
            {
                QabuzeAlbum objReturn;
                Console.WriteLine("Is Album");
                objReturn = new QabuzeAlbum();
                //QabuzeAlbum objReturn = new QabuzeAlbum();
                objReturn.title             = (string)obj["title"];
                objReturn.id                = (string)obj["id"];
                objReturn.genre             = (string)obj["genre"]["name"];
                objReturn.artist            = (string)obj["artist"]["name"];
                objReturn.artistID          = (int)obj["artist"]["id"];
                objReturn.description       = (string)obj["description"];
                objReturn.coverURL          = (string)obj["image"]["large"];
                objReturn.label             = (string)obj["label"]["name"];
                objReturn.track_count       = (int)obj["tracks_count"];
                objReturn.duration          = (int?)obj["duration"];
                objReturn.release_timestamp = (int?)obj["released_at"];
                int amt_tracks = (int)obj["tracks"]["total"];

                for (int i = 0; i < amt_tracks; i++)
                {
                    JObject track = (JObject)obj["tracks"]["items"][i];
                    try {
                        Console.WriteLine("Adding Track #" + i + " with ID " + track["id"] + "...");
                        QabuzeSong song = new QabuzeSong(
                            (string)track["id"],
                            (string)track["title"],
                            (string)track["performer"]["name"],
                            (string)obj["id"],
                            (int)track["duration"],
                            (int)track["track_number"],
                            (int)track["media_number"],
                            (string)obj["title"],
                            (string)obj["genre"]["name"]
                            );
                        KeyValuePair <int, QabuzeSong> kvp = new KeyValuePair <int, QabuzeSong>(i, song);
                        objReturn.songs.Add(kvp);
                    } catch (Exception e) {
                        Console.Error.WriteLine("Whoops. Track #" + i + " with ID " + track["id"] + " could not be added");
                    }
                }

                string start_date = "9999-12-31", end_date = "9999-12-31";

                /*  try
                 * {
                 *        start_date = (string)obj["rights"]["stream"][0]["start_date"];
                 *
                 * }
                 * catch (Exception)
                 * {*/
                try
                {
                    start_date = Utils.UnixTimeStampToDateTime((int)obj["streamable_at"]).ToString();
                }
                catch (Exception) { }

                /* }
                 * try
                 * {
                 *       end_date = (string)obj["rights"]["stream"][0]["end_date"];
                 *
                 * }
                 * catch (Exception) { }
                 */
                DateTime d_start = DateTime.Parse(start_date).ToUniversalTime();
                DateTime d_end   = DateTime.Parse(end_date).ToUniversalTime();
                DateTime d_curr  = DateTime.UtcNow;

                bool c_start = d_start > d_curr;
                bool c_end   = d_end > d_curr;

                if (c_start)
                {
                    objReturn.availableForStreaming = false;
                }
                else
                {
                    objReturn.availableForStreaming = true;
                }

                if (!c_end)
                {
                    objReturn.availableForStreaming = false;
                }

                Console.WriteLine("May stream from " + start_date + " until " + end_date);
                objReturn.availableFrom  = d_start;
                objReturn.availableUntil = d_end;

                return(objReturn);

                #endregion
                #region Album from Search
            }
            else if (obj["albums"] != null)
            {
                Console.WriteLine("Is Album Search");
                List <QabuzeAlbum> objReturn = new List <QabuzeAlbum>();
                //QabuzeAlbum objReturn = new QabuzeAlbum();
                int limit      = (int)obj["albums"]["limit"];
                int offset     = (int)obj["albums"]["offset"];
                int total      = (int)obj["albums"]["total"];
                int upperLimit = ((offset + limit) > total) ? total : (offset + limit);

                for (int i = 0; i < upperLimit - offset; i++)
                {
                    JObject jalbum = (JObject)obj["albums"]["items"][i];

                    QabuzeAlbum album = new QabuzeAlbum();
                    album.title       = (string)jalbum["title"];
                    album.id          = (string)jalbum["id"];
                    album.genre       = (string)jalbum["genre"]["name"];
                    album.artist      = (string)jalbum["artist"]["name"];
                    album.artistID    = (int?)jalbum["artist"]["id"];
                    album.description = (string)jalbum["description"];
                    album.coverURL    = (string)jalbum["image"]["large"];
                    album.label       = (string)jalbum["label"]["name"];
                    album.track_count = (int)jalbum["tracks_count"];

                    objReturn.Add(album);
                }
                return(objReturn);

                #endregion
                #region Track
            }
            else if (obj["track_number"] != null)
            {
                Console.WriteLine("Is Track");
                QabuzeSong objReturn = new QabuzeSong(
                    (string)obj["id"],
                    (string)obj["title"],
                    (string)obj["performer"]["name"],
                    (string)obj["album"]["id"],
                    (int)obj["duration"],
                    (int)obj["track_number"],
                    (int)obj["media_number"],
                    (string)obj["album"]["title"],
                    (string)obj["album"]["genre"]["name"]
                    );
                return(objReturn);

                #endregion
                #region Artist
            }
            else if (obj["albums_as_primary_artist_count"] != null)
            {
                Console.WriteLine("Is Artist");
                QabuzeArtist objReturn = new QabuzeArtist();

                objReturn.albums_as_primary_artist_count = (int)obj["albums_as_primary_artist_count"];
                objReturn.id       = (int)obj["id"];
                objReturn.name     = (string)obj["name"];
                objReturn.imageURL = (string)obj["image"]["mega"];
                if (obj["biography"] != null)
                {
                    objReturn.biography = (string)obj["biography"]["content"];
                }

                return(objReturn);
            }
            #endregion

            // Console.WriteLine(response);
            return(null);
        }