Skip to content

Commit

Permalink
Fix issue #471 New global setting for 'Download replies'
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas694 committed Sep 29, 2023
1 parent df1c573 commit 6847c13
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
13 changes: 5 additions & 8 deletions src/TumblThree/TumblThree.Applications/Crawler/TwitterCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public class TwitterCrawler : AbstractCrawler, ICrawler, IDisposable
private string oldestApiPost;
private string oldestApiPostPrevious;

// instead of new field reuse DownloadAnswer for replies
private bool BlogDownloadReplies => Blog.DownloadAnswer;

public TwitterCrawler(IShellService shellService, ICrawlerService crawlerService, IProgress<DownloadProgress> progress, IWebRequestFactory webRequestFactory,
ISharedCookieService cookieService, IPostQueue<AbstractPost> postQueue, IPostQueue<CrawlerData<Tweet>> jsonQueue, IBlog blog, IDownloader downloader,
ICrawlerDataDownloader crawlerDataDownloader, PauseToken pt, CancellationToken ct)
Expand Down Expand Up @@ -237,7 +234,7 @@ private async Task<string> GetApiUrl(string url, byte type, string cursor, int p
case 2:
if (!string.IsNullOrEmpty(cursor)) cursor = string.Format("%2C%22cursor%22%3A%22{0}%22", cursor.Replace("+", "%2B")); //HttpUtility.UrlEncode(cursor)
var restId = (await GetTwUser()).Data.User.RestId;
var includeReplies = BlogDownloadReplies.ToString().ToLower();
var includeReplies = Blog.DownloadReplies.ToString().ToLower();
url = string.Format("https://twitter.com/i/api/graphql/{0}/UserTweets" +
"?variables=%7B%22userId%22%3A%22{1}%22%2C%22count%22%3A{2}{3}%2C%22includePromotedContent%22%3Atrue%2C%22withQuickPromoteEligibilityTweetFields%22%3Atrue%2C%22withVoice%22%3Atrue%2C%22withV2Timeline%22%3Atrue%7D&features=%7B%22rweb_lists_timeline_redesign_enabled%22%3Atrue%2C%22responsive_web_graphql_exclude_directive_enabled%22%3Atrue%2C%22verified_phone_label_enabled%22%3Afalse%2C%22creator_subscriptions_tweet_preview_api_enabled%22%3Atrue%2C%22responsive_web_graphql_timeline_navigation_enabled%22%3Atrue%2C%22responsive_web_graphql_skip_user_profile_image_extensions_enabled%22%3Afalse%2C%22tweetypie_unmention_optimization_enabled%22%3Atrue%2C%22responsive_web_edit_tweet_api_enabled%22%3Atrue%2C%22graphql_is_translatable_rweb_tweet_is_translatable_enabled%22%3Atrue%2C%22view_counts_everywhere_api_enabled%22%3Atrue%2C%22longform_notetweets_consumption_enabled%22%3Atrue%2C%22responsive_web_twitter_article_tweet_consumption_enabled%22%3Afalse%2C%22tweet_awards_web_tipping_enabled%22%3Afalse%2C%22freedom_of_speech_not_reach_fetch_enabled%22%3Atrue%2C%22standardized_nudges_misinfo%22%3Atrue%2C%22tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled%22%3Atrue%2C%22longform_notetweets_rich_text_read_enabled%22%3Atrue%2C%22longform_notetweets_inline_media_enabled%22%3Atrue%2C%22responsive_web_media_download_video_enabled%22%3Afalse%2C%22responsive_web_enhance_cards_enabled%22%3Afalse%7D&fieldToggles=%7B%22withAuxiliaryUserLabels%22%3Afalse%2C%22withArticleRichContentState%22%3Afalse%7D",
graphQlTokenUserTweets, restId, pageSize, cursor);
Expand Down Expand Up @@ -823,7 +820,7 @@ private static List<Media> GetMedia(Tweet post)
private void AddPhotoUrlToDownloadList(Tweet post)
{
if (!Blog.DownloadPhoto) return;
if (!BlogDownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;
if (!Blog.DownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;

var media = GetMedia(post);

Expand All @@ -836,7 +833,7 @@ private void AddPhotoUrlToDownloadList(Tweet post)
private void AddVideoUrlToDownloadList(Tweet post)
{
if (!Blog.DownloadVideo && !Blog.DownloadVideoThumbnail) return;
if (!BlogDownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;
if (!Blog.DownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;

var media = GetMedia(post);

Expand All @@ -850,7 +847,7 @@ private void AddTextUrlToDownloadList(Tweet post)
{
if (!Blog.DownloadText) return;
if (!(post.Legacy.Entities == null || post.Legacy.Entities.Media == null || post.Legacy.Entities.Media.Count == 0)) return;
if (!BlogDownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;
if (!Blog.DownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;

var body = GetTweetText(post);
AddToDownloadList(new TextPost(body, post.Legacy.IdStr));
Expand All @@ -872,7 +869,7 @@ private static string GetTweetText(Tweet post)
private void AddGifUrlToDownloadList(Tweet post)
{
if (!Blog.DownloadPhoto || Blog.SkipGif) return;
if (!BlogDownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;
if (!Blog.DownloadReplies && !string.IsNullOrEmpty(post.Legacy.InReplyToStatusIdStr)) return;

var media = GetMedia(post);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public AppSettings()
[DataMember]
public bool DownloadAnswers { get; set; }

[DataMember]
public bool DownloadReplies { get; set; }

[DataMember]
public bool DownloadLinks { get; set; }

Expand Down Expand Up @@ -603,6 +606,7 @@ private void Initialize()
CreateImageMeta = false;
CreateVideoMeta = false;
CreateAudioMeta = false;
DownloadReplies = false;
MetadataFormat = MetadataType.Text;
OverrideTumblrBlogCrawler = false;
TumblrBlogCrawlerType = TumblrBlogCrawlerTypes.TumblrSVC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public IBlog TransferGlobalSettingsToBlog(IBlog blog)
blog.DownloadPhoto = shellService.Settings.DownloadImages;
blog.DownloadVideo = shellService.Settings.DownloadVideos;
blog.DownloadText = shellService.Settings.DownloadTexts;
blog.DownloadAnswer = blog.BlogType == Domain.Models.BlogTypes.twitter ? false : shellService.Settings.DownloadAnswers;
blog.DownloadAnswer = shellService.Settings.DownloadAnswers;
blog.DownloadQuote = shellService.Settings.DownloadQuotes;
blog.DownloadConversation = shellService.Settings.DownloadConversations;
blog.DownloadLink = shellService.Settings.DownloadLinks;
blog.CreatePhotoMeta = shellService.Settings.CreateImageMeta;
blog.CreateVideoMeta = shellService.Settings.CreateVideoMeta;
blog.CreateAudioMeta = shellService.Settings.CreateAudioMeta;
blog.DownloadReplies = shellService.Settings.DownloadReplies;
blog.MetadataFormat = shellService.Settings.MetadataFormat;
blog.SkipGif = shellService.Settings.SkipGif;
blog.DownloadVideoThumbnail = shellService.Settings.DownloadVideoThumbnails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class SettingsViewModel : ViewModel<ISettingsView>
private bool _downloadQuotes;
private bool _downloadTexts;
private bool _downloadAnswers;
private bool _downloadReplies;
private bool _downloadUrlList;
private bool _downloadVideos;
private bool _enablePreview;
Expand Down Expand Up @@ -692,6 +693,12 @@ public bool CreateAudioMeta
set => SetProperty(ref _createAudioMeta, value);
}

public bool DownloadReplies
{
get => _downloadReplies;
set => SetProperty(ref _downloadReplies, value);
}

public MetadataType MetadataFormat
{
get => _metadataFormat;
Expand Down Expand Up @@ -1260,6 +1267,7 @@ private void LoadSettings()
DownloadVideos = _settings.DownloadVideos;
DownloadTexts = _settings.DownloadTexts;
DownloadAnswers = _settings.DownloadAnswers;
DownloadReplies = _settings.DownloadReplies;
DownloadAudios = _settings.DownloadAudios;
DownloadConversations = _settings.DownloadConversations;
DownloadLinks = _settings.DownloadLinks;
Expand Down Expand Up @@ -1361,6 +1369,7 @@ private void LoadSettings()
CreateImageMeta = false;
CreateVideoMeta = false;
CreateAudioMeta = false;
DownloadReplies = false;
MetadataFormat = MetadataType.Text;
OverrideTumblrBlogCrawler = false;
TumblrBlogCrawlerType = TumblrBlogCrawlerTypes.TumblrSVC;
Expand Down Expand Up @@ -1530,6 +1539,7 @@ private void SaveSettings()
_settings.DownloadVideos = DownloadVideos;
_settings.DownloadTexts = DownloadTexts;
_settings.DownloadAnswers = DownloadAnswers;
_settings.DownloadReplies = DownloadReplies;
_settings.DownloadAudios = DownloadAudios;
_settings.DownloadConversations = DownloadConversations;
_settings.DownloadQuotes = DownloadQuotes;
Expand Down
17 changes: 17 additions & 0 deletions src/TumblThree/TumblThree.Domain/Models/Blogs/Blog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Blog : Model, IBlog
private bool createAudioMeta;
private bool createPhotoMeta;
private bool createVideoMeta;
private bool downloadReplies;
private bool downloadAudio;
private bool downloadConversation;
private bool downloadLink;
Expand Down Expand Up @@ -311,6 +312,17 @@ public bool CreateAudioMeta
}
}

[DataMember]
public bool DownloadReplies
{
get => downloadReplies;
set
{
SetProperty(ref downloadReplies, value);
Dirty = true;
}
}

[DataMember]
public bool DownloadRebloggedPosts
{
Expand Down Expand Up @@ -1088,6 +1100,11 @@ private IBlog LoadCore(string fileLocation)
{
blog.PnjDownloadFormat = nameof(PnjDownloadType.png);
}
if (blog.BlogType == BlogTypes.twitter && blog.DownloadAnswer && !blog.DownloadReplies)
{
blog.DownloadReplies = true;
blog.DownloadAnswer = false;
}

return blog;
}
Expand Down
2 changes: 2 additions & 0 deletions src/TumblThree/TumblThree.Domain/Models/Blogs/IBlog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public interface IBlog : INotifyPropertyChanged

bool CreateAudioMeta { get; set; }

bool DownloadReplies { get; set; }

MetadataType MetadataFormat { get; set; }

bool DumpCrawlerData { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@
Margin="3,0,0,0" Padding="3,0,0,0" />

<CheckBox Content="{x:Static p:Resources.DownloadReplies}"
IsChecked="{Binding BlogFile.DownloadAnswer, Mode=TwoWay}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="27"
IsChecked="{Binding BlogFile.DownloadReplies, Mode=TwoWay}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="27"
Margin="3,0,0,0" Padding="3,0,0,0" />

<CheckBox Content="{x:Static p:Resources.DownloadVideoThumbnails}" IsChecked="{Binding BlogFile.DownloadVideoThumbnail, Mode=TwoWay}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,14 @@
Margin="10,9"
Content="{x:Static p:Resources.DownloadTexts}"
IsChecked="{Binding DownloadTexts, Mode=TwoWay}" />
<CheckBox
x:Name="checkBoxDownloadReplies"
Grid.Row="4"
Grid.Column="4"
Grid.ColumnSpan="3"
Margin="10,9"
Content="{x:Static p:Resources.DownloadReplies}"
IsChecked="{Binding DownloadReplies, Mode=TwoWay}" />
<CheckBox
x:Name="checkBoxDownloadQuotes"
Grid.Row="5"
Expand Down

0 comments on commit 6847c13

Please sign in to comment.