Skip to content

Commit a5fa935

Browse files
committed
3.0.0.7
Added script usage Fixed downloading of LPSG images Fixed Instagram Stories Fixed date/time file pattern
1 parent c90dd56 commit a5fa935

28 files changed

+455
-115
lines changed

Changelog.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 3.0.0.7
2+
3+
- Added
4+
- Ability to run a script after the user download if complete
5+
- Hotkey ```F2``` for additional options in the user creation form
6+
- Fixed
7+
- (Issue #32) In some cases, Date and Time are still not added for Stories and Tagged Photos
8+
- (Issue #33) Instagram Stories downloading error
9+
- LPSG downloader does not download all content
10+
111
# 3.0.0.6
212

313
- Added

ProgramScreenshots/CreateUser.png

-15.5 KB
Binary file not shown.
-15.5 KB
Binary file not shown.
1.5 KB
Loading

ProgramScreenshots/MainContext.png

1.46 KB
Loading

ProgramScreenshots/MainContext2.png

-21 KB
Binary file not shown.

ProgramScreenshots/SettingsBasis.png

2.08 KB
Loading

SCrawler.Plugin.LPSG/Declarations.vb

+23-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
Imports PersonalUtilities.Functions.RegularExpressions
1010
Friend Module Declarations
1111
Friend ReadOnly Property PhotoRegEx As RParams = RParams.DM("(https://www.lpsg.com/attachments)(.+?)(?="")", 0, RegexReturn.List)
12+
Friend ReadOnly Property PhotoRegExExt As New RParams("img.data.src=""(/proxy[^""]+?)""", Nothing, 1, RegexReturn.List) With {
13+
.Converter = Function(Input) $"https://www.lpsg.com/{SymbolsConverter.HTML.Decode(Input)}"}
1214
Friend ReadOnly Property NextPageRegex As RParams = RParams.DMS("<link rel=""next"" href=""(.+?/page-(\d+))""", 2)
13-
Private Const FileUrlRegexDefault As String = "(.+[^/]+?)(jpg|jpeg|gif|png)"
15+
Private Const FileUrlRegexDefault As String = "([^/]+?)(jpg|jpeg|gif|png|webm)"
16+
Private ReadOnly InputFReplacer As New ErrorsDescriber(EDP.ReturnValue)
17+
Private ReadOnly InputForbidRemover As Func(Of String, String) = Function(Input) If(Input.IsEmptyString, Input, Input.StringRemoveWinForbiddenSymbols(, InputFReplacer))
1418
Friend ReadOnly Property FileRegEx As New RParams(FileUrlRegexDefault, Nothing, 0) With {
1519
.Converter = Function(ByVal Input As String) As String
20+
Input = InputForbidRemover.Invoke(Input)
1621
If Not Input.IsEmptyString Then
1722
Dim lv$ = Input.Split("-").LastOrDefault
1823
If Not lv.IsEmptyString Then
@@ -22,5 +27,22 @@ Friend Module Declarations
2227
End If
2328
Return Input
2429
End Function}
30+
Friend ReadOnly Property FileRegExExt As New RParams(FileUrlRegexDefault, 0, Nothing, InputForbidRemover)
31+
Friend ReadOnly Property FileRegExExt2 As New RParams("([^/]+?)(?=(\Z|&))", 0, Nothing, InputForbidRemover)
2532
Friend ReadOnly Property FileExistsRegEx As RParams = RParams.DMS(FileUrlRegexDefault, 2)
33+
Private Class PUMComparer : Implements IEqualityComparer, IEqualityComparer(Of PluginUserMedia)
34+
Private Overloads Function Equals(ByVal x As PluginUserMedia, ByVal y As PluginUserMedia) As Boolean Implements IEqualityComparer(Of PluginUserMedia).Equals
35+
Return x.URL = y.URL
36+
End Function
37+
Private Function IEqualityComparer_Equals(ByVal x As Object, ByVal y As Object) As Boolean Implements IEqualityComparer.Equals
38+
Return DirectCast(x, PluginUserMedia).URL = DirectCast(y, PluginUserMedia).URL
39+
End Function
40+
Private Overloads Function GetHashCode(ByVal Obj As Object) As Integer Implements IEqualityComparer.GetHashCode
41+
Throw New NotImplementedException()
42+
End Function
43+
Private Overloads Function GetHashCode(ByVal Obj As PluginUserMedia) As Integer Implements IEqualityComparer(Of PluginUserMedia).GetHashCode
44+
Throw New NotImplementedException()
45+
End Function
46+
End Class
47+
Friend ReadOnly TempListAddParams As New ListAddParams(LAP.NotContainsOnly) With {.Comparer = New PUMComparer}
2648
End Module

SCrawler.Plugin.LPSG/My Project/AssemblyInfo.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ Imports System.Runtime.InteropServices
3232
' by using the '*' as shown below:
3333
' <Assembly: AssemblyVersion("1.0.*")>
3434

35-
<Assembly: AssemblyVersion("1.0.0.1")>
36-
<Assembly: AssemblyFileVersion("1.0.0.1")>
35+
<Assembly: AssemblyVersion("1.0.0.2")>
36+
<Assembly: AssemblyFileVersion("1.0.0.2")>
3737
<Assembly: NeutralResourcesLanguage("en")>

SCrawler.Plugin.LPSG/UserData.vb

+49-19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Imports PersonalUtilities.Functions.RegularExpressions
1010
Imports UStates = SCrawler.Plugin.PluginUserMedia.States
1111
Imports UTypes = SCrawler.Plugin.PluginUserMedia.Types
12+
Imports Converters = PersonalUtilities.Functions.SymbolsConverter.Converters
1213
Public Class UserData : Implements IPluginContentProvider
1314
#Region "XML names"
1415
Private Const Name_LatestPage As String = "LatestPage"
@@ -60,13 +61,13 @@ Public Class UserData : Implements IPluginContentProvider
6061
#End Region
6162
Private Property LatestPage As String = String.Empty
6263
Private Property Responser As Response = Nothing
64+
Private Enum Mode : Internal : External : End Enum
6365
Public Sub GetMedia() Implements IPluginContentProvider.GetMedia
6466
Try
6567
If Not Responser Is Nothing Then Responser.Dispose()
6668
Responser = New Response
6769
With Responser : .Copy(Settings.Responser) : .Error = EDP.ThrowException : End With
6870

69-
Dim l As List(Of String) = Nothing
7071
Dim NextPage$
7172
Dim r$
7273
Dim _LPage As Func(Of String) = Function() If(LatestPage.IsEmptyString, String.Empty, $"page-{LatestPage}")
@@ -78,35 +79,60 @@ Public Class UserData : Implements IPluginContentProvider
7879
Thrower.ThrowAny()
7980
If Not r.IsEmptyString Then
8081
NextPage = RegexReplace(r, NextPageRegex)
81-
l.ListAddList(RegexReplace(r, PhotoRegEx), LAP.NotContainsOnly)
82+
UpdateMediaList(RegexReplace(r, PhotoRegEx), Mode.Internal)
83+
UpdateMediaList(RegexReplace(r, PhotoRegExExt), Mode.External)
8284
If NextPage = LatestPage Or NextPage.IsEmptyString Then Exit Do Else LatestPage = NextPage
8385
Else
8486
Exit Do
8587
End If
8688
Loop
8789

88-
If l.ListExists Then
89-
Dim f As SFile
90-
For Each u$ In l
91-
If Not IsEmptyString(RegexReplace(u, FileExistsRegEx)) Then
92-
f = CStr(RegexReplace(u, FileRegEx))
93-
f.Path = DataPath.CSFilePSN
94-
f.Separator = "\"
95-
TempMediaList.Add(New PluginUserMedia With {.ContentType = UTypes.Picture, .URL = u, .File = f})
96-
End If
97-
Next
98-
If TempMediaList.ListExists And ExistingContentList.ListExists Then _
99-
TempMediaList.RemoveAll(Function(m) ExistingContentList.Exists(Function(mm) mm.URL = m.URL))
100-
End If
90+
If TempMediaList.ListExists And ExistingContentList.ListExists Then _
91+
TempMediaList.RemoveAll(Function(m) ExistingContentList.Exists(Function(mm) mm.URL = m.URL))
10192
Catch oex As OperationCanceledException
10293
Catch dex As ObjectDisposedException
10394
Catch ex As Exception
104-
LogProvider.Add(ex, "[LPSG.UserData.GetMedia]")
95+
If Responser.StatusCode = Net.HttpStatusCode.ServiceUnavailable Then
96+
LogProvider.Add("LPSG not available")
97+
Else
98+
LogProvider.Add(ex, "[LPSG.UserData.GetMedia]")
99+
End If
105100
End Try
106101
End Sub
102+
Private Sub UpdateMediaList(ByVal l As List(Of String), ByVal m As Mode)
103+
If l.ListExists Then
104+
Dim f As SFile
105+
Dim u$
106+
Dim exists As Boolean
107+
Dim r As RParams
108+
Dim ude As New ErrorsDescriber(EDP.ReturnValue)
109+
For Each url$ In l
110+
If Not url.IsEmptyString Then u = SymbolsConverter.Decode(url, {Converters.HTML, Converters.ASCII}, ude) Else u = String.Empty
111+
If Not u.IsEmptyString Then
112+
exists = Not IsEmptyString(RegexReplace(u, FileExistsRegEx))
113+
If m = Mode.Internal Then
114+
r = FileRegEx
115+
Else
116+
r = FileRegExExt
117+
If Not exists Then
118+
r = FileRegExExt2
119+
exists = Not IsEmptyString(RegexReplace(u, FileRegExExt2))
120+
End If
121+
End If
122+
If exists Then
123+
f = CStr(RegexReplace(u, r))
124+
f.Path = DataPath.CSFilePSN
125+
f.Separator = "\"
126+
If f.Extension.IsEmptyString Then f.Extension = "jpg"
127+
TempMediaList.ListAddValue(New PluginUserMedia With {.ContentType = UTypes.Picture, .URL = url, .File = f}, TempListAddParams)
128+
End If
129+
End If
130+
Next
131+
End If
132+
End Sub
107133
Public Sub Download() Implements IPluginContentProvider.Download
108134
Try
109-
With Responser : .UseWebClient = True : .UseWebClientCookies = True : End With
135+
With Responser : .UseWebClient = True : .UseWebClientCookies = True : .ResetError() : End With
110136
If TempMediaList.ListExists Then
111137
Dim m As PluginUserMedia
112138
Dim eweb As ErrorsDescriber = EDP.ThrowException
@@ -122,8 +148,12 @@ Public Class UserData : Implements IPluginContentProvider
122148
Else
123149
m.DownloadState = UStates.Skipped
124150
End If
125-
Catch ex As Exception
126-
m.DownloadState = UStates.Skipped
151+
Catch wex As Exception
152+
If Responser.Client.StatusCode = Net.HttpStatusCode.ServiceUnavailable Then
153+
LogProvider.Add("LPSG not available")
154+
Else
155+
m.DownloadState = UStates.Skipped
156+
End If
127157
End Try
128158
RaiseEvent ProgressChanged(1)
129159
TempMediaList(i) = m

SCrawler/API/Base/UserDataBase.vb

+64-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Imports PersonalUtilities.Functions.XML
1010
Imports PersonalUtilities.Functions.RegularExpressions
1111
Imports PersonalUtilities.Forms.Toolbars
1212
Imports PersonalUtilities.Tools.WEB
13+
Imports PersonalUtilities.Tools
1314
Imports System.IO
1415
Imports System.Net
1516
Imports System.Threading
@@ -115,6 +116,9 @@ Namespace API.Base
115116
Private Const Name_PicturesCount As String = "PicturesCount"
116117
Private Const Name_LastUpdated As String = "LastUpdated"
117118

119+
Private Const Name_ScriptUse As String = "ScriptUse"
120+
Private Const Name_ScriptFile As String = "ScriptFile"
121+
118122
Private Const Name_DataMerging As String = "DataMerging"
119123
#Region "Downloaded data"
120124
Private Const Name_MediaType As String = "Type"
@@ -405,6 +409,10 @@ BlockNullPicture:
405409
End Get
406410
End Property
407411
#End Region
412+
#Region "Script"
413+
Friend Overridable Property ScriptUse As Boolean = False Implements IUserData.ScriptUse
414+
Friend Overridable Property ScriptFile As SFile Implements IUserData.ScriptFile
415+
#End Region
408416
#End Region
409417
#Region "Plugins Support"
410418
Protected Event ProgressChanged As IPluginContentProvider.ProgressChangedEventHandler Implements IPluginContentProvider.ProgressChanged
@@ -576,6 +584,17 @@ BlockNullPicture:
576584
DownloadedVideos(True) = x.Value(Name_VideoCount).FromXML(Of Integer)(0)
577585
DownloadedPictures(True) = x.Value(Name_PicturesCount).FromXML(Of Integer)(0)
578586
LastUpdated = AConvert(Of Date)(x.Value(Name_LastUpdated), ADateTime.Formats.BaseDateTime, Nothing)
587+
ScriptUse = x.Value(Name_ScriptUse).FromXML(Of Boolean)(False)
588+
Dim s$ = x.Value(Name_ScriptFile)
589+
If Not s.IsEmptyString Then
590+
If SFile.IsDirectory(s) Then
591+
ScriptFile = s
592+
Else
593+
ScriptFile = New SFile(s) With {.Path = MyFile.Path}
594+
End If
595+
Else
596+
ScriptFile = Nothing
597+
End If
579598
DataMerging = x.Value(Name_DataMerging).FromXML(Of Boolean)(False)
580599
ChangeCollectionName(x.Value(Name_CollectionName), False)
581600
Labels.ListAddList(x.Value(Name_LabelsName).StringToList(Of String, List(Of String))("|", EDP.ReturnValue), LAP.NotContainsOnly, LAP.ClearBeforeAdd)
@@ -615,6 +634,16 @@ BlockNullPicture:
615634
x.Add(Name_VideoCount, DownloadedVideos(True))
616635
x.Add(Name_PicturesCount, DownloadedPictures(True))
617636
x.Add(Name_LastUpdated, AConvert(Of String)(LastUpdated, ADateTime.Formats.BaseDateTime, String.Empty))
637+
x.Add(Name_ScriptUse, ScriptUse.BoolToInteger)
638+
If Not ScriptFile.IsEmptyString Then
639+
If ScriptFile.Path = MyFile.Path Then
640+
x.Add(Name_ScriptFile, ScriptFile.File)
641+
Else
642+
x.Add(Name_ScriptFile, ScriptFile)
643+
End If
644+
Else
645+
x.Add(Name_ScriptFile, String.Empty)
646+
End If
618647
x.Add(Name_CollectionName, CollectionName)
619648
x.Add(Name_LabelsName, Labels.ListToString(, "|", EDP.ReturnValue))
620649
x.Add(Name_DataMerging, DataMerging.BoolToInteger)
@@ -760,6 +789,7 @@ BlockNullPicture:
760789
If DownloadedTotal(False) > 0 Or EnvirChanged.Invoke Then
761790
If __SaveData Then
762791
LastUpdated = Now
792+
RunScript()
763793
DownloadedPictures(True) = SFile.GetFiles(User.File.CutPath, "*.jpg|*.jpeg|*.png|*.gif|*.webm",, EDP.ReturnValue).Count
764794
DownloadedVideos(True) = SFile.GetFiles(User.File.CutPath, "*.mp4|*.mkv|*.mov", SearchOption.AllDirectories, EDP.ReturnValue).Count
765795
If Labels.Contains(LabelsKeeper.NoParsedUser) Then Labels.Remove(LabelsKeeper.NoParsedUser)
@@ -919,16 +949,10 @@ BlockNullPicture:
919949
Dim ff As SFile = Nothing
920950
Try
921951
If Not f.IsEmptyString AndAlso f.Exists Then
922-
Dim d As Date? = m.Post.Date
923952
If Settings.FileReplaceNameByDate Then
924-
Dim dd$ = AConvert(Of String)(If(d, Now), FileDateAppenderProvider, String.Empty)
925953
ff = f
926-
ff.Name = dd
954+
ff.Name = String.Format(FileDateAppenderPattern, f.Name, CStr(AConvert(Of String)(If(m.Post.Date, Now), FileDateAppenderProvider, String.Empty)))
927955
ff = SFile.Indexed_IndexFile(ff,, New NumberedFile(ff))
928-
ElseIf d.HasValue AndAlso (Settings.FileAddDateToFileName Or Settings.FileAddTimeToFileName) AndAlso
929-
(Not FileDateAppenderProvider Is Nothing And Not FileDateAppenderPattern.IsEmptyString) Then
930-
ff = f
931-
ff.Name = String.Format(FileDateAppenderPattern, f.Name, CStr(AConvert(Of String)(d.Value, FileDateAppenderProvider, String.Empty)))
932956
End If
933957
If Not ff.Name.IsEmptyString Then My.Computer.FileSystem.RenameFile(f, ff.File) : Return ff
934958
End If
@@ -938,6 +962,27 @@ BlockNullPicture:
938962
Return f
939963
End Try
940964
End Function
965+
Private Sub RunScript()
966+
Try
967+
If ScriptUse Then
968+
Dim ScriptPattern$
969+
If Not ScriptFile.IsEmptyString Then
970+
ScriptPattern = ScriptFile
971+
Else
972+
ScriptPattern = Settings.ScriptFile.Value
973+
End If
974+
If Not ScriptPattern.IsEmptyString Then
975+
ScriptPattern &= " {0}"
976+
Using b As New BatchExecutor With {.RedirectStandardError = True}
977+
b.Execute({String.Format(ScriptPattern, MyFile.CutPath(1).ToString)}, EDP.SendInLog + EDP.ThrowException)
978+
If b.HasError Or Not b.ErrorOutput.IsEmptyString Then Throw New Exception(b.ErrorOutput, b.ErrorException)
979+
End Using
980+
End If
981+
End If
982+
Catch ex As Exception
983+
LogError(ex, "script execution error")
984+
End Try
985+
End Sub
941986
#End Region
942987
#Region "Delete, Move, Merge"
943988
Friend Overridable Function Delete() As Integer Implements IUserData.Delete
@@ -990,6 +1035,11 @@ BlockNullPicture:
9901035
End If
9911036
f.CutPath.Exists(SFO.Path)
9921037
Directory.Move(UserBefore.File.CutPath(, EDP.ThrowException).Path, f.Path)
1038+
If Not ScriptFile.IsEmptyString AndAlso ScriptFile.Path = UserBefore.File.Path Then
1039+
Dim ff As SFile = ScriptFile
1040+
f.Path = MyFile.Path
1041+
ScriptFile = ff
1042+
End If
9931043
Settings.UsersList.Remove(UserBefore)
9941044
Settings.UpdateUsersList(User)
9951045
UpdateUserInformation()
@@ -1043,6 +1093,11 @@ BlockNullPicture:
10431093
New ErrorsDescriber(False, False, False, New List(Of SFile))).Count = 0 Then
10441094
UserBefore.File.CutPath.Delete(SFO.Path, Settings.DeleteMode, EDP.SendInLog)
10451095
End If
1096+
If Not ScriptFile.IsEmptyString AndAlso ScriptFile.Path = UserBefore.File.Path Then
1097+
Dim f As SFile = ScriptFile
1098+
f.Path = MyFile.Path
1099+
ScriptFile = f
1100+
End If
10461101
UpdateUserInformation()
10471102
End If
10481103
Catch ioex As InvalidOperationException When ioex.HelpLink = 1
@@ -1207,6 +1262,8 @@ BlockNullPicture:
12071262
ReadOnly Property Key As String
12081263
Property DownloadImages As Boolean
12091264
Property DownloadVideos As Boolean
1265+
Property ScriptUse As Boolean
1266+
Property ScriptFile As SFile
12101267
Function GetLVI(ByVal Destination As ListView) As ListViewItem
12111268
Function GetLVIGroup(ByVal Destination As ListView) As ListViewGroup
12121269
Sub LoadUserInformation()

SCrawler/API/Instagram/UserData.vb

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ Namespace API.Instagram
193193
Case Sections.Stories
194194
If Not StoriesRequested Then
195195
StoriesList = GetStoriesList()
196+
StoriesRequested = True
196197
MySiteSettings.TooManyRequests(False)
197198
RequestsCount += 1
198199
ThrowAny(Token)

0 commit comments

Comments
 (0)