private async Task <List <LiveChannel> > GetLiveStreamsFromId(ChannelId channelId) { var liveChannels = new List <LiveChannel>(); var requestUrl = $"{youtubeSearchEndpoint}?part=snippet&channelId={channelId}&eventType=live&maxResults=25&type=video&key={youtubeApiKey}"; var request = new RestRequest(requestUrl, Method.GET); var response = await client.ExecuteTaskAsync <Core.Entities.YoutubeSearch.YoutubeSearchRoot>(request); var data = response?.Data; if (data?.items != null) { foreach (var item in data.items) { string videoid = item?.id?.videoId; if (!string.IsNullOrWhiteSpace(videoid)) { string url = $"https://www.youtube.com/watch?v={videoid}"; int viewers = await GetViewersFromStream(videoid); var liveChannel = new LiveChannel(item?.snippet?.channelTitle, item?.snippet?.title, "N/A", 0, "", item?.snippet?.thumbnails?.medium?.url, url); liveChannels.Add(liveChannel); } } } return(liveChannels); }
public override ListLiveChannelResult Deserialize(ServiceResponse xmlStream) { var model = ContentDeserializer.Deserialize(xmlStream.Content); var result = new ListLiveChannelResult { Prefix = model.Prefix, Marker = model.Marker }; if (model.MaxKeys.HasValue) { result.MaxKeys = model.MaxKeys.Value; } if (model.IsTruncated.HasValue) { result.IsTruncated = model.IsTruncated.Value; } result.NextMarker = model.NextMarker; var liveChannels = new List <LiveChannel>(); if (model.LiveChannels != null) { foreach (var e in model.LiveChannels) { var liveChannel = new LiveChannel() { Name = e.Name, Description = e.Description, Status = e.Status, LastModified = e.LastModified }; if (e.PublishUrls != null) { liveChannel.PublishUrl = e.PublishUrls.Url; } if (e.PlayUrls != null) { liveChannel.PlayUrl = e.PlayUrls.Url; } liveChannels.Add(liveChannel); } } result.LiveChannels = liveChannels; DeserializeGeneric(xmlStream, result); return(result); }
public async Task <IActionResult> AddChannles(LiveChannel channel) { string editState = Request.Form["editState"]; var uploadfile = Request.Form.Files["Image"]; string img = ""; if (uploadfile != null && uploadfile.Length > 0) { var now = DateTime.Now; var filePath = string.Format("/uploads/images/{0}/", now.ToString("yyyyMMdd")); //string bas = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath; //获取到bin目录 //string bas = AppContext.BaseDirectory;//获取到bin目录 string bas = Directory.GetCurrentDirectory() + "/wwwroot";//获取服务器目录 if (!Directory.Exists(bas + filePath)) { Directory.CreateDirectory(bas + filePath); } if (uploadfile != null) { //文件后缀 var fileExtension = Path.GetExtension(uploadfile.FileName); var strDateTime = DateTime.Now.ToString("yyMMddhhmmssfff"); //取得时间字符串 var strRan = Convert.ToString(new Random().Next(100, 999)); //生成三位随机数 var saveName = strDateTime + strRan + fileExtension; img = filePath + saveName; using (FileStream fs = System.IO.File.Create(bas + filePath + saveName)) { uploadfile.CopyTo(fs); fs.Flush(); channel.Image = img; } } } if (editState == "update") { LiveChannel data = _context.LiveChannels.Where(b => b.Id == channel.Id).FirstOrDefault(); data.Name = channel.Name; data.Url = channel.Url; data.VideoType = channel.VideoType; if (img.Length > 0) { data.Image = img; } } else { await _context.LiveChannels.AddAsync(channel); } await _context.SaveChangesAsync(); return(Redirect("/Admin/index")); }
public static LiveChannelUpdateRequestBuilder Update(string id, LiveChannel liveChannel) { return(new LiveChannelUpdateRequestBuilder(id, liveChannel)); }
public static LiveChannelAddRequestBuilder Add(LiveChannel liveChannel) { return(new LiveChannelAddRequestBuilder(liveChannel)); }
private void SendOutputValue(LiveChannel channel) { dataAquisition.SetChannelValue(channel.Channel, channel.Value); }
public static async Task AnnounceLiveChannel(string beamId) { IMixerManager mixerManager = new MixerManager(); var servers = BotFiles.GetConfiguredServers(); var beamServers = new List <DiscordServer>(); var ownerBeamServers = new List <DiscordServer>(); var userSharedServers = new List <DiscordServer>(); foreach (var server in servers) { if (server.ServerBeamChannels != null && server.ServerBeamChannelIds != null) { if (server.ServerBeamChannels.Count > 0 && server.ServerBeamChannelIds.Count > 0) { if (server.ServerBeamChannelIds.Contains(beamId)) { if (server.GoLiveChannel != 0) { beamServers.Add(server); } } } } if (!string.IsNullOrEmpty(server.OwnerBeamChannelId) && server.OwnerBeamChannelId.Equals(beamId)) { if (server.OwnerLiveChannel != 0) { ownerBeamServers.Add(server); } } } List <BroadcastMessage> messages = new List <BroadcastMessage>(); foreach (var server in beamServers) { // Check to see if we have a message already queued up. If so, jump to the next server. if (server.GoLiveChannel != 0 && server.Id != 0) { if (messages.FirstOrDefault(x => x.GuildId == server.Id && x.UserId == beamId) == null) { var stream = await mixerManager.GetChannelByName(beamId); string gameName = stream.type == null ? "a game" : stream.type.name; string url = "http://mixer.com/" + stream.token; string avatarUrl = stream.user.avatarUrl != null ? stream.user.avatarUrl : "https://mixer.com/_latest/assets/images/main/avatars/default.jpg"; string thumbnailUrl = "https://thumbs.mixer.com/channel/" + stream.id + ".small.jpg"; string channelId = stream.id.Value.ToString(); messages.Add(await MessagingHelper.BuildMessage(stream.token, gameName, stream.name, url, avatarUrl, thumbnailUrl, Constants.Mixer, channelId, server, server.GoLiveChannel, null)); } } } foreach (var server in ownerBeamServers) { if (server.OwnerLiveChannel != 0 && server.Id != 0) { if (messages.FirstOrDefault(x => x.GuildId == server.Id && x.UserId == beamId) == null) { var stream = await mixerManager.GetChannelByName(beamId); string gameName = stream.type == null ? "a game" : stream.type.name; string url = "http://mixer.com/" + stream.token; string avatarUrl = stream.user.avatarUrl != null ? stream.user.avatarUrl : "https://mixer.com/_latest/assets/images/main/avatars/default.jpg"; string thumbnailUrl = "https://thumbs.mixer.com/channel/" + stream.id + ".small.jpg"; string channelId = stream.id.Value.ToString(); messages.Add(await MessagingHelper.BuildMessage(stream.token, gameName, stream.name, url, avatarUrl, thumbnailUrl, Constants.Mixer, channelId, server, server.OwnerLiveChannel, null)); } } } if (messages.Count > 0) { var channel = new LiveChannel() { Name = beamId, Servers = new List <ulong>(), ChannelMessages = await MessagingHelper.SendMessages(Constants.Mixer, messages) }; File.WriteAllText( Constants.ConfigRootDirectory + Constants.LiveDirectory + Constants.MixerDirectory + beamId + ".json", JsonConvert.SerializeObject(channel)); } }