public static void GetImages(VkApi api, string HeaderName) { var Attachments = GetDialogsAttachments(api, HeaderName, MediaType.Photo); ChoiseMedia.Media[] images = new ChoiseMedia.Media[0]; for (int i = 0; i < Attachments.Count; i++) { var image = (Attachments[i].Attachment.Instance as VkNet.Model.Attachments.Photo); if (image.OwnerId != api.UserId) { Array.Resize(ref images, images.Length + 1); var value = (Attachments[i].Attachment.Instance as VkNet.Model.Attachments.Photo).Sizes.Last().Url .ToString(); var name = new Regex(@"[\S]+(.jpg)").Match(value).Value; name = name.Substring(name.LastIndexOf("/") + 1, name.Length - name.LastIndexOf("/") - 1); images[images.Length - 1] = new ChoiseMedia.Media() { url = value, name = name.Substring(1, name.Length - 1), duration = "IMG" }; } } Download.DownloadStart(images, MediaType.Photo); }
public static void GetList(long?id, VkApi api, string resource = "") { TextConsole.PrintConsole.Header($"Видеозаписи {resource}"); TextConsole.PrintConsole.Print("Получение списка видеозаписей", TextConsole.MenuType.InfoHeader); var videos = api.Video.Get(new VideoGetParams() { OwnerId = id }); ChoiseMedia.Media[] list = new ChoiseMedia.Media[0]; for (int i = 0; i < videos.Count; i++) { if (videos[i].Files.External != null) { continue; } Array.Resize(ref list, list.Length + 1); list[list.Length - 1] = new ChoiseMedia.Media() { url = GetMaxQuality(videos[i].Files), name = $"{videos[i].Title}", duration = GlobalFunctions.CurrentDuration((Int32)videos[i].Duration) }; if (list[list.Length - 1].url == null) { Array.Resize(ref list, list.Length - 1); } } Prepare(list, resource); }
/// <summary> /// Получить видео из сообщений /// </summary> /// <param name="api"></param> /// <param name="HeaderName"></param> public static ChoiseMedia.Media[] FromMessage(VkApi api, string HeaderName) { TextConsole.PrintConsole.Header(HeaderName); TextConsole.PrintConsole.Print("Получаем список видеозаписей...", TextConsole.MenuType.InfoHeader); string nextFrom = ""; var Attachments = Dialogs.Get.GetDialogsAttachments(api, HeaderName, MediaType.Video); ChoiseMedia.Media[] AttachmentsList = new ChoiseMedia.Media[0]; for (int i = 0; i < Attachments.Count; i++) { var attach = Attachments[i].Attachment.Instance as VkNet.Model.Attachments.Video; string url = GetMaxQuality(attach.Files); if (url == null) { continue; } Array.Resize(ref AttachmentsList, AttachmentsList.Length + 1); if (attach == null) { continue; } AttachmentsList[AttachmentsList.Length - 1] = new ChoiseMedia.Media() { url = url, duration = GlobalFunctions.CurrentDuration((int)attach.Duration), name = attach.Title, date = attach.Date.Value.ToString("dd/MM/yyyy hh:mm tt") }; } var list = ChoiseMedia.PrintList(AttachmentsList); if (list == null) { return(null); } ChoiseMedia.Media[] to_Download = new ChoiseMedia.Media[0]; for (int i = 0; i < list.Count; i++) { Array.Resize(ref to_Download, to_Download.Length + 1); to_Download[to_Download.Length - 1] = AttachmentsList[list[i]]; } return(to_Download); }
/// <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); }
static void Prepare(ChoiseMedia.Media[] media, string resource = "") { ChoiseMedia.Media[] selected = new ChoiseMedia.Media[0]; while (true) { var menuList = new List <string>() { "Все", "Выбрать" }; int pos = gMenu.Menu(menuList, $"Видеозаписи {resource}"); ChoiseMedia.Media[] copy = new ChoiseMedia.Media[media.Length]; for (int i = 0; i < media.Length; i++) { copy[i] = new ChoiseMedia.Media() { url = media[i].url, name = media[i].name, duration = media[i].duration }; } switch (pos) { case 1: Download.DownloadStart(copy, MediaType.Video); break; case 2: var videolist = ChoiseMedia.PrintList(copy); Console.ResetColor(); if (videolist == null) { return; } selected = new ChoiseMedia.Media[videolist.Count]; for (int i = 0; i < videolist.Count; i++) { selected[i] = copy[i].Clone() as ChoiseMedia.Media; } Download.DownloadStart(selected, MediaType.Video); break; case -1: return; } } }
/// <summary> /// Получить из сообщений /// </summary> /// <param name="api"></param> /// <param name="HeaderName"></param> public static ChoiseMedia.Media[] FromMessage(VkApi api, string HeaderName) { long ConvID = GetConversationID.Get(api, HeaderName); if (ConvID < 0) { return(null); } //var q = api.Messages.GetConversationsById(new List<long>() { ConvID }, new List<string>() { }, true); TextConsole.PrintConsole.Header(HeaderName); TextConsole.PrintConsole.Print("Получаем список аудиозаписей...", TextConsole.MenuType.InfoHeader); var Attachments = Dialogs.Get.GetDialogsAttachments(api, HeaderName, MediaType.Audio); ChoiseMedia.Media[] AttachmentsList = new ChoiseMedia.Media[0]; for (int i = 0; i < Attachments.Count; i++) { Array.Resize(ref AttachmentsList, AttachmentsList.Length + 1); AttachmentsList[AttachmentsList.Length - 1] = new ChoiseMedia.Media() { url = GetCurrentUrl((Attachments[i].Attachment.Instance as Audio).Url), duration = GlobalFunctions.CurrentDuration( (int)(Attachments[i].Attachment.Instance as Audio).Duration), name = $"{(Attachments[i].Attachment.Instance as Audio).Artist} - {(Attachments[i].Attachment.Instance as Audio).Title}" }; if (AttachmentsList[AttachmentsList.Length - 1].url == null) { Array.Resize(ref AttachmentsList, AttachmentsList.Length - 1); } } if (AttachmentsList.Length > 0) { var q = api.Messages.GetConversationsById(new List <long>() { ConvID }, new List <string>() { "first_name_ins", "last_name_ins" }, true); if (q.Items.First().ChatSettings != null) { AttachmentsList[0].other = q.Items.First().ChatSettings.Title; } else { AttachmentsList[0].other = "c " + q.Profiles.First().FirstNameIns + " " + q.Profiles.First().LastNameIns; } } return(AttachmentsList); }
/// <summary> /// Музыка со стены /// </summary> /// <param name="api"></param> /// <param name="cancellationToken"></param> /// <param name="pageId"></param> /// <returns></returns> static ChoiseMedia.Media[] FromBoard(VkApi api, CancellationToken cancellationToken, long?pageId) { ChoiseMedia.Media[] audioList = new ChoiseMedia.Media[0]; try { string HeaderName = "Музыка со стены "; HeaderName += GlobalFunctions.WhoIs(api, pageId, NameCase.Gen); TextConsole.PrintConsole.Header(HeaderName); var Walls = api.Wall.Get(new WallGetParams { OwnerId = pageId, Count = 1 }); if (Walls.TotalCount == 0) { TextConsole.PrintConsole.Print("Записей не найдено.", TextConsole.MenuType.InfoHeader); TextConsole.BackLine.Continue(); return(null); } ulong offset = 0; for (; ;) { cancellationToken.ThrowIfCancellationRequested(); TextConsole.PrintConsole.Header(HeaderName); TextConsole.PrintConsole.Print("Для остановки нажмите любую кнопку", TextConsole.MenuType.Warning); if (offset > Walls.TotalCount) { offset = Walls.TotalCount; } TextConsole.PrintConsole.Print( $"Проверено {offset} из {Walls.TotalCount}\nНайдено {audioList.Length} треков.", TextConsole.MenuType.InfoHeader); Walls = api.Wall.Get(new WallGetParams { OwnerId = pageId, Count = 100, Offset = offset }); if (Walls.WallPosts.Count == 0) { TextConsole.PrintConsole.Header(HeaderName); TextConsole.PrintConsole.Print($"Найдено {audioList.Length} треков.", TextConsole.MenuType.InfoHeader); TextConsole.PrintConsole.Print($"Для продолжения нажмите любую кнопку."); break; } for (int h = 0; h < Walls.WallPosts.Count; h++) { cancellationToken.ThrowIfCancellationRequested(); if (Walls.WallPosts[h].Attachments.Count > 0) { for (int w = 0; w < Walls.WallPosts[h].Attachments.Count; w++) { if (String.Compare(Walls.WallPosts[h].Attachments[w].Type.Name, "Audio") == 0) { Array.Resize(ref audioList, audioList.Length + 1); audioList[audioList.Length - 1] = new ChoiseMedia.Media() { name = $"{(Walls.WallPosts[h].Attachments[w].Instance as Audio).Artist} - {(Walls.WallPosts[h].Attachments[w].Instance as Audio).Title}", url = GetCurrentUrl((Walls.WallPosts[h].Attachments[w].Instance as Audio).Url), duration = GlobalFunctions.CurrentDuration((Walls.WallPosts[h].Attachments[w].Instance as Audio).Duration) }; } } } } offset += 100; } return(audioList); } catch (Exception ex) { if (cancellationToken.CanBeCanceled) { return(audioList); } return(null); } }
public static void View() { int profileNum = MainData.ChoiseProfile(); if (profileNum == -1) { return; } string HeaderName = "Видеозаписи"; VkApi api = MainData.Profiles.GetUser(profileNum).GetApi(); while (true) { var menuList = new List <string>() { "Мои видеозаписи", "Видеозаписи друзей", "Ввести ссылку пользователя/паблика", "Ввести ссылку на видео", "Из сообщений" }; int pos = gMenu.Menu(menuList.ToList(), HeaderName); switch (pos) { case 1: Get.GetList(api.UserId, api); break; case 2: var friendsList = api.Friends.Get(new FriendsGetParams() { Fields = ProfileFields.FirstName }); var friends = new List <string>(); for (int i = 0; i < friendsList.Count; i++) { friends.Add($"{friendsList[i].FirstName} {friendsList[i].LastName}"); } int selected = gMenu.Menu(friends.ToList(), "Выберите друга"); if (selected < 0) { return; } Get.GetList((long?)friendsList[selected - 1].Id, api, friendsList[selected - 1].FirstName + " " + friendsList[selected - 1].LastName); break; case 3: TextConsole.PrintConsole.Header(HeaderName); TextConsole.PrintConsole.Print("Введите ссылку: ", TextConsole.MenuType.Input); string url = Console.ReadLine(); long?id = GlobalFunctions.GetID(url, api.Token); Get.GetList(id, api); break; case 4: List <long?> video; while (true) { TextConsole.PrintConsole.Header(HeaderName); TextConsole.PrintConsole.Print("Введите ссылку: ", TextConsole.MenuType.Input); video = FromUrl(Console.ReadLine()); if (video != null) { break; } } var data = api.Video.Get(new VideoGetParams() { Videos = new List <VkNet.Model.Attachments.Video>() { new VkNet.Model.Attachments.Video() { OwnerId = video[0], Id = video[1] } }, OwnerId = video[0] }); if (data.Count < 1) { TextConsole.PrintConsole.Print("Не удалось получить ссылку на видеозапись.", TextConsole.MenuType.InfoHeader); TextConsole.BackLine.Continue(); break; } ChoiseMedia.Media[] toDownload = new ChoiseMedia.Media[1]; toDownload[0] = new ChoiseMedia.Media() { url = Get.GetMaxQuality(data[0].Files), name = data[0].Title, duration = GlobalFunctions.CurrentDuration((int)data[0].Duration) }; Download.DownloadStart(toDownload, MediaType.Video); break; case 5: var videos = Get.FromMessage(api, HeaderName); Download.DownloadStart(videos, MediaType.Video); break; case -1: return; } } }
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; } } }