Beispiel #1
0
        static void Main(string[] args)
        {

            var appId = "4935274";
            var apiVersion = "5.33";
            wb = new WebBrowser();
            wb.Navigated += Wb_Navigated;
            form = new Form();
            form.Controls.Add(wb);
            wb.Navigate($"https://oauth.vk.com/authorize?client_id={appId}&scope=friends,status,wall,groups,offline&redirect_uri=https://oauth.vk.com/blank.html&display=page&v={apiVersion}&response_type=token");
            form.ShowDialog();
            vk = new VkApi(appId, token, apiVersion);
            GetUserInfo();
            Console.ReadKey(false);

        }
Beispiel #2
0
        internal async Task<bool> Execute()
        {
            _reporter.Update(s => s.CurrentOperation = "Communicating with VK");

            _client = new VkApi(AppId.ToString(), _args.Token);

            _reporter.Update(s => s.CurrentOperationStatus = "Getting user info");
            var userInfo = await Users_Get(_args.UserId);
            _reporter.Update(s => s.CurrentOperation = $"Downloading music from {userInfo.LastName}, {userInfo.FirstName} to {_args.Folder}");

            _args.UserId = userInfo.Id;
            _args.Folder = Path.Combine(_args.Folder, $"{userInfo.FirstName}_{userInfo.LastName}");
            Directory.CreateDirectory(_args.Folder);

            _reporter.Update(s => s.CurrentOperationStatus = $"Getting full music list");
            var musicInfo = GetMusicInfo().ToList();
            _reporter.Update(s => s.CurrentOperationStatus = $"Getting full music list. Done");

            var filesInDestination = GetFilesInDestination().Select(f => f.Title).ToImmutableHashSet();

            var downloadCollection = new BlockingCollection<Music>();

            var tasks = new List<Task>();

            SpinWorkers(downloadCollection, tasks, 4);

            _stopwatch.Start();

            var songsToDownload = musicInfo.Where(m => !filesInDestination.Contains(CleanFileName(m.Title))).ToList();
            _reporter.Update(s => s.TotalSongsToDownload = songsToDownload.Count);

            foreach (var music in songsToDownload)
            {
                downloadCollection.Add(music);
            }

            downloadCollection.CompleteAdding();

            Task.WaitAll(tasks.ToArray());

            return true;
        }