1+ ' Copyright (C) 2023 Andy https://github.com/AAndyProgram
2+ ' This program is free software: you can redistribute it and/or modify
3+ ' it under the terms of the GNU General Public License as published by
4+ ' the Free Software Foundation, either version 3 of the License, or
5+ ' (at your option) any later version.
6+ '
7+ ' This program is distributed in the hope that it will be useful,
8+ ' but WITHOUT ANY WARRANTY
9+ Imports SCrawler.API.Base
10+ Imports SCrawler.Plugin
11+ Imports SCrawler.Plugin.Attributes
12+ Imports PersonalUtilities.Tools.Web.Clients
13+ Imports PersonalUtilities.Functions.RegularExpressions
14+ Namespace API.Facebook
15+ <Manifest( "AndyProgram_Facebook" ), SavedPosts, SeparatedTasks( 1 ), SpecialForm( False )>
16+ Friend Class SiteSettings : Inherits ThreadsNet.SiteSettings
17+ # Region "Declarations"
18+ # Region "Auth"
19+ <PropertyOption(AllowNull:= False , ControlText:= "Accept" , ControlToolTip:= "Header 'Accept'" , IsAuth:= True ), ControlNumber( 21 ), PXML, PClonable>
20+ Friend ReadOnly Property Header_Accept As PropertyValue
21+ <PropertyOption(ControlText:= "x-ig-app-id" , AllowNull:= True , IsAuth:= True )>
22+ Friend Overrides ReadOnly Property HH_IG_APP_ID As PropertyValue
23+ Get
24+ Return __HH_IG_APP_ID
25+ End Get
26+ End Property
27+ <DoNotUse> Friend Overrides ReadOnly Property HH_CSRF_TOKEN As PropertyValue
28+ Get
29+ Return __HH_CSRF_TOKEN
30+ End Get
31+ End Property
32+ <PropertyOption(ControlText:= "sec-ch-ua-platform-ver" , ControlToolTip:= "sec-ch-ua-platform-version" , IsAuth:= True , LeftOffset:= 120 ), ControlNumber( 51 ), PXML, PClonable>
33+ Friend ReadOnly Property HH_PLATFORM_VER As PropertyValue
34+ # End Region
35+ # Region "Defaults"
36+ <PropertyOption(ControlText:= "Download photos" , IsAuth:= False ), PXML, PClonable>
37+ Friend ReadOnly Property ParsePhotoBlock As PropertyValue
38+ <PropertyOption(ControlText:= "Download videos" , IsAuth:= False ), PXML, PClonable>
39+ Friend ReadOnly Property ParseVideoBlock As PropertyValue
40+ <PropertyOption(ControlText:= "Download stories" , IsAuth:= False ), PXML, PClonable>
41+ Friend ReadOnly Property ParseStoriesBlock As PropertyValue
42+ # End Region
43+ # End Region
44+ # Region "Initializer"
45+ Friend Sub New ( ByVal AccName As String , ByVal Temp As Boolean )
46+ MyBase .New( "Facebook" , "facebook.com" , AccName, Temp, My.Resources.SiteResources.FacebookIcon_32, My.Resources.SiteResources.FacebookPic_37)
47+
48+ With Responser.Headers
49+ .Add(HttpHeaderCollection.GetSpecialHeader(MyHeaderTypes.Authority, "www.facebook.com" ))
50+ .Add(HttpHeaderCollection.GetSpecialHeader(MyHeaderTypes.Origin, "https://www.facebook.com" ))
51+ .Remove(DeclaredNames.Header_FB_FRIENDLY_NAME)
52+ End With
53+ Header_Accept = New PropertyValue( String .Empty, GetType ( String ))
54+ HH_PLATFORM_VER = New PropertyValue( String .Empty, GetType ( String ))
55+ ParsePhotoBlock = New PropertyValue( True )
56+ ParseVideoBlock = New PropertyValue( True )
57+ ParseStoriesBlock = New PropertyValue( True )
58+
59+ UrlPatternUser = "https://www.facebook.com/{0}"
60+ UserRegex = RParams.DMS( "facebook.com/(profile.php\?id=\d+|[^\?&/]+)" , 1 )
61+ ImageVideoContains = "facebook.com"
62+ UserOptionsType = GetType (UserExchangeOptions)
63+ End Sub
64+ # End Region
65+ # Region "GetInstance"
66+ Friend Overrides Function GetInstance( ByVal What As ISiteSettings.Download) As IPluginContentProvider
67+ Return New UserData
68+ End Function
69+ # End Region
70+ # Region "UpdateResponserData"
71+ Friend Overrides Sub UpdateResponserData( ByVal Resp As Responser)
72+ With Responser.Cookies
73+ .Update(Resp.Cookies)
74+ If .Changed Then Responser.SaveCookies() : .Changed = False
75+ End With
76+ End Sub
77+ # End Region
78+ # Region "BaseAuthExists, GetUserUrl, GetUserPostUrl, IsMyUser, IsMyImageVideo"
79+ Friend Overrides Function BaseAuthExists() As Boolean
80+ Return Responser.CookiesExists And ACheck(HH_IG_APP_ID.Value)
81+ End Function
82+ Friend Overrides Function GetUserUrl( ByVal User As IPluginContentProvider) As String
83+ Return DirectCast (User, UserData).GetProfileUrl
84+ End Function
85+ Friend Overrides Function GetUserPostUrl( ByVal User As UserDataBase, ByVal Media As UserMedia) As String
86+ Return Media.URL_BASE
87+ End Function
88+ Friend Overrides Function IsMyUser( ByVal UserURL As String ) As ExchangeOptions
89+ Dim e As ExchangeOptions = MyBase .IsMyUser(UserURL)
90+ If e.Exists Then
91+ e.Options = e.UserName
92+ Dim v$ = RegexReplace(e.UserName, Regex_ProfileUrlID)
93+ If Not v.IsEmptyString Then
94+ e.UserName = v
95+ Else
96+ e.UserName = e.UserName.StringRemoveWinForbiddenSymbols
97+ End If
98+ End If
99+ Return e
100+ End Function
101+ Friend Overrides Function IsMyImageVideo( ByVal URL As String ) As ExchangeOptions
102+ If Not URL.IsEmptyString AndAlso Not CStr (AConvert( Of String )(URL, Regex_VideoIDFromURL, String .Empty)).IsEmptyString Then
103+ Return New ExchangeOptions(Site, String .Empty) With {.Exists = True }
104+ Else
105+ Return Nothing
106+ End If
107+ End Function
108+ # End Region
109+ End Class
110+ End Namespace
0 commit comments