protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); NavigationMode = e.NavigationMode; if (e.NavigationMode == NavigationMode.New) { GetType().RemovePageFromBackStack(); } try { if (e.Parameter is InstaMedia media) { MediaPrivate = /*ToPost*/ (media); MediaIdOrLINKPrivate = null; } else if (e.Parameter is string mediaIdOrLink) { MediaIdOrLINKPrivate = mediaIdOrLink; MediaPrivate = null; //HandleLinkOrMediaId(mediaIdOrLink); } } catch { } }
public InstaMediaContentDialog(InstaMedia Media) { this.InitializeComponent(); this.DataContext = Media; _med = Media; #if !DEBUG if (!Media.User.IsPrivate || Media.PhotoOfYou || Media.User.UserName == AppCore.InstaApi.GetLoggedUser().UserName) { #endif Commands.Items.Add(new LVItem { Text = "Copy URL", Tag = "Copy" }); Commands.Items.Add(new LVItem { Text = "Download content", Tag = "Download" }); #if !DEBUG } #endif Commands.Items.Add(new LVItem { Text = "Copy caption", Tag = "CC" }); Commands.Items.Add(new LVItem { Text = "Cancel", Tag = "Cancel" }); }
public async Task Execute(Queue queue, InstaBotContext db) { var allGroups = queue.LoadId.Split(' '); bool isMediaPosted = false; foreach (var group in allGroups) { var instaMediaList = await _instaApi.GetUserMediaAsync(group, PaginationParameters.MaxPagesToLoad(0)); InstaMedia firstMedia = instaMediaList?.Value?.FirstOrDefault(); if (firstMedia != null && firstMedia.MediaType != InstaMediaType.Video && !IsAlreadyPosted(firstMedia.InstaIdentifier, queue.LoginData.Name, db)) { var caption = GetCaption(queue, firstMedia); isMediaPosted = await PostMediaAsync(firstMedia, caption); } if (isMediaPosted || group.Equals(allGroups.LastOrDefault())) { await UpdateQueueLastActivityAsync(queue, db); await AddFinishedQueuToHistory(firstMedia.InstaIdentifier, queue, db); Console.WriteLine($"PostMediaExecutor for {queue.LoginData.Name}"); return; } } }
public async Task <ActionModel> DoComment(InstaMedia media, string comments) { ActionModel dataAction = new ActionModel { Type = "Comment", Username = userSession.UserName, Status = 0 }; try { var comment = await HelpersInstaApi.InstaApi.CommentProcessor.CommentMediaAsync(media.Pk, comments); if (comment.Succeeded) { dataAction.Status = 1; dataAction.Response = $"[+] {dataAction.Type} | Status: Success | Page: https://instagram.com/p/{media.Code} | Text: {comment.Value.Text}"; } else { dataAction.Response = $"[+] {dataAction.Type} | Status: Failed | Error: {comment.Info.Message}"; } } catch (Exception ex) { dataAction.Response = $"[+] {dataAction.Type} | Status: Failed | Error: {ex.Message}"; } return(dataAction); }
public static string GetLatestPictureOfUser(string name) { //IResult<InstaUser> usersearch = await api.GetUserAsync(username); string id = ""; IResult <InstaMediaList> media = _api.UserProcessor.GetUserMediaAsync(name, PaginationParameters.MaxPagesToLoad(1)).Result; //System.Threading.Thread.Sleep(1000); Console.Write(media.Info); if (!media.Succeeded) { Console.WriteLine(" " + "failed"); } else { List <InstaMedia> mediaList = media.Value.ToList(); InstaMedia firstInstaMedia = mediaList.First <InstaMedia>(); id = firstInstaMedia.InstaIdentifier; Console.WriteLine(id); } return(id); }
public async Task <SmartCaption> Enrich(InstaMedia message) { logger.LogInformation("Generating caption..."); SmartCaption captionHolder = captionHandler.Extract(message.Caption?.Text); logger.LogInformation("Found [{0}] tags in original caption", captionHolder.TotalTags); if (captionHolder.TotalTags > 20) { logger.LogInformation("Found more than 20 tags on photo - ignoring it"); return(captionHolder); } var original = captionHolder.Tags.ToArray(); var locationTags = await tagsByLocation.Get(message.Location).ConfigureAwait(false); foreach (var tag in locationTags.OrderByDescending(item => item.MediaCount).Take(totalLocationTags)) { if (captionHolder.TotalTags >= totalTags) { return(captionHolder); } captionHolder.AddTag(tag); } var results = await GetMix(original, totalTags - locationTags.Length).ConfigureAwait(false); foreach (var data in results) { captionHolder.AddTag(data); } return(captionHolder); }
public async void SetMedia(string mediaId) { var media = await Helper.InstaApi.MediaProcessor.GetMediaByIdAsync(mediaId); if (media.Succeeded) { Media = media.Value; if (ScrollView == null) { //if (NavigationMode == NavigationMode.Back) return; ScrollView = ItemsLV.FindScrollViewer(); if (ScrollView != null) { ScrollView.ViewChanging += ScrollViewViewChanging; } CommentsVM.SetLV(ScrollView); } CommentsVM.ResetCache(); ToggleGoUpButtonAnimation(false); if (Media != null) { CommentsVM.SetMedia(Media); } CommentsVM.RunLoadMore(true); } }
public static string PrintMedia(string header, InstaMedia media) { var content = $"{header}: {media.Caption?.Text.Truncate(30)}, {media.Code}"; content.Output(); return(content); }
public static InstaImageUpload AsUpload( this InstaImage image, InstaMedia media, string uri) { var imageUpload = new InstaImageUpload(uri, image.Width, image.Height); var tagsUpload = new List <InstaUserTagUpload>(); if (media.UserTags != null) { foreach (var tag in media.UserTags) { var tagUpload = new InstaUserTagUpload(); if (tag.User != null) { tagUpload.Username = tag.User.UserName; } if (tag.Position != null) { tagUpload.X = tag.Position.X; tagUpload.Y = tag.Position.Y; } tagsUpload.Add(tagUpload); } } imageUpload.UserTags.AddRange(tagsUpload); return(imageUpload); }
public static string PrintMedia(string header, InstaMedia media) { var content = $"{header}: {media.Caption?.Text.Truncate(30)}, {media.Code}"; Debug.WriteLine(content); return(content); }
public async void TotalDePublicacoes(string username, IInstaApi api) { IResult <InstaUser> userSearch = await api.GetUserAsync(username); Console.WriteLine($"USER:{userSearch.Value.FullName}\n\tFollowers: {userSearch.Value.FollowersCount}\n\t {userSearch.Value.IsVerified}"); IResult <InstaMediaList> media = await api.GetUserMediaAsync(username, PaginationParameters.MaxPagesToLoad(5)); List <InstaMedia> mediaList = mediaList = media.Value.ToList(); for (int i = 0; i < mediaList.Count; i++) { InstaMedia m = mediaList[i]; if (m != null && m.Caption != null) { string captionText = m.Caption.Text; if (captionText != null) { if (m.MediaType == InstaMediaType.Image) { for (int X = 0; X < m.Images.Count; X++) { if (m.Images[X] != null && m.Images[X].URI != null) { Console.WriteLine($"\n\t{captionText}"); string uri = m.Images[X].URI; Console.Write($"{uri}\n\t"); } } } } } } }
private string GetCaption(Queue queue, InstaMedia instaMedia) { var caption = ""; caption = queue.Notes ?? instaMedia.Caption.Text; return(caption); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter is InstaMedia media) { Media = media; } }
async void HandleLinkOrMediaId(string mediaIdOrLink) { try { if (string.IsNullOrEmpty(mediaIdOrLink)) { return; } mediaIdOrLink = mediaIdOrLink.Trim(); await MainPage.Current.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { ShowTopLoading(); try { string mediaId = mediaIdOrLink; if (mediaIdOrLink.StartsWith("http://") || mediaIdOrLink.StartsWith("https://") || mediaIdOrLink.StartsWith("www.")) { var mediaInfoFromUrl = await Helper.InstaApi.MediaProcessor.GetMediaIdFromUrlAsync(new Uri(mediaIdOrLink)); if (mediaInfoFromUrl.Succeeded) { mediaId = mediaInfoFromUrl.Value; } else { if (mediaInfoFromUrl.Info.ResponseType == InstagramApiSharp.Classes.ResponseType.PrivateMedia) { Helper.ShowNotify("This media is private and can't get view it with URL.", 5000); HideTopLoading(); Helpers.NavigationService.GoBack(); return; } else if (mediaInfoFromUrl.Info.ResponseType == InstagramApiSharp.Classes.ResponseType.NoMediaMatch) { Helper.ShowNotify("No media match.\r\nThis means media is deleted or something is wrong with URL you provided.", 5000); HideTopLoading(); Helpers.NavigationService.GoBack(); return; } } } var media = await Helper.InstaApi.MediaProcessor.GetMediaByIdAsync(mediaId); if (media.Succeeded) { Media = /*ToPost*/ (media.Value); } else { Helper.ShowNotify("Something went wrong!", 4000); } } catch { } HideTopLoading(); }); } catch { HideTopLoading(); } }
public static Media ToMedia(this InstaMedia instaMedia) { return(new Media { Id = instaMedia.Pk, LikesCount = instaMedia.LikesCount, User = instaMedia.User.ToUserInfo() }); }
public static IEnumerable <InstaImage> GetImages( this InstaMedia media) { if (media.Images == null) { return(new InstaImage[0]); } return(media.Images.Where(i => i.Width == media.Images.Max(m => m.Width))); }
public static IEnumerable <InstaVideo> GetOriginalVideos( this InstaMedia media) { if (media.Videos == null) { return(new InstaVideo[0]); } return(media.Videos.Where(i => i.Width == media.Width)); }
public static bool IsObsoleted( this InstaMedia media, int threshold) { if (media == null) { return(true); } return((DateTime.UtcNow - media.GetMediaDate()).TotalDays > threshold); }
public static string GetInstagramUrl( this InstaMedia media) { if (media == null || string.IsNullOrEmpty(media.Code)) { return(string.Empty); } return($"{InstagramConst.InstagramMediaUrl}{media.Code}"); }
internal async void OpenTV(InstaMedia tv) { try { await Helper.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => NavigationService.Navigate(typeof(Views.TV.TVPlayer), new object[] { new List <InstaMedia> { tv }, 0 })); } catch { } }
public void ResetEverything() { Media = null; UsernameText.Text = ""; DateText.Text = ""; TitleText.Text = ""; ViewCountRun.Text = ""; ViewCountRun.Text = ""; ProfileEllipse.Fill = null; SetLike(false); }
public void SetMedia(InstaMedia media) { Media = media; SetMedia(media.InstaIdentifier); //try //{ // if (media?.Caption != null) // Items.Add(media.Caption?.ToComment()); //} //catch { } }
public void ResetCache() { User = null; CurrentMedia = null; SelectedIndex = -1; PageCount = 1; Pagination = PaginationParameters.MaxPagesToLoad(1); IsLoading = true; HasMoreItems = true; Items.Clear(); FirstRun = true; }
private async Task <bool> PostMediaAsync(InstaMedia media, string caption) { MediaPost mediaPost = GetMediaPost(media); InstaImage[] instaImages = LoadImagesAsync(mediaPost.URICollection); bool postResult = await UploadPostAsync(instaImages, caption); //TODO delete all loaded images return(postResult); }
public static DateTime GetMediaDate( this InstaMedia media) { if (media.Caption == null || media.Caption.CreatedAtUtc == DateTime.MinValue || media.Caption.CreatedAtUtc == DateTime.UnixEpoch) { return(media.DeviceTimeStamp); } return(media.Caption.CreatedAtUtc); }
private async void BestNextPK(InstaLikersList value) { List <IResult <InstaUser> > PKList = new List <IResult <InstaUser> >(); if (value.Count >= 10) { for (int i = 0; i < 10; i++) { try { IResult <InstaUser> X = await UserWorkation.InstaApi.UserProcessor.GetUserAsync(value[i].UserName); PKList.Add(X); } catch (Exception ex) { Debug.WriteLine("okListErroe: " + ex); } } } else if (value.Count > 0) { for (int i = 0; i < value.Count; i++) { IResult <InstaUser> X = await UserWorkation.InstaApi.UserProcessor.GetUserAsync(value[i].UserName); PKList.Add(X); } } else { PKList = null; } //Remove user without post & chise a last post with many like! List <IResult <InstaUser> > CleanList = new List <IResult <InstaUser> >(); var ListOrdered = PKList.OrderBy(o => o.Value.FollowersCount); PaginationParameters pagination = PaginationParameters.MaxPagesToLoad(1); foreach (var u in ListOrdered) { var Posts = await UserWorkation.InstaApi.UserProcessor.GetUserMediaAsync(u.Value.UserName, pagination); foreach (var p in Posts.Value) { if (p.LikesCount > 10) { Best = p; } } } }
public void SetMedia(InstaMedia media) { Media = media; SetMedia(media.InstaIdentifier); try { if (media?.Caption != null) { Items.Add(media.Caption?.ToComment()); } } catch { } }
public GenerateCommentItems(InstaMedia instaMedia, ListView listView) { Media = instaMedia; Items = new ObservableCollection <InstaComment>(); LV = listView; Scroll = listView.FindScrollViewer(); if (Scroll != null) { Scroll.ViewChanging += Scroll_ViewChanging; } HasMoreItems = true; Pagination = PaginationParameters.MaxPagesToLoad(1); }
public void SetMedia(InstaMedia instaMedia) { Media = instaMedia; if (instaMedia == null) { ResetEverything(); return; } var content = string.Empty; if (instaMedia.ViewCount > 0) { content = $"{instaMedia.ViewCount.Divide()}"; } if (instaMedia.LikesCount > 0) { var likes = $"{instaMedia.LikesCount.Divide()}"; //if (!string.IsNullOrEmpty(content)) //content = likes; //else // content += $" | {likes}"; } if (!string.IsNullOrEmpty(instaMedia.CommentsCount)) { var c = int.Parse(instaMedia.CommentsCount); if (c > 0) { var comments = $"{c.Divide()}"; CommentsCountRun.Text = $"{comments}"; } } Liked = instaMedia.HasLiked; SetLike(instaMedia.HasLiked); ViewCountRun.Text = content; DateText.Text = instaMedia.TakenAt.ToString("MMMM dd", CultureInfo.InvariantCulture); UsernameText.Text = instaMedia.User.UserName; TitleText.Text = instaMedia.Title; ProfileEllipse.Fill = new ImageBrush { ImageSource = new BitmapImage(new Uri(instaMedia.User.ProfilePicture)) }; try { CanShowControls = true; PanelFadeinStory.Begin(); } catch { } }
public async Task WriteContent(InstaMedia media) { string fileName; var width = 0; var height = 0; var displayUrl = ""; switch (media.MediaType) { case InstaMediaType.Image: fileName = media.Pk + InputValidation.GetUriExtension(media.Images[0].URI); width = media.Images[0].Width; height = media.Images[0].Height; displayUrl = media.Images[0].URI; break; case InstaMediaType.Video: fileName = media.Pk + InputValidation.GetUriExtension(media.Videos[0].Url); width = media.Videos[0].Width; height = media.Videos[0].Height; displayUrl = media.Videos[0].Url; break; case InstaMediaType.Carousel: fileName = "Carousel"; break; default: throw new ArgumentOutOfRangeException(); } var csvData = new CsvData { FileName = $"{fileName}", ShortCode = media.Code, DisplaySrc = displayUrl, MediaId = media.Pk, Dimensions = $"W: {width} H: {height}", Caption = media.Caption?.Text, Likes = media.LikesCount.ToString(), Comments = media.CommentsCount, IsVideo = media.HasAudio, VideoViews = media.ViewCount.ToString(), Date = media.TakenAt.ToLocalTime() }; _csvWriter.WriteRecord(csvData); await _csvWriter.NextRecordAsync(); }