public static JsonArray ServerRequest(string requestUrl)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        string s = String.Format("Server error(HTTP {0}: {1}).",
                                                 response.StatusCode, response.StatusDescription);
                        throw new Exception(s);
                    }

                    Stream       receiveStream = response.GetResponseStream();
                    Deserializer d             = new Deserializer(receiveStream);
                    object       jd            = d.Deserialize();
                    JsonArray    ja            = jd as JsonArray;

                    response.Close();
                    receiveStream.Close();
                    return(ja);
                }
            }
            catch (Exception e)
            {
                SC.log(e.Message);
                return(null);
            }
        }
Example #2
0
        private void OnArtistAdditionResponse(object o, ResponseArgs args)
        {
            ArtistAdder editor  = (ArtistAdder)o;
            bool        destroy = true;

            try {
                if (args.ResponseId == ResponseType.Ok)
                {
                    if (String.IsNullOrEmpty(editor.ArtistName))
                    {
                        destroy             = false;
                        editor.ErrorMessage = Catalog.GetString("Please provide a artist name");
                    }
                    else
                    {
                        JsonArray results = IO.MakeRequest("people", editor.ArtistName);

                        foreach (JsonObject artist in results)
                        {
                            string artist_name = (string)artist["username"];
                            if (artist_name == editor.ArtistName)
                            {
                                //SC.log(artist.ToString());
                                JsonArray tracks = IO.MakeRequest("getalltracks",
                                                                  (int)artist["id"]);
                                //SC.log(tracks.ToString());
                                SC.log(String.Format("Artist: {0}, Track Count: {1}",
                                                     artist_name, tracks.Count));

                                foreach (JsonObject t in tracks)
                                {
                                    DatabaseTrackInfo track = IO.makeTrackInfo(t);
                                    track.PrimarySource = this;
                                    track.IsLive        = true;
                                    track.Save();
                                    SC.log("  added track: " + track.TrackTitle);
                                }
                            }
                        }
                        // If all is well, set the window to close.
                        destroy = true;
                    }
                }
            } finally {
                if (destroy)
                {
                    // Remove response-handler reference.
                    editor.Response -= OnArtistAdditionResponse;
                    editor.Destroy();
                }
            }
        }
Example #3
0
        public SoundCloudSource() : base(Catalog.GetString("SoundCloud"),
                                         Catalog.GetString("SoundCloud"), "soundcloud", 52)
        {
            Properties.SetString("Icon.Name", "soundcloud");
            TypeUniqueId = "soundcloud";
            IsLocal      = false;

            AfterInitialized();

            // Have OnAddArtist() respond to an 'Add' being performed in the GTK window.
            InterfaceActionService uia_service = ServiceManager.Get <InterfaceActionService>();

            uia_service.GlobalActions.Add(
                new ActionEntry("AddSoundCloudArtistAction", Stock.Add,
                                Catalog.GetString("Add SoundCloud Artist"), null,
                                Catalog.GetString("Add a SoundCloud artist or playlist"),
                                OnAddArtist)
                );
            uia_service.GlobalActions["AddSoundCloudArtistAction"].IsImportant = false;

            ui_id = uia_service.UIManager.AddUiFromResource("GlobalUI.xml");

            Properties.SetString("ActiveSourceUIResource", "ActiveSourceUI.xml");
            Properties.Set <bool>("ActiveSourceUIResourcePropagate", true);
            Properties.Set <System.Reflection.Assembly>("ActiveSourceUIResource.Assembly",
                                                        typeof(SoundCloudSource).Assembly);

            Properties.SetString("GtkActionPath", "/SoundCloudContextMenu");
            Properties.Set <bool>("Nereid.SourceContentsPropagate", false);

            Properties.Set <ISourceContents>("Nereid.SourceContents",
                                             new LazyLoadSourceContents <SoundCloudSourceContents>());

            Properties.Set <string>("SearchEntryDescription", Catalog.GetString("Search your SoundCloud artists"));

            Properties.SetString("TrackView.ColumnControllerXml", String.Format(@"
                <column-controller>
                  <!--<column modify-default=""IndicatorColumn"">
                    <renderer type=""Banshee.Podcasting.Gui.ColumnCellPodcastStatusIndicator"" />
                  </column>-->
                  <add-default column=""IndicatorColumn"" />
                  <add-default column=""GenreColumn"" />
                  <column modify-default=""GenreColumn"">
                    <visible>false</visible>
                  </column>
                  <add-default column=""TitleColumn"" />
                  <column modify-default=""TitleColumn"">
                    <title>{0}</title>
                    <long-title>{0}</long-title>
                  </column>
                  <add-default column=""ArtistColumn"" />
                  <column modify-default=""ArtistColumn"">
                    <title>{1}</title>
                    <long-title>{1}</long-title>
                  </column>
				  <add-default column=""CommentColumn"" />
                  <column modify-default=""CommentColumn"">
                    <title>{2}</title>
                    <long-title>{2}</long-title>
                  </column>
				  <add-default column=""YearColumn"" />
                  <column modify-default=""YearColumn"">
                    <title>{3}</title>
                    <long-title>{3}</long-title>
                  </column>
                  <add-default column=""RatingColumn"" />
                  <add-default column=""PlayCountColumn"" />
                  <add-default column=""LastPlayedColumn"" />
                  <add-default column=""LastSkippedColumn"" />
                  <add-default column=""DateAddedColumn"" />
                  <add-default column=""UriColumn"" />
                  <sort-column direction=""asc"">artist</sort-column>
                </column-controller>",
                                                                                Catalog.GetString("Track"),
                                                                                Catalog.GetString("Artist"),
                                                                                Catalog.GetString("Description"),
                                                                                Catalog.GetString("Year")
                                                                                ));

            ServiceManager.PlayerEngine.TrackIntercept += OnPlayerEngineTrackIntercept;

            TrackEqualHandler = delegate(DatabaseTrackInfo a, TrackInfo b) {
                RadioTrackInfo r = b as RadioTrackInfo;
                return(r != null && DatabaseTrackInfo.TrackEqual(
                           r.ParentTrack as DatabaseTrackInfo, a));
            };

            /**
             * TODO:
             *      Figure out how to tell Banshee where to find the track artwork. See below.
             *
             * TrackArtworkIdHandler = delegate(DatabaseTrackInfo a) {
             *      return;
             * };
             */
            SC.log("Initialized");
        }