@@ -92,7 +92,7 @@ Namespace API.Reddit
92
92
Dim URL$ = String .Empty
93
93
Try
94
94
Dim PostID$ = String .Empty
95
- Dim PostDate$
95
+ Dim PostDate$, PostTitle$
96
96
Dim n As EContainer, nn As EContainer, s As EContainer
97
97
Dim NewPostDetected As Boolean = False
98
98
Dim ExistsDetected As Boolean = False
@@ -107,7 +107,7 @@ Namespace API.Reddit
107
107
ThrowAny(Token)
108
108
Dim r$ = GetSiteResponse(URL)
109
109
If Not r.IsEmptyString Then
110
- Using w As EContainer = JsonDocument.Parse(r)
110
+ Using w As EContainer = JsonDocument.Parse(r).XmlIfNothing
111
111
If w.Count > 0 Then
112
112
n = w.GetNode(JsonNodesJson)
113
113
If Not n Is Nothing AndAlso n.Count > 0 Then
@@ -124,29 +124,32 @@ Namespace API.Reddit
124
124
ExistsDetected = True
125
125
Continue For
126
126
End If
127
+ PostTitle = nn.Value( "title" )
128
+
127
129
If CheckNode(nn) Then
128
130
_ItemsBefore = _TempMediaList.Count
129
131
added = True
130
132
s = nn.ItemF({ "source" , "url" })
131
133
If s.XmlIfNothingValue( "/" ).Contains( "redgifs.com" ) Then
132
- _TempMediaList.ListAddValue(MediaFromData(UTypes.VideoPre, s.Value, PostID, PostDate,, IsChannel), LNC)
133
- _TotalPostsDownloaded += 1
134
+ _TempMediaList.ListAddValue(MediaFromData(UTypes.VideoPre, s.Value, PostID, PostDate,, IsChannel, PostTitle), LNC)
134
135
Else
135
136
s = nn.ItemF({ "media" }).XmlIfNothing
136
137
__ItemType = s( "type" ).XmlIfNothingValue
137
138
Select Case __ItemType
138
- Case "gallery" : DownloadGallery(s, PostID, PostDate) : _TotalPostsDownloaded += 1
139
+ Case "gallery" : If Not DownloadGallery(s, PostID, PostDate,,, PostTitle) Then added = False
139
140
Case "image" , "gifvideo"
140
141
If s.Contains( "content" ) Then
141
142
_TempMediaList.ListAddValue(MediaFromData(UPicType(__ItemType), s.Value( "content" ),
142
- PostID, PostDate,, IsChannel), LNC)
143
- _TotalPostsDownloaded += 1
143
+ PostID, PostDate,, IsChannel, PostTitle), LNC)
144
+ Else
145
+ added = False
144
146
End If
145
147
Case "video"
146
148
If Settings.UseM3U8 AndAlso s( "hlsUrl" ).XmlIfNothingValue( "/" ).ToLower.Contains( "m3u8" ) Then
147
149
_TempMediaList.ListAddValue(MediaFromData(UTypes.m3u8, s.Value( "hlsUrl" ),
148
- PostID, PostDate,, IsChannel), LNC)
149
- _TotalPostsDownloaded += 1
150
+ PostID, PostDate,, IsChannel, PostTitle), LNC)
151
+ Else
152
+ added = False
150
153
End If
151
154
Case Else : added = False
152
155
End Select
@@ -164,8 +167,7 @@ Namespace API.Reddit
164
167
End Select
165
168
End With
166
169
If Not tmpType = UTypes.Undefined Then
167
- _TempMediaList.ListAddValue(MediaFromData(tmpType, s.Value, PostID, PostDate,, IsChannel), LNC)
168
- _TotalPostsDownloaded += 1
170
+ _TempMediaList.ListAddValue(MediaFromData(tmpType, s.Value, PostID, PostDate,, IsChannel, PostTitle), LNC)
169
171
End If
170
172
End If
171
173
End If
@@ -267,25 +269,30 @@ Namespace API.Reddit
267
269
End Sub
268
270
# End Region
269
271
# Region "Download Base Functions"
270
- Private Sub DownloadGallery( ByVal w As EContainer, ByVal PostID As String , ByVal PostDate As String ,
271
- Optional ByVal _UserID As String = Nothing , Optional ByVal FirstOnly As Boolean = False )
272
+ Private Function DownloadGallery( ByVal w As EContainer, ByVal PostID As String , ByVal PostDate As String ,
273
+ Optional ByVal _UserID As String = Nothing , Optional ByVal FirstOnly As Boolean = False ,
274
+ Optional ByVal Title As String = Nothing ) As Boolean
272
275
Try
276
+ Dim added As Boolean = False
273
277
Dim cn$ = IIf(IsChannel, "media_metadata" , "mediaMetadata" )
274
278
If Not w Is Nothing AndAlso w(cn).XmlIfNothing.Count > 0 Then
275
279
Dim t As EContainer
276
280
For Each n As EContainer In w(cn)
277
281
t = n.ItemF({ "s" , "u" })
278
282
If Not t Is Nothing AndAlso Not t.Value.IsEmptyString Then
279
- _TempMediaList.ListAddValue(MediaFromData(UTypes.Picture, t.Value, PostID, PostDate, _UserID, IsChannel), LNC)
283
+ _TempMediaList.ListAddValue(MediaFromData(UTypes.Picture, t.Value, PostID, PostDate, _UserID, IsChannel, Title), LNC)
284
+ added = True
280
285
If FirstOnly Then Exit For
281
286
End If
282
287
Next
283
288
End If
289
+ Return added
284
290
Catch ex As Exception
285
291
LogError(ex, "gallery parsing error" )
286
292
HasError = True
293
+ Return False
287
294
End Try
288
- End Sub
295
+ End Function
289
296
Protected Overrides Sub ReparseVideo( ByVal Token As CancellationToken)
290
297
Try
291
298
ThrowAny(Token)
@@ -333,13 +340,15 @@ Namespace API.Reddit
333
340
# End Region
334
341
# Region "Structure creator"
335
342
Protected Shared Function MediaFromData( ByVal t As UTypes, ByVal _URL As String , ByVal PostID As String , ByVal PostDate As String ,
336
- Optional ByVal _UserID As String = "" , Optional ByVal IsChannel As Boolean = False ) As UserMedia
343
+ Optional ByVal _UserID As String = "" , Optional ByVal IsChannel As Boolean = False ,
344
+ Optional ByVal Title As String = Nothing ) As UserMedia
337
345
If _URL.IsEmptyString And t = UTypes.Picture Then Return Nothing
338
346
_URL = LinkFormatterSecure(RegexReplace(_URL.Replace( "\" , String .Empty), LinkPattern))
339
347
Dim m As New UserMedia(_URL, t) With {.Post = New UserPost With {.ID = PostID, .UserID = _UserID}}
340
348
If t = UTypes.Picture Or t = UTypes.GIF Then m.File = UrlToFile(m.URL) Else m.File = Nothing
341
349
If m.URL.Contains( "preview" ) Then m.URL = $"https://i.redd.it/{m.File.File}"
342
350
If Not PostDate.IsEmptyString Then m.Post.Date = AConvert( Of Date )(PostDate, If (IsChannel, DateProviderChannel, DateProvider), Nothing ) Else m.Post.Date = Nothing
351
+ If Not Title.IsEmptyString Then m.Post.Title = Title
343
352
Return m
344
353
End Function
345
354
Private Function TryFile( ByVal URL As String ) As Boolean
@@ -436,7 +445,11 @@ Namespace API.Reddit
436
445
Case UTypes.Picture : DownloadedPictures += 1 : _CountPictures += 1
437
446
Case UTypes.Video, UTypes.m3u8 : DownloadedVideos += 1 : _CountVideo += 1
438
447
End Select
439
- v.File = f
448
+ If Not IsChannel Or Not SaveToCache Then
449
+ v.File = ChangeFileNameByProvider(f, v)
450
+ Else
451
+ v.File = f
452
+ End If
440
453
v.Post.CachedFile = f
441
454
v.State = UStates.Downloaded
442
455
dCount += 1
0 commit comments