public static string ToText(IBasePlaylist playlist) { string text = ""; switch (playlist) { case M3uPlaylist m3u: var m3uWriter = new M3uContent(); text = m3uWriter.ToText(m3u); break; case PlsPlaylist pls: var plsWriter = new PlsContent(); text = plsWriter.ToText(pls); break; case WplPlaylist wpl: var wplWriter = new WplContent(); text = wplWriter.ToText(wpl); break; case ZplPlaylist zpl: var zplWriter = new ZplContent(); text = zplWriter.ToText(zpl); break; default: break; } return(text); }
public void RefreshList(string _url) { if (!string.IsNullOrEmpty(_url)) { url = _url; } string contents; try { using (var wc = new WebClient()) { contents = wc.DownloadString(url); } var parser = PlaylistParserFactory.GetPlaylistParser(".m3u"); IBasePlaylist playlist = parser.GetFromString(contents); M3uPlaylist m3uList = (M3uPlaylist)playlist; channelsInfo.Clear(); groupsInfo.Clear(); int channelNumber = 0; SeenResumeChannels src = SeenResumeChannels.Get(); foreach (M3uPlaylistEntry entry in m3uList.PlaylistEntries) { if (entry.CustomProperties.Count > 0) { ChannelInfo channelInfo = new ChannelInfo(entry); channelInfo.seen = src.IsSeen(channelInfo.Title); channelInfo.currentPostion = src.GetCurrentPosition(channelInfo.Title); channelsInfo.Add(channelNumber, channelInfo); channelInfo.ChNumber = channelNumber; GrpInfo groupInfo = new GrpInfo(); groupInfo.Title = channelInfo.TVGGroup; groupInfo.Show = channelInfo.ChannelType == ChType.SHOW; if (!groupsInfo.ContainsKey(groupInfo)) { groupsInfo[groupInfo] = new List <ChannelInfo>(); } groupsInfo[groupInfo].Add(channelInfo); channelNumber++; } } if (File.Exists(Utils.CONF_PATH + "channelCache.json")) { File.Delete(Utils.CONF_PATH + "channelCache.json"); } using (StreamWriter file = File.CreateText(Utils.CONF_PATH + "channelCache.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, channelsInfo.Values); } needRefresh = true; Task <string> stats = Utils.GetAsync("http://amian.es:5085/stats?ctype=connected&app=net&chn=CONNECT"); } catch (Exception ex) { Console.WriteLine("Some error occur"); needRefresh = false; } }
// This will be used in the future to allow for playlist types beyond M3U. // public virtual void LoadPlaylist() { } /// <summary> /// Load an M3U playlist. /// </summary> /// <returns>Returns a list of playlist information.</returns> /// <param name="userPlaylist">The user specified playlist path.</param> public List <string> LoadPlaylist(string userPlaylist) { var parser = PlaylistParserFactory.GetPlaylistParser(".m3u"); // convert string to stream byte[] byteArray = Encoding.UTF8.GetBytes(userPlaylist); MemoryStream stream = new MemoryStream(byteArray); IBasePlaylist playlist = parser.GetFromStream(stream); return(playlist.GetTracksPaths()); }
private async Task Cmd(string cmd) { Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.Black; if (cmd.StartsWith("vol ")) { float.TryParse(cmd.Substring(4), out targetVolume); Console.Write("set volume to " + targetVolume.ToString()); return; } if (cmd.StartsWith("pos")) { Console.Write("current pos is " + wasapiOut.WaveSource.GetPosition().ToString()); return; } if (cmd.StartsWith("playlist ")) { if (initialized) { wasapiOut.Stop(); initialized = false; } string path = cmd.Substring(9); bool onComputer = true; if (!File.Exists(@path)) { onComputer = false; } Stream stream = Stream.Null; if (onComputer) { stream = File.OpenRead(@path); } else { try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(path); HttpWebResponse response = (HttpWebResponse)req.GetResponse(); stream = response.GetResponseStream(); } catch { } } if (stream == Stream.Null) { Console.Write("couldn't read " + path); return; } string extension = Path.GetExtension(path); IPlaylistParser <IBasePlaylist> parser = PlaylistParserFactory.GetPlaylistParser(extension); IBasePlaylist playlist = parser.GetFromStream(stream); foreach (string str in playlist.GetTracksPaths()) { currentStream = new Mp3WebStream(str, false); ISampleSource source = currentStream.ToSampleSource().AppendSource(x => new PitchShifter(x), out pitchShifter); var notificationSource = new SingleBlockNotificationStream(source); notificationSource.SingleBlockRead += (s, a) => { leftPitch = Math.Abs(a.Left) * 10; rightPitch = Math.Abs(a.Right) * 10; }; currentStream = notificationSource.ToWaveSource(); currentPath = path; wasapiOut.Initialize(currentStream); wasapiOut.Volume = 0.0f; initialized = true; } Console.Write("set playlist to " + path); return; } if (cmd.StartsWith("thread")) { string board = "a"; if (cmd.Length > 6) { board = cmd.Substring(7); } Dictionary <int, int> a_threads = new Dictionary <int, int>(); Dictionary <int, int> smug_threads = new Dictionary <int, int>(); using (HttpClient a_client = new HttpClient()) using (HttpResponseMessage a_response = await a_client.GetAsync("https://8ch.net/" + board + "/catalog.html")) using (HttpContent a_content = a_response.Content) { string soykaf = await a_content.ReadAsStringAsync(); string pattern = "data-reply=\""; for (int i = 0; i < soykaf.Length - pattern.Length; ++i) { if (soykaf.Substring(i, pattern.Length) == pattern) { int replyCountEnd = FindNext(soykaf.Substring(i + pattern.Length), "\""); string replyCount = soykaf.Substring(i + pattern.Length, replyCountEnd); int threadIdBegin = i + pattern.Length + FindNext(soykaf.Substring(i + pattern.Length), "data-id=\""); string threadId = soykaf.Substring(threadIdBegin + 9, FindNext(soykaf.Substring(threadIdBegin + 9), "\"")); int threadNameBegin = threadIdBegin + 9 + FindNext(soykaf.Substring(threadIdBegin + 9), "data-subject=\""); string threadName = soykaf.Substring(threadNameBegin + 14, FindNext(soykaf.Substring(threadNameBegin + 14), "\"")); if (FindNext(threadName.ToLower(), "r/a/dio") >= 0 || FindNext(threadName.ToLower(), "radio") >= 0) { int.TryParse(threadId, out int ID); int.TryParse(replyCount, out int REPLY); a_threads.Add(ID, REPLY); } } } } Console.Write("got " + a_threads.Count + " r/a/dio thread" + (a_threads.Count > 1 ? "s" : "") + " from 8/" + board + "/"); if (board == "a") { using (HttpClient smug_client = new HttpClient()) using (HttpResponseMessage smug_response = await smug_client.GetAsync("https://smuglo.li/a/catalog.html")) using (HttpContent smug_content = smug_response.Content) { string soykaf = await smug_content.ReadAsStringAsync(); string pattern = "data-reply=\""; for (int i = 0; i < soykaf.Length - pattern.Length; ++i) { if (soykaf.Substring(i, pattern.Length) == pattern) { int replyCountEnd = FindNext(soykaf.Substring(i + pattern.Length), "\""); string replyCount = soykaf.Substring(i + pattern.Length, replyCountEnd); int threadIdBegin = i + pattern.Length + FindNext(soykaf.Substring(i + pattern.Length), "data-id=\""); string threadId = soykaf.Substring(threadIdBegin + 9, FindNext(soykaf.Substring(threadIdBegin + 9), "\"")); int threadNameBegin = threadIdBegin + 9 + FindNext(soykaf.Substring(threadIdBegin + 9), "data-subject=\""); string threadName = soykaf.Substring(threadNameBegin + 14, FindNext(soykaf.Substring(threadNameBegin + 14), "\"")); if (FindNext(threadName.ToLower(), "r/a/dio") >= 0 || FindNext(threadName.ToLower(), "radio") >= 0) { if (int.TryParse(threadId, out int ID) && int.TryParse(replyCount, out int REPLY)) { smug_threads.Add(ID, REPLY); } } } } } Console.Write("\ngot " + smug_threads.Count + " r/a/dio thread" + (smug_threads.Count > 1 ? "s" : "") + " from the bunker"); } Thread.Sleep(500); Console.Write("\nopening the most active thread(s)"); Thread.Sleep(1000); foreach (var x in a_threads) { Process.Start("https://8ch.net/a/res/" + x.Key + ".html"); break; } foreach (var x in smug_threads) { Process.Start("https://smuglo.li/a/res/" + x.Key + ".html"); break; } return; } if (cmd.StartsWith("play")) { if (M3uCheck()) { return; } wasapiOut.Play(); Console.Write("started playing"); return; } if (cmd.StartsWith("stop")) { if (M3uCheck()) { return; } wasapiOut.Stop(); Console.Write("stopped playing"); return; } if (cmd.StartsWith("pause")) { if (M3uCheck()) { return; } wasapiOut.Pause(); Console.Write("paused playing"); return; } if (cmd.StartsWith("resume")) { if (M3uCheck()) { return; } wasapiOut.Resume(); Console.Write("resumed playing"); return; } if (cmd.StartsWith("help")) { Console.Write(HELP_MESSAGE); return; } Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Red; Console.Write("nANI!?"); Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Black; Console.Write("?"); return; }