public void ReturnsUsersMostRecentReblogIfPartnerIdentifierProvidedAndTheirTurn() { // Arrange var date = DateTime.Now; var yesterday = date.AddDays(-1); var threeDaysAgo = date.AddDays(-3); var fiveDaysAgo = date.AddDays(-5); var basePost = new BasePost { Notes = new List <BaseNote> { new BaseNote { PostId = "1", Type = NoteType.Reblog, Timestamp = threeDaysAgo, BlogName = "blackjackkent" }, new BaseNote { PostId = "2", Type = NoteType.Reblog, Timestamp = yesterday, BlogName = "someOtherBlog" }, new BaseNote { PostId = "3", Type = NoteType.Reblog, Timestamp = fiveDaysAgo, BlogName = "partnerblog" } } }; var adapter = new PostAdapter(basePost); // Act var note = adapter.GetMostRecentRelevantNote("blackjackkent", "partnerblog"); // Assert note.Should().NotBe(null); note.PostId.Should().Be("1"); note.Timestamp.Should().Be(threeDaysAgo); }
public void IgnoresBlogNameCase() { // Arrange var date = DateTime.Now; var yesterday = date.AddDays(-1); var threeDaysAgo = date.AddDays(-3); var fiveDaysAgo = date.AddDays(-5); var basePost = new BasePost { Notes = new List <BaseNote> { new BaseNote { PostId = "1", Type = NoteType.Reblog, Timestamp = threeDaysAgo, BlogName = "blackjackkent" }, new BaseNote { PostId = "2", Type = NoteType.Reblog, Timestamp = yesterday, BlogName = "partnerBlog" }, new BaseNote { PostId = "3", Type = NoteType.Reblog, Timestamp = fiveDaysAgo, BlogName = "partnerblog" } } }; var adapter = new PostAdapter(basePost); // Act var note = adapter.GetMostRecentRelevantNote("blackjackkent", "partnerblog"); // Assert note.Should().NotBe(null); note.PostId.Should().Be("2"); note.Timestamp.Should().Be(yesterday); }
public void AddPageAndPost(string privacy, string nameInput, string postInput) { if (privacy == "Public") { BasePage newPage = OFPublic.createPage(); newPage.PageName = nameInput; BasePost newPost = OFPublic.createPost(); newPost.Body = postInput; pageList.RepoAddPage(newPage); postList.RepoAddPost(newPost); } if (privacy == "Private") { BasePage newPage = OFPrivate.createPage(); newPage.PageName = nameInput; BasePost newPost = OFPrivate.createPost(); newPost.Body = postInput; pageList.RepoAddPage(newPage); postList.RepoAddPost(newPost); } foreach (BasePage pg in pageList.GetPageList()) { Console.WriteLine("Name: {0} | Public: {1}", pg.PageName, pg.ViewablePage); } Console.WriteLine(""); foreach (BasePost p in postList.GetPostList()) { Console.WriteLine("Body: {0} | Public: {1}", p.Body, p.ViewablePost); } }
public void ReturnsNullIfNotesContainsNoReblogs() { // Arrange var basePost = new BasePost { Notes = new List <BaseNote> { new BaseNote { Type = NoteType.Like }, new BaseNote { Type = NoteType.Reply }, new BaseNote { Type = NoteType.Posted } } }; var adapter = new PostAdapter(basePost); // Act var note = adapter.GetMostRecentRelevantNote("blackjackkent", "mypartner"); // Assert note.Should().BeNull(); }
private static void BasePostToBaseAdVM(BasePost basePost, BaseAdPostVM baseAdPostVM, bool isDetailed, int?descriptionSize = null, int?selectedPostId = null) { baseAdPostVM.DateCreated = DateConverter.GetAdDate(basePost.DateCreated); if (!isDetailed && basePost.Description.Length > descriptionSize) { baseAdPostVM.Description = basePost.Description.Substring(0, descriptionSize.Value); } else { baseAdPostVM.Description = basePost.Description; } baseAdPostVM.Place = basePost.Place.Name; baseAdPostVM.PostId = Encryptor.GetEncryptedString(basePost.PostId.ToString()); baseAdPostVM.Title = basePost.Title; baseAdPostVM.UerName = basePost.User.Name; baseAdPostVM.Complete = basePost.Complete; //if selectedPostId is null, then selected is set to default boolean value false; if (selectedPostId != null) { baseAdPostVM.Selected = basePost.PostId == selectedPostId.Value; } }
public IHttpActionResult PostPost(BasePost postData) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApplicationUser currentUser = db.Users.Find(User.Identity.GetUserId()); Topic currentTopic = db.Topics.Find(postData.TopicId); Post newPost = new Post { Content = postData.Content, Topic = currentTopic }; currentTopic.Posts.Add(newPost); try { db.Posts.Add(newPost); db.SaveChanges(); } catch (Exception e) { return(BadRequest("Not done")); } return(StatusCode(HttpStatusCode.OK)); }
void post_DownloadCompleted(object sender, EventArgs e) { BasePost item = (sender as BasePost); if (item == null) { return; } item.DownloadCompleted -= post_DownloadCompleted; // KBR 20150329 Crashes when try to modify DownloadList item.IsDownloaded = true; // KBR 20150220 Fix issue #2: if completed items aren't removed from the list, they'll be downloaded repeatedly. // DownloadList.Remove(item); // KBR 20150220 NOTE: the above change probably confuses the taskbar status display. Need to fix the "hacky test code"? var taskbar = Application.Current.MainWindow.TaskbarItemInfo; if (taskbar != null) { _itemsDownloadingCount++; taskbar.ProgressState = TaskbarItemProgressState.Normal; taskbar.ProgressValue = ((double)_itemsDownloadingCount / (double)DownloadList.Count); if (_itemsDownloadingCount >= DownloadList.Count) { taskbar.ProgressState = TaskbarItemProgressState.None; } } }
private static void BasePostToBasePostVM(BasePost basePost, BasePostVM vModel) { vModel.PostId = Encryptor.GetEncryptedString(basePost.PostId.ToString()); vModel.PlaceId = basePost.PlaceId; vModel.Title = basePost.Title; vModel.Description = basePost.Description; }
public BasePost GetGetPostwithNoteandPostAttribution() { BasePost result = null; bool found = false; long k = 1; while (found == false) { Console.Write("\rRead the next {0}th 20 posts...", k.ToString()); BasePost[] basePosts = client.GetDashboardPostsAsync(current, DashboardOption.Before, 0, 20, PostType.All, false, true).GetAwaiter().GetResult(); if (basePosts.Count() > 0) { current = basePosts[basePosts.Count() - 1].Id; } foreach (var basepost in basePosts) { if (basepost.NotesCount > 0) { foreach (var note in basepost.Notes) { if (note.Type == NoteType.Post_attribution) { result = basepost; found = true; break; } } } if (found == true) { break; } } k++; } Console.WriteLine(); Console.WriteLine(); return(result); }
public void ReturnsNullIfNotesAreEmpty() { // Arrange var basePost = new BasePost { Notes = new List <BaseNote>() }; var adapter = new PostAdapter(basePost); // Act var note = adapter.GetMostRecentRelevantNote("blackjackkent", "mypartner"); // Assert note.Should().BeNull(); }
public async Task TrailConverter() { TumblrClient tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret)); // find a post with trials BasePost post = null; bool findPostWithTrials = false; long currentID = 0; while (findPostWithTrials == false) { BasePost[] basePosts = await tc.GetDashboardPostsAsync(currentID, 0, 20, PostType.All, false, true); for (int i = 0; i < 20; i++) { BasePost basePost = basePosts[i]; if (basePost.Trails?.Count() > 0) { findPostWithTrials = true; post = basePost; break; } if (i == 19) { currentID = basePost.Id; } } } // convert post string json = JsonConvert.SerializeObject(post, Formatting.Indented); // deserialize post BasePost jsonPost = JsonConvert.DeserializeObject <BasePost>(json); //testing for (int i = 0; i < post.Trails.Count(); i++) { Trail baseTrail = post.Trails[i]; Trail jsonTrail = jsonPost.Trails[i]; Assert.AreEqual(baseTrail, jsonTrail); } }
public PrviewScreenView(BasePost post, ObservableCollection <BasePost> DowloadList) { InitializeComponent(); PreviewVM = new PreviewScreenVM(post, DowloadList); DataContext = PreviewVM; PreviewVM.AddedImageToFavorites += PreviewVM_AddedImageToFavorites; PreviewVM.RemovedImageFromFavorites += PreviewVM_RemovedImageFromFavorites; if (GlobalSettings.Instance.PreviewScreenWidth > 0) { this.Width = GlobalSettings.Instance.PreviewScreenWidth; this.Height = GlobalSettings.Instance.PreviewScreenHeight; } }
static void Main(string[] args) { Tumblr tumblr = new Tumblr(); BasePost basePost = tumblr.GetDrashBoardPostAsync().GetAwaiter().GetResult(); Console.WriteLine($"Post with ID {basePost.Id} found"); Console.WriteLine(); Console.WriteLine("Select a blog:"); int idx = 0; var blogs = tumblr.GetBlogs().GetAwaiter().GetResult(); foreach (var blog in blogs) { Console.WriteLine($" {idx} {blog}"); idx++; } Console.WriteLine(); Console.Write("Input: "); idx = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(); tumblr.Reblog(blogs[idx], basePost); Console.WriteLine("Post with standard date rebloged in queue"); Console.WriteLine(); Console.Write("Input a date: "); DateTime dateTime = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine(); tumblr.Reblog(blogs[idx], basePost, dateTime); Console.WriteLine($"Post with {dateTime} rebloged in queue"); System.Diagnostics.Process.Start($"https://www.tumblr.com/blog/{blogs[idx]}/queue"); Console.ReadLine(); }
public PreviewScreenVM(BasePost post, ObservableCollection <BasePost> downloadList) { _post = post; _downloadList = downloadList; ImageCache cache = new ImageCache(); _favoriteshandler = new FavoriteHandler(); ImageSource = cache.GetImage(post.FileMD, post.FullPictureURL, LateFilePath); PreviewPost = post; //ImageSource = _post.FullPictureURL; ShowTagList = Visibility.Collapsed; string[] splitter = { " ", "\n", "\r" }; TagList = new ObservableCollection <string>(post.Dimensions.Split(splitter, StringSplitOptions.RemoveEmptyEntries)); //if (!string.IsNullOrEmpty(post.Tags)) // _taglist = new ObservableCollection<string>(post.Tags.Split(splitter, StringSplitOptions.RemoveEmptyEntries)); //else // _taglist = new ObservableCollection<string>(); }
public PreviewScreenVM(BasePost post, ObservableCollection <BasePost> downloadList) { _post = post; _downloadList = downloadList; ImageCache cache = new ImageCache(); _favoriteshandler = new FavoriteHandler(); // KBR 20150405 Issue #5: extend GetImage to take a progress handler, so the preview download progress is visible PreviewPost = post; ImageSource = cache.GetImage(post.FileMD, post.FullPictureURL, LateFilePath, _post.client_DownloadProgressChanged); //ImageSource = _post.FullPictureURL; ShowTagList = Visibility.Collapsed; string[] splitter = { " ", "\n", "\r" }; TagList = new ObservableCollection <string>(post.Dimensions.Split(splitter, StringSplitOptions.RemoveEmptyEntries)); //if (!string.IsNullOrEmpty(post.Tags)) // _taglist = new ObservableCollection<string>(post.Tags.Split(splitter, StringSplitOptions.RemoveEmptyEntries)); //else // _taglist = new ObservableCollection<string>(); }
static void Main(string[] args) { Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Search post with notes, this note have a type post_attributation"); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine(); Tumblr tumblr = new Tumblr(); BasePost result = tumblr.GetGetPostwithNoteandPostAttribution(); if (result == null) { Console.WriteLine("Not found post"); } else { Console.WriteLine($"Post found: {result.Id}"); foreach (var note in result.Notes) { if (note.Type == NoteType.Post_attribution) { Console.WriteLine(); Console.WriteLine($" Note from {note.BlogName}"); PostAttributionNote postAttributionNote = (PostAttributionNote)note; Console.WriteLine($" type: {postAttributionNote.Post_attribution_type}"); Console.WriteLine($" typename: {postAttributionNote.Post_attribution_type_name}"); Console.WriteLine($" url: {postAttributionNote.Photo_url}"); Console.WriteLine($" width: {postAttributionNote.Photo_width}"); Console.WriteLine($" height: {postAttributionNote.Photo_height}"); } } } Console.ReadLine(); }
public MediaPanelViewModel(BasePost post) { this.post = post; }
public MediaPanelViewModel() { this.post = null; }
internal void GetImages(List <BasePost> ImageList, string tags, int page) { string finalURL = GetRequestURL(tags, page); try { StreamReader reader = new StreamReader(System.Net.WebRequest.Create(finalURL).GetResponse().GetResponseStream()); String json = ""; json = reader.ReadToEnd(); reader.Close(); if (json.Length > 4) { json = json.Substring(2, json.Length - 4); string[] splitter = { "},{" }; string[] split = json.Split(splitter, StringSplitOptions.None); foreach (string str in split) { BasePost post = new BasePost(); string[] node = str.Split(','); foreach (string str2 in node) { char[] splitter2 = { ':' }; string[] val = str2.Split(splitter2, 2); switch (val[0].ToLowerInvariant()) { //This is usually just a number, but it really makes no difference here case "\"id\"": post.PostId = val[1].Replace("\"", ""); break; case "\"tags\"": post.Tags = val[1].Replace("\"", ""); break; case "\"file_url\"": post.FullPictureURL = UtilityFunctions.NormaliseURL(val[1].Replace("\"", "")); break; case "\"width\"": int.TryParse(val[1], out post._width); break; case "\"height\"": int.TryParse(val[1], out post._height); break; case "\"rating\"": if (val[1].Contains("s")) { post.ImageRating = PostRating.Safe; } else if (val[1].Contains("e")) { post.ImageRating = PostRating.Explicit; } else { post.ImageRating = PostRating.Questionable; } break; case "\"md5\"": post.FileMD = val[1].Replace("\"", ""); break; case "\"preview_url\"": post.PreviewURL = UtilityFunctions.NormaliseURL(val[1].Replace("\"", "")); break; // This values have been added in danbooru v2 format so we can safely override some of the post values case "\"tag_string\"": post.Tags = val[1].Replace("\"", ""); break; case "\"file_ext\"": post.FileExtension = val[1].Replace("\"", ""); break; case "\"image_width\"": int.TryParse(val[1], out post._width); break; case "\"image_height\"": int.TryParse(val[1], out post._height); break; default: break; } } if (GlobalSettings.Instance.IsSafeMode && post.ImageRating != PostRating.Safe) { //Do nothing for now //TODO: add more UI level filtering later! } else { //Check for V2 Danbooru, if it is we need to work out filepaths manually... Thanks for that... if (GlobalSettings.Instance.CurrentBooru.ProviderType == ProviderAccessType.DanbooruV2) { string fullFilepath = "/data/" + post.FileMD + "." + post.FileExtension; post.FullPictureURL = UtilityFunctions.NormaliseURL(fullFilepath); string thumbFilepath = "/data/preview/" + post.FileMD + ".jpg"; post.PreviewURL = UtilityFunctions.NormaliseURL(thumbFilepath); } //Work out file extension at this point to save headaches later on if (string.IsNullOrEmpty(post.FileExtension)) { post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); } if (UtilityFunctions.GetUrlExtension(post.FullPictureURL) != null) { ImageList.Add(post); } } } } } catch (Exception exception) { throw new Exception(exception.ToString()); } if (!_booruTestMode) { GlobalSettings.Instance.PostsOffset = page * 20; //A crappy workaround as json queries don't return total post count from the imageboard if (ImageList.Count > 0) { GlobalSettings.Instance.TotalPosts = GlobalSettings.Instance.TotalPosts + GlobalSettings.Instance.PostsOffset + 1; } if (GlobalSettings.Instance.PostsOffset > GlobalSettings.Instance.TotalPosts) { throw new Exception("End of posts."); } } }
private void GetImages(List <BasePost> _PostFetcherImageList, string pageUrl) { //This is using the HtmlAgilityPack which basicly makes this similair to XMLDocument HtmlDocument page = new HtmlDocument(); page.LoadHtml(GetPage(pageUrl)); HtmlNode popular = page.DocumentNode.SelectSingleNode("//div[@id='popular-preview']"); if (popular != null) { popular.Remove(); } HtmlNodeCollection images = page.DocumentNode.SelectNodes("//span"); // KBR 20150413 This can happen if we get a bogus/error page. if (images == null) { return; } try { foreach (HtmlNode image in images) { BasePost post = new BasePost(); if (image.GetAttributeValue("class", "").Contains("thumb")) { post.PostId = image.GetAttributeValue("id", "").Replace("p", ""); HtmlNode _image = image.ChildNodes[0].ChildNodes[0]; // KBR 20150413 I don't get this: Sankaku currently returns URLs of the form "//c.sankakucomplex.com/data/preview/2b/83/2b833e3c466315fe1360c56af409a02d.jpg" which // I'm munging into "http://..." form. post.PreviewURL = _image.GetAttributeValue("src", "").Replace("//c", "http://c"); post.FileMD = Path.GetFileNameWithoutExtension(post.PreviewURL); string tagsAndRating = _image.GetAttributeValue("title", ""); if (!string.IsNullOrEmpty(tagsAndRating)) { // crashes when string is "Rating" (note capital R) post.Tags = tagsAndRating.Substring(0, tagsAndRating.IndexOf("rating", StringComparison.OrdinalIgnoreCase)); if (tagsAndRating.ToLower().Contains("explicit")) { post.ImageRating = PostRating.Explicit; } else if (tagsAndRating.ToLower().Contains("safe")) { post.ImageRating = PostRating.Safe; } else { post.ImageRating = PostRating.Questionable; } } // TODO KBR 20150413 Maybe consider doing this async. Right now it slows down the UI a lot. post.FullPictureURL = GetBigImageURL(post.PostId); post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); if (GlobalSettings.Instance.IsSafeMode && post.ImageRating != PostRating.Safe) { //Do nothing for now //TODO: add more UI level filtering later! } else { // KBR 20150413 These statements break things completely. Sankaku has changed their URLs radically. ////Check for V2 Danbooru, if it is we need to work out filepaths manually... Thanks for that... //if (GlobalSettings.Instance.CurrentBooru.ProviderType == ProviderAccessType.DanbooruV2) //{ // string fullFilepath = "/data/" + post.FileMD + "." + post.FileExtension; // post.FullPictureURL = UtilityFunctions.NormaliseURL(fullFilepath); // string thumbFilepath = "/data/preview/" + post.FileMD + ".jpg"; // post.PreviewURL = UtilityFunctions.NormaliseURL(thumbFilepath); ; //} // KBR 20150413 No longer necessary: don't munge the URLs. ////Work out file extension at this point to save headaches later on //if (string.IsNullOrEmpty(post.FileExtension)) // post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); if (UtilityFunctions.GetUrlExtension(post.FullPictureURL) != null) { _PostFetcherImageList.Add(post); } } } } } catch (Exception exception) { throw new Exception(exception.ToString()); } }
public async void Reblog(string blogName, BasePost basePost) { await client.ReblogAsync(blogName, basePost.Id, basePost.ReblogKey, PostCreationState.Queue); }
private static void BasePostVMToBasePost(BasePostVM vModel, BasePost basePost) { basePost.PlaceId = vModel.PlaceId; basePost.Title = vModel.Title; basePost.Description = vModel.Description; }
// Enforces dependency injection public Service(T post) { this.Model = post; }
public void Reblog(string blogName, BasePost basePost, DateTime dateTime) { client.ReblogAsync(blogName, basePost.Id, basePost.ReblogKey, PostCreationState.Queue, dateTime); }
public void RepoAddPost(BasePost post) { this.postList.Add(post); }
internal void GetImages(List<BasePost> ImageList, string tags, int page) { string finalURL = GetRequestURL(tags, page); try { XmlTextReader reader = new XmlTextReader(finalURL); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. var nodeName = reader.Name.ToLowerInvariant(); if (nodeName.Equals("posts") && !_booruTestMode) { while (reader.MoveToNextAttribute()) { if (reader.Name.ToLowerInvariant().Equals("count")) // Posts Count { GlobalSettings.Instance.TotalPosts = int.Parse(reader.Value); } if (reader.Name.ToLowerInvariant().Equals("offset")) // Posts Count { GlobalSettings.Instance.PostsOffset = int.Parse(reader.Value); } } } else if (nodeName.Equals("post")) { BasePost post = new BasePost(); while (reader.MoveToNextAttribute()) { switch (reader.Name.ToLowerInvariant()) { //This is usually just a number, but it really makes no difference here case "id": post.PostId = reader.Value; break; case "file_url": post.FullPictureURL = UtilityFunctions.NormaliseURL(reader.Value); break; case "preview_url": post.PreviewURL = UtilityFunctions.NormaliseURL(reader.Value); break; case "md5": post.FileMD = reader.Value; break; case "tags": post.Tags = reader.Value; break; case "width": int.TryParse(reader.Value, out post._width); break; case "height": int.TryParse(reader.Value, out post._height); break; case "rating": { if (reader.Value.Contains("s")) post.ImageRating = PostRating.Safe; else if (reader.Value.Contains("e")) post.ImageRating = PostRating.Explicit; else post.ImageRating = PostRating.Questionable; } break; } } if (GlobalSettings.Instance.IsSafeMode && post.ImageRating != PostRating.Safe) { //Do nothing for now //TODO: add more UI level filtering later! } else { //Work out file extension at this point to save headaches later on if (string.IsNullOrEmpty(post.FileExtension)) post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); if (UtilityFunctions.GetUrlExtension(post.FullPictureURL) != null) ImageList.Add(post); } } break; } } } catch (Exception exception) { throw new Exception(exception.ToString()); } if (!_booruTestMode && GlobalSettings.Instance.PostsOffset > GlobalSettings.Instance.TotalPosts) { throw new Exception("End of posts."); } }
private void GetImages(List<BasePost> _PostFetcherImageList, string pageUrl) { //This is using the HtmlAgilityPack which basicly makes this similair to XMLDocument HtmlDocument page = new HtmlDocument(); page.LoadHtml(GetPage(pageUrl)); HtmlNode popular = page.DocumentNode.SelectSingleNode("//div[@id='popular-preview']"); if (popular != null) popular.Remove(); HtmlNodeCollection images = page.DocumentNode.SelectNodes("//span"); // KBR 20150413 This can happen if we get a bogus/error page. if (images == null) return; try { foreach (HtmlNode image in images) { BasePost post = new BasePost(); if (image.GetAttributeValue("class", "").Contains("thumb")) { post.PostId = image.GetAttributeValue("id", "").Replace("p", ""); HtmlNode _image = image.ChildNodes[0].ChildNodes[0]; // KBR 20150413 I don't get this: Sankaku currently returns URLs of the form "//c.sankakucomplex.com/data/preview/2b/83/2b833e3c466315fe1360c56af409a02d.jpg" which // I'm munging into "http://..." form. post.PreviewURL = _image.GetAttributeValue("src", "").Replace("//c", "http://c"); post.FileMD = Path.GetFileNameWithoutExtension(post.PreviewURL); string tagsAndRating = _image.GetAttributeValue("title", ""); if (!string.IsNullOrEmpty(tagsAndRating)) { // crashes when string is "Rating" (note capital R) post.Tags = tagsAndRating.Substring(0, tagsAndRating.IndexOf("rating",StringComparison.OrdinalIgnoreCase)); if (tagsAndRating.ToLower().Contains("explicit")) post.ImageRating = PostRating.Explicit; else if (tagsAndRating.ToLower().Contains("safe")) post.ImageRating = PostRating.Safe; else post.ImageRating = PostRating.Questionable; } // TODO KBR 20150413 Maybe consider doing this async. Right now it slows down the UI a lot. post.FullPictureURL = GetBigImageURL(post.PostId); post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); if (GlobalSettings.Instance.IsSafeMode && post.ImageRating != PostRating.Safe) { //Do nothing for now //TODO: add more UI level filtering later! } else { // KBR 20150413 These statements break things completely. Sankaku has changed their URLs radically. ////Check for V2 Danbooru, if it is we need to work out filepaths manually... Thanks for that... //if (GlobalSettings.Instance.CurrentBooru.ProviderType == ProviderAccessType.DanbooruV2) //{ // string fullFilepath = "/data/" + post.FileMD + "." + post.FileExtension; // post.FullPictureURL = UtilityFunctions.NormaliseURL(fullFilepath); // string thumbFilepath = "/data/preview/" + post.FileMD + ".jpg"; // post.PreviewURL = UtilityFunctions.NormaliseURL(thumbFilepath); ; //} // KBR 20150413 No longer necessary: don't munge the URLs. ////Work out file extension at this point to save headaches later on //if (string.IsNullOrEmpty(post.FileExtension)) // post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); if (UtilityFunctions.GetUrlExtension(post.FullPictureURL) != null) _PostFetcherImageList.Add(post); } } } } catch (Exception exception) { throw new Exception(exception.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="PostAdapter"/> class. /// </summary> /// <param name="post">The post.</param> public PostAdapter(BasePost post) { _post = post; }
public async Task TrailsConverter() { TumblrClient tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret)); // find a post with trials BasePost post = null; bool findPostWithTrials = false; long currentID = 0; while (findPostWithTrials == false) { BasePost[] basePosts = await tc.GetDashboardPostsAsync(currentID, 0, 20, PostType.All, false, true); for (int i = 0; i < 20; i++) { BasePost basePost = basePosts[i]; if (basePost.Trails?.Count() > 0) { findPostWithTrials = true; post = basePost; } if (i == 19) { currentID = basePost.Id; } } } // convert post string json = JsonConvert.SerializeObject(post, Formatting.Indented); // deserialize post BasePost jsonPost = JsonConvert.DeserializeObject <BasePost>(json); //testing for (int i = 0; i < post.Trails.Count(); i++) { Trail baseTrail = post.Trails[i]; Trail jsonTrail = jsonPost.Trails[i]; Assert.AreEqual(baseTrail.Content, jsonTrail.Content); Assert.AreEqual(baseTrail.ContentRaw, jsonTrail.ContentRaw); Assert.AreEqual(baseTrail.Post.Id, jsonTrail.Post.Id); Assert.AreEqual(baseTrail.Blog.Active, jsonTrail.Blog.Active); Assert.AreEqual(baseTrail.Blog.CanBeFollowed, jsonTrail.Blog.CanBeFollowed); Assert.AreEqual(baseTrail.Blog.Name, jsonTrail.Blog.Name); Assert.AreEqual(baseTrail.Blog.ShareFollowing, jsonTrail.Blog.ShareFollowing); Assert.AreEqual(baseTrail.Blog.ShareLikes, jsonTrail.Blog.ShareLikes); Assert.AreEqual(baseTrail.Blog.Theme.AvatarShape, jsonTrail.Blog.Theme.AvatarShape); Assert.AreEqual(baseTrail.Blog.Theme.BackgroundColor, jsonTrail.Blog.Theme.BackgroundColor); Assert.AreEqual(baseTrail.Blog.Theme.BodyFont, jsonTrail.Blog.Theme.BodyFont); Assert.AreEqual(baseTrail.Blog.Theme.HeaderBounds, jsonTrail.Blog.Theme.HeaderBounds); Assert.AreEqual(baseTrail.Blog.Theme.HeaderFocusHeight, jsonTrail.Blog.Theme.HeaderFocusHeight); Assert.AreEqual(baseTrail.Blog.Theme.HeaderFocusWidth, jsonTrail.Blog.Theme.HeaderFocusWidth); Assert.AreEqual(baseTrail.Blog.Theme.HeaderFullHeight, jsonTrail.Blog.Theme.HeaderFullHeight); Assert.AreEqual(baseTrail.Blog.Theme.HeaderFullWidth, jsonTrail.Blog.Theme.HeaderFullWidth); Assert.AreEqual(baseTrail.Blog.Theme.HeaderImage, jsonTrail.Blog.Theme.HeaderImage); Assert.AreEqual(baseTrail.Blog.Theme.HeaderImageFocused, jsonTrail.Blog.Theme.HeaderImageFocused); Assert.AreEqual(baseTrail.Blog.Theme.HeaderImageScaled, jsonTrail.Blog.Theme.HeaderImageScaled); Assert.AreEqual(baseTrail.Blog.Theme.HeaderStretch, jsonTrail.Blog.Theme.HeaderStretch); Assert.AreEqual(baseTrail.Blog.Theme.LinkColor, jsonTrail.Blog.Theme.LinkColor); Assert.AreEqual(baseTrail.Blog.Theme.ShowAvatar, jsonTrail.Blog.Theme.ShowAvatar); Assert.AreEqual(baseTrail.Blog.Theme.ShowDescription, jsonTrail.Blog.Theme.ShowDescription); Assert.AreEqual(baseTrail.Blog.Theme.ShowHeaderImage, jsonTrail.Blog.Theme.ShowHeaderImage); Assert.AreEqual(baseTrail.Blog.Theme.ShowTitle, jsonTrail.Blog.Theme.ShowTitle); Assert.AreEqual(baseTrail.Blog.Theme.TitleColor, jsonTrail.Blog.Theme.TitleColor); Assert.AreEqual(baseTrail.Blog.Theme.TitleFont, jsonTrail.Blog.Theme.TitleFont); Assert.AreEqual(baseTrail.Blog.Theme.TitleFontWeight, jsonTrail.Blog.Theme.TitleFontWeight); } }
internal void GetImages(List<BasePost> ImageList, string tags, int page) { string finalURL = GetRequestURL(tags, page); try { StreamReader reader = new StreamReader(System.Net.WebRequest.Create(finalURL).GetResponse().GetResponseStream()); String json = ""; json = reader.ReadToEnd(); reader.Close(); if (json.Length > 4) { json = json.Substring(2, json.Length - 4); string[] splitter = { "},{" }; string[] split = json.Split(splitter, StringSplitOptions.None); foreach (string str in split) { BasePost post = new BasePost(); string[] node = str.Split(','); foreach (string str2 in node) { char[] splitter2 = { ':' }; string[] val = str2.Split(splitter2, 2); switch (val[0].ToLowerInvariant()) { //This is usually just a number, but it really makes no difference here case "\"id\"": post.PostId = val[1].Replace("\"", ""); break; case "\"tags\"": post.Tags = val[1].Replace("\"", ""); break; case "\"file_url\"": post.FullPictureURL = UtilityFunctions.NormaliseURL(val[1].Replace("\"", "")); break; case "\"width\"": int.TryParse(val[1], out post._width); break; case "\"height\"": int.TryParse(val[1], out post._height); break; case "\"rating\"": if (val[1].Contains("s")) post.ImageRating = PostRating.Safe; else if (val[1].Contains("e")) post.ImageRating = PostRating.Explicit; else post.ImageRating = PostRating.Questionable; break; case "\"md5\"": post.FileMD = val[1].Replace("\"", ""); break; case "\"preview_url\"": post.PreviewURL = UtilityFunctions.NormaliseURL(val[1].Replace("\"", "")); break; // This values have been added in danbooru v2 format so we can safely override some of the post values case "\"tag_string\"": post.Tags = val[1].Replace("\"", ""); break; case "\"file_ext\"": post.FileExtension = val[1].Replace("\"", ""); break; case "\"image_width\"": int.TryParse(val[1], out post._width); break; case "\"image_height\"": int.TryParse(val[1], out post._height); break; default: break; } } if (GlobalSettings.Instance.IsSafeMode && post.ImageRating != PostRating.Safe) { //Do nothing for now //TODO: add more UI level filtering later! } else { //Check for V2 Danbooru, if it is we need to work out filepaths manually... Thanks for that... if (GlobalSettings.Instance.CurrentBooru.ProviderType == ProviderAccessType.DanbooruV2) { string fullFilepath = "/data/" + post.FileMD + "." + post.FileExtension; post.FullPictureURL = UtilityFunctions.NormaliseURL(fullFilepath); string thumbFilepath = "/data/preview/" + post.FileMD + ".jpg"; post.PreviewURL = UtilityFunctions.NormaliseURL(thumbFilepath); } //Work out file extension at this point to save headaches later on if(string.IsNullOrEmpty(post.FileExtension)) post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); if (UtilityFunctions.GetUrlExtension(post.FullPictureURL) != null) ImageList.Add(post); } } } } catch (Exception exception) { throw new Exception(exception.ToString()); } if (!_booruTestMode) { GlobalSettings.Instance.PostsOffset = page * 20; //A crappy workaround as json queries don't return total post count from the imageboard if (ImageList.Count > 0) { GlobalSettings.Instance.TotalPosts = GlobalSettings.Instance.TotalPosts + GlobalSettings.Instance.PostsOffset + 1; } if (GlobalSettings.Instance.PostsOffset > GlobalSettings.Instance.TotalPosts) { throw new Exception("End of posts."); } } }
public void Add(BasePost post) { }
internal void GetImages(List <BasePost> ImageList, string tags, int page) { string finalURL = GetRequestURL(tags, page); try { XmlTextReader reader = new XmlTextReader(finalURL); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. var nodeName = reader.Name.ToLowerInvariant(); if (nodeName.Equals("posts") && !_booruTestMode) { while (reader.MoveToNextAttribute()) { if (reader.Name.ToLowerInvariant().Equals("count")) // Posts Count { GlobalSettings.Instance.TotalPosts = int.Parse(reader.Value); } if (reader.Name.ToLowerInvariant().Equals("offset")) // Posts Count { GlobalSettings.Instance.PostsOffset = int.Parse(reader.Value); } } } else if (nodeName.Equals("post")) { BasePost post = new BasePost(); while (reader.MoveToNextAttribute()) { switch (reader.Name.ToLowerInvariant()) { //This is usually just a number, but it really makes no difference here case "id": post.PostId = reader.Value; break; case "file_url": post.FullPictureURL = UtilityFunctions.NormaliseURL(reader.Value); break; case "preview_url": post.PreviewURL = UtilityFunctions.NormaliseURL(reader.Value); break; case "md5": post.FileMD = reader.Value; break; case "tags": post.Tags = reader.Value; break; case "width": int.TryParse(reader.Value, out post._width); break; case "height": int.TryParse(reader.Value, out post._height); break; case "rating": { if (reader.Value.Contains("s")) { post.ImageRating = PostRating.Safe; } else if (reader.Value.Contains("e")) { post.ImageRating = PostRating.Explicit; } else { post.ImageRating = PostRating.Questionable; } } break; } } if (GlobalSettings.Instance.IsSafeMode && post.ImageRating != PostRating.Safe) { //Do nothing for now //TODO: add more UI level filtering later! } else { //Work out file extension at this point to save headaches later on if (string.IsNullOrEmpty(post.FileExtension)) { post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); } if (UtilityFunctions.GetUrlExtension(post.FullPictureURL) != null) { ImageList.Add(post); } } } break; } } } catch (Exception exception) { throw new Exception(exception.ToString()); } if (!_booruTestMode && GlobalSettings.Instance.PostsOffset > GlobalSettings.Instance.TotalPosts) { throw new Exception("End of posts."); } }
private void GetImages(List <BasePost> _PostFetcherImageList, string pageUrl) { //This is using the HtmlAgilityPack which basicly makes this similair to XMLDocument HtmlDocument page = new HtmlDocument(); page.LoadHtml(GetPage(pageUrl)); HtmlNode popular = page.DocumentNode.SelectSingleNode("//div[@id='popular-preview']"); if (popular != null) { popular.Remove(); } HtmlNodeCollection images = page.DocumentNode.SelectNodes("//span"); try { foreach (HtmlNode image in images) { BasePost post = new BasePost(); if (image.GetAttributeValue("class", "").Contains("thumb")) { post.PostId = image.GetAttributeValue("id", "").Replace("p", ""); HtmlNode _image = image.ChildNodes[0].ChildNodes[0]; post.PreviewURL = _image.GetAttributeValue("src", ""); post.FileMD = Path.GetFileNameWithoutExtension(post.PreviewURL); string tagsAndRating = _image.GetAttributeValue("title", ""); if (!string.IsNullOrEmpty(tagsAndRating)) { // crashes when string is "Rating" (note capital R) post.Tags = tagsAndRating.Substring(0, tagsAndRating.IndexOf("rating", StringComparison.OrdinalIgnoreCase)); if (tagsAndRating.ToLower().Contains("explicit")) { post.ImageRating = PostRating.Explicit; } else if (tagsAndRating.ToLower().Contains("safe")) { post.ImageRating = PostRating.Safe; } else { post.ImageRating = PostRating.Questionable; } } post.FullPictureURL = GetBigImageURL(post.PostId); //post.FullPictureURL = post.PreviewURL; post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); if (GlobalSettings.Instance.IsSafeMode && post.ImageRating != PostRating.Safe) { //Do nothing for now //TODO: add more UI level filtering later! } else { //Check for V2 Danbooru, if it is we need to work out filepaths manually... Thanks for that... if (GlobalSettings.Instance.CurrentBooru.ProviderType == ProviderAccessType.DanbooruV2) { string fullFilepath = "/data/" + post.FileMD + "." + post.FileExtension; post.FullPictureURL = UtilityFunctions.NormaliseURL(fullFilepath); string thumbFilepath = "/data/preview/" + post.FileMD + ".jpg"; post.PreviewURL = UtilityFunctions.NormaliseURL(thumbFilepath);; } //Work out file extension at this point to save headaches later on if (string.IsNullOrEmpty(post.FileExtension)) { post.FileExtension = UtilityFunctions.GetUrlExtension(post.FullPictureURL); } if (UtilityFunctions.GetUrlExtension(post.FullPictureURL) != null) { _PostFetcherImageList.Add(post); } } } } } catch (Exception exception) { throw new Exception(exception.ToString()); } }