5353import org .jdownloader .plugins .controller .host .LazyHostPlugin ;
5454import org .jdownloader .scripting .JavaScriptEngineFactory ;
5555
56- @ DecrypterPlugin (revision = "$Revision: 51164 $" , interfaceVersion = 3 , names = {}, urls = {})
56+ @ DecrypterPlugin (revision = "$Revision: 51424 $" , interfaceVersion = 3 , names = {}, urls = {})
5757public class BunkrAlbum extends PluginForDecrypt {
5858 public BunkrAlbum (PluginWrapper wrapper ) {
5959 super (wrapper );
@@ -138,11 +138,21 @@ public ArrayList<DownloadLink> decryptIt(final CryptedLink param, ProgressContro
138138 if (br .getHttpConnection ().getResponseCode () == 404 ) {
139139 throw new PluginException (LinkStatus .ERROR_FILE_NOT_FOUND );
140140 }
141+ final boolean enforceAdvancedView = false ;// also works for smaller albums
142+ boolean advancedView = false ;
143+ if (br .containsHTML ("<a\\ s*href\\ s*=\\ s*\" \\ ?advanced=1\" " ) || enforceAdvancedView ) {
144+ // all images on one page
145+ br .getPage ("?advanced=1" );
146+ advancedView = true ;
147+ }
141148 final HashSet <String > dups = new HashSet <String >();
142149 /* Double-check for offline / empty album. */
143150 final String albumID = new Regex (param .getCryptedUrl (), PATTERN_ALBUM ).getMatch (0 );
144151 int numberofFiles = -1 ;
145- final String numberofFilesStr = br .getRegex (">\\ s*(\\ d+)\\ s*files" ).getMatch (0 );
152+ String numberofFilesStr = br .getRegex (">\\ s*(\\ d+)\\ s*files" ).getMatch (0 );
153+ if (numberofFilesStr == null ) {
154+ numberofFilesStr = br .getRegex ("\" Explore\\ s*this\\ s*album\\ s*with\\ s*(\\ d+)\\ s*files" ).getMatch (0 );
155+ }
146156 if (numberofFilesStr != null ) {
147157 numberofFiles = Integer .parseInt (numberofFilesStr );
148158 } else {
@@ -159,62 +169,97 @@ public ArrayList<DownloadLink> decryptIt(final CryptedLink param, ProgressContro
159169 } else {
160170 logger .warning ("Failed to find album title" );
161171 }
162- String json = br .getRegex ("<script\\ s*id\\ s*=\\ s*\" __NEXT_DATA__\" \\ s*type\\ s*=\\ s*\" application/json\" >\\ s*(\\ {.*?\\ })\\ s*</script" ).getMatch (0 );
163- if (json != null ) {
164- final Map <String , Object > map = restoreFromString (json , TypeRef .MAP );
165- List <Map <String , Object >> files = (List <Map <String , Object >>) JavaScriptEngineFactory .walkJson (map , "props/pageProps/files" );
166- if (files == null ) {
167- files = (List <Map <String , Object >>) JavaScriptEngineFactory .walkJson (map , "props/pageProps/album/files" );
168- }
169- if (files == null ) {
170- files = new ArrayList <Map <String , Object >>();
171- }
172- Map <String , Object > pagePropsFile = (Map <String , Object >) JavaScriptEngineFactory .walkJson (map , "props/pageProps/file" );
173- if (pagePropsFile == null ) {
174- pagePropsFile = (Map <String , Object >) JavaScriptEngineFactory .walkJson (map , "props/pageProps/album/file" );
175- }
176- if (pagePropsFile != null ) {
177- files .add (pagePropsFile );
178- }
179- if (files != null ) {
172+ if (advancedView ) {
173+ String advancedViewJson = br .getRegex ("<script[^>]*>\\ s*window\\ .albumFiles\\ s*=\\ s*(\\ [.*?\\ ]\\ s*);\\ s*(console.*?)?</script" ).getMatch (0 );
174+ if (advancedViewJson != null ) {
175+ advancedViewJson = advancedViewJson .replaceAll ("(\\ {|,)\\ s*(\\ w+)\\ s*:" , "$1\" $2\" :" );// convert from javascript to json
176+ final List <Map <String , Object >> files = (List <Map <String , Object >>) JavaScriptEngineFactory .jsonToJavaObject (advancedViewJson );
180177 for (final Map <String , Object > file : files ) {
181- final String name = (String ) file .get ("name" );
182- String cdn = (String ) file .get ("cdn" );
183- if (cdn == null ) {
184- cdn = (String ) file .get ("mediafiles" );
185- }
178+ final String slug = (String ) file .get ("slug" );
179+ final String originalName = (String ) file .get ("original" );
180+ final String serverName = (String ) file .get ("name" );
186181 final String size = StringUtils .valueOfOrNull (file .get ("size" ));
187- if (name != null && cdn != null ) {
188- final String directurl = URLHelper . parseLocation ( new URL ( cdn ), name );
189- add (ret , dups , directurl , name , size != null && size .matches ("[0-9]+" ) ? size : null , size != null && !size .matches ("[0-9]+" ) ? size : null , true );
182+ if (slug != null ) {
183+ final String directurl = br . getURL ( "/f/" + slug ). toExternalForm ( );
184+ add (ret , dups , directurl , StringUtils . firstNotEmpty ( originalName , serverName ) , size != null && size .matches ("[0-9]+" ) ? size : null , size != null && !size .matches ("[0-9]+" ) ? size : null , true );
190185 }
191186 }
192187 }
193- }
194- final String [] htmls = br .getRegex ("<div class=\" grid-images_box(?: rounded-lg)?[^\" ]+\" (.*?)</div>\\ s+</div>" ).getColumn (0 );
195- for (final String html : htmls ) {
196- String directurl = new Regex (html , "href\\ s*=\\ s*\" (https?://[^\" ]+)\" " ).getMatch (0 );
197- if (directurl == null ) {
198- final String [] urls = HTMLParser .getHttpLinks (html , br .getURL ());
199- for (final String url : urls ) {
200- if (new Regex (url , BunkrAlbum .PATTERN_SINGLE_FILE ).patternFind ()) {
201- directurl = url ;
202- break ;
188+ } else {
189+ final String oldJson = br .getRegex ("<script\\ s*id\\ s*=\\ s*\" __NEXT_DATA__\" \\ s*type\\ s*=\\ s*\" application/json\" >\\ s*(\\ {.*?\\ })\\ s*</script" ).getMatch (0 );
190+ if (oldJson != null ) {
191+ // TODO: can we remove this?
192+ final Map <String , Object > map = restoreFromString (oldJson , TypeRef .MAP );
193+ List <Map <String , Object >> files = (List <Map <String , Object >>) JavaScriptEngineFactory .walkJson (map , "props/pageProps/files" );
194+ if (files == null ) {
195+ files = (List <Map <String , Object >>) JavaScriptEngineFactory .walkJson (map , "props/pageProps/album/files" );
196+ }
197+ if (files == null ) {
198+ files = new ArrayList <Map <String , Object >>();
199+ }
200+ Map <String , Object > pagePropsFile = (Map <String , Object >) JavaScriptEngineFactory .walkJson (map , "props/pageProps/file" );
201+ if (pagePropsFile == null ) {
202+ pagePropsFile = (Map <String , Object >) JavaScriptEngineFactory .walkJson (map , "props/pageProps/album/file" );
203+ }
204+ if (pagePropsFile != null ) {
205+ files .add (pagePropsFile );
206+ }
207+ if (files != null ) {
208+ for (final Map <String , Object > file : files ) {
209+ final String name = (String ) file .get ("name" );
210+ String cdn = (String ) file .get ("cdn" );
211+ if (cdn == null ) {
212+ cdn = (String ) file .get ("mediafiles" );
213+ }
214+ final String size = StringUtils .valueOfOrNull (file .get ("size" ));
215+ if (name != null && cdn != null ) {
216+ final String directurl = URLHelper .parseLocation (new URL (cdn ), name );
217+ add (ret , dups , directurl , name , size != null && size .matches ("[0-9]+" ) ? size : null , size != null && !size .matches ("[0-9]+" ) ? size : null , true );
218+ }
203219 }
204220 }
205221 }
206- if (directurl != null ) {
207- String filesizeStr = new Regex (html , "<p class=\" mt-0 dark:text-white-900\" [^>]*>\\ s*([^<]*?)\\ s*</p>" ).getMatch (0 );
208- if (filesizeStr == null ) {
209- filesizeStr = new Regex (html , "<p class=\" [^\" ]*theSize[^\" ]*\" [^>]*>\\ s*([^<]*?)\\ s*</p>" ).getMatch (0 );
222+ Browser pageBr = br ;
223+ while (true ) {
224+ final String [] htmls = pageBr .getRegex ("<div class=\" grid-images_box(?: rounded-lg)?[^\" ]+\" (.*?)</div>\\ s+</div>" ).getColumn (0 );
225+ for (final String html : htmls ) {
226+ if (html .contains ("/f/' + file.slug" )) {
227+ // coding entry used by javascript filling for next entries while scroling
228+ continue ;
229+ }
230+ String directurl = new Regex (html , "href\\ s*=\\ s*\" (https?://[^\" ]+)\" " ).getMatch (0 );
231+ if (directurl == null || !new Regex (directurl , BunkrAlbum .PATTERN_SINGLE_FILE ).patternFind ()) {
232+ directurl = null ;
233+ final String [] urls = HTMLParser .getHttpLinks (html , pageBr .getURL ());
234+ for (final String url : urls ) {
235+ if (new Regex (url , BunkrAlbum .PATTERN_SINGLE_FILE ).patternFind ()) {
236+ directurl = url ;
237+ break ;
238+ }
239+ }
240+ }
241+ if (directurl != null ) {
242+ String filesizeStr = new Regex (html , "<p class=\" mt-0 dark:text-white-900\" [^>]*>\\ s*([^<]*?)\\ s*</p>" ).getMatch (0 );
243+ if (filesizeStr == null ) {
244+ filesizeStr = new Regex (html , "<p class=\" [^\" ]*theSize[^\" ]*\" [^>]*>\\ s*([^<]*?)\\ s*</p>" ).getMatch (0 );
245+ }
246+ String filename = new Regex (html , "<div\\ s*class\\ s*=\\ s*\" [^\" ]*details\" \\ s*>\\ s*<p\\ s*class[^>]*>\\ s*(.*?)\\ s*<" ).getMatch (0 );
247+ if (filename == null ) {
248+ filename = new Regex (html , "<p class=\" [^\" ]*theName[^\" ]*\" [^>]*>\\ s*([^<]*?)\\ s*</p>" ).getMatch (0 );
249+ }
250+ add (ret , dups , directurl , filename , null , filesizeStr , true );
251+ } else {
252+ logger .warning ("html Parser broken? HTML: " + html );
253+ }
210254 }
211- String filename = new Regex (html , "<div\\ s*class\\ s*=\\ s*\" [^\" ]*details\" \\ s*>\\ s*<p\\ s*class[^>]*>\\ s*(.*?)\\ s*<" ).getMatch (0 );
212- if (filename == null ) {
213- filename = new Regex (html , "<p class=\" [^\" ]*theName[^\" ]*\" [^>]*>\\ s*([^<]*?)\\ s*</p>" ).getMatch (0 );
255+ final String nextPage = pageBr .getRegex ("<a\\ s*href\\ s*=\\ s*\" (\\ ?page=\\ d+)\" \\ s*>\\ s*(»|»)\\ s*<" ).getMatch (0 );
256+ if (nextPage != null ) {
257+ logger .info ("next page," + nextPage );
258+ pageBr .getPage (nextPage );
259+ } else {
260+ logger .info ("no next page, stop" );
261+ break ;
214262 }
215- add (ret , dups , directurl , filename , null , filesizeStr , true );
216- } else {
217- logger .warning ("html Parser broken? HTML: " + html );
218263 }
219264 }
220265 if (ret .isEmpty ()) {
0 commit comments