@@ -72,20 +72,17 @@ protected override ImageLink[] GetImageLinksImpl(bool includeAlreadySaved = fals
72
72
73
73
public override void DownloadHtmlImpl ( )
74
74
{
75
- var thumbs = new List < string > ( ) ;
76
- var htmlPage = "" ;
77
- var baseUrl = "//i.4cdn.org/" + BoardCode + "/" ;
78
- var jsonUrl = "http://a.4cdn.org/" + BoardCode + "/thread/" + ID + ".json" ;
79
-
75
+ var thumbUrls = new List < string > ( ) ;
76
+ var baseUrl = $ "//i.4cdn.org/{ BoardCode } /";
77
+ var jsonUrl = $ "http://a.4cdn.org/{ BoardCode } /thread/{ ID } .json";
78
+ var htmlPage = string . Empty ;
80
79
JObject jObject ;
81
80
82
81
using ( var web = Utils . CreateWebClient ( ) )
83
82
{
84
83
htmlPage = web . DownloadString ( Url ) ;
85
-
86
- //Prevent the html from being destroyed by the anti adblock script
87
84
htmlPage = htmlPage . Replace ( "f=\" to\" " , "f=\" penis\" " ) ;
88
-
85
+
89
86
var json = web . DownloadString ( jsonUrl ) ;
90
87
jObject = JObject . Parse ( json ) ;
91
88
}
@@ -94,64 +91,68 @@ public override void DownloadHtmlImpl()
94
91
. SelectTokens ( "posts[*]" )
95
92
. Where ( x => x [ "ext" ] != null )
96
93
. ToList ( ) ;
97
-
94
+
98
95
foreach ( var post in posts )
99
96
{
100
- var old = baseUrl + post [ "tim" ] + post [ "ext" ] ;
101
- var replacement = post [ "tim" ] + ( string ) post [ "ext" ] ;
102
- htmlPage = htmlPage . Replace ( old , replacement ) ;
103
-
104
- //get the actual filename saved
105
- var filename = Path
106
- . GetFileNameWithoutExtension (
107
- new ImageLink ( post [ "tim" ] . Value < long > ( ) ,
108
- old ,
109
- post [ "filename" ] . ToString ( ) ,
110
- post [ "no" ] . Value < long > ( ) ,
111
- this
112
- )
113
- . GenerateFilename ( ( ImageFileNameFormat ) Settings . Default . ImageFilenameFormat ) ) ;
114
-
115
- //Save thumbs for files that need it
116
- if ( replacement . Split ( '.' ) [ 1 ] == "webm" )
97
+ var tim = post [ "tim" ] . ToString ( ) ;
98
+ var ext = post [ "ext" ] . ToString ( ) ;
99
+ var oldUrl = baseUrl + tim + ext ;
100
+ var newFilename = Path . GetFileNameWithoutExtension (
101
+ new ImageLink (
102
+ post [ "tim" ] . Value < long > ( ) ,
103
+ oldUrl ,
104
+ post [ "filename" ] . ToString ( ) ,
105
+ post [ "no" ] . Value < long > ( ) ,
106
+ this
107
+ ) . GenerateFilename ( ( ImageFileNameFormat ) Settings . Default . ImageFilenameFormat )
108
+ ) ;
109
+
110
+ htmlPage = htmlPage . Replace ( oldUrl , tim + ext ) ;
111
+
112
+ if ( ext == ".webm" )
117
113
{
118
- old = "//t.4cdn.org/" + BoardCode + "/" + post [ " tim" ] + " s.jpg";
119
- thumbs . Add ( "http:" + old ) ;
114
+ var thumbUrl = $ "//t.4cdn.org/{ BoardCode } / { tim } s.jpg";
115
+ thumbUrls . Add ( $ "http:{ thumbUrl } " ) ;
120
116
121
- htmlPage = htmlPage . Replace ( post [ " tim" ] . ToString ( ) , filename ) ;
122
- htmlPage = htmlPage . Replace ( "//i.4cdn.org/" + BoardCode + "/" + filename , "thumb/" + post [ " tim" ] ) ;
117
+ htmlPage = htmlPage . Replace ( tim , newFilename ) ;
118
+ htmlPage = htmlPage . Replace ( $ " { baseUrl } { newFilename } " , $ "thumb/{ tim } " ) ;
123
119
}
124
120
else
125
121
{
126
- var thumbName = replacement . Split ( '.' ) [ 0 ] + "s" ;
127
- htmlPage = htmlPage . Replace ( thumbName + " .jpg", replacement . Split ( '.' ) [ 0 ] + "." + replacement . Split ( '.' ) [ 1 ] ) ;
128
- htmlPage = htmlPage . Replace ( "/" + thumbName , thumbName ) ;
122
+ var thumbName = tim + "s" ;
123
+ htmlPage = htmlPage . Replace ( $ " { thumbName } .jpg", tim + ext ) ;
124
+ htmlPage = htmlPage . Replace ( $ "/ { thumbName } " , thumbName ) ;
129
125
130
- htmlPage = htmlPage . Replace ( "//i.4cdn.org/" + BoardCode + "/" + post [ " tim" ] , post [ " tim" ] . ToString ( ) ) ;
131
- htmlPage = htmlPage . Replace ( post [ " tim" ] . ToString ( ) , filename ) ; //easy fix for images
126
+ htmlPage = htmlPage . Replace ( $ " { baseUrl } { tim } " , tim ) ;
127
+ htmlPage = htmlPage . Replace ( tim , newFilename ) ;
132
128
}
133
129
134
- htmlPage = htmlPage . Replace ( "//is2.4chan.org/" + BoardCode + "/" + post [ " tim" ] , post [ " tim" ] . ToString ( ) ) ; //bandaid fix for is2 urls
135
- htmlPage = htmlPage . Replace ( "/" + replacement , replacement ) ;
130
+ htmlPage = htmlPage . Replace ( $ "//is2.4chan.org/{ BoardCode } / { tim } " , tim ) ;
131
+ htmlPage = htmlPage . Replace ( $ "/ { tim } { ext } " , tim + ext ) ;
136
132
}
137
133
134
+ // 4chan uses double slash urls (copy current protocol), when the user views it locally the protocol will no longer be http, so build it in.
135
+ // This is used for javascript references.
138
136
htmlPage = htmlPage . Replace ( "=\" //" , "=\" http://" ) ;
139
137
138
+ // Alter all content links like "http://is2.4chan.org/tv/123.jpg" to become local like "123.jpg".
139
+ htmlPage = htmlPage . Replace ( $ "http://is2.4chan.org/{ BoardCode } /", string . Empty ) ;
140
+
140
141
if ( Settings . Default . SaveThumbnails )
141
142
{
142
- //Save thumbs for files that need it
143
- for ( int i = 0 ; i < thumbs . Count ; i ++ )
143
+ foreach ( var thumb in thumbUrls )
144
144
{
145
- Utils . DownloadFile ( thumbs [ i ] , SaveTo + " \\ thumb") ;
145
+ Utils . DownloadFileIfDoesntExist ( thumb , $ " { SaveTo } \\ thumb") ;
146
146
}
147
147
}
148
148
149
149
if ( ! string . IsNullOrWhiteSpace ( htmlPage ) )
150
150
{
151
- File . WriteAllText ( SaveTo + " \\ Thread.html", htmlPage ) ;
151
+ File . WriteAllText ( $ " { SaveTo } \\ Thread.html", htmlPage ) ;
152
152
}
153
153
}
154
154
155
+
155
156
protected override string GetThreadSubject ( )
156
157
{
157
158
string subject = NO_SUBJECT ;
0 commit comments