Exemplo n.º 1
0
        /// <summary>
        /// Выбор плейлистов
        /// </summary>
        /// <param name="api"></param>
        /// <param name="id"></param>
        public static Get.Track[] GetPlaylists(VkApi api, long?id = null)
        {
            if (id == null)
            {
                id = api.UserId;
            }

            var playlists = api.Audio.GetPlaylists((long)id);

            ChoiseMedia.Media[] listPL = new ChoiseMedia.Media[playlists.Count];

            for (int i = 0; i < playlists.Count; i++)
            {
                listPL[i] = new ChoiseMedia.Media()
                {
                    name     = playlists[i].Title,
                    duration = "PLAYLIST",
                    url      = "null"
                };
            }

            var choised = ChoiseMedia.PrintList(listPL, "Выбрать плейлисты");

            Get.Track[] result = new Get.Track[0];

            foreach (var index in choised)
            {
                var trackList = Get.GetPlaylist(playlists[index], api);
                if (trackList == null)
                {
                    continue;
                }

                for (int i = 0; i < trackList.Length; i++)
                {
                    if (trackList[i].url == null)
                    {
                        continue;
                    }
                    Array.Resize(ref result, result.Length + 1);
                    result[result.Length - 1] = new Get.Track()
                    {
                        url      = GetCurrentUrl(new Uri(trackList[i].url)),
                        name     = trackList[i].artist + " - " + trackList[i].name,
                        duration = trackList[i].duration
                    };
                }
            }


            return(result);
        }
Exemplo n.º 2
0
        static void Prepare(AnyData.Data data, bool MediaListReady = false)
        {
            ChoiseMedia.Media[] list;

            if (MediaListReady)
            {
                list = (ChoiseMedia.Media[])data.mediaList;
                goto MediaListReady;
            }

            else
            {
                list = new ChoiseMedia.Media[data.audios.Length];
            }

            for (int i = 0; i < data.audios.Length; i++)
            {
                list[i] = new ChoiseMedia.Media()
                {
                    url      = data.audios[i].url,
                    name     = $"{data.audios[i].artist} - {data.audios[i].name} ",
                    duration = data.audios[i].duration
                };
            }

MediaListReady:
            Get.Track[] trackList = null;

            while (true)
            {
                if (data.mType == null)
                {
                    data.mType = MediaType.Audio;
                }

                var menuList = new List <string>()
                {
                    "Все", "Выбрать"
                };
                int pos = gMenu.Menu(menuList, $"Музыка {data.SubName}");

                switch (pos)
                {
                case 1:
                    if (!MediaListReady)
                    {
                        data.mediaList = list;
                    }

                    SubMenu(data);
                    break;

                case 2:
                    Console.Clear();

                    var audioList = ChoiseMedia.PrintList(list);

                    if (audioList == null)
                    {
                        break;
                    }
                    if (!MediaListReady)
                    {
                        trackList = new Get.Track[audioList.Count];

                        ChoiseMedia.Media[] mList = new ChoiseMedia.Media[0];

                        data.mediaList = new ChoiseMedia.Media[0];

                        for (int i = 0; i < audioList.Count; i++)
                        {
                            trackList[i] = data.audios[audioList[i]];
                            Array.Resize(ref mList, mList.Length + 1);
                            mList[mList.Length - 1] = new ChoiseMedia.Media()
                            {
                                duration = data.audios[audioList[i]].duration,
                                name     = $"{data.audios[audioList[i]].artist} - {data.audios[audioList[i]].name}",
                                url      = data.audios[audioList[i]].url
                            };
                        }

                        SubMenu(new AnyData.Data()
                        {
                            audios = trackList, api = data.api, type = data.type, mType = data.mType, SubName = data.SubName, mediaList = mList
                        });
                    }
                    else
                    {
                        ChoiseMedia.Media[] mList = new ChoiseMedia.Media[audioList.Count];

                        for (int q = 0; q < mList.Length; q++)
                        {
                            mList[q] = (data.mediaList as ChoiseMedia.Media[])[audioList[q]];
                        }

                        SubMenu(new AnyData.Data()
                        {
                            audios = trackList, api = data.api, type = data.type, SubName = data.SubName, mType = data.mType, mediaList = mList
                        });
                    }

                    break;

                case -1:
                    return;
                }
            }
        }