예제 #1
0
        public static async Task <string[]> GetMatchingUrlSerialize(string input)
        {
            string path = ValidFileName(input);
            string url  = "https://soundcloud.com/search?q=" + input.Replace(" ", "%20");
            await WebSocket.DownloadBytesTo(path + ".txt", url);

            using (var sr = File.OpenText(path))
            {
                List <string> stringList = new List <string>(20);
                while (!sr.EndOfStream)
                {
                    string str = await sr.ReadLineAsync();

//#if DEBUG
//                    Console.WriteLine(str);
//                    Console.ReadLine();
//#endif
                    if (str.Trim() == Identifier)
                    {
//#if DEBUG
//                        Console.WriteLine("Identifier detected");
//                        Console.ReadLine();
//#endif
                        await sr.ReadLineAsync(); //</ul>

                        await sr.ReadLineAsync(); //<ul>

                        string nextLine;
                        using (var sre = File.CreateText(path + "entries.txt"))
                        {
                            while ((nextLine = (await sr.ReadLineAsync()).Trim()) != "</ul>")
                            {
                                SearchEntry se    = GetSearchEntry(nextLine).Value;
                                string      sestr = $"{se.title}»{se.url}";
                                await sre.WriteLineAsync(sestr);

                                stringList.Add(sestr);
                            }
                        }
                    }
                }
                return(stringList.ToArray());
            }
        }
예제 #2
0
        public static async Task <string[]> GetMatchingUrlPure(string input)
        {
            string path       = ValidFileName(input);
            string url        = "https://soundcloud.com/search?q=" + input.Replace(" ", "%20");
            string htmlString = await WebSocket.GetStringFrom(url);

            //TODO: fix this vvv
            int startIndex = htmlString.IndexOf(Identifier) + Identifier.Length;

            using (var sr = File.OpenText(path + "txt"))
            {
                List <string> stringList = new List <string>(20);
                while (!sr.EndOfStream)
                {
                    string str = await sr.ReadLineAsync();

                    if (str.Trim() == Identifier)
                    {
                        await sr.ReadLineAsync(); //</ul>

                        await sr.ReadLineAsync(); //<ul>

                        string nextLine;
                        using (var sre = File.CreateText(path + "entries.txt"))
                        {
                            while ((nextLine = (await sr.ReadLineAsync()).Trim()) != "</ul>")
                            {
                                SearchEntry se    = GetSearchEntry(nextLine).Value;
                                string      sestr = $"{se.title}»{se.url}";
                                await sre.WriteLineAsync(sestr);

                                stringList.Add(sestr);
                            }
                        }
                    }
                }
                return(stringList.ToArray());
            }
        }
예제 #3
0
        public static async Task <SearchEntry[]> GetSearchEntriesAsync(string input)
        {
            string path = ValidFileName(input);
            string url  = "https://soundcloud.com/search?q=" + input.Replace(" ", "%20");
            await WebSocket.DownloadBytesTo(path, url);

            //By now, the program had downloaded info of Soundcloud page to path^
            using (StreamReader sr = File.OpenText(path))
            {
                SearchEntry[] entries = new SearchEntry[MaxEntriesPerPage];
                for (; ;)
                {
                    string str = await sr.ReadLineAsync();

                    if (str.Trim() == Identifier)
                    {
                        await sr.ReadLineAsync();

                        await sr.ReadLineAsync();

                        //Hard coded actions ^^^
                        //More incoming
                        for (int i = 0; i < MaxEntriesPerPage; i++)
                        {
                            SearchEntry?se = GetSearchEntry((await sr.ReadLineAsync()).Trim());
                            if (!se.HasValue)
                            {
                                break;
                            }
                            entries[i] = se.Value;
                        }
                        sr.Close();
                        File.Delete(path);
                        return(entries);
                    }
                }
            }
        }