Beispiel #1
0
        /// <summary>
        /// Чтение
        /// </summary>
        /// <returns></returns>
        public static bool ReadData(bool load = true)
        {
            string path = $"{Environment.CurrentDirectory}\\Data.txt";

            if (File.Exists(path))
            {
                var data = JsonConvert.DeserializeObject <Classes.Data>(File.ReadAllText(path, Encoding.UTF8));
                if (data != null)
                {
                    for (int i = 0; i < data.LastChoise.Length; i++)
                    {
                        LastChoise.Add(new KeyValuePair <long?, string>(data.LastChoise[i].url,
                                                                        data.LastChoise[i].name), true);
                    }
                }
            }

            ReadUsers();
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Отмена
        /// </summary>
        /// <param name="task">Задача</param>
        /// <param name="cts">Токен</param>

        public static void Menu()
        {
            int profileNum = ChoiseProfile();

            if (profileNum == -1)
            {
                return;
            }


            VkApi api = Profiles.GetUser(profileNum).GetApi();

            while (true)
            {
                var menuList = new List <string>()
                {
                    "Моя музыка", "Рекомендации", "Указать ссылку", "Последние", "Из сообщений", "Со стены", "По Вашим предпочтениям"
                };
                int pos = gMenu.Menu(menuList.ToList(), HeaderName);

                switch (pos)
                {
                case 1:
                    var subMenuList = new List <string>()
                    {
                        "Музыка", "Плейлисты", "Всё (плейлисты вначале)"
                    };
                    int subPos = gMenu.Menu(subMenuList, HeaderName);

                    switch (subPos)
                    {
                    case 1:

                        Prepare(new AnyData.Data()
                        {
                            api    = api,
                            audios = Get.GetList(new AnyData.Data()
                            {
                                api = api
                            }),
                            SubName = GlobalFunctions.WhoIs(api, null, NameCase.Gen),
                            id      = api.UserId
                        });
                        break;

                    case 2:
                        Prepare(new AnyData.Data()
                        {
                            api     = api,
                            audios  = Get.GetPlaylists(api),
                            SubName = GlobalFunctions.WhoIs(api, null, NameCase.Gen),
                            id      = api.UserId
                        });
                        break;

                    case 3:
                        var trackListFromPlaylists = Get.GetPlaylists(api);
                        var trackList = Get.GetList(new AnyData.Data()
                        {
                            api = api
                        });
                        var fullList = trackListFromPlaylists.Concat(trackList).ToArray();
                        Prepare(new AnyData.Data()
                        {
                            api     = api,
                            audios  = fullList,
                            SubName = GlobalFunctions.WhoIs(api, null, NameCase.Gen),
                            id      = api.UserId
                        });
                        break;

                    case -1:
                        break;
                    }


                    break;

                case 2:
                    PrintConsole.Header(HeaderName, "Получаем категории");
                    var response = Get.GetCategoriesInRecommended(api).response;

                    //Удаляем ненужные категории
                    var temp = response.items;
                    for (int i = 0; i < response.items.Length; i++)
                    {
                        if (response.items[i].source.IndexOf("recoms_communities") != 0 && response.items[i].source.IndexOf("recoms_friends") != 0)
                        {
                            Array.Resize(ref temp, temp.Length + 1);
                            temp[temp.Length - 1] = response.items[i];
                        }
                    }

                    response.items = temp;

                    while (true)
                    {
                        var recCat = new List <string>()
                        {
                            $"Категории [{response.items.Length}]", $"Группы [{response.groups.Length}]", $"Пользователи [{response.profiles.Length}]"
                        };
                        int recCatPos = gMenu.Menu(recCat, "Рекомендации");

                        switch (recCatPos)
                        {
                        case 1:
                            var menuRec = new List <string>()
                            {
                            };
                            for (int i = 0; i < response.items.Length; i++)
                            {
                                menuRec.Add($"{response.items[i].title} [{response.items[i].count}]");
                            }
                            while (true)
                            {
                                int cPos = gMenu.Menu(menuRec.ToList(), "Категории");

                                switch (cPos)
                                {
                                default:
                                    PrintConsole.Header("Получаем данные");
                                    var result = Get.GetTrackListFromRec(api, response.items[cPos - 1]);

                                    if (result != null && result.Length > 0)
                                    {
                                        Prepare(new AnyData.Data()
                                        {
                                            api     = api,
                                            audios  = result,
                                            SubName = response.items[cPos - 1].title
                                        });
                                    }

                                    break;

                                case -1:
                                    return;
                                }
                            }

                        case 2:
                            var menuGroups = new List <string>()
                            {
                            };
                            for (int i = 0; i < response.groups.Length; i++)
                            {
                                menuGroups.Add($"{response.groups[i].name}");
                            }

                            while (true)
                            {
                                int cPos = gMenu.Menu(menuGroups.ToList(), "Группы");
                                switch (cPos)
                                {
                                default:
                                    Prepare(new AnyData.Data()
                                    {
                                        api     = api,
                                        audios  = Get.GetAudio(api, response.groups[cPos - 1].id * -1),
                                        SubName = response.groups[cPos - 1].name,
                                        id      = response.groups[cPos - 1].id
                                    });

                                    break;

                                case -1:
                                    return;
                                }
                            }

                        case 3:
                            var menuUsers = new List <string>()
                            {
                            };
                            for (int i = 0; i < response.profiles.Length; i++)
                            {
                                menuUsers.Add($"{response.profiles[i].first_name} {response.profiles[i].last_name}");
                            }

                            while (true)
                            {
                                int cPos = gMenu.Menu(menuUsers.ToList(), "Пользователи");
                                switch (cPos)
                                {
                                default:
                                    Prepare(new AnyData.Data()
                                    {
                                        api     = api,
                                        audios  = Get.GetAudio(api, response.profiles[cPos - 1].id),
                                        SubName = $"{response.profiles[cPos - 1].first_name} {response.profiles[cPos - 1].last_name}",
                                        id      = response.profiles[cPos - 1].id
                                    });

                                    break;

                                case -1:
                                    return;
                                }
                            }

                        case -1:
                            return;
                        }
                    }

                case 3:
GetFromUrl:
                    PrintConsole.Header(HeaderName, "Получаем список категорий");
                    PrintConsole.Print("[0] - Назад", MenuType.Back);
                    PrintConsole.Print($"Введите ссылку:  ", MenuType.Input);

                    string id = Console.ReadLine();

                    if (string.Compare(id, "0") == 0)
                    {
                        return;
                    }

                    long?_id = GlobalFunctions.GetID(id, Profiles.GetUser(profileNum).GetToken());

                    if (_id == null)
                    {
                        goto GetFromUrl;
                    }

                    AnyData.Data url = new AnyData.Data()
                    {
                        api    = api,
                        audios = Get.GetList(new AnyData.Data()
                        {
                            id = _id, api = api
                        }),
                        SubName = GlobalFunctions.WhoIs(api, _id, NameCase.Gen),
                        id      = _id
                    };

                    LastChoise.Add(new KeyValuePair <long?, string>(url.id, url.SubName));

                    Prepare(url);

                    break;

                case 4:
                    Last_Choise(api);
                    break;

                case 5:
                    var media = Get.FromMessage(api, HeaderName);

                    if (media != null)
                    {
                        Prepare(new AnyData.Data()
                        {
                            mType     = MediaType.Audio,
                            mediaList = media,
                            api       = api,
                            SubName   = $"Из беседы {(string)media[0].other}",
                            type      = Get.Type.Recommendation
                        }, true);
                    }

                    break;

                case 6:
                    GetDataFromBoard(api);
                    break;

                case 7:
                    var daily = new List <string>()
                    {
                        $"Дневной плейлист", $"Недельный плейлист"
                    };
                    int dpos = gMenu.Menu(daily, "По Вашим предпочтениям");

                    switch (dpos)
                    {
                    case 1:
                        Prepare(new AnyData.Data()
                        {
                            api    = api,
                            audios = Get.GetList(new AnyData.Data()
                            {
                                api = api, type = Get.Type.Daily
                            }),
                            SubName = GlobalFunctions.WhoIs(api, null, NameCase.Gen),
                            type    = Get.Type.Daily,
                            id      = api.UserId
                        });
                        break;

                    case 2:
                        Prepare(new AnyData.Data()
                        {
                            api    = api,
                            audios = Get.GetList(new AnyData.Data()
                            {
                                api = api, type = Get.Type.Weekly
                            }),
                            SubName = GlobalFunctions.WhoIs(api, null, NameCase.Gen),
                            type    = Get.Type.Weekly,
                            id      = api.UserId
                        });
                        break;

                    case -1:
                        return;
                    }
                    break;

                case -1:
                    return;
                }
            }
        }