Пример #1
0
        private void OnBroadcast()
        {
            var source = StreamSource;
            var contentReaderFactory = ContentType;

            if (!CanBroadcast(source, contentReaderFactory, channelName))
            {
                return;
            }
            IYellowPageClient yellowPage = this.yellowPage;
            var channelInfo  = CreateChannelInfo(this);
            var channelTrack = CreateChannelTrack(this);

            var channel_id = PeerCastStation.Core.BroadcastChannel.CreateChannelID(
                peerCast.BroadcastID,
                channelName,
                genre,
                source.ToString());
            var source_stream =
                selectedSourceStream ??
                peerCast.SourceStreamFactories
                .Where(sstream => (sstream.Type & SourceStreamType.Broadcast) != 0)
                .FirstOrDefault(sstream => sstream.Scheme == source.Scheme);
            var channel = peerCast.BroadcastChannel(
                yellowPage,
                channel_id,
                channelInfo,
                source,
                source_stream,
                contentReaderFactory);

            if (channel != null)
            {
                channel.ChannelTrack = channelTrack;
            }

            var info = new BroadcastInfoViewModel {
                StreamUrl   = this.StreamUrl,
                StreamType  = this.SelectedSourceStream != null ? this.SelectedSourceStream.Name : null,
                Bitrate     = this.bitrate.HasValue ? this.bitrate.Value : 0,
                ContentType = this.ContentType.Name,
                YellowPage  = this.YellowPage != null ? this.YellowPage.Name : null,
                ChannelName = this.ChannelName,
                Genre       = this.Genre,
                Description = this.Description,
                Comment     = this.Comment,
                ContactUrl  = this.ContactUrl,
                TrackTitle  = this.TrackTitle,
                TrackAlbum  = this.TrackAlbum,
                TrackArtist = this.TrackArtist,
                TrackGenre  = this.TrackGenre,
                TrackUrl    = this.TrackUrl,
                Favorite    = false,
            };

            uiSettings.AddBroadcastHistory(info);
            uiSettings.Save();
        }
Пример #2
0
            private string BroadcastChannel(int?yellowPageId, string sourceUri, string contentReader, JObject info, JObject track)
            {
                IYellowPageClient yp = null;

                if (yellowPageId.HasValue)
                {
                    yp = PeerCast.YellowPages.FirstOrDefault(y => y.GetHashCode() == yellowPageId.Value);
                    if (yp == null)
                    {
                        throw new RPCError(RPCErrorCode.InvalidParams, "Yellow page not found");
                    }
                }
                if (sourceUri == null)
                {
                    throw new RPCError(RPCErrorCode.InvalidParams, "source uri required");
                }
                Uri source;

                try {
                    source = new Uri(sourceUri);
                }
                catch (UriFormatException) {
                    throw new RPCError(RPCErrorCode.InvalidParams, "Invalid Uri");
                }
                var content_reader = PeerCast.ContentReaderFactories.FirstOrDefault(reader => reader.Name == contentReader);

                if (content_reader == null)
                {
                    throw new RPCError(RPCErrorCode.InvalidParams, "Content reader not found");
                }

                var new_info = new AtomCollection();

                if (info != null)
                {
                    if (info["name"] != null)
                    {
                        new_info.SetChanInfoName((string)info["name"]);
                    }
                    if (info["url"] != null)
                    {
                        new_info.SetChanInfoURL((string)info["url"]);
                    }
                    if (info["genre"] != null)
                    {
                        new_info.SetChanInfoGenre((string)info["genre"]);
                    }
                    if (info["desc"] != null)
                    {
                        new_info.SetChanInfoDesc((string)info["desc"]);
                    }
                    if (info["comment"] != null)
                    {
                        new_info.SetChanInfoComment((string)info["comment"]);
                    }
                }
                var channel_info = new ChannelInfo(new_info);

                if (channel_info.Name == null || channel_info.Name == "")
                {
                    throw new RPCError(RPCErrorCode.InvalidParams, "Channel name must not be empty");
                }
                var channel_id = Utils.CreateChannelID(
                    PeerCast.BroadcastID,
                    channel_info.Name,
                    channel_info.Genre ?? "",
                    source.ToString());
                var channel = PeerCast.BroadcastChannel(yp, channel_id, channel_info, source, content_reader);

                if (track != null)
                {
                    var new_track = new AtomCollection(channel.ChannelTrack.Extra);
                    if (track["name"] != null)
                    {
                        new_track.SetChanTrackTitle((string)track["name"]);
                    }
                    if (track["genre"] != null)
                    {
                        new_track.SetChanTrackGenre((string)track["genre"]);
                    }
                    if (track["album"] != null)
                    {
                        new_track.SetChanTrackAlbum((string)track["album"]);
                    }
                    if (track["creator"] != null)
                    {
                        new_track.SetChanTrackCreator((string)track["creator"]);
                    }
                    if (track["url"] != null)
                    {
                        new_track.SetChanTrackURL((string)track["url"]);
                    }
                    channel.ChannelTrack = new ChannelTrack(new_track);
                }
                return(channel.ChannelID.ToString("N").ToUpper());
            }