Skip to content

Commit 1d3412b

Browse files
committed
Fix attachments, add user agent, update UDP
1 parent 8806efa commit 1d3412b

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

PatreonDownloader.App/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static async Task<PatreonDownloaderSettings> InitializeSettings(CommandL
148148
PatreonDownloaderSettings settings = new PatreonDownloaderSettings
149149
{
150150
UrlBlackList = (_configuration["UrlBlackList"] ?? "").ToLowerInvariant().Split("|").ToList(),
151-
UserAgent = null,
151+
UserAgent = "Patreon/72.2.28 (Android; Android 14; Scale/2.10)",
152152
CookieContainer = null,
153153
SaveAvatarAndCover = commandLineOptions.SaveAvatarAndCover,
154154
SaveDescriptions = commandLineOptions.SaveDescriptions,

PatreonDownloader.Implementation/Models/JSONObjects/Posts.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class AccessRules
120120
public List<Data> Data { get; set; }
121121
}
122122

123-
public class Attachments
123+
public class AttachmentsMedia
124124
{
125125
[JsonProperty("data")]
126126
public List<Data> Data { get; set; }
@@ -192,8 +192,8 @@ public class RootDataRelationships
192192
{
193193
[JsonProperty("access_rules")]
194194
public AccessRules AccessRules { get; set; }
195-
[JsonProperty("attachments")]
196-
public Attachments Attachments { get; set; }
195+
[JsonProperty("attachments_media")]
196+
public AttachmentsMedia AttachmentsMedia { get; set; }
197197
[JsonProperty("audio")]
198198
public Audio Audio { get; set; }
199199
[JsonProperty("campaign")]

PatreonDownloader.Implementation/PatreonPageCrawler.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal sealed class PatreonPageCrawler : IPageCrawler
3131

3232
//TODO: Research possibility of not hardcoding this string
3333
private const string CrawlStartUrl = "https://www.patreon.com/api/posts?" +
34-
"include=user%2Cattachments%2Ccampaign%2Cpoll.choices%2Cpoll.current_user_responses.user%2Cpoll.current_user_responses.choice%2Cpoll.current_user_responses.poll%2Caccess_rules.tier.null%2Cimages.null%2Caudio.null" +
34+
"include=user%2Cattachments_media%2Ccampaign%2Cpoll.choices%2Cpoll.current_user_responses.user%2Cpoll.current_user_responses.choice%2Cpoll.current_user_responses.poll%2Caccess_rules.tier.null%2Cimages.null%2Caudio.null" +
3535
"&fields[post]=change_visibility_at%2Ccomment_count%2Ccontent%2Ccurrent_user_can_delete%2Ccurrent_user_can_view%2Ccurrent_user_has_liked%2Cembed%2Cimage%2Cis_paid%2Clike_count%2Cmin_cents_pledged_to_view%2Cpost_file%2Cpost_metadata%2Cpublished_at%2Cpatron_count%2Cpatreon_url%2Cpost_type%2Cpledge_url%2Cthumbnail_url%2Cteaser_text%2Ctitle%2Cupgrade_url%2Curl%2Cwas_posted_by_campaign_owner" +
3636
"&fields[user]=image_url%2Cfull_name%2Curl" +
3737
"&fields[campaign]=show_audio_post_download_links%2Cavatar_photo_url%2Cearnings_visibility%2Cis_nsfw%2Cis_monthly%2Cname%2Curl" +
@@ -126,7 +126,7 @@ private async Task<ParsingResult> ParsePage(string json)
126126
{
127127
_logger.Warn($"[{jsonEntry.Id}] Current user cannot view this post");
128128

129-
string[] skippedAttachments = jsonEntry.Relationships.Attachments?.Data.Select(x => x.Id).ToArray() ?? new string[0];
129+
string[] skippedAttachments = jsonEntry.Relationships.AttachmentsMedia?.Data.Select(x => x.Id).ToArray() ?? new string[0];
130130
string[] skippedMedia = jsonEntry.Relationships.Images?.Data.Select(x => x.Id).ToArray() ?? new string[0];
131131
_logger.Debug($"[{jsonEntry.Id}] Adding {skippedAttachments.Length} attachments and {skippedMedia.Length} media items to skipped list");
132132

@@ -225,20 +225,20 @@ await File.WriteAllTextAsync(
225225

226226
_logger.Debug($"[{jsonEntry.Id}] Scanning attachment data");
227227
//Attachments
228-
if(jsonEntry.Relationships.Attachments?.Data != null)
228+
if(jsonEntry.Relationships.AttachmentsMedia?.Data != null)
229229
{
230-
foreach (var attachment in jsonEntry.Relationships.Attachments.Data)
230+
foreach (var attachment in jsonEntry.Relationships.AttachmentsMedia.Data)
231231
{
232232
_logger.Debug($"[{jsonEntry.Id} A-{attachment.Id}] Scanning attachment");
233-
if (attachment.Type != "attachment") //sanity check
233+
if (attachment.Type != "media") //sanity check
234234
{
235235
string msg = $"Invalid attachment type for {attachment.Id}!!!";
236236
_logger.Fatal($"[{jsonEntry.Id}] {msg}");
237237
OnCrawlerMessage(new CrawlerMessageEventArgs(CrawlerMessageType.Error, msg, jsonEntry.Id));
238238
continue;
239239
}
240240

241-
var attachmentData = jsonRoot.Included.FirstOrDefault(x => x.Type == "attachment" && x.Id == attachment.Id);
241+
var attachmentData = jsonRoot.Included.FirstOrDefault(x => x.Type == "media" && x.Id == attachment.Id);
242242

243243
if (attachmentData == null)
244244
{
@@ -249,8 +249,8 @@ await File.WriteAllTextAsync(
249249
}
250250

251251
PatreonCrawledUrl subEntry = (PatreonCrawledUrl)entry.Clone(); ;
252-
subEntry.Url = attachmentData.Attributes.Url;
253-
subEntry.Filename = attachmentData.Attributes.Name;
252+
subEntry.Url = attachmentData.Attributes.DownloadUrl;
253+
subEntry.Filename = attachmentData.Attributes.FileName;
254254
subEntry.UrlType = PatreonCrawledUrlType.PostAttachment;
255255
subEntry.FileId = attachmentData.Id;
256256
crawledUrls.Add(subEntry);

0 commit comments

Comments
 (0)