Esempio n. 1
0
        /**
         * @param inputStream an open input stream positioned at the beginning of the file
         * @param format requires the playlist to be this format
         * @param encoding required encoding for the playlist
         * @param parsingMode indicates how to handle unknown lines in the input stream
         */
        public PlaylistParser(Stream inputStream, Format format, Encoding encoding, ParsingMode parsingMode)
        {
            if (inputStream == null)
            {
                throw new ArgumentNullException("inputStream is null");
            }

            if (encoding == null)
            {
                throw new ArgumentNullException("encoding is null");
            }

            if (parsingMode == null && format != Format.M3U)
            {
                throw new ArgumentNullException("parsingMode is null");
            }

            switch (format)
            {
            case Format.M3U:
                mPlaylistParser = new M3uParser(inputStream, encoding);
                break;

            case Format.EXT_M3U:
                mPlaylistParser = new ExtendedM3uParser(inputStream, encoding, parsingMode);
                break;

            default:
                throw new Exception("unsupported format detected, this should be impossible: " + format);
            }
        }
Esempio n. 2
0
 public HddPlaylistRepository()
 {
     Parser = new AimpPlaylistParser();
 }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
 public PlaylistLoader(ILogger <PlaylistLoader> logger, IPlaylistParser playlistParser)
 {
     _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
     _playlistParser = playlistParser ?? throw new ArgumentNullException(nameof(playlistParser));
 }