@@ -92,7 +92,7 @@ Namespace API.Reddit
9292 Dim URL$ = String .Empty
9393 Try
9494 Dim PostID$ = String .Empty
95- Dim PostDate$
95+ Dim PostDate$, PostTitle$
9696 Dim n As EContainer, nn As EContainer, s As EContainer
9797 Dim NewPostDetected As Boolean = False
9898 Dim ExistsDetected As Boolean = False
@@ -107,7 +107,7 @@ Namespace API.Reddit
107107 ThrowAny(Token)
108108 Dim r$ = GetSiteResponse(URL)
109109 If Not r.IsEmptyString Then
110- Using w As EContainer = JsonDocument.Parse(r)
110+ Using w As EContainer = JsonDocument.Parse(r).XmlIfNothing
111111 If w.Count > 0 Then
112112 n = w.GetNode(JsonNodesJson)
113113 If Not n Is Nothing AndAlso n.Count > 0 Then
@@ -124,29 +124,32 @@ Namespace API.Reddit
124124 ExistsDetected = True
125125 Continue For
126126 End If
127+ PostTitle = nn.Value( "title" )
128+
127129 If CheckNode(nn) Then
128130 _ItemsBefore = _TempMediaList.Count
129131 added = True
130132 s = nn.ItemF({ "source" , "url" })
131133 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)
134135 Else
135136 s = nn.ItemF({ "media" }).XmlIfNothing
136137 __ItemType = s( "type" ).XmlIfNothingValue
137138 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
139140 Case "image" , "gifvideo"
140141 If s.Contains( "content" ) Then
141142 _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
144146 End If
145147 Case "video"
146148 If Settings.UseM3U8 AndAlso s( "hlsUrl" ).XmlIfNothingValue( "/" ).ToLower.Contains( "m3u8" ) Then
147149 _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
150153 End If
151154 Case Else : added = False
152155 End Select
@@ -164,8 +167,7 @@ Namespace API.Reddit
164167 End Select
165168 End With
166169 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)
169171 End If
170172 End If
171173 End If
@@ -267,25 +269,30 @@ Namespace API.Reddit
267269 End Sub
268270# End Region
269271# 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
272275 Try
276+ Dim added As Boolean = False
273277 Dim cn$ = IIf(IsChannel, "media_metadata" , "mediaMetadata" )
274278 If Not w Is Nothing AndAlso w(cn).XmlIfNothing.Count > 0 Then
275279 Dim t As EContainer
276280 For Each n As EContainer In w(cn)
277281 t = n.ItemF({ "s" , "u" })
278282 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
280285 If FirstOnly Then Exit For
281286 End If
282287 Next
283288 End If
289+ Return added
284290 Catch ex As Exception
285291 LogError(ex, "gallery parsing error" )
286292 HasError = True
293+ Return False
287294 End Try
288- End Sub
295+ End Function
289296 Protected Overrides Sub ReparseVideo( ByVal Token As CancellationToken)
290297 Try
291298 ThrowAny(Token)
@@ -333,13 +340,15 @@ Namespace API.Reddit
333340# End Region
334341# Region "Structure creator"
335342 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
337345 If _URL.IsEmptyString And t = UTypes.Picture Then Return Nothing
338346 _URL = LinkFormatterSecure(RegexReplace(_URL.Replace( "\" , String .Empty), LinkPattern))
339347 Dim m As New UserMedia(_URL, t) With {.Post = New UserPost With {.ID = PostID, .UserID = _UserID}}
340348 If t = UTypes.Picture Or t = UTypes.GIF Then m.File = UrlToFile(m.URL) Else m.File = Nothing
341349 If m.URL.Contains( "preview" ) Then m.URL = $"https://i.redd.it/{m.File.File}"
342350 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
343352 Return m
344353 End Function
345354 Private Function TryFile( ByVal URL As String ) As Boolean
@@ -436,7 +445,11 @@ Namespace API.Reddit
436445 Case UTypes.Picture : DownloadedPictures += 1 : _CountPictures += 1
437446 Case UTypes.Video, UTypes.m3u8 : DownloadedVideos += 1 : _CountVideo += 1
438447 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
440453 v.Post.CachedFile = f
441454 v.State = UStates.Downloaded
442455 dCount += 1
0 commit comments