public async Task DoShow() { var tagFeed = await _instaApi.GetTagFeedAsync("quadcopter", PaginationParameters.MaxPagesToLoad(5)); if (tagFeed.Succeeded) { Console.WriteLine( $"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}"); foreach (var media in tagFeed.Value.Medias) { ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength); } } }
public async Task <List <InstaImage> > GetMedia() { _logger.Info($"Getting images for hashtag {_settings.Hashtag.Value} (requesting {_settings.PagesCount.Value} pages)"); var tagFeed = await _instaApi.GetTagFeedAsync(_settings.Hashtag.Value, PaginationParameters.MaxPagesToLoad(_settings.PagesCount.Value)); if (tagFeed.Succeeded) { var images = tagFeed.Value.Medias.Where(x => x.Images != null) .Where(x => x.Images.Any()) .Where(x => x.TakenAt > _settings.StartDate.Value) .Select(s => new InstaImage() { Url = s.Images.First().URI, User = s.User?.FullName ?? "Unknown" }).ToList(); var carouselMedias = tagFeed.Value.Medias.Where(x => x.Carousel != null && x.Carousel.Any()) .Where(s => s.TakenAt > _settings.StartDate.Value); foreach (var media in carouselMedias) { if (media.TakenAt > _settings.StartDate.Value) { foreach (var item in media.Carousel) { if (item.Images.Any()) { images.Add(new InstaImage() { Url = item.Images.First().URI, User = media.User?.FullName ?? "Unknown" }); } } } } return(images); } _logger.Error($"Error when getting pictures for hashtag {tagFeed.Info.Message}"); return(new List <InstaImage>()); }
async void Sbor() { info.File = setting.SborAcc_SaveFileName; info.Status = "Выполняется"; int progress = 0; info.Progress = $"{progress}/{setting.SborHashTags_CountUneUser * setting.SborHashTags_ListHashTags.Count}"; EventUpdateGrid(this, new UpdateGridAudience(info)); foreach (string hashTag in setting.SborHashTags_ListHashTags) { if (_source == null || _source.IsCancellationRequested) { break; } var tag = await api.GetTagFeedAsync(hashTag, PaginationParameters.MaxPagesToLoad(45)); ew.WaitOne(); if (tag.Succeeded) { int count = 0; for (int i = 0; i < tag.Value.MediaItemsCount; i++) { for (int x = 0; x < tag.Value.Medias[i].Likers.Count; x++) { try { if (_source == null || _source.IsCancellationRequested) { break; } var media = tag.Value.Medias[i]; if (setting.SborHashTags_CheckedLikeUnderPublish) { if (media.LikesCount > setting.SborHashTags_CountLikeUnderPublish_Max || media.LikesCount < setting.SborHashTags_CountLikeUnderPublish_Min) { continue; } } if (setting.SborHashTags_CheckedCommentUnderPublish) { if (Convert.ToInt32(media.CommentsCount) > setting.SborHashTags_CountCommentUnderPublish_Max || Convert.ToInt32(media.CommentsCount) < setting.SborHashTags_CountCommentUnderPublish_Min) { continue; } } if (setting.SborHashTags_TypePublish == TypePublish.Photo) { var type = media.MediaType; if (type != InstaMediaType.Image) { continue; } } if (setting.SborHashTags_TypePublish == TypePublish.Video) { var type = media.MediaType; if (type != InstaMediaType.Video) { continue; } } var user = tag.Value.Medias[i].Likers[x]; if (setting.SborHashTags_WhatPars == WhatPars.Login) { listAcc.Add(user.UserName); } if (setting.SborHashTags_WhatPars == WhatPars.ID) { listAcc.Add(user.Pk.ToString()); } ew.WaitOne(); count++; progress++; info.Progress = $"{progress}/{setting.SborHashTags_CountUneUser * setting.SborHashTags_ListHashTags.Count}"; EventUpdateGrid(this, new UpdateGridAudience(info)); if (count > setting.SborHashTags_CountUneUser) { break; } } catch { continue; } } if (count > setting.SborHashTags_CountUneUser) { count = 0; break; } } Thread.Sleep(500); } else { Thread.Sleep(5000); } } info.Status = "Выполнено"; EventUpdateGrid(this, new UpdateGridAudience(info)); Save(); }
private async Task DownloadTagMediaAsync(string input, int downloadLimit) { var downloadCount = 0; var downloadFolder = _mediaFilter.CustomFolder ? $@"{_downloadFolder}\{input}" : _downloadFolder; var statsFile = $@"{_statsDirectory}\{input}.csv"; if (!File.Exists(statsFile)) { using (var csv = new Csv(statsFile, _delimiter)) { csv.WriteHeader(); } } var maxId = ""; do { var tagMedia = await _instaApi.GetTagFeedAsync(input, PaginationParameters.MaxPagesToLoad(1).StartFromId(maxId)); if (!tagMedia.Succeeded) { return; } maxId = tagMedia.Value.NextId; if (!_mediaFilter.SkipTopPosts) { foreach (var rankedMedia in tagMedia.Value.RankedMedias) { _cancellationToken.ThrowIfCancellationRequested(); if (_mediaFilter.CheckFilters(rankedMedia)) { continue; } if (CheckTotalDownloads() && CheckDownloadLimit(downloadCount++, downloadLimit)) { await DownloadInstaMediaAsync(rankedMedia, statsFile, downloadFolder); } else { return; } } } foreach (var media in tagMedia.Value.Medias) { _cancellationToken.ThrowIfCancellationRequested(); if (_mediaFilter.CheckFilters(media)) { continue; } if (CheckTotalDownloads() && CheckDownloadLimit(downloadCount++, downloadLimit)) { await DownloadInstaMediaAsync(media, statsFile, downloadFolder); } else { return; } } } while (maxId != null); }
public async Task DoShow() { // get currently logged in user var currentUser = await _instaApi.GetCurrentUserAsync(); Console.WriteLine( $"Logged in: username - {currentUser.Value.UserName}, full name - {currentUser.Value.FullName}"); // get self followers var followers = await _instaApi.GetUserFollowersAsync(currentUser.Value.UserName, 5); Console.WriteLine($"Count of followers [{currentUser.Value.UserName}]:{followers.Value.Count}"); // get self folling var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, 5); Console.WriteLine($"Count of following [{currentUser.Value.UserName}]:{following.Value.Count}"); // get self user's media, latest 5 pages var currentUserMedia = await _instaApi.GetUserMediaAsync(currentUser.Value.UserName, 5); if (currentUserMedia.Succeeded) { Console.WriteLine($"Media count [{currentUser.Value.UserName}]: {currentUserMedia.Value.Count}"); foreach (var media in currentUserMedia.Value) { ConsoleUtils.PrintMedia("Self media", media, _maxDescriptionLength); } } //get user time line feed, latest 5 pages var userFeed = await _instaApi.GetUserTimelineFeedAsync(5); if (userFeed.Succeeded) { Console.WriteLine( $"Feed items (in {userFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {userFeed.Value.Medias.Count}"); foreach (var media in userFeed.Value.Medias) { ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength); } //like first 10 medias from user timeline feed foreach (var media in userFeed.Value.Medias.Take(10)) { var likeResult = await _instaApi.LikeMediaAsync(media.InstaIdentifier); var resultString = likeResult.Value ? "liked" : "not liked"; Console.WriteLine($"Media {media.Code} {resultString}"); } } // get tag feed, latest 5 pages var tagFeed = await _instaApi.GetTagFeedAsync("quadcopter", 5); if (tagFeed.Succeeded) { Console.WriteLine( $"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}"); foreach (var media in tagFeed.Value.Medias) { ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength); } } }
public async Task <List <Media> > GetTagFeedAsync(string hashtag, int maxPageToLoad = 10) { IResult <InstaTagFeed> tagFeeds = await instaApi.GetTagFeedAsync(hashtag, PaginationParameters.MaxPagesToLoad(maxPageToLoad)); return(tagFeeds.Value.Medias.ToMediaList()); }
public async Task DoShow() { // get currently logged in user var currentUser = await _instaApi.GetCurrentUserAsync(); Console.WriteLine( $"Logged in: username - {currentUser.Value.UserName}, full name - {currentUser.Value.FullName}"); // get followers of user 'elonmusk' var followers = await _instaApi.GetUserFollowersAsync("elonmusk", PaginationParameters.MaxPagesToLoad(5) .StartFromId("AQAC8w90POWyM7zMjHWmO9vsZNL_TuLp6FR506_C_y3fUAjlCclrIDI2RdSGvur5UjLrq4Cq7NJN8QUhHG-vpbT6pCLB5X9crDxBOHUEuNJ4fA")); Console.WriteLine($"Count of followers [elonmusk]:{followers.Value.Count}"); Console.WriteLine($"Next id will be: '{followers.Value.NextId}'"); // get self folling var following = await _instaApi.GetUserFollowingAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(5)); Console.WriteLine($"Count of following [{currentUser.Value.UserName}]:{following.Value.Count}"); // get self user's media, latest 5 pages var currentUserMedia = await _instaApi.GetUserMediaAsync(currentUser.Value.UserName, PaginationParameters.MaxPagesToLoad(5)); if (currentUserMedia.Succeeded) { Console.WriteLine($"Media count [{currentUser.Value.UserName}]: {currentUserMedia.Value.Count}"); foreach (var media in currentUserMedia.Value) { ConsoleUtils.PrintMedia("Self media", media, _maxDescriptionLength); } } //get user time line feed, latest 5 pages var userFeed = await _instaApi.GetUserTimelineFeedAsync(PaginationParameters.MaxPagesToLoad(5)); if (userFeed.Succeeded) { Console.WriteLine( $"Feed items (in {userFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {userFeed.Value.Medias.Count}"); foreach (var media in userFeed.Value.Medias) { ConsoleUtils.PrintMedia("Feed media", media, _maxDescriptionLength); } //like first 10 medias from user timeline feed foreach (var media in userFeed.Value.Medias.Take(10)) { var likeResult = await _instaApi.LikeMediaAsync(media.InstaIdentifier); var resultString = likeResult.Value ? "liked" : "not liked"; Console.WriteLine($"Media {media.Code} {resultString}"); } } // get tag feed, latest 5 pages var tagFeed = await _instaApi.GetTagFeedAsync("quadcopter", PaginationParameters.MaxPagesToLoad(5)); if (tagFeed.Succeeded) { Console.WriteLine( $"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}"); foreach (var media in tagFeed.Value.Medias) { ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength); } } }
private async void ProcessHashtag(string tag) { try { // ищем информацию о теге var hashtagInfo = await api.GetHashtagInfo(tag); if (hashtagInfo.Succeeded) { //logBox.Items.Add("Hashtag: #" + hashtagInfo.Value.Name + ", media count = " + hashtagInfo.Value.MediaCount); // получаем ленту с постами по хештегу var tagFeed = await api.GetTagFeedAsync(hashtagInfo.Value.Name, PaginationParameters.MaxPagesToLoad(5)); int count = actionCount < (tagFeed.Value.Medias.Count) ? actionCount : tagFeed.Value.Medias.Count; foreach (var media in tagFeed.Value.Medias.Take(count)) { if (chk_boxLike.Checked) { // ставим лайки каждому посту var likeResult = await api.LikeMediaAsync(media.InstaIdentifier); var resultString = likeResult.Value ? "liked" : "not liked"; if (media.Images.Count > 0) { logger.WriteLog($"Hashtag: #{hashtagInfo.Value.Name}, URI:{media.Images[0].URI}"); } logger.WriteLog($" Post URI: https://www.instagram.com/p/{media.Code}"); logger.WriteLog($"User: {media.User.UserName} {resultString}"); } if (chk_follow.Checked) { // подписываемся на автора картинки var followResult = await api.FollowUserAsync(media.User.Pk); var resultString = followResult.Succeeded ? "followed" : "not folowwed"; logger.WriteLog($"{resultString} {media.User.UserName}"); folowingUsers.Add(media.User.Pk.ToString()); } if (chk_boxComment.Checked && commentsArr.Length > 0) { // ставим случайный комментарий автору фотки Random rnd = new Random(); int randIndx = rnd.Next(0, commentsArr.Length - 1); string comment = commentsArr[randIndx]; var commentResult = await api.CommentMediaAsync(media.InstaIdentifier, comment); var resultString = commentResult.Succeeded ? "comented" : "not comented"; logger.WriteLog($"{resultString}"); logger.WriteLog($"-------------------------------------------------------------"); } if (media.Images.Count > 1) { PrintImage(media.Images[1].URI); } progressBar.Increment(1); } } } catch (Exception ex) { logger.CloseLog(); MessageBox.Show(ex.ToString()); } }