Compare commits

...
180 Commits
Author SHA1 Message Date
death-claw bf532dd1d0 v2.12.0 2020-05-21 16:43:03 +01:00
death-claw eb1a125e59 Use new user hash from the api 2020-05-21 16:41:16 +01:00
death-claw 256659a72d v2.11.7 2020-05-08 12:57:41 +01:00
death-claw dbf3aa7e7d Fix bug with paths creation
Move Open Link button
Rename rename all title
2020-05-08 12:56:11 +01:00
death-claw a75ce181ff v2.11.6 2020-05-04 21:07:16 +01:00
death-claw 37ae6b4ebf Merge branch 'master' of https://github.com/death-claw/vripper-project 2020-05-04 21:06:48 +01:00
death-claw 6631a6a95b PNG filenames are now correctly named
Fix issue with special characters in post titles
2020-05-04 21:04:51 +01:00
death-clawandGitHub 918f8578ad Update CHANGELOG.md 2020-05-03 16:40:26 +01:00
death-claw 10fa9f68ae v2.11.5 2020-05-03 15:18:28 +01:00
death-claw 6b5c9ccb0f Reduce rows buffer size 2020-05-03 15:16:31 +01:00
death-claw 652e8f1a9d v2.11.4 2020-05-03 14:24:27 +01:00
death-claw fe53ae733d Code cleanup
Dependencies update
2020-05-03 14:22:40 +01:00
death-claw 690dab2ae8 v2.11.3 2020-04-30 18:26:42 +01:00
death-claw 530542163e Add missing files 2020-04-30 18:26:23 +01:00
death-claw cf7f4c75c0 Source code restructure
UI fixes and enhancements
Add menu entry to rename a gallery to first alternative title
Add menu on toolbar for massive rename to first alternative title
2020-04-30 18:23:11 +01:00
death-claw c6b395cf4c v2.11.2 2020-04-26 22:06:34 +01:00
death-claw e72edeed62 Fix icon
Bug fixes
2020-04-26 22:02:51 +01:00
death-claw 3f22d53f89 v2.11.1 2020-04-25 16:32:25 +01:00
death-claw 08c0fa62b1 Add option to rename gallery
Code source maintenance
2020-04-25 16:28:56 +01:00
death-claw 4c79cca079 v2.11.0 2020-03-29 17:37:28 +01:00
death-clawandGitHub 67096242a2 Merge pull request #4 from life-claw/pixroute
Added Support for pixroute.com
2020-03-29 17:30:34 +01:00
death-claw f66112375d Merge branch 'master' of https://github.com/death-claw/vripper-project 2020-03-29 17:28:39 +01:00
death-claw c5a082e248 Upgrade Electron to v8
Upgrade Angular to v9
App settings are now portable in a json file
Add grab post title from thread option
General code source maintenance
2020-03-29 17:03:14 +01:00
life-claw c2a1b0aa33 Added Support for pixroute.com 2020-03-08 13:25:57 -05:00
death-clawandGitHub a89dcc96d8 Update README.md 2020-02-11 21:16:37 +01:00
death-claw b2a10eafd9 v2.10.8 2020-01-25 16:00:05 +01:00
death-claw f027aff89d Fix app url 2020-01-25 15:57:45 +01:00
death-claw b4eaf0d1c4 v2.10.7 2020-01-25 14:45:54 +01:00
death-claw 9d2975faaa Drop SockJs and switch to WebSocket
Autoreconnect front to back
2020-01-25 14:39:50 +01:00
death-claw 0c0fdf9d78 v2.10.6 2020-01-19 13:01:03 +01:00
death-claw e17afa0ef3 Limit cache size 2020-01-19 12:59:47 +01:00
death-claw 3d3eb6aa36 v2.10.5 2020-01-18 22:28:27 +01:00
death-claw e22132255e Bug fixes 2020-01-18 22:24:53 +01:00
death-claw ef041526ec v2.10.4 2020-01-18 13:27:47 +01:00
death-claw 704311dd9a Zero value for total max download will disable the limit
Add system notification
Bug fixes
2020-01-18 13:21:46 +01:00
death-claw 9617a6f20f v2.10.3 2020-01-16 21:39:59 +01:00
death-claw bc17442961 Some bug fixes
Enhance download queue logic
Clear cache button
Fix the partial status
2020-01-16 21:34:09 +01:00
death-claw 574d6818c1 Refactor PostImgHost 2020-01-14 21:03:35 +01:00
death-clawandGitHub 5c416055ee Merge pull request #3 from life-claw/postimg
Added Support for postimg.cc
2020-01-14 19:01:41 +01:00
death-clawandGitHub fa30458dc6 Merge pull request #1 from life-claw/imagevenue
Add support for imagevenue.com
2020-01-14 18:47:47 +01:00
death-clawandGitHub 638af93225 Merge pull request #2 from life-claw/urlSpaces
Sanitize URLs that contain spaces
2020-01-14 18:14:47 +01:00
life-claw 2c6ca741c7 Added PostImgHost 2020-01-07 16:50:11 -06:00
life-claw d7f2df2540 Sanitize URLs with that contain spaces 2020-01-07 16:18:45 -06:00
life-claw b85ade1dba Added ImageVenueHost 2020-01-07 16:04:04 -06:00
death-claw 1c61a0b34e v2.10.2 2019-12-29 11:35:59 +01:00
death-claw 46b9449969 Upgrade electron to v7
Update the retry policy
2019-12-29 11:33:03 +01:00
death-claw cc1bbd1231 v2.10.1 2019-12-27 23:05:10 +01:00
death-claw b29cba2911 Bug fix 2019-12-27 22:58:33 +01:00
death-claw 13bde3aa2c 2.10.0 2019-12-27 21:27:27 +01:00
death-claw 35b4f5fc97 Add support for imgspice
Fix spring dependency bug
2019-12-27 21:25:33 +01:00
death-claw 1b0482b7d4 v2.9.1 2019-12-27 20:10:31 +01:00
death-claw c9ff6eeab6 Fix build issue 2019-12-27 20:09:16 +01:00
death-claw 5ac57b743d v2.9.0 2019-12-27 20:07:19 +01:00
death-claw f7b219701f Allow many hosts to run at the same time
Add title to gallery
Add global concurrent downloads
Decrease timeout for fast fail
Add counter badge in link collector
2019-12-27 20:03:35 +01:00
death-claw d009aa3f8c v2.8.1 2019-12-24 20:21:29 +01:00
death-claw 078d49f883 v2.8.1 2019-12-24 20:18:22 +01:00
death-claw f1bf517ba5 Fix issue with path creation 2019-12-24 20:15:03 +01:00
death-claw 6269ed6f6e v2.8.0 2019-12-24 19:47:17 +01:00
death-claw 43b8dedbb1 Use pointer cursor on gallery items 2019-12-24 19:42:45 +01:00
death-claw 978be7bd49 Add view photos settings
Some improvements
2019-12-23 22:46:46 +01:00
death-claw 1b7f3aef62 Add missing css and script includes 2019-12-23 19:36:07 +01:00
death-claw 7d24ee4867 Use photoswipe for image gallery 2019-12-23 00:02:13 +01:00
death-claw 269a3475b0 Generate thumbnails on the fly and cache them 2019-12-21 19:17:51 +01:00
death-claw 18e2bc6afc Add Photo Viewer 2019-12-21 17:23:22 +01:00
death-claw c6ef54e115 v2.7.1 2019-12-21 11:24:03 +01:00
death-claw 441b2831fc Add version to title 2019-12-21 11:16:53 +01:00
death-claw 3cf4d60eca v2.7.0 2019-12-21 09:59:17 +01:00
death-claw d228c89a1c Add support for pixxxels
Add missing icon
2019-12-21 09:56:57 +01:00
death-claw f3b592e81b v2.6.0 2019-12-21 08:39:04 +01:00
death-claw a5ff659fb4 Better quality app icon
Implement context menu on download tab
Add stop remove and start button to context menu
Link will not be removed automatically from link collector tab
Some UI fixes
2019-12-21 08:34:56 +01:00
death-claw ab80e2f3b3 v2.5.1 2019-12-09 20:26:52 +01:00
death-claw 2ef082f87e Add hosts column in Link collector grab menu
Disable download button when nothing selected in Link collector grab menu
2019-12-09 19:56:26 +01:00
death-claw a1b97e76a7 v2.5.0 2019-12-08 20:13:58 +01:00
death-claw 185a078b4d Missing change 2019-12-08 20:08:42 +01:00
death-claw 28a4c944ee Add support for multiple links at a time
Add the Link collector feature
Fix bug with previews
2019-12-08 20:07:13 +01:00
death-claw 23d3553d99 Include startup icon
Fix UI layout
2019-12-06 23:09:57 +01:00
death-claw fb09e4c46b v2.4.1 2019-11-26 20:03:10 +01:00
death-claw 4feb6f5fe1 Increase attempts for establishing ws connection between front and back end
Change default download folder to Home folder (installer), App folder (portable)
2019-11-26 20:01:08 +01:00
death-claw df1b9efbbb v2.4.0 2019-11-23 14:50:16 +01:00
death-claw 553924fa1d Pimpandhost Host support 2019-11-23 14:48:05 +01:00
death-claw a90dbd568f v2.3.2 2019-11-23 12:15:42 +01:00
death-claw ca7ca1ce8e Fix a bug with the scan component 2019-11-23 12:14:07 +01:00
death-claw b3ab239a1e v2.3.1 2019-11-22 20:07:41 +01:00
death-claw 6e212c791c Fix connexion reset issue
Fix Post Status when autostart option is selected
Add stop all button
2019-11-22 20:05:14 +01:00
death-claw c6067ef147 v2.3.0 2019-11-21 21:17:25 +01:00
death-claw 8333f0c34e Fix Restoring post status on App startup
Use local sockjs and material icons font
2019-11-21 21:16:24 +01:00
death-claw 75becd8bb4 UI enhancements and overhaul
Stability fixes with HTTP connections
MacOS official support
2019-11-21 20:54:44 +01:00
death-claw 667376301a v2.2.5 2019-11-09 13:26:54 +01:00
death-claw 128e6b68a3 More robust parsing
Fix pixhost and imagezilla to exclude thumbs
2019-11-09 13:16:09 +01:00
death-claw a7c2844ab4 Change Retry duration 2019-11-09 10:13:12 +01:00
death-claw bd0b7d274b Fix macOs paths 2019-10-06 13:33:29 +01:00
death-claw bc57fad52b Remove failing rule 2019-10-06 12:00:01 +01:00
death-claw b81ef53cb9 Add support for macOs 2019-10-06 11:22:48 +01:00
death-claw c182bf0a08 v2.2.4 2019-10-05 18:06:40 +01:00
death-claw 07802b4b13 Add AppImage target 2019-10-05 18:03:32 +01:00
death-claw 50c4d947ed v2.2.3 2019-10-01 23:28:12 +01:00
death-claw b9b20e86dd Strip libjvm.so for debian 2019-10-01 23:27:01 +01:00
death-claw 64b93ce7e1 v2.2.2 2019-10-01 22:59:39 +01:00
death-claw 0bde4399e3 Update product name 2019-10-01 22:57:13 +01:00
death-claw 9b7818c5a7 v2.2.1 2019-10-01 22:44:19 +01:00
death-claw 1f2dcff353 Update dependency list for deb package 2019-10-01 22:42:28 +01:00
death-claw 4d82622fdb v2.2.0 2019-10-01 21:26:27 +01:00
death-claw e7393caf01 Fix 'Start' on pending items
Upgrade to Java 11
Embedd JRE within the app
2019-10-01 21:24:02 +01:00
death-claw 8e5cb958ea v2.1.0 2019-09-30 21:12:56 +01:00
death-claw bc2cf02ec6 Add a create a subfolder per thread option 2019-09-30 21:06:40 +01:00
death-claw 7a8ecb306f v2.0.4 2019-09-27 20:52:25 +01:00
death-claw 76c3901afa Fix some issues with ImxHost 2019-09-27 20:50:51 +01:00
death-claw f16b2227a1 v2.0.3 2019-09-23 17:38:36 +01:00
death-claw d8d7ca5408 Update deb dependencies 2019-09-23 17:36:10 +01:00
death-claw 28c6b71e99 v2.0.2 2019-09-23 16:46:37 +01:00
death-claw c40d3e2377 Add portable mode 2019-09-23 16:43:52 +01:00
death-claw 2217fea0ad v2.0.1 2019-09-22 21:55:30 +01:00
death-claw 94746441b5 Update app name 2019-09-22 21:48:35 +01:00
death-claw c3e861fa8b v2.0.0 2019-09-22 20:58:24 +01:00
death-claw ae1d644dba Update icons 2019-09-22 20:41:32 +01:00
death-claw 1fcb7e4e42 Fix a bug in data file 2019-09-22 20:29:34 +01:00
death-claw 646cbba21c Update package.json 2019-09-22 20:21:05 +01:00
death-claw eef4d13235 Change data and log paths 2019-09-22 20:15:03 +01:00
death-claw 9d1fe4c6b6 Electron app changes 2019-09-22 18:41:27 +01:00
death-claw 610d08f4ca Add sub folder option
Add clear finished option
UI enhancements
Bug fixes
2019-09-22 16:23:52 +01:00
death-claw 7e52d0d6de v1.6.5 2019-09-18 23:20:58 +01:00
death-claw 4f0c5925ad electron update 2019-09-18 23:19:01 +01:00
death-claw 245668b374 v1.6.4 2019-09-18 20:29:18 +01:00
death-claw d3f5a70bfb Change menu item name 2019-09-18 20:27:36 +01:00
death-claw 5fd70a821b v1.6.3 2019-09-18 19:44:45 +01:00
death-claw 6e9c912118 Better multithread management
Fix partial state UI
2019-09-18 19:41:48 +01:00
death-claw 19a98ea056 v1.6.2 2019-09-17 23:00:55 +01:00
death-claw 229bc46227 Rework UI colors
Fix scan input bug
2019-09-17 22:59:04 +01:00
death-claw 374946c6f2 v1.6.1 2019-09-16 22:56:57 +01:00
death-claw f8eccfb4ad Rework UI
Fix clipboard monitoring
2019-09-16 22:54:18 +01:00
death-claw 4223bce5f3 v1.6.0 2019-09-15 22:19:53 +01:00
death-claw ea9a98bb3e Rework the UI
Add a dark theme
Fix the force ordering bug
Other bug fixes
2019-09-15 22:14:17 +01:00
death-claw a416a7e7d7 v1.5.2 2019-09-01 15:46:41 +01:00
death-claw 24dd46ab2c Fix imx host 2019-09-01 15:40:34 +01:00
death-claw 82f4d1bc6a v1.5.1 2019-08-24 19:23:49 +01:00
death-claw 819d844f23 Bug fixes and electron upgrade 2019-08-24 19:19:31 +01:00
death-claw ab4711ffef v1.5.0
- Display logged in user
- Add post details when clicking on main list items (Status, Post URL, Host)
- Add open download location on main list items menu
- Add support for multi-post threads (Show a menu to select posts to download)
- Add link to image from details list
2019-08-24 14:57:43 +01:00
death-claw f107acf376 Merge branch 'master' of https://github.com/death-claw/vripper-project into development 2019-08-16 11:50:24 +01:00
death-claw 43788a0f96 v1.4.10 2019-08-15 18:33:45 +01:00
death-claw 9ee8b90003 Fix image rename on windows 2019-08-15 18:30:58 +01:00
death-claw 54c9a21861 v1.4.9 2019-08-13 15:00:41 +01:00
death-claw fe3543a4ab Update Built-By to be generic 2019-08-13 14:56:19 +01:00
death-claw eeb24ae7c1 v1.4.8 2019-08-13 14:39:41 +01:00
death-claw 9b9c5ac5c8 Add option to force image ordering 2019-08-13 14:34:46 +01:00
death-claw bf2e8c4bb6 v1.4.7 2019-08-13 11:21:54 +01:00
death-claw 5d449fa4e5 Fixed a bug in image filename extensions 2019-08-13 11:07:11 +01:00
death-claw 35cd3c53e1 Implement thread parse with vr api 2019-08-06 20:03:13 +01:00
death-claw 13d1d134f6 INTERMEDIATE COMMIT 2019-08-06 18:24:20 +01:00
death-claw c8b76b2dfb v1.4.6
* Fixed a bug when creating image file names
* Remove unnecessary logs
* Fix data.json init
2019-08-06 16:44:38 +01:00
death-claw e3e9935e15 * Remove old data.json
* Switch to fixedDelay scheduler for speed calculation
2019-08-03 18:19:24 +01:00
death-claw 83b41763bd Next snapshot version 2019-08-03 18:17:44 +01:00
death-clawandGitHub ec479cb920 Update README.md 2019-08-03 17:02:15 +01:00
death-claw 4827a88ac4 Include a README.md 2019-08-03 16:26:19 +01:00
death-claw d4980ad6a3 v1.4.5
* Add download speed to status bar
* Add min width and height
2019-08-03 13:37:07 +01:00
death-claw f9fc8de3a5 v1.4.4 2019-08-01 22:04:27 +01:00
death-claw 9a9df9c8e9 * Implement start, stop
* Fix npm dependencies
* Enhance UI
* Refactor maven build
2019-08-01 21:18:04 +01:00
death-claw 46083b6c91 * Check response code when downloading host page
* Fix image name of ImgboxHost
* Add start and stop button in UI
2019-07-30 19:06:32 +01:00
death-claw 8abd8dbf9e v1.4.4-SNAPSHOT
* Better app management
* Imagetwist support
* Global state feature
2019-07-19 22:48:45 +01:00
death-claw 4a143c349f v1.4.3 2019-07-14 15:00:12 +01:00
death-claw 5813dfca3f * Update some messages
* Fix scrolling issue
2019-07-14 14:54:51 +01:00
death-claw 2faefba98e Update changelog 2019-07-14 14:35:25 +01:00
death-claw d2141d6c10 v1.4.2 2019-07-14 14:27:58 +01:00
death-claw 6b7da93562 * Fix layout issue in web mode 2019-07-14 14:23:38 +01:00
death-claw 0b3e4ee295 v1.4.1 2019-07-14 13:44:04 +01:00
death-claw 42fddde18c * Add borders
* Fix layout issues
* Update title bar font
2019-07-14 13:36:29 +01:00
death-claw dcbdaf8e41 Update version to 1.4.0 2019-07-14 09:45:12 +01:00
death-claw 62bfe72611 * Refactor remove rows mechanism
* Ignore the stdio on spawn node process
* Reset the title to default for ImageZillaHost
* Add option to remove all posts
* Fix bug when persisting state
* Remove the headless mode option (not needed anymore)
* Add confirmation on remove
* Fix websocket handler bug that causes creating more than one connection per client with the server
2019-07-14 09:11:07 +01:00
death-claw 6c8d3229f1 * Persist on interrupt before closing
* Add console logger back
2019-07-10 22:30:00 +01:00
death-claw fea9697817 Update version to 1.4.0-SNAPSHOT 2019-07-10 22:29:15 +01:00
death-claw 74ad8ce8ee Update icon.icns 2019-07-10 21:38:35 +01:00
death-claw df5aae8cf3 Update icon.png 2019-07-10 19:30:14 +01:00
death-claw cbf8da2723 Rename logo.png 2019-07-10 19:26:43 +01:00
death-claw 0d752fa9bd Add logo.png 2019-07-10 19:25:00 +01:00
death-claw b9c9b820ba Better support for icons 2019-07-10 18:57:23 +01:00
death-claw 402025fbda 1.4.0
### Changed
- Better error handling on startup
- Better support for linux AppImage
### Added
- Clear all completed
- Add clipboard support
2019-07-09 19:55:33 +01:00
death-claw 8d497947a3 v1.3.0-rc0
### Changed
- Change default setting for autostart false -> true
- Change default setting for max concurrent downloads 1 -> 4
### Added
- Desktop app built with electron
- Add the option to remove a post
2019-07-04 22:13:45 +01:00
death-claw e5f58e9079 v1.3.0
### Changed
- Change default setting for autostart false -> true
- Change default setting for max concurrent downloads 1 -> 4
### Added
- Desktop app built with electron
- Add the option to remove a post
2019-07-04 21:49:08 +01:00
death-claw d992cb2b92 Add changelog file 2019-06-23 20:21:34 +01:00
death-claw 721a61ec72 v1.2.0 2019-06-23 18:46:23 +01:00
death-claw 713fbebb51 * Add a shutdown button
* Browse to application on open
2019-06-23 18:43:54 +01:00
226 changed files with 19935 additions and 6996 deletions
+1
View File
@@ -2,4 +2,5 @@
/**/*/node_modules
/**/*/target
/**/*/build-dir
/**/*/java-runtime
.idea
+372
View File
@@ -0,0 +1,372 @@
# Changelog
## [2.12.0] - 2020-05-21
### Changed
- Use new user hash from the api
## [2.11.7] - 2020-05-08
### Changed
- Fix bug with paths creation
- Move Open Link button
- Rename rename all title
## [2.11.6] - 2020-05-04
### Changed
- PNG filenames are now correctly named
- Fix issue with special characters in post titles
## [2.11.5] - 2020-05-03
### Changed
- Reduce rows buffer size
## [2.11.4] - 2020-05-03
### Changed
- Code cleanup
- Dependencies update
## [2.11.3] - 2020-04-30
### Changed
- Source code restructure
- UI fixes and enhancements
### Added
- Add menu entry to rename a gallery to first alternative title
- Add menu on toolbar for massive rename to first alternative title
## [2.11.2] - 2020-04-26
### Changed
- Bug fixes
## [2.11.1] - 2020-04-25
### Changed
- Code source maintenance
### Added
- Added option to rename gallery
## [2.11.0] - 2020-03-29
### Changed
- Upgrade Electron to v8
- Upgrade Angular to v9
- App settings are now portable in a json file
- General code source maintenance
### Added
- Added Support for pixroute.com
- Added grab post title from thread option
## [2.10.8] - 2020-01-25
### Changed
- Fix app url
## [2.10.7] - 2020-01-25
### Changed
- Drop SockJs and switch to WebSocket
- Autoreconnect front to back
## [2.10.6] - 2020-01-19
### Changed
- Limit cache size
## [2.10.5] - 2020-01-18
### Changed
- Bug fixes
## [2.10.4] - 2020-01-18
### Changed
- Zero value for total max download will disable the limit
- Add system notification
- Bug fixes
## [2.10.3] - 2020-01-16
### Changed
- Some bug fixes
- Enhance download queue logic
- Clear cache button
- Fix the partial status
- Sanitize URLs with spaces
### Added
- Support for Postimg host
- Support for Imagevenue host
## [2.10.2] - 2019-12-29
### Changed
- Upgrade electron to v7
- Bug fix
## [2.10.1] - 2019-12-27
### Changed
- Bug fix
## [2.10.0] - 2019-12-27
### Changed
- Fix spring dependency bug
### Added
- Add support for imgspice
## [2.9.0] - 2019-12-27
### Changed
- Fix build issue
## [2.9.0] - 2019-12-27
### Changed
- Decrease timeout for fast fail
### Added
- Allow many hosts to run at the same time
- Add title to gallery
- Add global concurrent downloads
- Add counter badge in link collector
## [2.8.1] - 2019-12-24
### Changed
- Fix issue with path creation
## [2.8.0] - 2019-12-24
### Added
- Photo gallery feature
## [2.7.1] - 2019-12-21
### Added
- Add version to title bar
## [2.7.0] - 2019-12-21
### Changed
- Add missing icon
### Added
- Add support for pixxxels
## [2.6.0] - 2019-12-21
### Changed
- Disable download button when nothing selected in Link collector grab menu
- Better quality app icon
- Implement context menu on download tab
- Add stop remove and start button to context menu
- Link will not be removed automatically from link collector tab
- Some UI fixes
## [2.5.1] - 2019-12-09
### Changed
- Disable download button when nothing selected in Link collector grab menu
### Added
- Add hosts column in Link collector grab menu
## [2.5.0] - 2019-12-08
### Changed
- Change loading screen
- UI Fixes
- Fix bug with previews
### Added
- Add link collector feature
- Add support for multiple links at a time
## [2.4.1] - 2019-11-26
### Changed
- Increase attempts for establishing ws connection between front and back end
- Change default download folder to Home folder (installer), App folder (portable)
## [2.4.0] - 2019-11-23
### Changed
- Pimpandhost Host support
## [2.3.2] - 2019-11-23
### Changed
- Fix a bug with the scan component
## [2.3.1] - 2019-11-22
### Changed
- Fix connexion reset issue
- Fix Post Status when autostart option is selected
- Add stop all button
## [2.3.0] - 2019-11-21
### Changed
- UI enhancements and overhaul
- Stability fixes with HTTP connections
- MacOS official support
- Use local sockjs and material icons font
## [2.2.5] - 2019-11-09
### Changed
- Exclude thumbs download for imagezilla and pixhost
- Change retry on fail logic (may help avoid having download errors)
## [2.2.4] - 2019-10-05
### Added
- AppImage target for linux
## [2.2.3] - 2019-10-01
### Changed
- Strip libjvm.so for debian
## [2.2.2] - 2019-10-01
### Changed
- Update product name
## [2.2.1] - 2019-10-01
### Changed
- Update dependency list for deb package
## [2.2.0] - 2019-10-01
### Added
- Embedd JRE within the app
### Changed
- Fix 'Start' on pending items
- Upgrade to Java 11
## [2.1.0] - 2019-09-30
### Added
- Add a create a subfolder per thread option
## [2.0.4] - 2019-09-27
### Changed
- Fix some issues with ImxHost
## [2.0.3] - 2019-09-23
### Changed
- Update deb dependencies
## [2.0.2] - 2019-09-23
### Changed
- Add portable mode
## [2.0.1] - 2019-09-22
### Changed
- Change app name
## [2.0.0] - 2019-09-22
### Added
- Add sub folder option
- Add clear finished option
### Changed
- UI enhancements
- Bug fixes
- Change data and log paths
## [1.6.5] - 2019-09-18
### Changed
- electron update
## [1.6.4] - 2019-09-18
### Changed
- Change menu item name
## [1.6.3] - 2019-09-18
### Changed
- Better multithread management
- Fix partial state UI
## [1.6.2] - 2019-09-17
### Changed
- Rework UI colors
- Fix scan input bug
## [1.6.1] - 2019-09-16
### Changed
- Rework UI
- Fix clipboard monitoring
## [1.6.0] - 2019-09-15
### Changed
- Rework the UI
- Add a dark theme
- Fix the force ordering bug
- Other bug fixes
## [1.5.2] - 2019-09-01
### Added
- imx.to host fix
## [1.5.1] - 2019-08-24
### Added
- Bug fixes
## [1.5.0] - 2019-08-24
### Added
- Display logged in user
- Add post details when clicking on main list items (Status, Post URL, Host)
- Add open download location on main list items menu
- Add support for multi-post threads (Show a menu to select posts to download)
- Add link to image from details list
## [1.4.10] - 2019-08-15
### Changed
- Fix a rename issue on windows
## [1.4.9] - 2019-08-13
### Changed
- Update Built-By to be generic
## [1.4.8] - 2019-08-13
### Changed
- Add option to force image ordering
## [1.4.7] - 2019-08-13
### Changed
- Fixed a bug in image filename extensions
## [1.4.6] - 2019-08-06
### Changed
- Fixed a bug when creating image file names
- Remove unnecessary logs
- Fix data.json init
## [1.4.5] - 2019-08-03
### Changed
- Add min width and height for electron app
### Added
- Add download speed to status bar
## [1.4.4] - 2019-08-01
### Changed
- Fix names for ImgboxHost
- Enhance UI
- Minor fixes
### Added
- Add start and stop button
## [1.4.3] - 2019-07-14
### Changed
- Update some messages
- Fix scrolling issue
## [1.4.2] - 2019-07-14
### Changed
- Fix layout issue in web mode
## [1.4.1] - 2019-07-14
### Changed
- Change title's font
### Added
- Add borders
## [1.4.0] - 2019-07-14
### Changed
- Better error handling on startup
- Better support for linux AppImage
### Added
- Clear all completed
- Add clipboard support
- Add option to remove all posts
- Add confirmation on remove
## [1.3.0-rc0] - 2019-07-04
### Changed
- Change default setting for autostart false -> true
- Change default setting for max concurrent downloads 1 -> 4
### Added
- Desktop app built with electron
- Add the option to remove a post
## [1.2.0] - 2019-06-23
### Added
- Add a shutdown button to gracefully shutdown the app
- Open and redirect the browser to the app address on startup
- Add the option to run the app in headless mode (-Djava.awt.headless=true)
## [1.1.1] - 2019-06-22
### Changed
- Fix a stability issue with progress updates when the app is runninh for a long time
## [1.0.0] - 2019-06-22
### Added
- Add real time communication for progress updates via websocket (SockJS)
- Add settings for download path, max concurrent download, enable/disable integration with vipergirls
- Add integration with vipergitls.to (possibility to auto leave thanks after grab post)
- Add support for acidimg.cc, imagezilla.net, imgbox.com, imx.to, pixhost.to, turboimagehost.com
+24
View File
@@ -0,0 +1,24 @@
# Viper Ripper!
This is my spin for a cross platform gallery ripper app for [vipergirls](https://vipergirls.to) website.
The purpose of this project is to build a robust and clean application to conveniently download photo galleries using modern web technologies, Java + Spring boot for the back end and angular + electron for the front end.
## How to build
You need a recent version of maven 3.6.1+.
The application support 2 build modes:
- Desktop app: Self contained app, built with electron includes Java runtimes.
- Server app: Depends on Java runtimes, you need a web browser to access the app UI.
Most people will be interested only on the desktop app, however if you have a nas or a server, the server app is there for you.
To build the server app:
mvn clean install -DskipTests
To build the desktop app:
mvn clean install -Pelectron -DskipTests
Maven will automatically handle front end compilation. However, for development, you will need to install a recent version of nodejs on your system.
[![Donate with PayPal](https://raw.githubusercontent.com/stefan-niedermann/paypal-donate-button/master/paypal-donate-button.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SC7M5LNWZ528Q)
+2 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>1.1.1</version>
<version>2.12.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
@@ -15,5 +15,6 @@
<modules>
<module>vripper-server</module>
<module>vripper-ui</module>
<module>vripper-electron</module>
</modules>
</project>
+47
View File
@@ -0,0 +1,47 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
# profiling files
chrome-profiler-events.json
speed-measure-plugin.json
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
# System Files
.DS_Store
Thumbs.db
dist
build/vripper-ui
+7
View File
@@ -0,0 +1,7 @@
{
"esversion": 6,
"node": true,
"globals": {
"BigInt": false
}
}
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

+157
View File
@@ -0,0 +1,157 @@
require('v8-compile-cache');
const { app, BrowserWindow } = require("electron");
const path = require("path");
const url = require("url");
const getPort = require("get-port");
const { spawn } = require("child_process");
const { ipcMain } = require("electron");
const { dialog } = require("electron");
const axios = require('axios');
const appDir = process.env.APPDIR;
let win;
let vripperServer;
let serverPort;
const maxTerminationAttemps = 5;
let terminationAttemps = 0;
let terminationInteval;
let terminated = false;
process.on("uncaughtException", err => {
dialog.showErrorBox(err.message, err.stack);
process.exit(1);
});
function createWindow() {
if (process.platform === 'win32') {
app.setAppUserModelId("tn.mnlr.vripper");
}
let icon;
if(process.platform === "win32") {
icon = __dirname + '/icon.ico';
} else {
icon = __dirname + '/icon.png';
}
win = new BrowserWindow({
width: 1024,
height: 800,
minWidth: 800,
minHeight: 600,
webPreferences: {
nodeIntegration: true
},
icon: icon
});
win.removeMenu();
win.setMenu(null);
win.setMenuBarVisibility(false);
win.loadURL(
url.format({
pathname: path.join(__dirname, `vripper-ui/index.html`),
protocol: "file:",
slashes: true
})
);
// win.webContents.openDevTools();
win.on("closed", () => {
win = null;
});
}
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
getPort().then(port => {
serverPort = port;
ipcMain.on("get-port", event => {
event.reply("port", port);
});
let javaBinPath;
if(appDir !== undefined) {
javaBinPath = path.join(appDir, "java-runtime/bin/java");
} else {
if(process.platform === 'darwin') {
javaBinPath = path.join(app.getPath('exe'), "../../java-runtime/bin/java");
} else {
javaBinPath = path.join(app.getPath('exe'), "../java-runtime/bin/java");
}
}
let jarPath;
if(appDir !== undefined) {
jarPath = path.join(appDir, "bin/vripper-server.jar");
} else {
if(process.platform === 'darwin') {
jarPath = path.join(app.getPath('exe'), "../../bin/vripper-server.jar");
} else {
jarPath = path.join(app.getPath('exe'), "../bin/vripper-server.jar");
}
}
vripperServer = spawn(javaBinPath, [
"-Xms256m",
"-Dvripper.server.port=" + port,
"-jar",
jarPath
], {
stdio: 'ignore'
});
vripperServer.on('exit', (code, signal) => {
console.log(`vripper server terminated, code = ${code}, signal = ${signal}`);
terminated = true;
app.quit();
});
});
app.on("second-instance", (event, commandLine, workingDirectory) => {
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
}
});
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
axios.post('http://localhost:' + serverPort + '/actuator/shutdown', {}, {
headers: { 'content-type': 'application/json' },
}).then((response) => {
terminationInteval= setInterval(() => {
terminationAttemps++;
if(terminated) {
console.log('viper server terminated');
clearInterval(terminationInteval);
app.quit();
} else if(terminationAttemps > maxTerminationAttemps) {
console.log('viper server is not terminated');
console.log('Proceed to kill');
vripperServer.kill('SIGKILL');
clearInterval(terminationInteval);
app.quit();
}
}, 1000);
})
.catch((error) => {
// Terminate immediately
console.log(error);
vripperServer.kill('SIGKILL');
terminated = true;
app.quit();
});
}
});
app.on("activate", () => {
if (win === null) {
createWindow();
}
});
}
+2586
View File
File diff suppressed because it is too large Load Diff
+85
View File
@@ -0,0 +1,85 @@
{
"name": "vripper-electron",
"version": "2.12.0",
"description": "A ripper for vipergirls.to built using web technolgies",
"main": "main.js",
"author": "death-claw <53543762+death-claw@users.noreply.github.com>",
"homepage": "https://github.com/death-claw/vripper-project",
"license": "ISC",
"build": {
"appId": "tn.mnlr.vripper",
"productName": "VRipper",
"files": [
"**/*",
"!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}",
"!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
"!**/node_modules/*.d.ts",
"!**/node_modules/.bin",
"!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}",
"!.editorconfig",
"!**/._*",
"!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,.gitignore,.gitattributes}",
"!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}",
"!**/{appveyor.yml,.travis.yml,circle.yml}",
"!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}",
{
"from": "./build/",
"to": "."
}
],
"extraFiles": [
{
"from": "../vripper-server/target/vripper-server-${version}-electron.jar",
"to": "bin/vripper-server.jar"
},
{
"from": "java-runtime",
"to": "java-runtime"
}
],
"win": {
"icon": "icon.ico",
"target": [
"nsis"
]
},
"nsis": {
"createDesktopShortcut": "always",
"oneClick": false,
"perMachine": false
},
"linux": {
"synopsis": "vipergirls.to ripper",
"category": "Utility",
"packageCategory": "Utility",
"icon": "icons",
"target": [
"AppImage"
]
},
"mac": {
"category": "public.app-category.utilities",
"target": [
"dmg"
],
"icon": "icon.icns"
}
},
"scripts": {
"start": "electron .",
"dist": "node pre-build.js && electron-builder"
},
"devDependencies": {
"electron": "8.2.4",
"electron-builder": "22.6.0"
},
"dependencies": {
"axios": "^0.19.0",
"cheerio": "^1.0.0-rc.3",
"copy-dir": "^1.1.0",
"electron-context-menu": "^0.13.0",
"get-port": "^5.0.0",
"rimraf": "^2.6.3",
"v8-compile-cache": "^2.1.0"
}
}
+77
View File
@@ -0,0 +1,77 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>2.12.0</version>
</parent>
<artifactId>vripper-electron</artifactId>
<name>vripper-electron</name>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${buildClassifier}</classifier>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>electron</id>
<properties>
<buildClassifier>electron</buildClassifier>
</properties>
<dependencies>
<dependency>
<groupId>tn.mnlr</groupId>
<artifactId>vripper-server</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<classifier>${buildClassifier}</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<nodeVersion>v12.2.0</nodeVersion>
<npmVersion>6.9.0</npmVersion>
<workingDirectory>build-dir</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run dist</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
+25
View File
@@ -0,0 +1,25 @@
const cheerio = require('cheerio');
const fs = require('fs');
const rimraf = require("rimraf");
const copydir = require("copy-dir");
const { execSync } = require("child_process");
rimraf.sync('./build/vripper-ui');
copydir.sync('../vripper-ui/dist/vripper-ui', './build/vripper-ui', {});
const index = fs.readFileSync('./build/vripper-ui/index.html');
const $ = cheerio.load(index);
$('body').prepend(`<script>require('../renderer.js')</script>`);
fs.writeFileSync('./build/vripper-ui/index.html', $.html());
console.log('Building runtime environment');
rimraf.sync('java-runtime');
execSync('jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules java.base,java.desktop,java.instrument,java.management,java.naming,java.prefs,java.rmi,java.scripting,java.security.jgss,java.sql,jdk.httpserver,jdk.unsupported,jdk.crypto.ec --output java-runtime');
if(process.platform === 'linux') {
console.log('Stripping libjvm.so');
execSync('strip -p --strip-unneeded java-runtime/lib/server/libjvm.so');
}
+3
View File
@@ -0,0 +1,3 @@
console.log("renderer intialized");
const contextMenu = require("electron-context-menu");
contextMenu({});
File diff suppressed because one or more lines are too long
+70 -17
View File
@@ -5,14 +5,14 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>1.1.1</version>
<version>2.12.0</version>
</parent>
<artifactId>vripper-server</artifactId>
<name>vripper-server</name>
<description>vripper-server</description>
<properties>
<java.version>1.8</java.version>
<java.version>11</java.version>
</properties>
<dependencies>
@@ -28,7 +28,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@@ -64,38 +67,44 @@
<artifactId>failsafe</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>tn.mnlr</groupId>
<artifactId>vripper-ui</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<classifier>${buildClassifier}</classifier>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}-${git.commit.id.describe-short}</finalName>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${buildClassifier}</classifier>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<id>repackage</id>
<goals>
<goal>copy-resources</goal>
<goal>repackage</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/static</outputDirectory>
<resources>
<resource>
<directory>${project.parent.basedir}/vripper-ui/dist/vripper-ui/
</directory>
</resource>
</resources>
<classifier>${buildClassifier}</classifier>
</configuration>
</execution>
</executions>
@@ -130,6 +139,7 @@
<archive>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Built-By>${user.name}</Built-By>
</manifestEntries>
<manifestSections>
<manifestSection>
@@ -149,4 +159,47 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>web</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<buildClassifier>web</buildClassifier>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/static</outputDirectory>
<resources>
<resource>
<directory>${project.parent.basedir}/vripper-ui/dist/vripper-ui/
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>electron</id>
<properties>
<buildClassifier>electron</buildClassifier>
</properties>
</profile>
</profiles>
</project>
@@ -0,0 +1,24 @@
package tn.mnlr.vripper;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import tn.mnlr.vripper.services.PersistenceService;
@Component
public class EventListenerBean {
@Autowired
private PersistenceService persistenceService;
@Getter
private static boolean init = false;
@EventListener
public void onApplicationEvent(ContextRefreshedEvent event) {
init = true;
persistenceService.restore();
}
}
@@ -1,8 +1,11 @@
package tn.mnlr.vripper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
import java.util.Map;
@@ -10,26 +13,30 @@ import java.util.Map;
@Component
public class SpringContext implements ApplicationContextAware {
private static ApplicationContext context;
private static final Logger logger = LoggerFactory.getLogger(SpringContext.class);
/**
* Returns the Spring managed bean instance of the given class type (if it exists).
* Returns null otherwise.
* @param beanClass
* @return
*/
public static <T extends Object> T getBean(Class<T> beanClass) {
private static ConfigurableApplicationContext context;
public static <T> T getBean(Class<T> beanClass) {
return context.getBean(beanClass);
}
public static <T extends Object> Map<String, T> getBeansOfType(Class<T> beanClass) {
public static <T> Map<String, T> getBeansOfType(Class<T> beanClass) {
return context.getBeansOfType(beanClass);
}
public static void close() {
logger.info("Application terminating...");
if (context != null) {
context.close();
}
}
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
// store ApplicationContext reference to access required beans later on
SpringContext.context = context;
SpringContext.context = ((ConfigurableApplicationContext) context);
}
}
@@ -1,55 +1,31 @@
package tn.mnlr.vripper;
import net.jodah.failsafe.RetryPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;
import tn.mnlr.vripper.exception.VripperException;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.services.PersistenceService;
import tn.mnlr.vripper.services.VipergirlsAuthService;
import java.io.File;
import java.util.prefs.Preferences;
import java.time.temporal.ChronoUnit;
@SpringBootApplication
public class VripperApplication {
private static final Logger logger = LoggerFactory.getLogger(VripperApplication.class);
public static final RetryPolicy<Object> retryPolicy = new RetryPolicy<>()
.handleIf(e -> !(e instanceof InterruptedException))
.withDelay(1, 3, ChronoUnit.SECONDS)
.withMaxAttempts(5)
.abortOn(InterruptedException.class)
.onFailedAttempt(e -> logger.warn(String.format("#%d tries failed", e.getAttemptCount()), e.getLastFailure()));
public static final String dataPath = System.getProperty("vripper.datapath", ".") + File.separator + "data.json";
public static void main(String[] args) {
SpringApplication.run(VripperApplication.class, args);
}
@Component
public class AppCommandRunner implements CommandLineRunner {
@Autowired
private VipergirlsAuthService authService;
@Autowired
private PersistenceService persistenceService;
@Autowired
private AppSettingsService appSettingsService;
@Override
public void run(String... args) {
persistenceService.restore();
appSettingsService.restore();
try {
authService.authenticate();
} catch (VripperException e) {
logger.error("Cannot authenticate user with ViperGirls", e);
}
public static void main(String[] args) {
try {
Runtime.getRuntime().addShutdownHook(new Thread(SpringContext::close));
SpringApplication.run(VripperApplication.class, args);
} catch (Exception e) {
logger.error("Failed to run the application", e);
}
}
}
@@ -3,51 +3,53 @@ package tn.mnlr.vripper.entities;
import io.reactivex.disposables.Disposable;
import io.reactivex.processors.BehaviorProcessor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.services.AppStateService;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
@Getter
@NoArgsConstructor
public class Image {
@Setter
private AppStateService appStateService;
private Disposable subscription;
private static final Logger logger = LoggerFactory.getLogger(Image.class);
private final AppStateService appStateService;
private final String type = "img";
private String postId;
private String postName;
private Host host;
private String url;
private int index;
private AtomicLong current = new AtomicLong(0);
private Status status;
private BehaviorProcessor<Image> imageStateProcessor;
@Setter
private long total = 0;
private Status status;
private BehaviorProcessor<Image> imageStateProcessor;
private Disposable subscription;
public Image(String url, String postId, String postName, Host host, AppStateService appStateService) {
private Image() {
this.appStateService = SpringContext.getBean(AppStateService.class);
}
public Image(String url, String postId, String postName, Host host, int index) throws PostParseException {
this();
this.url = url;
this.postId = postId;
this.postName = postName;
this.host = host;
this.appStateService = appStateService;
status = Status.PENDING;
imageStateProcessor = BehaviorProcessor.create();
appStateService.getCurrentImages().put(this.url, this);
appStateService.getLiveImageUpdates().onNext(this);
init();
this.index = index;
status = Status.STOPPED;
if (!appStateService.newImage(this)) {
throw new PostParseException("Image already loaded");
}
}
public void setStatus(Status status) {
@@ -60,21 +62,25 @@ public class Image {
}
public void init() {
cleanup();
imageStateProcessor = BehaviorProcessor.create();
subscription = imageStateProcessor
.onBackpressureBuffer()
.doOnNext(appStateService::imageUpdated)
.subscribe();
current.set(0);
status = Status.STOPPED;
imageStateProcessor.onNext(this);
}
public void cleanup() {
if (imageStateProcessor != null) {
imageStateProcessor.onComplete();
}
if (subscription != null) {
subscription.dispose();
}
imageStateProcessor = BehaviorProcessor.create();
subscription = imageStateProcessor
.onBackpressureLatest()
.doOnNext(appStateService::onImageUpdate)
.subscribe();
current.set(0);
status = Status.PENDING;
imageStateProcessor.onNext(this);
}
public void setCurrent(int current) {
@@ -88,7 +94,7 @@ public class Image {
}
private void update() {
if(imageStateProcessor == null) {
if (imageStateProcessor == null) {
return;
}
imageStateProcessor.onNext(this);
@@ -1,23 +1,29 @@
package tn.mnlr.vripper.entities;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.services.AppStateService;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Getter
@ToString
@NoArgsConstructor
public class Post {
@Setter
private AppStateService appStateService;
public enum METADATA {
PREVIEWS, RESOLVED_NAME, POSTED_BY, THANKED
}
private final AppStateService appStateService;
private Status status;
@@ -25,40 +31,80 @@ public class Post {
private String postId;
private String threadTitle;
private String threadId;
private String title;
private String url;
private List<Image> images;
private Map<String, String> metadata;
private Map<String, Object> metadata;
private AtomicInteger done = new AtomicInteger(0);
private final AtomicInteger done = new AtomicInteger(0);
private int total;
public Post(String title, String url, List<Image> images, Map<String, String> metadata, String postId, AppStateService appStateService) {
private Set<String> hosts;
private boolean removed = false;
private String forum;
private String securityToken;
@Setter
private String postFolderName;
private Post() {
this.appStateService = SpringContext.getBean(AppStateService.class);
}
public Post(String title, String url, List<Image> images, Map<String, Object> metadata, String postId, String threadId, String threadTitle, String forum, String securityToken) throws PostParseException {
this();
this.title = title;
this.url = url;
this.images = images;
this.metadata = metadata;
this.postId = postId;
this.appStateService = appStateService;
this.forum = forum;
this.threadId = threadId;
this.threadTitle = threadTitle;
this.securityToken = securityToken;
this.hosts = this.images.stream().map(Image::getHost).map(Host::getHost).collect(Collectors.toSet());
total = images.size();
status = Status.PENDING;
appStateService.getCurrentPosts().put(postId, this);
appStateService.getLivePostsState().onNext(this);
status = Status.STOPPED;
if (!this.appStateService.newPost(this)) {
throw new PostParseException("Post already loaded");
}
}
public void setTitle(String title) {
this.title = title;
updateNotification();
}
public void setRemoved(boolean removed) {
this.removed = removed;
updateNotification();
}
public void increase() {
done.incrementAndGet();
appStateService.getLivePostsState().onNext(this);
updateNotification();
}
public void setStatus(Status status) {
this.status = status;
updateNotification();
}
private void updateNotification() {
if (appStateService != null) {
appStateService.getLivePostsState().onNext(this);
appStateService.postUpdated(this);
}
}
@@ -5,10 +5,14 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.reactivex.disposables.Disposable;
import io.reactivex.processors.BehaviorProcessor;
import lombok.Getter;
import lombok.Setter;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.services.AppStateService;
@Getter
@Setter
public abstract class ImagePersistanceMixin {
@JsonSerialize(converter = HostToString.class)
@@ -1,8 +1,12 @@
package tn.mnlr.vripper.entities.mixin.persistance;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import tn.mnlr.vripper.services.AppStateService;
@Getter
@Setter
public abstract class PostPersistanceMixin {
@JsonIgnore
@@ -10,4 +14,8 @@ public abstract class PostPersistanceMixin {
@JsonIgnore
private AppStateService appStateService;
@JsonIgnore
private boolean removed;
}
@@ -3,10 +3,14 @@ package tn.mnlr.vripper.entities.mixin.ui;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.reactivex.disposables.Disposable;
import io.reactivex.processors.BehaviorProcessor;
import lombok.Getter;
import lombok.Setter;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.services.AppStateService;
@Getter
@Setter
public abstract class ImageUIMixin {
@JsonIgnore
@@ -1,20 +1,20 @@
package tn.mnlr.vripper.entities.mixin.ui;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.services.AppStateService;
import java.util.List;
import java.util.Map;
@Getter
@Setter
public abstract class PostUIMixin {
@JsonIgnore
private List<Image> images;
@JsonIgnore
private Map<String, String> metadata;
@JsonIgnore
private AppStateService appStateService;
}
@@ -6,7 +6,7 @@ public class DownloadException extends Exception {
super(message);
}
public DownloadException(Exception e) {
public DownloadException(Throwable e) {
super(e);
}
}
@@ -1,7 +1,7 @@
package tn.mnlr.vripper.exception;
public class HostException extends Exception {
public HostException(Exception e) {
public HostException(Throwable e) {
super(e);
}
@@ -9,7 +9,7 @@ public class HostException extends Exception {
super(message);
}
public HostException(String message, Exception e) {
public HostException(String message, Throwable e) {
super(message,e);
}
}
@@ -2,7 +2,7 @@ package tn.mnlr.vripper.exception;
public class HtmlProcessorException extends Exception {
public HtmlProcessorException(Exception e) {
public HtmlProcessorException(Throwable e) {
super(e);
}
}
@@ -1,7 +1,16 @@
package tn.mnlr.vripper.exception;
public class PostParseException extends Exception {
public PostParseException(Exception e) {
public PostParseException(String message) {
super(message);
}
public PostParseException(String message, Throwable e) {
super(message, e);
}
public PostParseException(Throwable e) {
super(e);
}
}
@@ -5,7 +5,7 @@ public class VripperException extends Exception {
super(message);
}
public VripperException(Exception e) {
public VripperException(Throwable e) {
super(e);
}
}
@@ -1,7 +1,7 @@
package tn.mnlr.vripper.exception;
public class XpathException extends Exception {
public XpathException(Exception e) {
public XpathException(Throwable e) {
super(e);
}
}
@@ -4,8 +4,8 @@ import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
@@ -29,31 +29,40 @@ public class AcidimgHost extends Host {
private static final String host = "acidimg.cc";
private static final String CONTINUE_BUTTON_XPATH = "//input[@id='continuebutton']";
public static final String IMG_XPATH = "//img[@class='centred']";
private static final String IMG_XPATH = "//img[@class='centred']";
@Autowired
private ConnectionManager cm;
public AcidimgHost() {
super();
}
@Override
protected String getHost() {
public String getHost() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData) throws HostException {
public String getLookup() {
return host;
}
Document doc = getDocument(url);
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Node contDiv;
try {
logger.info(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
contDiv = xpathService.getAsNode(doc, CONTINUE_BUTTON_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
if (contDiv != null) {
logger.info(String.format("Click button found for %s", url));
logger.debug(String.format("Click button found for %s", url));
HttpClient client = cm.getClient().build();
HttpPost httpPost = cm.buildHttpPost(url);
httpPost.addHeader("Referer", url);
@@ -65,9 +74,9 @@ public class AcidimgHost extends Host {
throw new HostException(e);
}
logger.info(String.format("Requesting %s", httpPost));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpPost)) {
logger.info(String.format("Cleaning response for %s", httpPost));
logger.debug(String.format("Requesting %s", httpPost));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpPost, context)) {
logger.debug(String.format("Cleaning response for %s", httpPost));
doc = htmlProcessorService.clean(EntityUtils.toString(response.getEntity()));
EntityUtils.consumeQuietly(response.getEntity());
} catch (Exception e) {
@@ -77,18 +86,18 @@ public class AcidimgHost extends Host {
Node imgNode;
try {
logger.info(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
if(imgNode == null) {
if (imgNode == null) {
throw new HostException("Cannot find the image node");
}
try {
logger.info(String.format("Resolving name and image url for %s", url));
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
@@ -1,29 +1,39 @@
package tn.mnlr.vripper.host;
import lombok.Getter;
import org.apache.http.Header;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.HtmlProcessorException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
import tn.mnlr.vripper.services.HtmlProcessorService;
import tn.mnlr.vripper.services.XpathService;
import tn.mnlr.vripper.services.*;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Iterator;
import java.util.Objects;
@Service
abstract public class Host {
@@ -41,118 +51,180 @@ abstract public class Host {
@Autowired
private AppSettingsService appSettingsService;
@Autowired
private AppStateService appStateService;
@Autowired
private ConnectionManager cm;
abstract protected String getHost();
@Autowired
private DownloadSpeedService downloadSpeedService;
@Autowired
private PathService pathService;
@Autowired
private AppStateExchange appStateExchange;
@Autowired
private VipergirlsAuthService authService;
protected Host() {
public boolean isSupported(String url) {
return url.contains(getHost());
}
public void download(Image image, ImageFileData imageFileData) throws DownloadException, InterruptedException {
abstract public String getHost();
abstract public String getLookup();
public boolean isSupported(String url) {
return url.contains(getLookup());
}
public void download(final Post post, final Image image, final ImageFileData imageFileData) throws DownloadException, InterruptedException {
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(new BasicCookieStore());
try {
File destinationFolder;
synchronized (appStateExchange.getPost(post.getPostId())) {
if (post.getPostFolderName() == null) {
pathService.createDefaultPostFolder(post);
}
destinationFolder = pathService.getDownloadDestinationFolder(post);
authService.leaveThanks(post);
}
appStateService.postDownloadingUpdate(image.getPostId());
imageFileData.setPageUrl(image.getUrl());
/**
/*
* HOST SPECIFIC
*/
logger.info(String.format("Getting image url and name from %s using %s", image.getUrl(), this.getHost()));
setNameAndUrl(image.getUrl(), imageFileData);
logger.info(String.format("Resolved name for %s: %s", image.getUrl(), imageFileData.getImageName()));
logger.info(String.format("Resolved image url for %s: %s", image.getUrl(), imageFileData.getImageUrl()));
logger.debug(String.format("Getting image url and name from %s using %s", image.getUrl(), this.getHost()));
setNameAndUrl(image.getUrl(), imageFileData, context);
logger.debug(String.format("Resolved name for %s: %s", image.getUrl(), imageFileData.getImageName()));
logger.debug(String.format("Resolved image url for %s: %s", image.getUrl(), imageFileData.getImageUrl()));
logger.info(String.format("Building image request for %s", image.getUrl()));
logger.debug(String.format("Building image request for %s", image.getUrl()));
setImageRequest(imageFileData);
/**
/*
* END HOST SPECIFIC
*/
if(!imageFileData.getImageName().toLowerCase().endsWith(".jpg")) {
imageFileData.setImageName(imageFileData.getImageName() + ".jpg");
}
File destinationFolder = new File(appSettingsService.getDownloadPath(), sanitize(image.getPostName()));
logger.info(String.format("Saving to %s", destinationFolder.getPath()));
if (!destinationFolder.exists()) {
logger.info(String.format("Creating %s", destinationFolder.getPath()));
destinationFolder.mkdirs();
} else {
logger.warn(String.format("%s already exists, the file will be overridden", destinationFolder.getPath()));
}
String formatImageFileName = pathService.formatImageFileName(imageFileData.getImageName());
logger.debug(String.format("Sanitizing image name from %s to %s", imageFileData.getImageName(), formatImageFileName));
imageFileData.setImageName(formatImageFileName);
logger.debug(String.format("Saving to %s", destinationFolder.getPath()));
HttpClient client = cm.getClient().build();
logger.info(String.format("Downloading %s", imageFileData.getImageUrl()));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(imageFileData.getImageRequest())) {
logger.debug(String.format("Downloading %s", imageFileData.getImageUrl()));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(imageFileData.getImageRequest(), context)) {
if(response.getStatusLine().getStatusCode() / 100 != 2) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
EntityUtils.consumeQuietly(response.getEntity());
throw new DownloadException(String.format("Server returned code %d", response.getStatusLine().getStatusCode()));
}
try (
InputStream downloadStream = response.getEntity().getContent();
FileOutputStream fos = new FileOutputStream(destinationFolder.getPath() + File.separator + imageFileData.getImageName())
) {
File outputFile = new File(destinationFolder.getPath() + File.separator + String.format("%03d_", image.getIndex()) + imageFileData.getImageName() + ".tmp");
try (InputStream downloadStream = response.getEntity().getContent(); FileOutputStream fos = new FileOutputStream(outputFile)) {
image.setTotal(response.getEntity().getContentLength());
logger.info(String.format("%s length is %d", imageFileData.getImageUrl(), image.getTotal()));
logger.info(String.format("Starting data transfer for %s", imageFileData.getImageUrl()));
logger.debug(String.format("%s length is %d", imageFileData.getImageUrl(), image.getTotal()));
logger.debug(String.format("Starting data transfer for %s", imageFileData.getImageUrl()));
byte[] buffer = new byte[READ_BUFFER_SIZE];
int read;
while ((read = downloadStream.read(buffer, 0, READ_BUFFER_SIZE)) != -1) {
fos.write(buffer, 0, read);
image.increase(read);
downloadSpeedService.increase(read);
}
fos.flush();
EntityUtils.consumeQuietly(response.getEntity());
}
File finalName = checkImageTypeAndRename(post, outputFile, imageFileData.getImageName(), image.getIndex());
imageFileData.setFileName(finalName.getName());
}
} catch (Exception e) {
if(Thread.interrupted()) {
if (Thread.interrupted()) {
throw new InterruptedException("Download was interrupted");
}
throw new DownloadException(e);
}
}
/**
* Just for testing, you may ignore
* @throws Exception
*/
private void randomFail() throws Exception {
Random random = new Random();
int i = random.nextInt(100);
if (i < 50) {
throw new Exception("Purpose error");
private File checkImageTypeAndRename(Post post, File outputFile, String imageName, int index) throws HostException {
try (ImageInputStream iis = ImageIO.createImageInputStream(outputFile)) {
Iterator<ImageReader> it = ImageIO.getImageReaders(iis);
if (!it.hasNext()) {
throw new HostException("Image file is not recognized!");
}
ImageReader reader = it.next();
if (reader.getFormatName().toUpperCase().equals("JPEG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_jpg") && !imageNameLC.endsWith("_jpeg")) {
imageName += ".jpg";
} else {
String toReplace = null;
if (imageNameLC.endsWith("_jpg")) {
toReplace = "_jpg";
} else if (imageNameLC.endsWith("_jpeg")) {
toReplace = "_jpeg";
}
if (toReplace != null) {
imageName = imageName.substring(0, imageName.length() - toReplace.length()) + ".jpg";
}
}
} else if (reader.getFormatName().toUpperCase().equals("PNG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_png")) {
imageName += ".png";
} else {
String toReplace = null;
if (imageNameLC.endsWith("_png")) {
toReplace = "_png";
}
if (toReplace != null) {
imageName = imageName.substring(0, imageName.length() - toReplace.length()) + ".png";
}
}
}
} catch (Exception e) {
throw new HostException("Failed to guess image format", e);
}
try {
File downloadDestinationFolder = pathService.getDownloadDestinationFolder(post);
File outImage = new File(downloadDestinationFolder, (appSettingsService.getSettings().getForceOrder() ? String.format("%03d_", index) : "") + imageName);
if (outImage.exists() && outImage.delete()) {
logger.debug(String.format("%s is deleted", outImage.toString()));
}
return Files.move(outputFile.toPath(), outImage.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile();
} catch (Exception e) {
throw new HostException("Failed to rename the image", e);
}
}
protected final String sanitize(final String folderName) {
String sanitizedFolderName = folderName.replaceAll("\\.|\\\\|/|\\||:|\\?|\\*|\"|<|>|\\p{Cntrl}", "_");
logger.debug(String.format("%s sanitized to %s", folderName, sanitizedFolderName));
return sanitizedFolderName;
}
protected final String getDefaultImageName(final String imgUrl) {
String imageTitle = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
final String getDefaultImageName(final String imgUrl) {
String imageTitle = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
logger.debug(String.format("Extracting name from url %s: %s", imgUrl, imageTitle));
return imgUrl;
}
protected final Document getDocument(final String url) throws HostException {
final Response getResponse(final String url, final HttpClientContext context) throws HostException {
String basePage;
HttpClient client = cm.getClient().build();
HttpGet httpGet = cm.buildHttpGet(url);
logger.info(String.format("Requesting %s", url));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpGet)) {
Header[] headers;
logger.debug(String.format("Requesting %s", url));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpGet, context)) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new HostException(String.format("Unexpected response code: %d", response.getStatusLine().getStatusCode()));
}
headers = response.getAllHeaders();
basePage = EntityUtils.toString(response.getEntity());
logger.debug(String.format("%s response: %n%s", url, basePage));
EntityUtils.consumeQuietly(response.getEntity());
@@ -161,18 +233,62 @@ abstract public class Host {
}
try {
logger.info(String.format("Cleaning %s response", url));
return htmlProcessorService.clean(basePage);
logger.debug(String.format("Cleaning %s response", url));
return new Response(htmlProcessorService.clean(basePage), headers);
} catch (HtmlProcessorException e) {
throw new HostException(e);
}
}
protected void setImageRequest(final ImageFileData imageFileData) {
protected String appendUri(String uri, String appendQuery) throws URISyntaxException {
URI oldUri = new URI(uri);
String newQuery = oldUri.getQuery();
if (newQuery == null) {
newQuery = appendQuery;
} else {
newQuery += "&" + appendQuery;
}
return new URI(oldUri.getScheme(), oldUri.getAuthority(),
oldUri.getPath(), newQuery, oldUri.getFragment()).toString();
}
private void setImageRequest(final ImageFileData imageFileData) {
HttpGet httpGet = cm.buildHttpGet(imageFileData.getImageUrl());
httpGet.addHeader("Referer", imageFileData.getPageUrl());
imageFileData.setImageRequest(httpGet);
}
protected abstract void setNameAndUrl(final String url, final ImageFileData imageFileData) throws HostException;
protected abstract void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Host host = (Host) o;
return Objects.equals(getHost(), host.getHost());
}
@Override
public int hashCode() {
return Objects.hash(getHost());
}
@Getter
public static class Response {
protected Response(Document document, Header[] headers) {
this.document = document;
this.headers = headers;
}
private Document document;
private Header[] headers;
}
@Override
public String toString() {
return getHost();
}
}
@@ -0,0 +1,98 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.HtmlProcessorException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
import java.io.IOException;
@Service
public class ImageBamHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(ImageBamHost.class);
private static final String host = "imagebam.com";
private static final String CONTINUE_BUTTON_XPATH = "//a[@title='Continue to your image']";
private static final String IMG_XPATH = "//img[@class='image']";
@Autowired
private ConnectionManager cm;
public ImageBamHost() {
super();
}
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
Response response = getResponse(url, context);
Document doc = response.getDocument();
Node contDiv;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
contDiv = xpathService.getAsNode(doc, CONTINUE_BUTTON_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
if (contDiv != null) {
logger.debug(String.format("Click button found for %s", url));
HttpClient client = cm.getClient().build();
HttpGet httpGet = cm.buildHttpGet(url);
httpGet.addHeader("Referer", url);
logger.debug(String.format("Requesting %s", httpGet));
try (CloseableHttpResponse res = (CloseableHttpResponse) client.execute(httpGet, context)) {
String s = EntityUtils.toString(res.getEntity());
logger.debug(String.format("%s response is:%n%s", httpGet, s));
logger.debug(String.format("Cleaning response for %s", httpGet));
doc = htmlProcessorService.clean(s);
EntityUtils.consumeQuietly(res.getEntity());
} catch (IOException | HtmlProcessorException e) {
throw new HostException(e);
}
}
Node imgNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("id").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -0,0 +1,60 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import java.util.Optional;
@Service
public class ImageTwistHost extends Host {
private static final String IMG_XPATH = "//img[contains(@class, 'img')]";
private static final Logger logger = LoggerFactory.getLogger(ImageTwistHost.class);
private static final String host = "imagetwist.com";
public ImageTwistHost() {
super();
}
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Node imgNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = Optional.ofNullable(imgNode.getAttributes().getNamedItem("alt")).map(Node::getTextContent).map(String::trim).orElse(null);
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -0,0 +1,83 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import java.net.URI;
@Service
public class ImageVenueHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(ImageVenueHost.class);
private static final String host = "imagevenue.com";
private static final String CONTINUE_BUTTON_XPATH = "//a[@title='Continue to your image']";
private static final String IMG_XPATH = "//img[@id='thepic']";
public ImageVenueHost() {
super();
}
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
//Sadly, they do not support https.
//If they add such support in the future,
//then we should automatically adapt the URL here as done elsewhere.
Response resp = getResponse(url, context);
Document doc = resp.getDocument();
try {
logger.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
if(xpathService.getAsNode(doc, CONTINUE_BUTTON_XPATH) != null) {
//Button detected. No need to actually click it, just make the call again.
resp = getResponse(url, context);
doc = resp.getDocument();
}
} catch (XpathException e) {
throw new HostException(e);
}
Node imgNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
if (imgNode == null) {
throw new HostException("Failed to locate image");
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
URI baseUri = new URI(url);
imageFileData.setImageUrl(new URI(baseUri.getScheme(), baseUri.getHost(), '/'+imgUrl, null).toString());
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
} catch(Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -1,18 +1,14 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
import java.io.IOException;
@Service
public class ImageZillaHost extends Host {
@@ -20,27 +16,34 @@ public class ImageZillaHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(ImageZillaHost.class);
private static final String host = "imagezilla.net";
public static final String IMG_XPATH = "//img[@id='photo']";
private static final String lookup = "imagezilla.net/show";
private static final String IMG_XPATH = "//img[@id='photo']";
@Autowired
private ConnectionManager cm;
public ImageZillaHost() {
super();
}
@Override
protected String getHost() {
public String getHost() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData) throws HostException {
public String getLookup() {
return lookup;
}
Document doc = getDocument(url);
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
String title;
try {
logger.info(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
Node titleNode = xpathService.getAsNode(doc, IMG_XPATH).getAttributes().getNamedItem("title");
logger.info(String.format("Resolving name for %s", url));
if(titleNode != null) {
logger.debug(String.format("Resolving name for %s", url));
if (titleNode != null) {
title = titleNode.getTextContent().trim();
} else {
title = null;
@@ -49,13 +52,13 @@ public class ImageZillaHost extends Host {
throw new HostException(e);
}
if(title == null || title.isEmpty()) {
if (title == null || title.isEmpty()) {
title = getDefaultImageName(url);
}
try {
imageFileData.setImageUrl(url.replace("show", "images"));
imageFileData.setImageName(title.substring(8));
imageFileData.setImageName(title);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -0,0 +1,61 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
@Service
public class ImgSpiceHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(ImgSpiceHost.class);
private static final String host = "imgspice.com";
private static final String IMG_XPATH = "//img[@id='imgpreview']";
public ImgSpiceHost() {
super();
}
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Response resp = getResponse(url, context);
Document doc = resp.getDocument();
Node imgNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -1,5 +1,6 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,36 +18,45 @@ public class ImgboxHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(ImgboxHost.class);
private static final String host = "imgbox.com";
public static final String IMG_XPATH = "//img[@id='img']";
private static final String IMG_XPATH = "//img[@id='img']";
@Autowired
private ConnectionManager cm;
public ImgboxHost() {
super();
}
@Override
protected String getHost() {
public String getHost() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData) throws HostException {
public String getLookup() {
return host;
}
Document doc = getDocument(url);
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Node imgNode;
try {
logger.info(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.info(String.format("Resolving name and image url for %s", url));
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("title").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.substring(8));
imageFileData.setImageName(imgTitle);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -5,6 +5,7 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
@@ -29,68 +30,80 @@ public class ImxHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(ImxHost.class);
private static final String host = "imx.to";
public static final String CONTINUE_BUTTON_XPATH = "//div[@id='continuetoimage']";
public static final String IMG_XPATH = "//img[@class='centred']";
private static final String CONTINUE_BUTTON_XPATH = "//*[@name='imgContinue']";
private static final String IMG_XPATH = "//img[@class='centred']";
@Autowired
private ConnectionManager cm;
@Override
protected String getHost() {
public String getHost() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData) throws HostException {
public String getLookup() {
return host;
}
Document doc = getDocument(url);
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Response resp = getResponse(url, context);
Document doc = resp.getDocument();
Node contDiv;
String value = null;
try {
logger.info(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
contDiv = xpathService.getAsNode(doc, CONTINUE_BUTTON_XPATH);
Node node = contDiv.getAttributes().getNamedItem("value");
if (node != null) {
value = node.getTextContent();
}
} catch (XpathException e) {
throw new HostException(e);
}
if (contDiv != null) {
logger.info(String.format("Click button found for %s", url));
HttpClient client = cm.getClient().build();
HttpPost httpPost = cm.buildHttpPost(url);
httpPost.addHeader("Referer", url);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("imgContinue", "Continue to image ... "));
try {
httpPost.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new HostException(e);
}
logger.info(String.format("Requesting %s", httpPost));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpPost)) {
logger.debug(String.format("Cleaning response for %s", httpPost));
doc = htmlProcessorService.clean(EntityUtils.toString(response.getEntity()));
EntityUtils.consumeQuietly(response.getEntity());
} catch (IOException | HtmlProcessorException e) {
throw new HostException(e);
}
if (value == null) {
throw new HostException("Failed to obtain value attribute from continue input");
}
logger.debug(String.format("Click button found for %s", url));
HttpClient client = cm.getClient().build();
HttpPost httpPost = cm.buildHttpPost(url);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("imgContinue", value));
try {
httpPost.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new HostException(e);
}
logger.debug(String.format("Requesting %s", httpPost));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpPost, context)) {
logger.debug(String.format("Cleaning response for %s", httpPost));
doc = htmlProcessorService.clean(EntityUtils.toString(response.getEntity()));
EntityUtils.consumeQuietly(response.getEntity());
} catch (IOException | HtmlProcessorException e) {
throw new HostException(e);
}
Node imgNode;
try {
logger.info(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.info(String.format("Resolving name and image url for %s", url));
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
} catch(Exception e) {
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
@@ -0,0 +1,67 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
@Service
public class PimpandhostHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(PimpandhostHost.class);
private static final String host = "pimpandhost.com";
private static final String IMG_XPATH = "//img[contains(@class, 'original')]";
public PimpandhostHost() {
super();
}
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
String url;
try {
url = appendUri(_url.replace("http://", "https://"), "size=original");
} catch (Exception e) {
throw new HostException(e);
}
Response resp = getResponse(url, context);
Document doc = resp.getDocument();
Node imgNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = "https:" + imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -0,0 +1,58 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
@Service
public class PixRouteHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(PixRouteHost.class);
private static final String host = "pixroute.com";
private static final String IMG_XPATH = "//img[@id='imgpreview']";
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Document doc = getResponse(url, context).getDocument();
Node imgNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
if (imgNode == null) {
throw new HostException("Failed to locate image");
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
imageFileData.setImageUrl(imgNode.getAttributes().getNamedItem("src").getTextContent().trim());
imageFileData.setImageName(imgNode.getAttributes().getNamedItem("alt").getTextContent().trim());
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -1,15 +1,14 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
@Service
public class PixhostHost extends Host {
@@ -17,31 +16,38 @@ public class PixhostHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(PixhostHost.class);
private static final String host = "pixhost.to";
public static final String IMG_XPATH = "//img[@id='image']";
private static final String lookup = "pixhost.to/show";
private static final String IMG_XPATH = "//img[@id='image']";
@Autowired
private ConnectionManager cm;
public PixhostHost() {
super();
}
@Override
protected String getHost() {
public String getHost() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData) throws HostException {
public String getLookup() {
return lookup;
}
Document doc = getDocument(url);
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Node imgNode;
try {
logger.info(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.info(String.format("Resolving name and image url for %s", url));
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
@@ -0,0 +1,66 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
@Service
public class PixxxelsHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(PixxxelsHost.class);
private static final String host = "pixxxels.cc";
private static final String IMG_XPATH = "//*[@id='download']";
private static final String TITLE_XPATH = "//*[contains(@class,'imagename')]";
public PixxxelsHost() {
super();
}
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Response resp = getResponse(url, context);
Document doc = resp.getDocument();
Node imgNode, titleNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
imgNode = xpathService.getAsNode(doc, IMG_XPATH);
logger.debug(String.format("Looking for xpath expression %s in %s", TITLE_XPATH, url));
titleNode = xpathService.getAsNode(doc, TITLE_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = titleNode.getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("href").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -0,0 +1,65 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import java.util.Optional;
@Service
public class PostImgHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(PostImgHost.class);
private static final String host = "postimg.cc";
private static final String TITLE_XPATH = "//span[contains(@class,'imagename')]";
private static final String IMG_XPATH = "//a[@id='download']";
public PostImgHost() {
super();
}
@Override
public String getHost() {
return host;
}
@Override
public String getLookup() {
return host;
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Document doc = getResponse(url, context).getDocument();
Node urlNode, titleNode;
try {
logger.debug(String.format("Looking for xpath expression %s in %s", TITLE_XPATH, url));
titleNode = xpathService.getAsNode(doc, TITLE_XPATH);
logger.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
urlNode = xpathService.getAsNode(doc, IMG_XPATH);
} catch (XpathException e) {
throw new HostException(e);
}
try {
logger.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = Optional.ofNullable(titleNode).map(node -> node.getTextContent().trim()).orElseGet(() -> getDefaultImageName(url));
imageFileData.setImageUrl(urlNode.getAttributes().getNamedItem("href").getTextContent().trim());
imageFileData.setImageName(imgTitle);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
}
}
@@ -1,15 +1,14 @@
package tn.mnlr.vripper.host;
import org.apache.http.client.protocol.HttpClientContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
@Service
public class TurboImageHost extends Host {
@@ -17,28 +16,34 @@ public class TurboImageHost extends Host {
private static final Logger logger = LoggerFactory.getLogger(TurboImageHost.class);
private static final String host = "turboimagehost.com";
public static final String TITLE_XPATH = "//div[contains(@class,'titleFullS')]/h1";
public static final String IMG_XPATH = "//img[@id='uImage']";
private static final String TITLE_XPATH = "//div[contains(@class,'titleFullS')]/h1";
private static final String IMG_XPATH = "//img[@id='uImage']";
@Autowired
private ConnectionManager cm;
public TurboImageHost() {
super();
}
@Override
protected String getHost() {
public String getHost() {
return host;
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData) throws HostException {
public String getLookup() {
return host;
}
Document doc = getDocument(url);
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
String title;
try {
logger.info(String.format("Looking for xpath expression %s in %s", TITLE_XPATH, url));
logger.debug(String.format("Looking for xpath expression %s in %s", TITLE_XPATH, url));
Node titleNode = xpathService.getAsNode(doc, TITLE_XPATH);
logger.info(String.format("Resolving name for %s", url));
if(titleNode != null) {
logger.debug(String.format("Resolving name for %s", url));
if (titleNode != null) {
title = titleNode.getTextContent().trim();
} else {
title = null;
@@ -47,7 +52,7 @@ public class TurboImageHost extends Host {
throw new HostException(e);
}
if(title == null || title.isEmpty()) {
if (title == null || title.isEmpty()) {
title = getDefaultImageName(url);
}
@@ -4,6 +4,7 @@ import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import java.util.Objects;
import java.util.concurrent.Callable;
@@ -14,21 +15,23 @@ public class DownloadJob implements Callable<Image> {
@Getter
private final Image image;
private final Post post;
@Getter
private final ImageFileData imageFileData = new ImageFileData();
public DownloadJob(Image image) {
DownloadJob(Post post, Image image) {
this.image = image;
this.post = post;
}
@Override
public Image call() throws Exception {
logger.info(String.format("Starting downloading %s", image.getUrl()));
logger.debug(String.format("Starting downloading %s", image.getUrl()));
image.setStatus(Image.Status.DOWNLOADING);
image.setCurrent(0);
image.getHost().download(image, imageFileData);
image.getHost().download(post, image, imageFileData);
image.setStatus(Image.Status.COMPLETE);
return image;
}
@@ -1,125 +1,87 @@
package tn.mnlr.vripper.q;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.services.AppStateService;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;
import java.util.Map;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingDeque;
@Service
public class DownloadQ {
private static final Logger logger = LoggerFactory.getLogger(DownloadQ.class);
@Autowired
private AppStateService appStateService;
private final AppStateService appStateService;
private final AppSettingsService appSettingsService;
private final List<Host> hosts;
private final ConcurrentHashMap<Host, BlockingDeque<DownloadJob>> downloadQ = new ConcurrentHashMap<>();
@Autowired
private ExecutionService executionService;
public DownloadQ(AppStateService appStateService, AppSettingsService appSettingsService, List<Host> hosts) {
this.appStateService = appStateService;
this.appSettingsService = appSettingsService;
this.hosts = hosts;
}
private BlockingQueue<DownloadJob> downloadQ = new LinkedBlockingQueue<>();
@PostConstruct
private void init() {
hosts.forEach(host -> downloadQ.put(host, new LinkedBlockingDeque<>()));
}
@Getter
private boolean notPauseQ = true;
public void put(Post post, Image image) throws InterruptedException {
logger.debug(String.format("Enqueuing a job for %s", image.getUrl()));
image.init();
DownloadJob downloadJob = new DownloadJob(post, image);
downloadQ.get(downloadJob.getImage().getHost()).putLast(downloadJob);
appStateService.newDownloadJob(downloadJob);
}
public synchronized void put(Image image) {
try {
logger.info(String.format("Enqueuing a job for %s", image.getUrl()));
DownloadJob downloadJob = new DownloadJob(image);
downloadQ.put(downloadJob);
appStateService.newDownloadJob(downloadJob);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
public void remove(final DownloadJob downloadJob) {
downloadQ.get(downloadJob.getImage().getHost()).remove(downloadJob);
}
public List<DownloadJob> peek() {
List<DownloadJob> downloadJobs = new ArrayList<>();
if (hosts.size() == 0) {
return downloadJobs;
}
}
public DownloadJob take() throws InterruptedException {
DownloadJob downloadJob = downloadQ.take();
logger.info(String.format("Retrieving a job for %s", downloadJob.getImage().getUrl()));
return downloadJob;
}
public void enqueue(Post post) {
post.getImages()
.forEach(this::put);
}
public void restart(String postId) {
if (appStateService.getRunningPosts().get(postId) != null && appStateService.getRunningPosts().get(postId).get() > 0) {
logger.warn(String.format("Cannot restart, jobs are currently running for post id %s", postId));
return;
}
List<Image> images = appStateService.getPost(postId)
.getImages()
.stream()
.filter(e -> !e.getStatus().equals(Image.Status.COMPLETE))
.collect(Collectors.toList());
if (images.isEmpty()) {
return;
}
appStateService.getPost(postId).setStatus(Post.Status.PENDING);
logger.info(String.format("Restarting %d jobs for post id %s", images.size(), postId));
images.forEach(image -> {
image.init();
put(image);
});
}
public void removeScheduled(Image image) {
image.setStatus(Image.Status.STOPPED);
logger.info(String.format("Removing scheduled job for %s", image.getUrl()));
Iterator<DownloadJob> iterator = downloadQ.iterator();
boolean removed = false;
while(iterator.hasNext()) {
DownloadJob next = iterator.next();
if(next.getImage().getPostId().equals(image.getPostId())) {
iterator.remove();
appStateService.doneDownloadJob(image);
logger.info(String.format("Scheduled job for %s is removed", image.getUrl()));
removed = true;
break;
for (Host host : hosts) {
Iterator<DownloadJob> it = downloadQ.get(host).iterator();
for (int i = 0; i < appSettingsService.getSettings().getMaxThreads(); i++) {
DownloadJob downloadJob = it.hasNext() ? it.next() : null;
if (downloadJob != null) {
downloadJobs.add(downloadJob);
}
}
}
return downloadJobs;
}
if(!removed) {
logger.warn(String.format("Job for %s does not exist", image.getUrl()));
public void enqueue(Post post) throws InterruptedException {
for (Image image : post.getImages()) {
put(post, image);
}
}
public void removeRunning(String postId) {
logger.info(String.format("Interrupting running jobs for post id %s", postId));
executionService.stop(postId);
public int size() {
return downloadQ.values().stream().mapToInt(BlockingDeque::size).sum();
}
public synchronized void stop(String postId) {
try {
notPauseQ = false;
appStateService.getPost(postId).setStatus(Post.Status.STOPPED);
List<Image> images = appStateService.getPost(postId)
.getImages()
.stream()
.filter(e -> !e.getStatus().equals(Image.Status.COMPLETE))
.collect(Collectors.toList());
if (images.isEmpty()) {
return;
}
logger.info(String.format("Stopping %d jobs for post id %s", images.size(), postId));
images.forEach(image -> removeScheduled(image));
removeRunning(postId);
} finally {
notPauseQ = true;
}
public Iterable<? extends Map.Entry<Host, BlockingDeque<DownloadJob>>> entries() {
return downloadQ.entrySet();
}
}
@@ -1,26 +1,22 @@
package tn.mnlr.vripper.q;
import lombok.NonNull;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.FailsafeException;
import net.jodah.failsafe.RetryPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.services.AppStateService;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.services.*;
import javax.annotation.PostConstruct;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.annotation.PreDestroy;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@@ -28,114 +24,267 @@ import java.util.stream.Collectors;
public class ExecutionService {
private static final Logger logger = LoggerFactory.getLogger(ExecutionService.class);
private static final List<Post.Status> FINISHED = Arrays.asList(Post.Status.ERROR, Post.Status.COMPLETE, Post.Status.STOPPED);
@Autowired
private DownloadQ downloadQ;
private final DownloadQ downloadQ;
private final AppSettingsService settings;
private final AppStateService appStateService;
private final AppStateExchange appStateExchange;
private final ThumbnailGenerator thumbnailGenerator;
private final AppSettingsService appSettingsService;
private final CommonExecutor commonExecutor;
@Autowired
private AppSettingsService settings;
private final int MAX_POOL_SIZE = 12;
@Autowired
private AppStateService appStateService;
private final ConcurrentHashMap<Host, AtomicInteger> threadCount = new ConcurrentHashMap<>();
private AtomicInteger threadCount = new AtomicInteger();
private boolean notPauseQ = true;
private ExecutorService executor = Executors.newFixedThreadPool(MAX_POOL_SIZE);
private ExecutorService executor = Executors.newFixedThreadPool(10);
private Thread executionThread;
private RetryPolicy<Object> retryPolicy;
private BlockingQueue<DownloadJob> queue = new LinkedBlockingQueue<>();
private List<DownloadJob> running = Collections.synchronizedList(new ArrayList<>());
private Map<String, Future<?>> futures = new ConcurrentHashMap<>();
private Thread pollThread;
@Autowired
public ExecutionService(DownloadQ downloadQ, AppSettingsService settings, AppStateService appStateService, AppStateExchange appStateExchange, ThumbnailGenerator thumbnailGenerator, AppSettingsService appSettingsService, CommonExecutor commonExecutor) {
this.downloadQ = downloadQ;
this.settings = settings;
this.appStateService = appStateService;
this.appStateExchange = appStateExchange;
this.thumbnailGenerator = thumbnailGenerator;
this.appSettingsService = appSettingsService;
this.commonExecutor = commonExecutor;
}
@PostConstruct
private void init() {
retryPolicy = new RetryPolicy<>()
.handleIf(e -> !(e instanceof InterruptedException))
.withDelay(Duration.ofSeconds(20))
.withMaxRetries(2)
.abortOn(InterruptedException.class)
.onFailedAttempt(e -> logger.warn(String.format("#%d tries failed", e.getAttemptCount()), e.getLastFailure()));
executionThread = new Thread(this::start, "Executor thread");
pollThread = new Thread(this::poll, "Polling thread");
pollThread.start();
executionThread.start();
}
private ExecutionService() {
@PreDestroy
private void destroy() throws InterruptedException {
logger.info("Shutting down ExecutionService");
executionThread.interrupt();
pollThread.interrupt();
executor.shutdown();
appStateExchange.getPosts().keySet().forEach(p -> {
logger.debug(String.format("Stopping download jobs for %s", p));
this.stopRunning(p);
});
executor.awaitTermination(10, TimeUnit.SECONDS);
}
@PostConstruct
private void runExecutorThread() {
new Thread(this::start, "Executor thread").start();
}
public void stop(String postId) {
private void stopRunning(@NonNull String postId) {
List<DownloadJob> data = running
.stream()
.filter(e -> e.getImage().getPostId().equals(postId))
.peek(e -> e.getImage().setStatus(Image.Status.STOPPED))
.collect(Collectors.toList());
logger.warn(String.format("Interrupting %d jobs for post id %s", data.size(), postId));
logger.debug(String.format("Interrupting %d jobs for post id %s", data.size(), postId));
data.forEach(e -> {
futures.get(e.getImage().getUrl()).cancel(true);
e.getImageFileData().getImageRequest().abort();
if (e.getImageFileData().getImageRequest() != null) {
e.getImageFileData().getImageRequest().abort();
}
e.getImage().cleanup();
});
}
boolean canRun() {
boolean canRun = threadCount.get() < settings.getMaxThreads();
if (canRun && downloadQ.isNotPauseQ()) {
threadCount.incrementAndGet();
public synchronized void stopAll(List<String> posIds) {
if (posIds != null) {
posIds.forEach(this::stop);
} else {
appStateExchange.getPosts().values().forEach(p -> this.stop(p.getPostId()));
}
}
public synchronized void restartAll(List<String> posIds) {
if (posIds != null) {
posIds.forEach(this::restart);
} else {
appStateExchange.getPosts().values().forEach(p -> this.restart(p.getPostId()));
}
}
private void restart(@NonNull String postId) {
if (appStateService.isRunning(postId)) {
logger.warn(String.format("Cannot restart, jobs are currently running for post id %s", postId));
return;
}
Post post = appStateExchange.getPost(postId);
List<Image> images = post
.getImages()
.stream()
.filter(e -> !e.getStatus().equals(Image.Status.COMPLETE))
.collect(Collectors.toList());
if (images.isEmpty()) {
return;
}
post.setStatus(Post.Status.PENDING);
logger.debug(String.format("Restarting %d jobs for post id %s", images.size(), postId));
for (Image image : images) {
try {
downloadQ.put(post, image);
} catch (InterruptedException e) {
logger.warn("Thread was interrupted", e);
Thread.currentThread().interrupt();
}
}
}
private void removeScheduled(Image image) {
image.setStatus(Image.Status.STOPPED);
logger.debug(String.format("Removing scheduled job for %s", image.getUrl()));
boolean removed = false;
main:
for (Map.Entry<Host, BlockingDeque<DownloadJob>> entry : downloadQ.entries()) {
Iterator<DownloadJob> iterator = entry.getValue().iterator();
while (iterator.hasNext()) {
DownloadJob next = iterator.next();
if (next.getImage().getPostId().equals(image.getPostId())) {
iterator.remove();
appStateService.doneDownloadJob(image);
logger.debug(String.format("Scheduled job for %s is removed", image.getUrl()));
removed = true;
break main;
}
}
}
if (!removed) {
logger.debug(String.format("Job for %s does not exist", image.getUrl()));
}
image.cleanup();
}
private void removeRunning(String postId) {
logger.debug(String.format("Interrupting running jobs for post id %s", postId));
stopRunning(postId);
}
private void stop(String postId) {
try {
final Post post = appStateExchange.getPost(postId);
if (post == null) {
return;
}
if (FINISHED.contains(post.getStatus())) {
return;
}
notPauseQ = false;
post.setStatus(Post.Status.STOPPED);
List<Image> images = post
.getImages()
.stream()
.filter(e -> !e.getStatus().equals(Image.Status.COMPLETE))
.collect(Collectors.toList());
if (images.isEmpty()) {
return;
}
logger.debug(String.format("Stopping %d jobs for post id %s", images.size(), postId));
images.forEach(this::removeScheduled);
removeRunning(postId);
} finally {
notPauseQ = true;
}
}
private boolean canRun(Host host) {
boolean canRun;
AtomicInteger count = threadCount.get(host);
if (count == null) {
threadCount.put(host, new AtomicInteger(0));
}
canRun = threadCount.get(host).get() < settings.getSettings().getMaxThreads() && (settings.getSettings().getMaxTotalThreads() == 0 ? threadCount.values().stream().mapToInt(AtomicInteger::get).sum() < MAX_POOL_SIZE : threadCount.values().stream().mapToInt(AtomicInteger::get).sum() < settings.getSettings().getMaxTotalThreads());
if (canRun && notPauseQ) {
threadCount.get(host).incrementAndGet();
return true;
}
return false;
}
public void start() {
while (true) {
if (canRun()) {
DownloadJob take = null;
try {
take = downloadQ.take();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
DownloadJob finalTake = take;
Runnable task = () -> {
running.add(finalTake);
Failsafe.with(retryPolicy)
.onFailure(e -> {
if (e.getFailure() instanceof InterruptedException || (e.getFailure() instanceof FailsafeException && e.getFailure().getCause() instanceof InterruptedException)) {
logger.info("Job successfully interrupted");
return;
}
logger.error(String.format("Failed to download %s after %d tries", finalTake.getImage().getUrl(), e.getAttemptCount()), e.getFailure());
finalTake.getImage().setStatus(Image.Status.ERROR);
})
.onComplete(e -> {
appStateService.doneDownloadJob(finalTake.getImage());
logger.info(String.format("Finished downloading %s", finalTake.getImage().getUrl()));
synchronized (threadCount) {
int i = threadCount.decrementAndGet();
running.remove(finalTake);
futures.remove(finalTake.getImage().getUrl());
threadCount.notify();
}
})
.get(finalTake::call);
};
logger.info(String.format("Scheduling a job for %s", finalTake.getImage().getUrl()));
futures.put(finalTake.getImage().getUrl(), executor.submit(task));
} else {
synchronized (threadCount) {
try {
threadCount.wait(2_000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
private void poll() {
while (!Thread.interrupted()) {
try {
List<DownloadJob> peek = downloadQ.peek();
for (DownloadJob downloadJob : peek) {
if (canRun(downloadJob.getImage().getHost())) {
queue.offer(downloadJob);
downloadQ.remove(downloadJob);
}
}
synchronized (threadCount) {
threadCount.wait(2_000);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
private void start() {
while (!Thread.interrupted()) {
try {
push(queue.take());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
} catch (Exception e) {
logger.error("Execution Service failed", e);
break;
}
}
}
private void push(DownloadJob take) {
Runnable task = () -> {
running.add(take);
Failsafe.with(VripperApplication.retryPolicy)
.onFailure(e -> {
if (e.getFailure() instanceof InterruptedException || (e.getFailure() instanceof FailsafeException && e.getFailure().getCause() instanceof InterruptedException)) {
logger.debug("Job successfully interrupted");
return;
}
logger.error(String.format("Failed to download %s after %d tries", take.getImage().getUrl(), e.getAttemptCount()), e.getFailure());
take.getImage().setStatus(Image.Status.ERROR);
})
.onComplete(e -> {
appStateService.doneDownloadJob(take.getImage());
logger.debug(String.format("Finished downloading %s", take.getImage().getUrl()));
if (appSettingsService.getSettings().getViewPhotos()) {
commonExecutor.getGeneralExecutor().submit(
() -> thumbnailGenerator.getThumbnails()
.get(new ThumbnailGenerator.CacheKey(take.getImage().getPostId(), take.getImageFileData().getFileName())));
}
threadCount.get(take.getImage().getHost()).decrementAndGet();
running.remove(take);
futures.remove(take.getImage().getUrl());
synchronized (threadCount) {
threadCount.notify();
}
})
.get(take::call);
};
logger.debug(String.format("Scheduling a job for %s", take.getImage().getUrl()));
futures.put(take.getImage().getUrl(), executor.submit(task));
}
public int runningCount() {
return running.size();
}
}
@@ -10,6 +10,7 @@ public class ImageFileData {
private String pageUrl;
private String imageName;
private String fileName;
private String imageUrl;
private HttpUriRequest imageRequest;
}
@@ -1,78 +1,161 @@
package tn.mnlr.vripper.services;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.exception.ValidationException;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import static java.nio.file.StandardOpenOption.*;
@Service
@Getter
@Setter
public class AppSettingsService {
private static final Logger logger = LoggerFactory.getLogger(AppSettingsService.class);
private final String MAX_TOTAL_THREADS = "MAX_TOTAL_THREADS";
private final String baseDir;
private Preferences prefs = Preferences.userNodeForPackage(AppSettingsService.class);
private final Path configPath;
private final Logger logger = LoggerFactory.getLogger(AppSettingsService.class);
private final ObjectMapper om = new ObjectMapper();
private final String DOWNLOAD_PATH = "DOWNLOAD_PATH";
private final String MAX_THREADS = "MAX_THREADS";
private final String AUTO_START = "AUTO_START";
private final String V_LOGIN = "VLOGIN";
private final String V_USERNAME = "VUSERNAME";
private final String V_PASSWORD = "VPASSWORD";
private final String V_THANKS = "VTHANKS";
private Settings settings = new Settings();
private String downloadPath;
private int maxThreads;
private boolean autoStart;
private boolean vLogin;
private String vUsername;
private String vPassword;
private boolean vThanks;
public AppSettingsService(@Value("${base.dir}") String baseDir) {
this.baseDir = baseDir;
this.configPath = Paths.get(baseDir, ".vripper", "config.json");
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
public void setVPassword(String vPassword) {
if(vPassword.isEmpty()) {
this.vPassword = "";
@PostConstruct
private void init() {
restore();
}
public void newSettings(Settings settings) {
if (settings.getVLogin()) {
if (!this.settings.getVPassword().equals(settings.getVPassword())) {
settings.setVPassword(settings.getVPassword());
}
} else {
this.vPassword = DigestUtils.md5Hex(vPassword);
settings.setVUsername("");
settings.setVPassword("");
settings.setVThanks(false);
}
this.settings = settings;
save();
}
public void restore() {
try {
settings = om.readValue(configPath.toFile(), Settings.class);
try {
check(this.settings);
} catch (ValidationException e) {
logger.error(String.format("Your settings are invalid, either remove %s, or fix it", configPath.toString()), e);
SpringContext.close();
}
} catch (IOException e) {
logger.error("Failed restore user settings", e);
settings = new Settings();
}
downloadPath = prefs.get(DOWNLOAD_PATH, System.getProperty("user.dir"));
maxThreads = prefs.getInt(MAX_THREADS, 1);
autoStart = prefs.getBoolean(AUTO_START, false);
vLogin = prefs.getBoolean(V_LOGIN, false);
vUsername = prefs.get(V_USERNAME, "");
vPassword = prefs.get(V_PASSWORD, "");
vThanks = prefs.getBoolean(V_THANKS, false);
if (settings.getDownloadPath() == null) {
settings.setDownloadPath(baseDir);
}
if (settings.getMaxThreads() == null) {
settings.setMaxThreads(4);
}
if (settings.getMaxTotalThreads() == null) {
settings.setMaxTotalThreads(0);
}
if (settings.getAutoStart() == null) {
settings.setAutoStart(true);
}
if (settings.getVLogin() == null) {
settings.setVLogin(false);
}
if (settings.getVUsername() == null) {
settings.setVUsername("");
}
if (settings.getVPassword() == null) {
settings.setVPassword("");
}
if (settings.getVThanks() == null) {
settings.setVThanks(false);
}
if (settings.getDesktopClipboard() == null) {
settings.setDesktopClipboard(false);
}
if (settings.getForceOrder() == null) {
settings.setForceOrder(false);
}
if (settings.getSubLocation() == null) {
settings.setSubLocation(false);
}
if (settings.getThreadSubLocation() == null) {
settings.setThreadSubLocation(false);
}
if (settings.getClearCompleted() == null) {
settings.setClearCompleted(false);
}
if (settings.getDarkTheme() == null) {
settings.setDarkTheme(false);
}
if (settings.getViewPhotos() == null) {
settings.setViewPhotos(false);
}
if (settings.getNotification() == null) {
settings.setNotification(false);
}
save();
}
@PreDestroy
public void save() {
prefs.put(DOWNLOAD_PATH, downloadPath);
prefs.putInt(MAX_THREADS, maxThreads);
prefs.putBoolean(AUTO_START, autoStart);
prefs.putBoolean(V_LOGIN, vLogin);
prefs.put(V_USERNAME, vUsername);
prefs.put(V_PASSWORD, vPassword);
prefs.putBoolean(V_THANKS, vThanks);
try {
prefs.sync();
} catch (BackingStoreException e) {
// force disable gallery
settings.setViewPhotos(false);
Files.write(configPath, om.writeValueAsBytes(settings), CREATE, WRITE, TRUNCATE_EXISTING, SYNC);
} catch (IOException e) {
logger.error("Failed to store user settings", e);
}
}
@@ -91,37 +174,81 @@ public class AppSettingsService {
throw new ValidationException(String.format("%s is not a directory", settings.getDownloadPath()));
}
if (settings.getMaxThreads() < 1 || settings.getMaxThreads() > 8) {
throw new ValidationException(String.format("Invalid max concurrent download settings, values must be in [%d,%d]", 1, 8));
if (settings.getMaxTotalThreads() < 0 || settings.getMaxTotalThreads() > 12) {
throw new ValidationException(String.format("Invalid max global concurrent download settings, values must be in [%d,%d]", 0, 12));
}
if (settings.getMaxThreads() < 1 || settings.getMaxThreads() > 4) {
throw new ValidationException(String.format("Invalid max concurrent download settings, values must be in [%d,%d]", 1, 4));
}
}
public Theme getTheme() {
return new Theme(this.settings.getDarkTheme());
}
public void setTheme(Theme theme) {
this.settings.setDarkTheme(theme.darkTheme);
save();
}
@Getter
@NoArgsConstructor
public static class Theme {
@JsonProperty("darkTheme")
private boolean darkTheme;
Theme(boolean darkTheme) {
this.darkTheme = darkTheme;
}
}
@Getter
@Setter
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Settings {
@JsonProperty("downloadPath")
private String downloadPath;
@JsonProperty("maxThreads")
private int maxThreads;
private Integer maxThreads;
@JsonProperty("maxTotalThreads")
private Integer maxTotalThreads;
@JsonProperty("autoStart")
private boolean autoStart;
private Boolean autoStart;
@JsonProperty("vLogin")
private boolean vLogin;
private Boolean vLogin;
@JsonProperty("vUsername")
private String vUsername;
@JsonProperty("vPassword")
private String vPassword;
@JsonProperty("vThanks")
private boolean vThanks;
private Boolean vThanks;
@JsonProperty("desktopClipboard")
private Boolean desktopClipboard;
@JsonProperty("forceOrder")
private Boolean forceOrder;
@JsonProperty("subLocation")
private Boolean subLocation;
@JsonProperty("threadSubLocation")
private Boolean threadSubLocation;
@JsonProperty("clearCompleted")
private Boolean clearCompleted;
@JsonProperty("viewPhotos")
private Boolean viewPhotos;
@JsonProperty("notification")
private Boolean notification;
@JsonProperty("darkTheme")
private Boolean darkTheme;
public Settings(String downloadPath, int maxThreads, boolean autoStart, boolean vLogin, String vUsername, String vPassword, boolean vThanks) {
this.downloadPath = downloadPath;
this.maxThreads = maxThreads;
this.autoStart = autoStart;
this.vLogin = vLogin;
this.vUsername = vUsername;
this.vPassword = vPassword;
this.vThanks = vThanks;
public void setVPassword(String vPassword) {
if (vPassword == null || vPassword.isEmpty()) {
this.vPassword = "";
} else {
this.vPassword = DigestUtils.md5Hex(vPassword);
}
}
}
}
@@ -0,0 +1,73 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@Service
public class AppStateExchange {
private Map<String, Image> currentImages = new ConcurrentHashMap<>();
private Map<String, Post> currentPosts = new ConcurrentHashMap<>();
private Map<String, AtomicInteger> runningPosts = new ConcurrentHashMap<>();
private Map<String, QueuedVGLink> grabQueue = new ConcurrentHashMap<>();
private PublishProcessor<QueuedVGLink> liveGrabQueue = PublishProcessor.create();
private PublishProcessor<Image> liveImageUpdates = PublishProcessor.create();
private PublishProcessor<Post> livePostsState = PublishProcessor.create();
public Map<String, AtomicInteger> running() {
return runningPosts;
}
public Map<String, Post> getPosts() {
return this.currentPosts;
}
public Post getPost(String postId) {
return currentPosts.get(postId);
}
public Map<String, Image> getImages() {
return currentImages;
}
public PublishProcessor<Image> liveImage() {
return liveImageUpdates;
}
public PublishProcessor<Post> livePost() {
return livePostsState;
}
public Map<String, QueuedVGLink> getQueue() {
return grabQueue;
}
public PublishProcessor<QueuedVGLink> liveQueue() {
return liveGrabQueue;
}
public synchronized void restore(Map<String, Post> read) {
currentPosts.clear();
currentPosts.putAll(read);
currentPosts.values().forEach(p -> {
if (Arrays.asList(Post.Status.DOWNLOADING, Post.Status.PARTIAL, Post.Status.PENDING).contains(p.getStatus())) {
p.setStatus(Post.Status.STOPPED);
}
});
currentImages.clear();
read.values().stream().flatMap(e -> e.getImages().stream()).forEach(e -> currentImages.put(e.getUrl(), e));
}
}
@@ -1,96 +1,176 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import io.reactivex.processors.ReplayProcessor;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.q.DownloadJob;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
@Getter
public class AppStateService {
private Map<String, Image> currentImages = new ConcurrentHashMap<>();
private Map<String, Post> currentPosts = new ConcurrentHashMap<>();
private Map<String, AtomicInteger> runningPosts = new ConcurrentHashMap<>();
private PublishProcessor<Image> liveImageUpdates = PublishProcessor.create();
// private ReplayProcessor<Image> allImageState = ReplayProcessor.create();
// private ReplayProcessor<Post> snapshotPostsState = ReplayProcessor.create();
private PublishProcessor<Post> livePostsState = PublishProcessor.create();
private final PersistenceService persistenceService;
private final AppSettingsService appSettingsService;
private final AppStateExchange appStateExchange;
@Autowired
private PersistenceService persistenceService;
public AppStateService(PersistenceService persistenceService, AppSettingsService appSettingsService, AppStateExchange appStateExchange) {
this.appStateExchange = appStateExchange;
this.persistenceService = persistenceService;
this.appSettingsService = appSettingsService;
}
public void onImageUpdate(Image imageState) {
public synchronized void newQueueLink(QueuedVGLink queuedVGLink) {
appStateExchange.getQueue().put(queuedVGLink.getThreadId(), queuedVGLink);
appStateExchange.liveQueue().onNext(queuedVGLink);
}
persistenceService.getProcessor().onNext(currentPosts);
public synchronized void queueLinkUpdated(QueuedVGLink queuedVGLink) {
appStateExchange.liveQueue().onNext(queuedVGLink);
}
liveImageUpdates.onNext(imageState);
if (imageState.isCompleted()) {
public synchronized void removeQueueLink(String threadId) {
Optional.ofNullable(appStateExchange.getQueue().remove(threadId)).ifPresent(QueuedVGLink::remove);
}
Post postState = currentPosts.get(imageState.getPostId());
public synchronized boolean newPost(@NonNull Post post) {
if (appStateExchange.getPosts().containsKey(post.getPostId())) {
return false;
} else {
appStateExchange.getPosts().put(post.getPostId(), post);
appStateExchange.livePost().onNext(post);
persistenceService.getProcessor().onNext(appStateExchange.getPosts());
return true;
}
}
public synchronized void postUpdated(@NonNull Post post) {
appStateExchange.livePost().onNext(post);
persistenceService.getProcessor().onNext(appStateExchange.getPosts());
}
public boolean newImage(Image image) {
if (appStateExchange.getImages().containsKey(image.getUrl())) {
return false;
} else {
appStateExchange.getImages().put(image.getUrl(), image);
appStateExchange.liveImage().onNext(image);
persistenceService.getProcessor().onNext(appStateExchange.getPosts());
return true;
}
}
public synchronized void imageUpdated(Image image) {
persistenceService.getProcessor().onNext(appStateExchange.getPosts());
appStateExchange.liveImage().onNext(image);
if (image.isCompleted()) {
Post postState = appStateExchange.getPosts().get(image.getPostId());
postState.increase();
}
}
public Image createImage(String pageUrl, String postId, String postName, Host host) {
return new Image(pageUrl, postId, postName, host, this);
}
public Post createPost(String title, String url, List<Image> images, Map<String, String> metadata, String postId) {
return new Post(title, url, images, metadata, postId, this);
}
public Post getPost(String postId) {
return currentPosts.get(postId);
}
public synchronized void newDownloadJob(DownloadJob downloadJob) {
public synchronized void newDownloadJob(@NonNull DownloadJob downloadJob) {
String postId = downloadJob.getImage().getPostId();
checkKeyRunningPosts(postId);
int i = runningPosts.get(postId).incrementAndGet();
if (i > 0) {
Post post = currentPosts.get(postId);
appStateExchange.running().get(postId).incrementAndGet();
}
public synchronized void postDownloadingUpdate(@NonNull String postId) {
Post post = appStateExchange.getPosts().get(postId);
if (!post.getStatus().equals(Post.Status.DOWNLOADING) && !post.getStatus().equals(Post.Status.PARTIAL)) {
post.setStatus(Post.Status.DOWNLOADING);
livePostsState.onNext(post);
appStateExchange.livePost().onNext(post);
}
}
public void doneDownloadJob(Image image) {
public synchronized void doneDownloadJob(@NonNull Image image) {
String postId = image.getPostId();
int i = runningPosts.get(postId).decrementAndGet();
Post post = currentPosts.get(postId);
if(image.getStatus().equals(Image.Status.ERROR)) {
int i = appStateExchange.running().get(postId).decrementAndGet();
Post post = appStateExchange.getPosts().get(postId);
if (image.getStatus().equals(Image.Status.ERROR)) {
post.setStatus(Post.Status.PARTIAL);
}
if (i == 0) {
if (post.getImages().stream().map(Image::getStatus).filter(e -> e.equals(Image.Status.ERROR)).count() > 0) {
appStateExchange.running().remove(postId);
if (post.getImages().stream().map(Image::getStatus).anyMatch(e -> e.equals(Image.Status.ERROR))) {
post.setStatus(Post.Status.ERROR);
} else {
post.setStatus(Post.Status.COMPLETE);
if (!Post.Status.STOPPED.equals(post.getStatus())) {
post.setStatus(Post.Status.COMPLETE);
if (appSettingsService.getSettings().getClearCompleted()) {
remove(image.getPostId());
}
}
}
livePostsState.onNext(post);
}
}
private synchronized void checkKeyRunningPosts(String key) {
if (!runningPosts.containsKey(key)) {
runningPosts.put(key, new AtomicInteger(0));
public boolean isRunning(String postId) {
AtomicInteger runningCount = appStateExchange.running().get(postId);
return runningCount != null && runningCount.get() > 0;
}
public synchronized List<String> clearAll() {
return this.appStateExchange.getPosts()
.values()
.stream()
.filter(e -> e.getStatus().equals(Post.Status.COMPLETE) && e.getDone().get() >= e.getTotal())
.map(Post::getPostId)
.peek(this::remove)
.collect(Collectors.toList());
}
public synchronized List<String> removeAll(List<String> postIds) {
if (postIds != null && !postIds.isEmpty()) {
postIds.forEach(this::remove);
return postIds;
} else {
return this.appStateExchange.getPosts()
.values()
.stream()
.map(Post::getPostId)
.peek(this::remove)
.collect(Collectors.toList());
}
}
private void checkKeyRunningPosts(@NonNull String key) {
if (!appStateExchange.running().containsKey(key)) {
appStateExchange.running().put(key, new AtomicInteger(0));
}
}
private void remove(@NonNull String postId) {
final Post post = appStateExchange.getPosts().get(postId);
if (post == null) {
return;
}
post.setRemoved(true);
appStateExchange.running().remove(postId);
appStateExchange.getPosts().remove(postId);
appStateExchange.getImages().entrySet().removeIf(entry -> entry.getValue().getPostId().equals(postId));
persistenceService.getProcessor().onNext(appStateExchange.getPosts());
}
@Getter
public static class CachedThread {
private Map<String, Post> posts = new ConcurrentHashMap<>();
private AtomicInteger parsed = new AtomicInteger(0);
@Setter
private int total = 0;
}
}
@@ -0,0 +1,29 @@
package tn.mnlr.vripper.services;
import io.reactivex.Scheduler;
import io.reactivex.schedulers.Schedulers;
import lombok.Getter;
import org.springframework.stereotype.Service;
import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@Service
public class CommonExecutor {
@Getter
private final ExecutorService generalExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
private final ExecutorService schedulerExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Getter
private final Scheduler scheduler = Schedulers.from(schedulerExecutor);
@PreDestroy
private void destroy() throws InterruptedException {
generalExecutor.shutdown();
generalExecutor.awaitTermination(10, TimeUnit.SECONDS);
schedulerExecutor.shutdown();
schedulerExecutor.awaitTermination(10, TimeUnit.SECONDS);
}
}
@@ -4,13 +4,19 @@ import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.net.URI;
import java.util.concurrent.TimeUnit;
@Service
@EnableScheduling
public class ConnectionManager {
private ConnectionManager() {
@@ -20,35 +26,48 @@ public class ConnectionManager {
private PoolingHttpClientConnectionManager pcm;
private RequestConfig rc = RequestConfig.custom()
.setConnectionRequestTimeout(10_000)
.setConnectTimeout(10_000)
.setSocketTimeout(10_000)
.setConnectionRequestTimeout(5_000)
.setConnectTimeout(5_000)
.setSocketTimeout(5_000)
.setCookieSpec(CookieSpecs.STANDARD)
.build();
private void buildConnectionPool() {
pcm = new PoolingHttpClientConnectionManager();
pcm.setMaxTotal(200);
pcm.setDefaultMaxPerRoute(10);
pcm.setMaxTotal(50);
pcm.setDefaultMaxPerRoute(4);
}
@Scheduled(fixedDelay = 1000)
private void idleConnectionMonitoring() {
pcm.closeExpiredConnections();
pcm.closeIdleConnections(30, TimeUnit.SECONDS);
}
public HttpClientBuilder getClient() {
return HttpClients.custom()
.setConnectionManager(pcm)
.setRetryHandler(new DefaultHttpRequestRetryHandler(5, true))
.setRedirectStrategy(new LaxRedirectStrategy())
.disableAutomaticRetries()
.setDefaultRequestConfig(rc);
}
public HttpGet buildHttpGet(String url) {
HttpGet httpGet = new HttpGet(url);
HttpGet httpGet = new HttpGet(url.replace(" ", "+"));
httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
return httpGet;
}
public HttpPost buildHttpPost(String url) {
HttpPost httpPost = new HttpPost(url);
HttpPost httpPost = new HttpPost(url.replace(" ", "+"));
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
return httpPost;
}
public HttpGet buildHttpGet(URI uri) {
HttpGet httpGet = new HttpGet(uri);
httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
return httpGet;
}
}
@@ -0,0 +1,26 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
@Getter
public class DownloadSpeed {
private final String type = "downSpeed";
private String speed;
public DownloadSpeed(long bytes) {
speed = formatSI(bytes);
}
private String formatSI(long bytes) {
return humanReadableByteCount(bytes, false);
}
private String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
}
@@ -0,0 +1,40 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import lombok.Getter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.concurrent.atomic.AtomicLong;
@Service
@EnableScheduling
public class DownloadSpeedService {
private AtomicLong read = new AtomicLong(0);
private long currentValue;
@Getter
private PublishProcessor<Long> readBytesPerSecond = PublishProcessor.create();
private boolean allowWrite = false;
public void increase(long read) {
if (allowWrite) {
this.read.addAndGet(read);
}
}
@Scheduled(fixedDelay = 1000)
private void calc() {
allowWrite = false;
long newValue = read.getAndSet(0);
if (newValue != currentValue) {
currentValue = newValue;
readBytesPerSecond.onNext(currentValue);
}
allowWrite = true;
}
}
@@ -0,0 +1,35 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
import java.util.Objects;
@Getter
public class GlobalState {
private final String type = "globalState";
private long running;
private long queued;
private long remaining;
private long error;
GlobalState(long running, long queued, long remaining, long error) {
this.running = running;
this.queued = queued;
this.remaining = remaining;
this.error = error;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GlobalState that = (GlobalState) o;
return running == that.running && queued == that.queued && remaining == that.remaining && error == that.error;
}
@Override
public int hashCode() {
return Objects.hash(type, running, queued, remaining, error);
}
}
@@ -0,0 +1,54 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.q.DownloadQ;
import tn.mnlr.vripper.q.ExecutionService;
@Service
@EnableScheduling
public class GlobalStateService {
private final DownloadQ downloadQ;
private final ExecutionService executionService;
private final AppStateExchange appStateExchange;
@Getter
private GlobalState currentState;
@Getter
private PublishProcessor<GlobalState> liveGlobalState = PublishProcessor.create();
@Autowired
public GlobalStateService(DownloadQ downloadQ, ExecutionService executionService, AppStateExchange appStateExchange) {
this.downloadQ = downloadQ;
this.executionService = executionService;
this.appStateExchange = appStateExchange;
}
@Scheduled(fixedDelay = 3000)
private void interval() {
GlobalState newGlobalState = new GlobalState(
executionService.runningCount(),
downloadQ.size(),
appStateExchange.getImages()
.values()
.stream()
.filter(e -> e.getTotal() == 0 || e.getTotal() != e.getCurrent().get())
.count(),
appStateExchange.getImages()
.values()
.stream()
.filter(e -> e.getStatus().equals(Image.Status.ERROR))
.count());
if (!newGlobalState.equals(currentState)) {
currentState = newGlobalState;
liveGlobalState.onNext(currentState);
}
}
}
@@ -11,10 +11,6 @@ import tn.mnlr.vripper.exception.HtmlProcessorException;
@Service
public class HtmlProcessorService {
private HtmlProcessorService() {
}
public Document clean(String htmlContent) throws HtmlProcessorException {
try {
TagNode clean = new HtmlCleaner().clean(htmlContent);
@@ -0,0 +1,119 @@
package tn.mnlr.vripper.services;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.entities.Post;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
public class PathService {
private static final Logger logger = LoggerFactory.getLogger(PathService.class);
private final AppSettingsService appSettingsService;
private final CommonExecutor commonExecutor;
private final int MAX_DELETE_ATTEMPTS = 180;
@Autowired
public PathService(AppSettingsService appSettingsService, CommonExecutor commonExecutor) {
this.appSettingsService = appSettingsService;
this.commonExecutor = commonExecutor;
}
public final File getDownloadDestinationFolder(Post post) {
return _getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), post.getPostFolderName());
}
private File _getDownloadDestinationFolder(@NonNull String forum, @NonNull String threadTitle, @NonNull String title) {
File sourceFolder = appSettingsService.getSettings().getSubLocation() ? new File(appSettingsService.getSettings().getDownloadPath(), sanitize(forum)) : new File(appSettingsService.getSettings().getDownloadPath());
sourceFolder = appSettingsService.getSettings().getThreadSubLocation() ? new File(sourceFolder, threadTitle) : sourceFolder;
return new File(sourceFolder, title);
}
public synchronized final void createDefaultPostFolder(Post post) {
File sourceFolder = _getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(post.getTitle()));
File destFolder = makeDirs(sourceFolder);
post.setPostFolderName(destFolder.getName());
}
public synchronized final void rename(Post post, String altName) {
post.setTitle(altName);
if (post.getPostFolderName() == null) {
return;
}
File newDestFolder = makeDirs(_getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(altName)));
File currentDesFolder = getDownloadDestinationFolder(post);
post.setPostFolderName(newDestFolder.getName());
List<File> files = Optional.ofNullable(currentDesFolder.listFiles()).stream().flatMap(Arrays::stream).filter(e -> !e.getName().endsWith(".tmp")).collect(Collectors.toList());
for (File f : files) {
try {
Files.move(f.toPath(), Paths.get(newDestFolder.toString(), f.toPath().getFileName().toString()), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
logger.error(String.format("Failed to move files from %s to %s", currentDesFolder.toString(), newDestFolder.toString()), e);
return;
}
}
commonExecutor.getGeneralExecutor().submit(() -> {
int attemptCount = 0;
while (Objects.requireNonNull(currentDesFolder.listFiles()).length != 0 && attemptCount < MAX_DELETE_ATTEMPTS) {
try {
attemptCount++;
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
if (!currentDesFolder.delete()) {
logger.warn(String.format("Failed to remove %s", currentDesFolder.toString()));
}
});
}
private synchronized File makeDirs(@NonNull final File sourceFolder) {
int counter = 1;
File folder = sourceFolder;
while (folder.exists()) {
folder = new File(sourceFolder.toString() + '.' + counter++);
}
if (!folder.mkdirs()) {
throw new RuntimeException(String.format("Failed to create the folder %s", sourceFolder.toString()));
}
return folder;
}
private String sanitize(final String folderName) {
String sanitizedFolderName = folderName.replaceAll("\\.|\\\\|/|\\||:|\\?|\\*|\"|<|>|\\p{Cntrl}", "_");
logger.debug(String.format("%s sanitized to %s", folderName, sanitizedFolderName));
return sanitizedFolderName;
}
/**
* Will sanitize the image name and remove extension
*
* @param imageName path string
* @return Sanitized local path string
*/
public final String formatImageFileName(String imageName) {
return sanitize(imageName);
}
}
@@ -1,22 +1,31 @@
package tn.mnlr.vripper.services;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.reactivex.disposables.Disposable;
import io.reactivex.processors.PublishProcessor;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.EventListenerBean;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.entities.mixin.persistance.ImagePersistanceMixin;
import tn.mnlr.vripper.entities.mixin.persistance.PostPersistanceMixin;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -26,29 +35,77 @@ public class PersistenceService {
private static final Logger logger = LoggerFactory.getLogger(PersistenceService.class);
@Autowired
private AppStateService stateService;
private final AppStateExchange appStateExchange;
@Value("${base.dir}")
private String baseDir;
@Getter
private String dataPath;
private ObjectMapper om;
private Disposable subscription;
@Getter
private PublishProcessor<Map<String, Post>> processor = PublishProcessor.create();
private PersistenceService() {
@Autowired
private PersistenceService(AppStateExchange appStateExchange) {
this.appStateExchange = appStateExchange;
om = new ObjectMapper();
om.addMixIn(Image.class, ImagePersistanceMixin.class);
om.addMixIn(Post.class, PostPersistanceMixin.class);
processor
.onBackpressureLatest()
.buffer(10, TimeUnit.SECONDS)
subscription = processor
.onBackpressureBuffer()
.buffer(1, TimeUnit.SECONDS)
.filter(e -> !e.isEmpty())
.map(e -> e.get(0))
.doOnNext(this::persist)
.doOnNext(e -> this.persist(e.get(0)))
.subscribe();
}
public void persist(Map<String, Post> currentPosts) {
try(PrintWriter out = new PrintWriter(VripperApplication.dataPath)) {
@PostConstruct
public void init() {
dataPath = baseDir + File.separator + ".vripper" + File.separator + "data.json";
File dataFile = new File(dataPath);
if (!dataFile.exists()) {
try {
if (dataFile.getParentFile().mkdirs()) {
logger.debug(String.format("%s is created", dataFile.getParentFile().toString()));
}
if (!dataFile.getParentFile().isDirectory() || !dataFile.getParentFile().canWrite()) {
logger.error(String.format("Unable to write in %s", dataFile.getParent()));
SpringContext.close();
}
if (dataFile.createNewFile()) {
logger.debug("Data file successfully created");
try (FileWriter fw = new FileWriter(dataFile)) {
fw.write("{}");
}
} else {
logger.warn("Data file already exists");
}
} catch (IOException e) {
logger.error("Unable to create data file", e);
SpringContext.close();
}
}
}
@PreDestroy
public void preDestroy() {
this.subscription.dispose();
logger.info(String.format("Destroying %s", PersistenceService.class.getSimpleName()));
logger.info("Persisting data before destroying");
if (EventListenerBean.isInit()) {
this.persist(appStateExchange.getPosts());
}
}
private void persist(Map<String, Post> currentPosts) {
try (PrintWriter out = new PrintWriter(dataPath, StandardCharsets.UTF_8)) {
out.print(om.writeValueAsString(currentPosts));
} catch (IOException e) {
logger.error("Failed to persist app state", e);
@@ -61,6 +118,14 @@ public class PersistenceService {
return om.readValue(content, om.getTypeFactory().constructMapType(HashMap.class, String.class, Post.class));
} catch (IOException e) {
logger.error("Failed to read app state", e);
long timestamp = new Date().getTime();
logger.warn(String.format("trying to rename old data file from %s to %s", dataPath, dataPath + "." + timestamp + ".old"));
try {
Files.move(new File(dataPath).toPath(), new File(dataPath + "." + timestamp + ".old").toPath());
} catch (IOException ex) {
logger.error(String.format("Failed to rename %s to %s", dataPath, dataPath + ".old"));
SpringContext.close();
}
}
return new HashMap<>();
@@ -68,29 +133,14 @@ public class PersistenceService {
public void restore() {
String jsonContent;
String jsonContent = null;
try {
jsonContent = new String(Files.readAllBytes(Paths.get(VripperApplication.dataPath)));
jsonContent = String.join("", Files.readAllLines(Paths.get(dataPath), StandardCharsets.UTF_8));
} catch (Exception e) {
logger.warn("data file not found, previous state cannot be restored", e);
return;
logger.error("data file cannot be read, previous state cannot be restored", e);
SpringContext.close();
}
Map<String, Post> read = read(jsonContent);
stateService.getCurrentPosts().clear();
stateService.getCurrentPosts().putAll(read);
stateService.getCurrentImages().clear();
read.values().stream().flatMap(e -> e.getImages().stream()).forEach(e -> {
e.setAppStateService(stateService);
stateService.getCurrentImages().put(e.getUrl(), e);
// stateService.getAllImageState().onNext(e);
});
read.values().forEach(e -> {
e.setAppStateService(stateService);
// stateService.getSnapshotPostsState().onNext(e);
});
appStateExchange.restore(read(jsonContent));
}
}
@@ -1,187 +1,60 @@
package tn.mnlr.vripper.services;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.host.Host;
import java.util.ArrayList;
import java.util.List;
import tn.mnlr.vripper.q.DownloadQ;
@Service
public class PostParser {
private static final Logger logger = LoggerFactory.getLogger(PostParser.class);
private final static String VIPER_GIRLS_BASE_ADRESS = "https://vipergirls.to/";
private final static String POSTS_XPATH = "//li[contains(@id,'post_')][not(contains(@id,'post_thank'))]";
private final static String REAL_THREAD_XPATH = ".//a[@class='postcounter']";
private final static String THREAD_TITLE_XPATH = "//li[contains(@class, 'lastnavbit')]/span";
private final static String POST_TITLE_XPATH = ".//h2";
private final static String POST_LINKS_XPATH = ".//a";
static final String VR_API = "https://vipergirls.to/vr.php";
private final AppStateExchange appStateExchange;
private final AppSettingsService appSettingsService;
private final DownloadQ downloadQ;
@Autowired
private ConnectionManager cm;
public PostParser(AppStateExchange appStateExchange, AppSettingsService appSettingsService, DownloadQ downloadQ) {
this.appStateExchange = appStateExchange;
this.appSettingsService = appSettingsService;
this.downloadQ = downloadQ;
}
@Autowired
private HtmlProcessorService htmlProcessorService;
public synchronized void addPost(String postId, String threadId) throws PostParseException {
@Autowired
private XpathService xpathService;
@Autowired
private List<Host> supportedHosts;
@Autowired
private AppStateService appStateService;
public List<Post> parse(String threadUrl) throws PostParseException {
logger.info(String.format("Parsing thread %s", threadUrl));
List<Post> posts = new ArrayList<>();
String postResponse;
HttpClient connection = cm.getClient().build();
HttpGet httpGet = cm.buildHttpGet(threadUrl);
logger.info(String.format("Requesting %s", httpGet));
try (CloseableHttpResponse response = (CloseableHttpResponse) connection.execute(httpGet)) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new DownloadException(String.format("Unexpected response code '%d' for %s", response.getStatusLine().getStatusCode(), httpGet));
}
postResponse = EntityUtils.toString(response.getEntity());
logger.debug(String.format("Content received for %s:%n%s", httpGet, postResponse));
EntityUtils.consumeQuietly(response.getEntity());
} catch (Exception e) {
throw new PostParseException(e);
if (appStateExchange.getPosts().containsKey(postId)) {
logger.warn(String.format("skipping %s, already loaded", postId));
return;
}
Document document;
try {
logger.debug(String.format("Cleaning HTML response for XML parsing: %s", postResponse));
document = htmlProcessorService.clean(postResponse);
} catch (Exception e) {
throw new PostParseException(e);
}
VRPostParser vrPostParser = new VRPostParser(threadId, postId);
Post post = vrPostParser.parse();
String threadTitle = null;
try {
logger.info(String.format("Looking for thread title using xpath: %s", THREAD_TITLE_XPATH));
Node threadTitleNode = xpathService.getAsNode(document, THREAD_TITLE_XPATH);
if (threadTitleNode != null) {
threadTitle = threadTitleNode.getTextContent().trim();
logger.info(String.format("Thread title found %s", threadTitle));
}
if (threadTitle == null) {
logger.warn("Cannot find thread's title");
}
} catch (Exception e) {
throw new PostParseException(e);
}
NodeList postsNodeList;
try {
logger.info(String.format("Looking for posts using xpath: %s", POSTS_XPATH));
postsNodeList = xpathService.getAsNodeList(document, POSTS_XPATH);
} catch (Exception e) {
throw new PostParseException(e);
}
logger.info(String.format("Found %d posts in thread %s", postsNodeList.getLength(), threadUrl));
for (int i = 0; i < postsNodeList.getLength(); i++) {
String realUrl;
logger.info(String.format("Parsing post #%d", i + 1));
if (appSettingsService.getSettings().getAutoStart()) {
logger.debug("Auto start downloads option is enabled");
logger.debug(String.format("Starting to enqueue %d jobs for %s", post.getImages().size(), post.getUrl()));
post.setStatus(Post.Status.PENDING);
try {
logger.info(String.format("Finding posts's link"));
realUrl = VIPER_GIRLS_BASE_ADRESS.concat(xpathService
.getAsNode(postsNodeList.item(i), REAL_THREAD_XPATH)
.getAttributes()
.getNamedItem("href")
.getTextContent()
.trim());
logger.info(String.format("Post's link: %s", realUrl));
} catch (Exception e) {
throw new PostParseException(e);
}
logger.info("Finding posts's id");
String postId = realUrl.substring(realUrl.indexOf("#")).replace("#post", "");
logger.info(String.format("Post's id: %s", postId));
if (appStateService.getCurrentPosts().containsKey(postId)) {
logger.warn(String.format("Post with id %s is already loaded, skipping", postId));
continue;
}
String postTitle;
try {
logger.info(String.format("Finding post's title"));
Node titleNode = xpathService.getAsNode(postsNodeList.item(i), POST_TITLE_XPATH);
if (titleNode != null) {
postTitle = titleNode.getTextContent().trim();
logger.info(String.format("Found post's title: %s", postTitle));
} else {
logger.info("Cannot find post's title");
if (threadTitle != null) {
logger.info("Falling back to thread title to generate a post name");
postTitle = threadTitle + "#" + postId;
} else {
logger.info("Falling back to post id to generate a post name");
postTitle = "#" + postId;
}
}
} catch (Exception e) {
throw new PostParseException(e);
}
ArrayList<Image> imagesList = new ArrayList<>();
try {
logger.info(String.format("Finding all links for post with id %s using xpath %s", postId, POST_LINKS_XPATH));
NodeList imagesNodeList = xpathService.getAsNodeList(postsNodeList.item(i), POST_LINKS_XPATH);
for (int j = 0; j < imagesNodeList.getLength(); j++) {
Node imageHref = imagesNodeList.item(j).getAttributes().getNamedItem("href");
Host foundHost;
if (imageHref != null) {
String imageUrl = imageHref.getTextContent().trim();
logger.info(String.format("Scanning %s", imageUrl));
foundHost = supportedHosts.stream().filter(host -> host.isSupported(imageUrl)).findFirst().orElse(null);
} else {
logger.warn("href is null, skipping");
continue;
}
if (foundHost != null) {
logger.info(String.format("Found supported host %s for %s", foundHost.getClass().getSimpleName(), imageHref));
imagesList.add(appStateService.createImage(imageHref.getTextContent(), postId, postTitle, foundHost));
} else {
logger.warn(String.format("unsupported host for %s, skipping", imageHref));
continue;
}
}
} catch (Exception e) {
throw new PostParseException(e);
}
if (!imagesList.isEmpty()) {
logger.info(String.format("Found %d images for post with id %s", imagesList.size(), postId));
posts.add(appStateService.createPost(postTitle, realUrl, imagesList, null, postId));
} else {
logger.warn(String.format("No images found for post with id %s, skipping", postId));
downloadQ.enqueue(post);
} catch (InterruptedException e) {
logger.warn("Interruption was caught");
Thread.currentThread().interrupt();
return;
}
logger.debug(String.format("Done enqueuing jobs for %s", post.getUrl()));
} else {
post.setStatus(Post.Status.STOPPED);
logger.debug("Auto start downloads option is disabled");
}
return posts;
}
public VRThreadParser createVRThreadParser(QueuedVGLink queuedVGLink) {
return new VRThreadParser(queuedVGLink);
}
}
@@ -0,0 +1,64 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
import lombok.ToString;
import tn.mnlr.vripper.SpringContext;
import java.util.Objects;
@ToString
@Getter
public class QueuedVGLink {
private final String type = "grabQueue";
private final AppStateService appStateService;
private final String link;
private final String threadId;
private final String postId;
private int count = 0;
private boolean loading = true;
private boolean removed = false;
public QueuedVGLink(String link, String threadId, String postId) {
this.appStateService = SpringContext.getBean(AppStateService.class);
this.link = link;
this.threadId = threadId;
this.postId = postId;
}
public void done() {
this.loading = false;
this.appStateService.queueLinkUpdated(this);
}
public void increment() {
this.count++;
this.appStateService.queueLinkUpdated(this);
}
public void setCount(int count) {
this.count = count;
}
public void remove() {
this.removed = true;
appStateService.queueLinkUpdated(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
QueuedVGLink that = (QueuedVGLink) o;
return Objects.equals(threadId, that.threadId);
}
@Override
public int hashCode() {
return Objects.hash(threadId);
}
}
@@ -0,0 +1,173 @@
package tn.mnlr.vripper.services;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.Weigher;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.imgscalr.Scalr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.FileSystemUtils;
import tn.mnlr.vripper.entities.Post;
import javax.annotation.PostConstruct;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Duration;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
@Service
public class ThumbnailGenerator {
@Getter
private LoadingCache<CacheKey, byte[]> thumbnails;
@Value("${base.dir}")
private String baseDir;
private final PathService pathService;
private final AppStateExchange appStateExchange;
@Getter
private File cacheFolder;
CacheLoader<CacheKey, byte[]> loader = new CacheLoader<>() {
@Override
public byte[] load(CacheKey key) throws Exception {
Post post = appStateExchange.getPost(key.getPostId());
File destinationFolder = pathService.getDownloadDestinationFolder(post);
if (!destinationFolder.exists() || !destinationFolder.isDirectory()) {
return null;
}
return Files.readAllBytes(generateThumbnail(new File(destinationFolder, key.getImgName()), key.getPostId()).toPath());
}
};
@Autowired
public ThumbnailGenerator(PathService pathService, AppStateExchange appStateExchange) {
this.pathService = pathService;
this.appStateExchange = appStateExchange;
}
@PostConstruct
private void init() throws Exception {
cacheFolder = new File(baseDir + File.separator + ".vripper" + File.separator + "cache");
cacheFolder.mkdirs();
if (!cacheFolder.exists()) {
throw new Exception(String.format("%s could not be created", cacheFolder.toString()));
}
thumbnails = CacheBuilder.newBuilder()
.expireAfterAccess(Duration.ofMinutes(30))
.weigher((Weigher<CacheKey, byte[]>) (k, v) -> v.length)
.maximumWeight(104_857_600)
.build(loader);
}
public void clearCache() {
thumbnails.invalidateAll();
for (File file : Optional.ofNullable(cacheFolder.listFiles()).orElse(new File[]{})) {
FileSystemUtils.deleteRecursively(file);
}
}
public long cacheSize() {
final AtomicLong size = new AtomicLong(0);
try {
Files.walkFileTree(cacheFolder.toPath(), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
size.addAndGet(attrs.size());
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
System.out.println("skipped: " + file + " (" + exc + ")");
// Skip folders that can't be traversed
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
if (exc != null)
System.out.println("had trouble traversing: " + dir + " (" + exc + ")");
else
size.addAndGet(dir.toFile().length());
// Ignore errors traversing a folder
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new AssertionError("walkFileTree will not throw IOException if the FileVisitor does not");
}
return size.get();
}
private File generateThumbnail(File inputFile, String postId) throws Exception {
if (!inputFile.exists()) {
throw new Exception(String.format("Input file %s does not exist", inputFile.toString()));
}
File postsCacheFolder = new File(cacheFolder, postId);
postsCacheFolder.mkdirs();
if (!postsCacheFolder.exists()) {
throw new Exception(String.format("%s could not be created", postsCacheFolder.toString()));
}
File thumbFile = new File(postsCacheFolder, inputFile.getName());
if (thumbFile.exists()) {
return thumbFile;
}
BufferedImage image = ImageIO.read(inputFile);
BufferedImage resize = Scalr.resize(image, 350, 350);
ImageIO.write(resize, "jpg", thumbFile);
image.flush();
resize.flush();
return thumbFile;
}
@Getter
@Setter
@NoArgsConstructor
public static class CacheKey {
private String postId;
private String imgName;
public CacheKey(String postId, String imgName) {
this.postId = postId;
this.imgName = imgName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CacheKey cacheKey = (CacheKey) o;
return Objects.equals(postId, cacheKey.postId) &&
Objects.equals(imgName, cacheKey.imgName);
}
@Override
public int hashCode() {
return Objects.hash(postId, imgName);
}
}
}
@@ -0,0 +1,75 @@
package tn.mnlr.vripper.services;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import lombok.Getter;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
@Service
public class VGHandler {
private static final Logger logger = LoggerFactory.getLogger(VGHandler.class);
private final AppStateService appStateService;
private final PostParser postParser;
private final CommonExecutor commonExecutor;
@Getter
private final LoadingCache<QueuedVGLink, List<VRPostState>> cache;
@Autowired
public VGHandler(AppStateService appStateService, PostParser postParser, CommonExecutor commonExecutor) {
this.appStateService = appStateService;
this.postParser = postParser;
this.commonExecutor = commonExecutor;
CacheLoader<QueuedVGLink, List<VRPostState>> loader = new CacheLoader<>() {
@Override
public List<VRPostState> load(@NonNull QueuedVGLink queuedVGLink) throws Exception {
VRThreadParser vrThreadParser = postParser.createVRThreadParser(queuedVGLink);
return vrThreadParser.parse();
}
};
cache = CacheBuilder.newBuilder()
.expireAfterWrite(30, TimeUnit.MINUTES)
.build(loader);
}
public void handle(List<QueuedVGLink> queuedVGLinks) throws Exception {
for (QueuedVGLink queuedVGLink : queuedVGLinks) {
if (queuedVGLink.getPostId() != null) {
postParser.addPost(queuedVGLink.getPostId(), queuedVGLink.getThreadId());
} else {
Callable<Void> cl = () -> {
List<VRPostState> vrPostStates = cache.get(queuedVGLink);
queuedVGLink.setCount(vrPostStates.size());
queuedVGLink.done();
logger.debug(String.format("%d found for %s", vrPostStates.size(), queuedVGLink.getLink()));
if (vrPostStates.size() == 1) {
queuedVGLink.remove();
postParser.addPost(vrPostStates.get(0).getPostId(), vrPostStates.get(0).getThreadId());
logger.debug(String.format("threadId %s, postId %s is added automatically for download", queuedVGLink.getThreadId(), queuedVGLink.getPostId()));
} else {
appStateService.newQueueLink(queuedVGLink);
}
return null;
};
commonExecutor.getGeneralExecutor().submit(cl);
}
}
}
public void remove(String threadId) {
appStateService.removeQueueLink(threadId);
}
}
@@ -0,0 +1,268 @@
package tn.mnlr.vripper.services;
import net.jodah.failsafe.Failsafe;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.host.Host;
import javax.xml.parsers.SAXParserFactory;
import java.net.URISyntaxException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import static tn.mnlr.vripper.services.PostParser.VR_API;
class VRPostParser {
private static final Logger logger = LoggerFactory.getLogger(VRPostParser.class);
private static SAXParserFactory factory = SAXParserFactory.newInstance();
private static List<String> dictionary = Arrays.asList("download", "link", "rapidgator", "filefactory", "filefox");
private final String threadId;
private final String postId;
private final ConnectionManager cm;
private final VipergirlsAuthService vipergirlsAuthService;
private final HtmlProcessorService htmlProcessorService;
private final XpathService xpathService;
VRPostParser(String threadId, String postId) {
this.threadId = threadId;
this.postId = postId;
this.cm = SpringContext.getBean(ConnectionManager.class);
this.vipergirlsAuthService = SpringContext.getBean(VipergirlsAuthService.class);
this.htmlProcessorService = SpringContext.getBean(HtmlProcessorService.class);
this.xpathService = SpringContext.getBean(XpathService.class);
}
public Post parse() throws PostParseException {
logger.debug(String.format("Parsing post %s", postId));
HttpGet httpGet;
try {
URIBuilder uriBuilder = new URIBuilder(VR_API);
uriBuilder.setParameter("p", postId);
httpGet = cm.buildHttpGet(uriBuilder.build());
} catch (URISyntaxException e) {
throw new PostParseException(e);
}
AtomicReference<Throwable> thr = new AtomicReference<>();
HashMap<String, Object> metadata = new HashMap<>();
String postUrl = String.format("https://vipergirls.to/threads/%s/?p=%s&viewfull=1#post%s", threadId, postId, postId);
getPostExtraMetadata(postId, metadata, postUrl, thr);
if (thr.get() != null) {
logger.warn(String.format("Failed to get metadata for thread %s, post %s", threadId, postId), thr.get());
thr.set(null);
}
VRApiPostHandler handler = new VRApiPostHandler(threadId, postId, postUrl, metadata);
logger.debug(String.format("Requesting %s", httpGet));
Optional<Post> post = getPost(httpGet, handler, thr);
if (thr.get() != null || post.isEmpty()) {
logger.error(String.format("parsing failed for thread %s, post %s", threadId, postId), thr.get());
throw new PostParseException(thr.get());
}
return post.get();
}
private Optional<Post> getPost(HttpGet httpGet, VRApiPostHandler handler, AtomicReference<Throwable> thr) {
return Failsafe.with(VripperApplication.retryPolicy)
.onFailure(e -> thr.set(e.getFailure()))
.get(() -> {
HttpClient connection = cm.getClient().build();
try (CloseableHttpResponse response = (CloseableHttpResponse) connection.execute(httpGet, vipergirlsAuthService.getContext())) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new DownloadException(String.format("Unexpected response code '%d' for %s", response.getStatusLine().getStatusCode(), httpGet));
}
factory.newSAXParser().parse(response.getEntity().getContent(), handler);
EntityUtils.consumeQuietly(response.getEntity());
return handler.getParsedPost();
}
});
}
private void getPostExtraMetadata(String postId, HashMap<String, Object> metadata, String url, AtomicReference<Throwable> thr) {
HttpGet httpGet = cm.buildHttpGet(url);
Failsafe.with(VripperApplication.retryPolicy)
.onFailure(e -> thr.set(e.getFailure()))
.get(() -> {
HttpClient connection = cm.getClient().build();
try (CloseableHttpResponse response = (CloseableHttpResponse) connection.execute(httpGet, vipergirlsAuthService.getContext())) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new DownloadException(String.format("Unexpected response code '%d' for %s", response.getStatusLine().getStatusCode(), httpGet));
}
try {
Document document = htmlProcessorService.clean(EntityUtils.toString(response.getEntity()));
Node postNode = xpathService.getAsNode(document, String.format("//li[@id='post_%s']/div[contains(@class, 'postdetails')]", postId));
String postedBy = xpathService.getAsNode(postNode, "./div[contains(@class, 'userinfo')]//a[contains(@class, 'username')]//font").getTextContent().trim();
metadata.put(Post.METADATA.POSTED_BY.name(), postedBy);
Node node = xpathService.getAsNode(document, String.format("//div[@id='post_message_%s']", postId));
metadata.put(Post.METADATA.RESOLVED_NAME.name(), findTitleInContent(node));
return null;
} catch (Exception e) {
throw new PostParseException(String.format("Failed to parse thread %s, post %s", threadId, postId), e);
} finally {
EntityUtils.consumeQuietly(response.getEntity());
}
}
});
}
private List<String> findTitleInContent(Node node) {
List<String> altTitle = new ArrayList<>();
findTitle(node, altTitle);
return altTitle;
}
private boolean findTitle(Node node, List<String> altTitle) {
if (node.getNodeName().equals("a") || node.getNodeName().equals("img")) {
return false;
}
if (node.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
Node item = node.getChildNodes().item(i);
findTitle(item, altTitle);
}
} else if (node.getNodeType() == Node.TEXT_NODE) {
String text = node.getTextContent().trim();
if (!text.isEmpty() && dictionary.stream().noneMatch(e -> text.toLowerCase().contains(e.toLowerCase()))) {
altTitle.add(text);
}
}
return true;
}
}
class VRApiPostHandler extends DefaultHandler {
private static final Logger logger = LoggerFactory.getLogger(VRApiPostHandler.class);
private final Collection<Host> supportedHosts;
private final String threadId;
private final String postId;
private final HashMap<String, Object> metadata;
private final String postUrl;
private List<Image> images = new ArrayList<>();
private List<String> previews = new ArrayList<>();
private String threadTitle;
private String postTitle;
private String forum;
private String userHash;
private int previewCounter = 0;
private int index = 0;
private int imageCount;
private Post parsedPost;
VRApiPostHandler(String threadId, String postId, String postUrl, HashMap<String, Object> metadata) {
this.threadId = threadId;
this.postId = postId;
this.postUrl = postUrl;
this.metadata = metadata;
this.supportedHosts = SpringContext.getBeansOfType(Host.class).values();
}
public Optional<Post> getParsedPost() {
return Optional.ofNullable(parsedPost);
}
@Override
public void startDocument() {
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
switch (qName.toLowerCase()) {
case "forum":
forum = attributes.getValue("title").trim();
break;
case "user":
userHash = attributes.getValue("hash").trim();
break;
case "thread":
threadTitle = attributes.getValue("title").trim();
break;
case "post":
imageCount = Integer.parseInt(attributes.getValue("imagecount").trim());
postTitle = Optional.ofNullable(attributes.getValue("title")).map(e -> e.trim().isEmpty() ? null : e.trim()).orElse(threadTitle);
break;
case "image":
index++;
if (previewCounter++ < 4) {
Optional.ofNullable(attributes.getValue("thumb_url")).map(String::trim).ifPresent(previews::add);
}
String mainUrl = Optional.ofNullable(attributes.getValue("main_url")).map(String::trim).orElse(null);
if (mainUrl != null) {
Host foundHost = supportedHosts.stream().filter(host -> host.isSupported(mainUrl)).findFirst().orElse(null);
if (foundHost != null) {
logger.debug(String.format("Found supported host %s for %s", foundHost.getClass().getSimpleName(), mainUrl));
try {
images.add(new Image(mainUrl, postId, postTitle, foundHost, index));
} catch (PostParseException e) {
logger.error(String.format("Error occurred while parsing postId %s", postId));
}
} else {
logger.warn(String.format("unsupported host for %s, skipping", mainUrl));
}
}
break;
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if ("post".equals(qName.toLowerCase())) {
if (imageCount != 0) {
metadata.put(Post.METADATA.PREVIEWS.name(), previews);
AtomicReference<Throwable> thr = new AtomicReference<>();
if (thr.get() != null) {
logger.error(String.format("Failed to get extra metadata for %s", postUrl), thr.get());
}
try {
parsedPost = new Post(
postTitle,
postUrl,
images,
metadata,
postId,
threadId,
threadTitle,
forum,
userHash);
} catch (PostParseException e) {
logger.error(String.format("Error occurred while parsing postId %s", postId));
}
}
index = 0;
previewCounter = 0;
previews = new ArrayList<>();
images = new ArrayList<>();
}
}
}
@@ -0,0 +1,29 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
import java.util.List;
@Getter
public class VRPostState {
private final String type = "postParse";
private final String threadId;
private String postId;
private int number;
private String title;
private int imageCount;
private String url;
private List<String> previews;
private String hosts;
VRPostState(String threadId, String postId, int number, String title, int imageCount, String url, List<String> previews, String hosts) {
this.threadId = threadId;
this.postId = postId;
this.number = number;
this.title = title;
this.imageCount = imageCount;
this.previews = previews;
this.url = url;
this.hosts = hosts;
}
}
@@ -0,0 +1,163 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
import net.jodah.failsafe.Failsafe;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.host.Host;
import javax.xml.parsers.SAXParserFactory;
import java.io.BufferedInputStream;
import java.net.URISyntaxException;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import static tn.mnlr.vripper.services.PostParser.VR_API;
public class VRThreadParser {
private static final Logger logger = LoggerFactory.getLogger(VRThreadParser.class);
private static SAXParserFactory factory = SAXParserFactory.newInstance();
private final QueuedVGLink queuedVGLink;
private final ConnectionManager cm;
private final VipergirlsAuthService vipergirlsAuthService;
VRThreadParser(QueuedVGLink queuedVGLink) {
this.queuedVGLink = queuedVGLink;
this.cm = SpringContext.getBean(ConnectionManager.class);
this.vipergirlsAuthService = SpringContext.getBean(VipergirlsAuthService.class);
}
public List<VRPostState> parse() throws PostParseException {
logger.debug(String.format("Parsing thread %s", queuedVGLink));
HttpGet httpGet;
try {
URIBuilder uriBuilder = new URIBuilder(VR_API);
uriBuilder.setParameter("t", queuedVGLink.getThreadId());
httpGet = cm.buildHttpGet(uriBuilder.build());
} catch (URISyntaxException e) {
throw new PostParseException(e);
}
VRThreadHandler handler = new VRThreadHandler(queuedVGLink);
AtomicReference<Throwable> thr = new AtomicReference<>();
logger.debug(String.format("Requesting %s", httpGet));
List<VRPostState> posts = Failsafe.with(VripperApplication.retryPolicy)
.onFailure(e -> thr.set(e.getFailure()))
.get(() -> {
HttpClient connection = cm.getClient().build();
try (CloseableHttpResponse response = (CloseableHttpResponse) connection.execute(httpGet, vipergirlsAuthService.getContext())) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new DownloadException(String.format("Unexpected response code '%d' for %s", response.getStatusLine().getStatusCode(), httpGet));
}
try {
factory.newSAXParser().parse(new BufferedInputStream(response.getEntity().getContent()), handler);
return handler.getPosts();
} catch (Exception e) {
throw new PostParseException(String.format("Failed to parse thread %s", queuedVGLink), e);
} finally {
EntityUtils.consumeQuietly(response.getEntity());
}
}
});
if (thr.get() != null) {
logger.error(String.format("parsing failed for thread %s", queuedVGLink), thr.get());
throw new PostParseException(thr.get());
}
return posts;
}
}
class VRThreadHandler extends DefaultHandler {
private final QueuedVGLink queuedVGLink;
private final Collection<Host> supportedHosts;
private final Map<Host, AtomicInteger> hostMap = new HashMap<>();
private List<String> previews = new ArrayList<>();
private String threadTitle;
private String postId;
private String postTitle;
private int imageCount;
private int postCounter;
private int previewCounter = 0;
@Getter
private List<VRPostState> posts = new ArrayList<>();
VRThreadHandler(QueuedVGLink queuedVGLink) {
this.queuedVGLink = queuedVGLink;
this.supportedHosts = SpringContext.getBeansOfType(Host.class).values();
}
@Override
public void startDocument() {
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
switch (qName.toLowerCase()) {
case "thread":
threadTitle = attributes.getValue("title").trim();
break;
case "post":
imageCount = Integer.parseInt(attributes.getValue("imagecount").trim());
postId = attributes.getValue("id").trim();
postCounter = Integer.parseInt(attributes.getValue("number").trim());
postTitle = Optional.ofNullable(attributes.getValue("title")).map(e -> e.trim().isEmpty() ? null : e.trim()).orElse(threadTitle);
break;
case "image":
Optional.ofNullable(attributes.getValue("main_url"))
.map(String::trim)
.flatMap(mainUrl -> supportedHosts.stream().filter(host -> host.isSupported(mainUrl)).findFirst())
.ifPresent(host -> Optional.ofNullable(hostMap.get(host)).ifPresentOrElse(AtomicInteger::incrementAndGet, () -> hostMap.put(host, new AtomicInteger(0))));
if (previewCounter++ < 4) {
Optional.ofNullable(attributes.getValue("thumb_url")).map(String::trim).ifPresent(previews::add);
}
break;
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if ("post".equals(qName.toLowerCase())) {
if (imageCount != 0) {
posts.add(new VRPostState(
queuedVGLink.getThreadId(),
postId,
postCounter,
postTitle,
imageCount,
String.format("https://vipergirls.to/threads/%s/?p=%s&viewfull=1#post%s", queuedVGLink, postId, postId),
previews,
hostMap.entrySet().stream().filter(v -> v.getValue().get() > 0).map(e -> e.getKey().getHost() + " (" + e.getValue().get() + ")").collect(Collectors.joining(", "))
));
queuedVGLink.increment();
}
previewCounter = 0;
previews = new ArrayList<>();
hostMap.clear();
}
}
@Override
public void endDocument() {
queuedVGLink.done();
}
}
@@ -1,10 +1,14 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import lombok.Getter;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
@@ -12,11 +16,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.exception.VripperException;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
@@ -24,55 +28,76 @@ public class VipergirlsAuthService {
private static final Logger logger = LoggerFactory.getLogger(VipergirlsAuthService.class);
@Autowired
private ConnectionManager cm;
private final ConnectionManager cm;
private final AppSettingsService appSettingsService;
private final CommonExecutor commonExecutor;
@Autowired
private HtmlProcessorService htmlProcessorService;
@Autowired
private XpathService xpathService;
@Autowired
private AppSettingsService appSettingsService;
private String cookies;
@Getter
private final HttpClientContext context = HttpClientContext.create();
@Getter
private boolean authenticated = false;
@Getter
private String loggedUser;
@Getter
private final PublishProcessor<String> loggedInUser = PublishProcessor.create();
@Autowired
public VipergirlsAuthService(ConnectionManager cm, AppSettingsService appSettingsService, CommonExecutor commonExecutor) {
this.cm = cm;
this.appSettingsService = appSettingsService;
this.commonExecutor = commonExecutor;
}
@PostConstruct
private void init() {
context.setCookieStore(new BasicCookieStore());
try {
authenticate();
} catch (VripperException e) {
logger.error("Cannot authenticate user with ViperGirls", e);
}
}
public void authenticate() throws VripperException {
logger.info("Authenticating using ViperGirls credentials");
authenticated = false;
if(!appSettingsService.isVLogin()) {
logger.warn("Authentication option is disabled");
cookies = null;
if (!appSettingsService.getSettings().getVLogin()) {
logger.debug("Authentication option is disabled");
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
return;
}
String username = appSettingsService.getVUsername();
String password = appSettingsService.getVPassword();
String username = appSettingsService.getSettings().getVUsername();
String password = appSettingsService.getSettings().getVPassword();
if (username == null || password == null || username.isEmpty() || password.isEmpty()) {
logger.error("Cannot authenticate with ViperGirls credentials, username or password is empty");
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
return;
}
HttpPost postAuth = cm.buildHttpPost("https://vipergirls.to/login.php?do=login");
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("vb_login_username", username));
params.add(new BasicNameValuePair("vb_login_password", ""));
params.add(new BasicNameValuePair("vb_login_password_hint", "Password"));
params.add(new BasicNameValuePair("cookieuser", "1"));
params.add(new BasicNameValuePair("securitytoken", "guest"));
params.add(new BasicNameValuePair("do", "login"));
params.add(new BasicNameValuePair("vb_login_md5password", password));
params.add(new BasicNameValuePair("vb_login_md5password_utf", password));
try {
postAuth.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
throw new VripperException(e);
}
@@ -81,95 +106,67 @@ public class VipergirlsAuthService {
CloseableHttpClient client = cm.getClient().build();
try (CloseableHttpResponse response = client.execute(postAuth)) {
try (CloseableHttpResponse response = client.execute(postAuth, context)) {
StringBuilder sb = new StringBuilder();
Arrays.asList(response.getHeaders("set-cookie"))
.stream()
.map(e -> e.getValue())
.map(e -> e.split(";")[0])
.filter(e -> e.startsWith("vg_lastactivity") || e.startsWith("vg_userid") || e.startsWith("vg_password"))
.forEach(e -> sb.append(e).append(";"));
String cookies = sb.toString();
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new VripperException(String.format("Unexpected response code returned %s", response.getStatusLine().getStatusCode()));
}
String responseBody = EntityUtils.toString(response.getEntity());
logger.debug(String.format("Authentication with ViperGirls response body:%n%s", responseBody));
EntityUtils.consumeQuietly(response.getEntity());
if(!cookies.contains("vg_userid")) {
if (context.getCookieStore().getCookies().stream().map(Cookie::getName).noneMatch(e -> e.equals("vg_userid"))) {
throw new VripperException("Failed to authenticate user with ViperRipper");
}
this.cookies = cookies;
} catch (Exception e) {
throw new VripperException(e);
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
if (e instanceof VripperException) {
throw (VripperException) e;
} else {
throw new VripperException(e);
}
}
authenticated = true;
loggedUser = username;
logger.info(String.format("Authenticated: %s", username));
loggedInUser.onNext(loggedUser);
}
public void leaveThanks(String postUrl, String postId) throws VripperException {
if (!appSettingsService.isVLogin()) {
logger.warn("Authentication with ViperGirls option is disabled");
public void leaveThanks(Post post) {
if (!appSettingsService.getSettings().getVLogin()) {
logger.debug("Authentication with ViperGirls option is disabled");
return;
}
if (!appSettingsService.isVThanks()) {
logger.warn("Leave thanks option is disabled");
if (!appSettingsService.getSettings().getVThanks()) {
logger.debug("Leave thanks option is disabled");
return;
}
if (!authenticated) {
logger.error("You are not authenticated");
return;
}
try {
postThanks(postId, getSecurityToken(postUrl));
} catch (VripperException e) {
throw new VripperException(e);
if (post.getMetadata().get(Post.METADATA.THANKED.name()) != null && (boolean) post.getMetadata().get(Post.METADATA.THANKED.name())) {
logger.debug("Already left a thanks");
return;
}
commonExecutor.getGeneralExecutor().submit(() -> {
try {
postThanks(post);
} catch (Exception e) {
logger.error(String.format("Failed to leave a thanks for url %s, post id %s", post.getUrl(), post.getPostId()), e);
}
});
}
private String getSecurityToken(String url) throws VripperException {
String securityToken = "";
HttpGet httpGet = cm.buildHttpGet(url);
httpGet.addHeader("Referer", "https://vipergirls.to/");
httpGet.addHeader("Host", "vipergirls.to");
httpGet.addHeader("Cookie", cookies);
CloseableHttpClient client = cm.getClient().build();
try (CloseableHttpResponse response = client.execute(httpGet)) {
String postPage = EntityUtils.toString(response.getEntity());
Document document = htmlProcessorService.clean(postPage);
String thanksUrl = xpathService
.getAsNode(document, "//li[contains(@id,'post_')][not(contains(@id,'post_thank'))]//a[@class='post_thanks_button']")
.getAttributes()
.getNamedItem("href")
.getTextContent()
.trim();
securityToken = Arrays.asList(thanksUrl.split("&amp;")).stream()
.filter(v -> v.startsWith("securitytoken"))
.findAny()
.orElse("")
.replace("securitytoken=", "");
EntityUtils.consumeQuietly(response.getEntity());
} catch (Exception e) {
throw new VripperException(e);
}
return securityToken;
}
private void postThanks(String postId, String securityKey) throws VripperException {
private void postThanks(Post post) throws VripperException {
HttpPost postThanks = cm.buildHttpPost("https://vipergirls.to/post_thanks.php");
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("do", "post_thanks_add"));
params.add(new BasicNameValuePair("using_ajax", "1"));
params.add(new BasicNameValuePair("p", postId));
params.add(new BasicNameValuePair("securitytoken", securityKey));
params.add(new BasicNameValuePair("p", post.getPostId()));
params.add(new BasicNameValuePair("securitytoken", post.getSecurityToken()));
try {
postThanks.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
@@ -178,15 +175,20 @@ public class VipergirlsAuthService {
postThanks.addHeader("Referer", "https://vipergirls.to/");
postThanks.addHeader("Host", "vipergirls.to");
postThanks.addHeader("Cookie", cookies);
CloseableHttpClient client = cm.getClient().build();
try (CloseableHttpResponse response = client.execute(postThanks)) {
try (CloseableHttpResponse response = client.execute(postThanks, context)) {
if (response.getStatusLine().getStatusCode() / 100 == 2) {
post.getMetadata().put(Post.METADATA.THANKED.name(), true);
}
EntityUtils.consumeQuietly(response.getEntity());
} catch (Exception e) {
throw new VripperException(e);
}
if (!((Boolean) post.getMetadata().get(Post.METADATA.THANKED.name()))) {
throw new VripperException("Failed to leave");
}
}
}
@@ -12,20 +12,8 @@ import javax.xml.xpath.XPathFactory;
@Service
public class XpathService {
private XpathService() {
}
private XPath xpath = XPathFactory.newInstance().newXPath();
public NodeList getAsNodeList(Node source, String xpathExpression) throws XpathException {
try {
return (NodeList) xpath.compile(xpathExpression).evaluate(source, XPathConstants.NODESET);
} catch (Exception e) {
throw new XpathException(e);
}
}
public Node getAsNode(Node source, String xpathExpression) throws XpathException {
try {
return (Node) xpath.compile(xpathExpression).evaluate(source, XPathConstants.NODE);
@@ -34,4 +22,12 @@ public class XpathService {
}
}
public NodeList getAsNodeList(Node source, String xpathExpression) throws XpathException {
try {
return (NodeList) xpath.compile(xpathExpression).evaluate(source, XPathConstants.NODESET);
} catch (Exception e) {
throw new XpathException(e);
}
}
}
@@ -1,10 +1,14 @@
package tn.mnlr.vripper.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
import tn.mnlr.vripper.web.wsendpoints.WebSocketHandler;
@Configuration
@@ -16,6 +20,24 @@ public class WebSocketConfig implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(handler, "/endpoint").setAllowedOrigins("*").withSockJS();
registry.addHandler(handler, "/endpoint").setAllowedOrigins("*");
}
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(2);
scheduler.setThreadNamePrefix("scheduled-task-");
scheduler.setDaemon(true);
return scheduler;
}
@Bean
public ServletServerContainerFactoryBean createWebSocketContainer() {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxSessionIdleTimeout(0L);
return container;
}
}
@@ -0,0 +1,212 @@
package tn.mnlr.vripper.web.restendpoints;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.services.AppStateExchange;
import tn.mnlr.vripper.services.PathService;
import tn.mnlr.vripper.services.ThumbnailGenerator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@RestController
@CrossOrigin(value = "*")
public class GalleryEndpoint {
private static final Logger logger = LoggerFactory.getLogger(GalleryEndpoint.class);
private static final String cacheControl = CacheControl.maxAge(365, TimeUnit.DAYS).getHeaderValue();
private final PathService pathService;
private final ThumbnailGenerator thumbnailGenerator;
private final AppSettingsService appSettingsService;
private final AppStateExchange appStateExchange;
@Autowired
public GalleryEndpoint(PathService pathService, ThumbnailGenerator thumbnailGenerator, AppSettingsService appSettingsService, AppStateExchange appStateExchange) {
this.pathService = pathService;
this.thumbnailGenerator = thumbnailGenerator;
this.appSettingsService = appSettingsService;
this.appStateExchange = appStateExchange;
}
@ExceptionHandler(Exception.class)
public ResponseEntity handleException(Exception e) {
logger.error("Error when process request", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(e.getMessage());
}
@GetMapping(value = "/image/{postId}/{imgName}", produces = {MediaType.IMAGE_JPEG_VALUE})
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<byte[]> getImage(@PathVariable("postId") @NonNull String postId, @PathVariable("imgName") @NonNull String imgName, HttpServletResponse response) throws Exception {
if (!appSettingsService.getSettings().getViewPhotos()) {
return new ResponseEntity("Gallery option is disabled", HttpStatus.BAD_REQUEST);
}
response.addHeader("Cache-Control", cacheControl);
Post post = appStateExchange.getPost(postId);
File destinationFolder = pathService.getDownloadDestinationFolder(post);
return ResponseEntity.ok(Files.readAllBytes(Paths.get(destinationFolder.toPath().toString(), imgName)));
}
@GetMapping(value = "/image/thumb/{postId}/{imgName}", produces = {MediaType.IMAGE_JPEG_VALUE})
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<byte[]> getImageThumb(@PathVariable("postId") @NonNull String postId, @PathVariable("imgName") @NonNull String imgName, HttpServletResponse response) throws Exception {
if (!appSettingsService.getSettings().getViewPhotos()) {
return new ResponseEntity("Gallery option is disabled", HttpStatus.BAD_REQUEST);
}
response.addHeader("Cache-Control", cacheControl);
Post post = appStateExchange.getPost(postId);
File destinationFolder = pathService.getDownloadDestinationFolder(post);
if (destinationFolder.exists() && destinationFolder.isDirectory()) {
return ResponseEntity.ok(thumbnailGenerator.getThumbnails().get(new ThumbnailGenerator.CacheKey(postId, imgName)));
}
return new ResponseEntity("Gallery does not exist in download location, you probably removed it", HttpStatus.BAD_REQUEST);
}
@GetMapping("/gallery/{postId}")
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<List<GalleryImage>> getGallery(@PathVariable("postId") @NonNull String postId) {
if (!appSettingsService.getSettings().getViewPhotos()) {
return new ResponseEntity("Gallery option is disabled", HttpStatus.BAD_REQUEST);
}
Post post = appStateExchange.getPost(postId);
File destinationFolder = pathService.getDownloadDestinationFolder(post);
if (destinationFolder.exists() && destinationFolder.isDirectory()) {
return ResponseEntity.ok(
Arrays.stream(Objects.requireNonNull(destinationFolder.listFiles()))
.filter(f -> !f.getName().endsWith("tmp"))
.filter(f -> f.getName().toLowerCase().endsWith(".jpg") || f.getName().toLowerCase().endsWith(".jpeg"))
.sorted(Comparator.comparing(File::getName))
.map(GalleryImage::fromFile)
.filter(Objects::nonNull)
.collect(Collectors.toList())
);
}
return new ResponseEntity("Gallery does not exist in download location, you probably removed it", HttpStatus.BAD_REQUEST);
}
@GetMapping("/gallery/cache")
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<CacheSize> getCacheSize() {
return ResponseEntity.ok(new CacheSize(humanReadableByteCount(thumbnailGenerator.cacheSize(), false)));
}
@GetMapping("/gallery/cache/clear")
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<CacheSize> clearCache() {
thumbnailGenerator.clearCache();
return ResponseEntity.ok(new CacheSize(humanReadableByteCount(thumbnailGenerator.cacheSize(), false)));
}
private String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
}
@Getter
@Setter
@NoArgsConstructor
class CacheSize {
private String size;
public CacheSize(String size) {
this.size = size;
}
}
@Getter
@Setter
@NoArgsConstructor
class GalleryImage {
private static final CacheLoader<File, Dimension> loader = new CacheLoader<>() {
@Override
public Dimension load(File file) {
try (ImageInputStream in = ImageIO.createImageInputStream(file)) {
final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
if (readers.hasNext()) {
ImageReader reader = readers.next();
try {
reader.setInput(in);
return new Dimension(reader.getWidth(0), reader.getHeight(0));
} finally {
reader.dispose();
}
} else {
logger.error(String.format("No reader found for image %s", file.toString()));
return null;
}
} catch (Exception e) {
logger.error(String.format("Failed to create image object for %s", file.toString()), e);
return null;
}
}
};
private static final LoadingCache<File, Dimension> cache = CacheBuilder.newBuilder()
.maximumSize(20000)
.build(loader);
private static final Logger logger = LoggerFactory.getLogger(GalleryImage.class);
private String title;
private String src;
private String msrc;
private double w;
private double h;
public GalleryImage(String title, String src, String msrc, double w, double h) {
this.title = title;
this.src = src;
this.msrc = msrc;
this.w = w;
this.h = h;
}
public static GalleryImage fromFile(File file) {
Dimension dimension = null;
try {
dimension = cache.get(file);
} catch (ExecutionException e) {
logger.error(String.format("Failed to get image dimensions for %s", file.toString()), e);
}
if (dimension == null) {
return null;
}
return new GalleryImage(file.getName(), file.getName(), file.getName(), dimension.getWidth(), dimension.getHeight());
}
}
@@ -1,21 +1,27 @@
package tn.mnlr.vripper.web.restendpoints;
import lombok.Getter;
import lombok.ToString;
import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.q.DownloadQ;
import tn.mnlr.vripper.services.AppStateService;
import tn.mnlr.vripper.services.PostParser;
import tn.mnlr.vripper.services.VipergirlsAuthService;
import tn.mnlr.vripper.entities.Post.METADATA;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.q.ExecutionService;
import tn.mnlr.vripper.services.*;
import tn.mnlr.vripper.web.restendpoints.domain.posts.*;
import tn.mnlr.vripper.web.restendpoints.exceptions.BadRequestException;
import tn.mnlr.vripper.web.restendpoints.exceptions.NotFoundException;
import tn.mnlr.vripper.web.restendpoints.exceptions.ServerErrorException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@RestController
@CrossOrigin(value = "*")
@@ -23,79 +29,174 @@ public class PostRestEndpoint {
private static final Logger logger = LoggerFactory.getLogger(PostRestEndpoint.class);
@Autowired
private AppStateService appStateService;
private static final Pattern VG_URL_PATTERN = Pattern.compile("https://vipergirls\\.to/threads/(\\d+)((.*p=)(\\d+))?");
private final AppStateService appStateService;
private final AppStateExchange appStateExchange;
private final PathService pathService;
private final VGHandler vgHandler;
private final ExecutionService executionService;
private final PostParser postParser;
private final CommonExecutor commonExecutor;
@Autowired
private AppSettingsService appSettingsService;
@Autowired
private VipergirlsAuthService authService;
@ExceptionHandler(Exception.class)
public ResponseEntity handleException(Exception e) {
logger.error("Error when process request", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(e.getMessage());
public PostRestEndpoint(AppStateService appStateService, AppStateExchange appStateExchange, PathService pathService, VGHandler vgHandler, ExecutionService executionService, PostParser postParser, CommonExecutor commonExecutor) {
this.appStateService = appStateService;
this.appStateExchange = appStateExchange;
this.pathService = pathService;
this.vgHandler = vgHandler;
this.executionService = executionService;
this.postParser = postParser;
this.commonExecutor = commonExecutor;
}
@Autowired
private DownloadQ downloadQ;
@Autowired
private PostParser postParser;
@PostMapping("/post")
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity processPost(@RequestBody ThreadUrl url) throws Exception {
logger.info(String.format("Starting to process thread: %s", url.url));
if (url.url == null || url.url.isEmpty()) {
return new ResponseEntity<>("Failed to process empty request", HttpStatus.BAD_REQUEST);
} else if (!url.url.startsWith("https://vipergirls.to")) {
return new ResponseEntity<>("ViperGirls only links are supported", HttpStatus.BAD_REQUEST);
@ResponseStatus(code = HttpStatus.OK)
public void processPost(@RequestBody ThreadUrl _url) {
if (_url.getUrl() == null || _url.getUrl().isEmpty()) {
throw new BadRequestException("Failed to process empty request");
}
List<Post> parsed = postParser.parse(url.url);
logger.info(String.format("%d posts found from thread %s", parsed.size(), url.url));
parsed.forEach(p -> {
try {
authService.leaveThanks(p.getUrl(), p.getPostId());
} catch (Exception e) {
logger.error(String.format("Failed to leave thanks for %s", p.getUrl()), e);
List<String> urls = Arrays.stream(_url.getUrl().split("\\r?\\n")).map(String::trim).filter(e -> !e.isEmpty()).collect(Collectors.toList());
ArrayList<QueuedVGLink> queuedVGLinks = new ArrayList<>();
for (String url : urls) {
logger.debug(String.format("Starting to process thread: %s", url));
if (!url.startsWith("https://vipergirls.to")) {
logger.error(String.format("Unsupported link %s", url));
continue;
}
});
if(appSettingsService.isAutoStart()) {
logger.info("Auto start downloads option is enabled");
logger.info(String.format("Starting to enqueue %d jobs for %s", parsed.stream().flatMap(e -> e.getImages().stream()).count(), url.url));
parsed.forEach(post -> downloadQ.enqueue(post));
logger.info(String.format("Done enqueuing jobs for %s", url.url));
} else {
logger.info("Auto start downloads option is disabled");
String threadId, postId;
Matcher m = VG_URL_PATTERN.matcher(url);
if (m.find()) {
threadId = m.group(1);
postId = m.group(4);
} else {
throw new BadRequestException(String.format("Cannot retrieve thread id from URL %s", url));
}
queuedVGLinks.add(new QueuedVGLink(url, threadId, postId));
}
try {
vgHandler.handle(queuedVGLinks);
} catch (Exception e) {
throw new ServerErrorException(e.getMessage());
}
logger.info(String.format("Done processing thread: %s", url.url));
return new ResponseEntity(HttpStatus.OK);
}
@PostMapping("/post/restart")
@ResponseStatus(value = HttpStatus.OK)
public void restartPost(@RequestBody PostId postId) throws Exception {
downloadQ.restart(postId.getPostId());
public void restartPost(@RequestBody @NonNull List<PostId> postIds) {
executionService.restartAll(postIds.stream().map(PostId::getPostId).collect(Collectors.toList()));
}
@PostMapping("/post/add")
@ResponseStatus(value = HttpStatus.OK)
public void addPost(@RequestBody List<PostToAdd> posts) {
for (PostToAdd post : posts) {
commonExecutor.getGeneralExecutor().submit(() -> {
try {
postParser.addPost(post.getPostId(), post.getThreadId());
} catch (PostParseException e) {
logger.error(String.format("Failed to add post %s", post.getPostId()), e);
}
});
}
}
@GetMapping("/post/path/{postId}")
@ResponseStatus(value = HttpStatus.OK)
public DownloadPath folderPath(@PathVariable("postId") String postId) {
Post post = appStateExchange.getPost(postId);
if (post.getPostFolderName() == null) {
throw new NotFoundException("Download has not been started yet for this post");
} else {
return new DownloadPath(pathService.getDownloadDestinationFolder(post).getPath());
}
}
@PostMapping("/post/restart/all")
@ResponseStatus(value = HttpStatus.OK)
public void restartPost() {
executionService.restartAll(null);
}
@PostMapping("/post/stop")
@ResponseStatus(value = HttpStatus.OK)
public void stop(@RequestBody PostId postId) throws Exception {
downloadQ.stop(postId.getPostId());
public void stop(@RequestBody @NonNull List<PostId> postIds) {
executionService.stopAll(postIds.stream().map(PostId::getPostId).collect(Collectors.toList()));
}
@Getter
@ToString
private static class ThreadUrl {
private String url;
@PostMapping("/post/stop/all")
@ResponseStatus(value = HttpStatus.OK)
public void stopAll() {
executionService.stopAll(null);
}
@Getter
private static class PostId {
private String postId;
@PostMapping("/post/remove")
@ResponseStatus(value = HttpStatus.OK)
public List<RemoveResult> remove(@RequestBody @NonNull List<PostId> postIds) {
List<RemoveResult> result = new ArrayList<>();
List<String> collect = postIds.stream().map(PostId::getPostId).peek(e -> result.add(new RemoveResult(e))).collect(Collectors.toList());
executionService.stopAll(collect);
appStateService.removeAll(collect);
return result;
}
@PostMapping("/post/rename")
@ResponseStatus(value = HttpStatus.OK)
public List<AltPostName> rename(@RequestBody @NonNull List<AltPostName> postToRename) {
for (AltPostName altPostName : postToRename) {
Post post = appStateExchange.getPost(altPostName.getPostId());
try {
pathService.rename(post, altPostName.getAltName());
} catch (Exception e) {
throw new ServerErrorException(e.getMessage());
}
}
return postToRename;
}
@PostMapping("/post/rename/first")
@ResponseStatus(value = HttpStatus.OK)
public List<PostId> renameFirst(@RequestBody @NonNull List<PostId> postToRename) {
for (PostId postId : postToRename) {
Post post = appStateExchange.getPost(postId.getPostId());
if (post.getMetadata().get(METADATA.RESOLVED_NAME.name()) != null) {
List<String> resolvedNames = ((List<String>) post.getMetadata().get(METADATA.RESOLVED_NAME.name()));
if (!resolvedNames.isEmpty()) {
try {
pathService.rename(post, resolvedNames.get(0));
} catch (Exception e) {
throw new ServerErrorException(e.getMessage());
}
}
}
}
return postToRename;
}
@PostMapping("/post/clear/all")
@ResponseStatus(value = HttpStatus.OK)
public RemoveAllResult clearAll() {
return new RemoveAllResult(appStateService.clearAll());
}
@PostMapping("/post/remove/all")
@ResponseStatus(value = HttpStatus.OK)
public RemoveAllResult removeAll() {
return new RemoveAllResult(appStateService.removeAll(null));
}
@GetMapping("/grab/{threadId}")
@ResponseStatus(value = HttpStatus.OK)
public List<VRPostState> grab(@PathVariable("threadId") @NonNull String threadId) throws Exception {
QueuedVGLink queuedVGLink = appStateExchange.getQueue().values().stream().filter(e -> e.getThreadId().equals(threadId)).findFirst().orElseThrow();
return vgHandler.getCache().get(queuedVGLink);
}
@PostMapping("/grab/remove")
@ResponseStatus(value = HttpStatus.OK)
public ThreadId grabRemove(@RequestBody @NonNull ThreadId threadId) {
vgHandler.remove(threadId.getThreadId());
return threadId;
}
}
@@ -1,89 +1,62 @@
package tn.mnlr.vripper.web.restendpoints;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.exception.ValidationException;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.services.VipergirlsAuthService;
import tn.mnlr.vripper.web.restendpoints.exceptions.BadRequestException;
@RestController
@CrossOrigin(value = "*")
public class SettingsRestEndpoint {
private static final Logger logger = LoggerFactory.getLogger(SettingsRestEndpoint.class);
private final AppSettingsService appSettingsService;
private final VipergirlsAuthService vipergirlsAuthService;
@Autowired
private AppSettingsService settings;
public SettingsRestEndpoint(AppSettingsService appSettingsService, VipergirlsAuthService vipergirlsAuthService) {
this.appSettingsService = appSettingsService;
this.vipergirlsAuthService = vipergirlsAuthService;
}
@Autowired
private VipergirlsAuthService vipergirlsAuthService;
@PostMapping("/settings/theme")
@ResponseStatus(value = HttpStatus.OK)
public AppSettingsService.Theme postTheme(@RequestBody AppSettingsService.Theme theme) {
synchronized (this.appSettingsService) {
this.appSettingsService.setTheme(theme);
return appSettingsService.getTheme();
}
}
@ExceptionHandler(Exception.class)
public ResponseEntity handleException(Exception e) {
logger.error("Error when process request", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(e.getMessage());
@GetMapping("/settings/theme")
@ResponseStatus(value = HttpStatus.OK)
public AppSettingsService.Theme getTheme() {
return appSettingsService.getTheme();
}
@PostMapping("/settings")
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity postSettings(@RequestBody AppSettingsService.Settings settings) throws Exception {
public AppSettingsService.Settings postSettings(@RequestBody AppSettingsService.Settings settings) throws Exception {
try {
this.settings.check(settings);
} catch (ValidationException e) {
return new ResponseEntity(new Response(e.getMessage()), HttpStatus.BAD_REQUEST);
}
this.settings.setDownloadPath(settings.getDownloadPath());
this.settings.setMaxThreads(settings.getMaxThreads());
this.settings.setAutoStart(settings.isAutoStart());
this.settings.setVLogin(settings.isVLogin());
if(settings.isVLogin()) {
this.settings.setVUsername(settings.getVUsername());
if (!this.settings.getVPassword().equals(settings.getVPassword())) {
this.settings.setVPassword(settings.getVPassword());
synchronized (this.appSettingsService) {
try {
this.appSettingsService.check(settings);
} catch (ValidationException e) {
throw new BadRequestException(e.getMessage());
}
this.settings.setVThanks(settings.isVThanks());
} else {
this.settings.setVUsername("");
this.settings.setVPassword("");
this.settings.setVThanks(false);
this.appSettingsService.newSettings(settings);
vipergirlsAuthService.authenticate();
}
this.settings.save();
vipergirlsAuthService.authenticate();
return new ResponseEntity(HttpStatus.OK);
return getAppSettingsService();
}
@GetMapping("/settings")
@ResponseStatus(value = HttpStatus.OK)
public AppSettingsService.Settings getSettings() throws Exception {
public AppSettingsService.Settings getAppSettingsService() {
return new AppSettingsService.Settings(
settings.getDownloadPath(),
settings.getMaxThreads(),
settings.isAutoStart(),
settings.isVLogin(),
settings.getVUsername(),
settings.getVPassword(),
settings.isVThanks()
);
}
@Getter
class Response {
String message;
public Response(String message) {
this.message = message;
}
return appSettingsService.getSettings();
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class AltPostName {
private String postId;
private String altName;
}
@@ -0,0 +1,18 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class DownloadPath {
private String path;
public DownloadPath(String path) {
this.path = path;
}
}
@@ -0,0 +1,18 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class PostId {
private String postId;
public PostId(String postId) {
this.postId = postId;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class PostToAdd {
private String threadId;
private String postId;
}
@@ -0,0 +1,22 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class RemoveAllResult {
private List<String> postIds;
private int removed;
public RemoveAllResult(List<String> postIds) {
this.removed = postIds.size();
this.postIds = postIds;
}
}
@@ -0,0 +1,18 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class RemoveResult {
private String postId;
public RemoveResult(String postId) {
this.postId = postId;
}
}
@@ -0,0 +1,14 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class ThreadId {
private String threadId;
}
@@ -0,0 +1,14 @@
package tn.mnlr.vripper.web.restendpoints.domain.posts;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class ThreadUrl {
private String url;
}
@@ -0,0 +1,11 @@
package tn.mnlr.vripper.web.restendpoints.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public class BadRequestException extends RuntimeException {
public BadRequestException(String message) {
super(message);
}
}
@@ -0,0 +1,11 @@
package tn.mnlr.vripper.web.restendpoints.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.NOT_FOUND)
public class NotFoundException extends RuntimeException {
public NotFoundException(String message) {
super(message);
}
}
@@ -0,0 +1,11 @@
package tn.mnlr.vripper.web.restendpoints.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
public class ServerErrorException extends RuntimeException {
public ServerErrorException(String message) {
super(message);
}
}
@@ -2,8 +2,9 @@ package tn.mnlr.vripper.web.wsendpoints;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,12 +17,15 @@ import tn.mnlr.vripper.entities.Image;
import tn.mnlr.vripper.entities.Post;
import tn.mnlr.vripper.entities.mixin.ui.ImageUIMixin;
import tn.mnlr.vripper.entities.mixin.ui.PostUIMixin;
import tn.mnlr.vripper.services.AppStateService;
import tn.mnlr.vripper.services.*;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -30,30 +34,31 @@ public class WebSocketHandler extends TextWebSocketHandler {
private static final Logger logger = LoggerFactory.getLogger(WebSocketHandler.class);
@Getter
private static class WSMessage {
private final GlobalStateService globalStateService;
private final AppStateExchange appStateExchange;
private final DownloadSpeedService downloadSpeedService;
private final VipergirlsAuthService vipergirlsAuthService;
private final CommonExecutor commonExecutor;
private final Map<String, Disposable> postsSubscriptions = new ConcurrentHashMap<>();
private final Map<String, Disposable> postDetailsSubscriptions = new ConcurrentHashMap<>();
private final Map<String, Disposable> stateSubscriptions = new ConcurrentHashMap<>();
private final Map<String, Disposable> downloadSpeedSubscriptions = new ConcurrentHashMap<>();
private final Map<String, Disposable> userSubscriptions = new ConcurrentHashMap<>();
private final Map<String, Disposable> grabQueueSubscriptions = new ConcurrentHashMap<>();
private final Map<String, Future<Void>> threadParseRequests = new ConcurrentHashMap<>();
private String cmd;
private String payload;
enum CMD {
POSTS_SUB,
POST_DETAILS_SUB,
POSTS_UNSUB,
POST_DETAILS_UNSUB
}
}
public WebSocketHandler() {
om.addMixIn(Image.class, ImageUIMixin.class).addMixIn(Post.class, PostUIMixin.class);
}
private Map<String, Disposable> postsSubscriptions = new ConcurrentHashMap<>();
private Map<String, Disposable> postDetailsSubscriptions = new ConcurrentHashMap<>();
private ObjectMapper om = new ObjectMapper();
private final ObjectMapper om = new ObjectMapper();
@Autowired
private AppStateService appStateService;
public WebSocketHandler(GlobalStateService globalStateService, AppStateExchange appStateExchange, DownloadSpeedService downloadSpeedService, VipergirlsAuthService vipergirlsAuthService, CommonExecutor commonExecutor) {
this.globalStateService = globalStateService;
this.appStateExchange = appStateExchange;
this.downloadSpeedService = downloadSpeedService;
this.vipergirlsAuthService = vipergirlsAuthService;
this.commonExecutor = commonExecutor;
om.addMixIn(Image.class, ImageUIMixin.class).addMixIn(Post.class, PostUIMixin.class);
}
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
@@ -61,6 +66,18 @@ public class WebSocketHandler extends TextWebSocketHandler {
WSMessage wsMessage = om.readValue(message.getPayload(), WSMessage.class);
WSMessage.CMD cmd = WSMessage.CMD.valueOf(wsMessage.getCmd());
switch (cmd) {
case GRAB_QUEUE_SUB:
subscribeForGrabQueue(session);
break;
case GLOBAL_STATE_SUB:
subscribeForGlobalState(session);
break;
case SPEED_SUB:
subscribeForSpeed(session);
break;
case USER_SUB:
subscribeForUser(session);
break;
case POSTS_SUB:
subscribeForPosts(session);
break;
@@ -68,67 +85,182 @@ public class WebSocketHandler extends TextWebSocketHandler {
subscribeForPostDetails(session, wsMessage.getPayload());
break;
case POST_DETAILS_UNSUB:
logger.info(String.format("Client %s unsubscribed from post details", session.getId()));
Optional.ofNullable(postDetailsSubscriptions.remove(session.getId())).ifPresent(d -> d.dispose());
logger.debug(String.format("Client %s unsubscribed from post details", session.getId()));
Optional.ofNullable(postDetailsSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
break;
case POSTS_UNSUB:
logger.info(String.format("Client %s unsubscribed from posts", session.getId()));
Optional.ofNullable(postsSubscriptions.remove(session.getId())).ifPresent(d -> d.dispose());
logger.debug(String.format("Client %s unsubscribed from posts", session.getId()));
Optional.ofNullable(postsSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
break;
case GLOBAL_STATE_UNSUB:
logger.debug(String.format("Client %s unsubscribed from global state", session.getId()));
Optional.ofNullable(stateSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
break;
case SPEED_UNSUB:
logger.debug(String.format("Client %s unsubscribed from download speed info", session.getId()));
Optional.ofNullable(downloadSpeedSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
break;
case USER_UNSUB:
logger.debug(String.format("Client %s unsubscribed from user info", session.getId()));
Optional.ofNullable(userSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
break;
case GRAB_QUEUE_UNSUB:
logger.debug(String.format("Client %s unsubscribed from grab queue", session.getId()));
Optional.ofNullable(grabQueueSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
break;
}
}
private void subscribeForGlobalState(WebSocketSession session) {
logger.debug(String.format("Client %s subscribed for global state", session.getId()));
if (stateSubscriptions.containsKey(session.getId())) {
stateSubscriptions.get(session.getId()).dispose();
}
try {
send(session, new TextMessage(om.writeValueAsString(Collections.singletonList(globalStateService.getCurrentState()))));
} catch (Exception e) {
logger.error("Unexpected error occurred", e);
}
stateSubscriptions.put(session.getId(),
globalStateService.getLiveGlobalState()
.subscribeOn(commonExecutor.getScheduler())
.onBackpressureBuffer()
.map(Collections::singleton)
.map(om::writeValueAsString)
.map(TextMessage::new)
.subscribe(msg -> send(session, msg), e -> logger.error("Failed to send data to client", e))
);
}
private void subscribeForSpeed(WebSocketSession session) {
logger.debug(String.format("Client %s subscribed for download speed info", session.getId()));
if (downloadSpeedSubscriptions.containsKey(session.getId())) {
downloadSpeedSubscriptions.get(session.getId()).dispose();
}
try {
send(session, new TextMessage(om.writeValueAsString(Collections.singletonList(new DownloadSpeed(0)))));
} catch (Exception e) {
logger.error("Unexpected error occurred", e);
}
downloadSpeedSubscriptions.put(session.getId(),
downloadSpeedService.getReadBytesPerSecond()
.subscribeOn(commonExecutor.getScheduler())
.onBackpressureBuffer()
.map(e -> Collections.singleton(new DownloadSpeed(e)))
.map(om::writeValueAsString)
.map(TextMessage::new)
.subscribe(msg -> send(session, msg), e -> logger.error("Failed to send data to client", e))
);
}
private void subscribeForUser(WebSocketSession session) {
logger.debug(String.format("Client %s subscribed for user info", session.getId()));
if (userSubscriptions.containsKey(session.getId())) {
userSubscriptions.get(session.getId()).dispose();
}
try {
send(session, new TextMessage(om.writeValueAsString(Collections.singletonList(new LoggedUser(vipergirlsAuthService.getLoggedUser())))));
} catch (Exception e) {
logger.error("Unexpected error occurred", e);
}
userSubscriptions.put(session.getId(),
vipergirlsAuthService.getLoggedInUser()
.subscribeOn(commonExecutor.getScheduler())
.onBackpressureBuffer()
.map(e -> Collections.singleton(new LoggedUser(e)))
.map(om::writeValueAsString)
.map(TextMessage::new)
.subscribe(msg -> send(session, msg), e -> logger.error("Failed to send data to client", e))
);
}
private void subscribeForPosts(WebSocketSession session) {
logger.info(String.format("Client %s subscribed for posts", session.getId()));
logger.debug(String.format("Client %s subscribed for posts", session.getId()));
if (postsSubscriptions.containsKey(session.getId())) {
postsSubscriptions.get(session.getId()).dispose();
}
try {
send(session, new TextMessage(om.writeValueAsString(appStateService.getCurrentPosts().values())));
send(session, new TextMessage(om.writeValueAsString(appStateExchange.getPosts().values())));
} catch (Exception e) {
logger.error("Unexpected error occurred", e);
}
postsSubscriptions.put(session.getId(), appStateService.getLivePostsState()
.onBackpressureBuffer()
.observeOn(Schedulers.io())
.buffer(2, TimeUnit.SECONDS)
.filter(e -> !e.isEmpty())
.map(e -> e.stream().distinct().collect(Collectors.toList()))
.map(om::writeValueAsString)
.map(TextMessage::new)
.subscribe(msg -> send(session, msg), e -> logger.error("Failed to send data to client", e))
postsSubscriptions.put(session.getId(),
appStateExchange.livePost()
.subscribeOn(commonExecutor.getScheduler())
.onBackpressureBuffer()
.buffer(2000, TimeUnit.MILLISECONDS, 200)
.filter(e -> !e.isEmpty())
.map(HashSet::new)
.map(om::writeValueAsString)
.map(TextMessage::new)
.subscribe(msg -> send(session, msg), e -> logger.error("Failed to send data to client", e))
);
}
private void subscribeForGrabQueue(WebSocketSession session) {
logger.debug(String.format("Client %s subscribed for grab queue", session.getId()));
if (grabQueueSubscriptions.containsKey(session.getId())) {
grabQueueSubscriptions.get(session.getId()).dispose();
}
try {
send(session, new TextMessage(om.writeValueAsString(appStateExchange.getQueue().values())));
} catch (Exception e) {
logger.error("Unexpected error occurred", e);
}
grabQueueSubscriptions.put(session.getId(),
appStateExchange.liveQueue()
.subscribeOn(commonExecutor.getScheduler())
.onBackpressureBuffer()
.buffer(2000, TimeUnit.MILLISECONDS, 200)
.filter(e -> !e.isEmpty())
.map(HashSet::new)
.map(om::writeValueAsString)
.map(TextMessage::new)
.subscribe(msg -> send(session, msg), e -> logger.error("Failed to send data to client", e))
);
}
private void subscribeForPostDetails(WebSocketSession session, String postId) {
logger.info(String.format("Client %s subscribed for post details with id = %s", session.getId(), postId));
logger.debug(String.format("Client %s subscribed for post details with id = %s", session.getId(), postId));
if (postDetailsSubscriptions.containsKey(session.getId())) {
postDetailsSubscriptions.get(session.getId()).dispose();
}
try {
send(session, new TextMessage(om.writeValueAsString(
appStateService.getCurrentImages()
appStateExchange.getImages()
.values()
.stream()
.filter(e -> e.getPostId().equals(postId))
.collect(Collectors.toList())))
.collect(Collectors.toSet())))
);
} catch (Exception e) {
logger.error("Unexpected error occurred", e);
}
postDetailsSubscriptions.put(session.getId(), appStateService.getLiveImageUpdates()
postDetailsSubscriptions.put(session.getId(), appStateExchange.liveImage()
.subscribeOn(commonExecutor.getScheduler())
.onBackpressureBuffer()
.observeOn(Schedulers.io())
.filter(e -> e.getPostId().equals(postId))
.buffer(2, TimeUnit.SECONDS)
.buffer(2000, TimeUnit.MILLISECONDS, 500)
.filter(e -> !e.isEmpty())
.map(e -> e.stream().distinct().collect(Collectors.toList()))
.map(HashSet::new)
.map(om::writeValueAsString)
.map(TextMessage::new)
.subscribe(msg -> send(session, msg), e -> logger.error("Failed to send data to client", e))
@@ -141,13 +273,55 @@ public class WebSocketHandler extends TextWebSocketHandler {
@Override
public void afterConnectionEstablished(WebSocketSession session) {
logger.debug(String.format("Connection open for client id: %s", session.getId()));
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
Optional.ofNullable(postsSubscriptions.remove(session.getId())).ifPresent(d -> d.dispose());
Optional.ofNullable(postDetailsSubscriptions.remove(session.getId())).ifPresent(d -> d.dispose());
Optional.ofNullable(postsSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
Optional.ofNullable(postDetailsSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
Optional.ofNullable(stateSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
Optional.ofNullable(downloadSpeedSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
Optional.ofNullable(userSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
Optional.ofNullable(grabQueueSubscriptions.remove(session.getId())).ifPresent(Disposable::dispose);
Optional.ofNullable(threadParseRequests.remove(session.getId())).ifPresent(d -> d.cancel(true));
logger.debug(String.format("Connection closed for client id: %s", session.getId()));
}
@Getter
@Setter
@NoArgsConstructor
private static class WSMessage {
private String cmd;
private String payload;
enum CMD {
POSTS_SUB,
POST_DETAILS_SUB,
POSTS_UNSUB,
POST_DETAILS_UNSUB,
GLOBAL_STATE_SUB,
GLOBAL_STATE_UNSUB,
SPEED_SUB,
SPEED_UNSUB,
USER_SUB,
USER_UNSUB,
GRAB_QUEUE_SUB,
GRAB_QUEUE_UNSUB
}
}
@Getter
private static class LoggedUser {
private final String type = "user";
private String user;
LoggedUser(String user) {
this.user = user;
}
}
}
@@ -0,0 +1 @@
base.dir=${user.home}
@@ -0,0 +1 @@
base.dir=${user.dir}
@@ -1,4 +1,9 @@
logging.level.org.springframework.web=INFO
logging.level.root=INFO
logging.level.org.apache.http=INFO
logging.file=${user.dir}/vripper.log
logging.file=${base.dir}/.vripper/vripper.log
server.port=${vripper.server.port:8080}
management.endpoints.web.exposure.include=shutdown
management.endpoint.shutdown.enabled=true
spring.profiles.active=portable
#spring.profiles.active=installer
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource=
"org/springframework/boot/logging/logback/defaults.xml" />
<include resource=
"org/springframework/boot/logging/logback/file-appender.xml" />
<include resource=
"org/springframework/boot/logging/logback/console-appender.xml" />
<appender name="ASYNC-FILE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNC-CONSOLE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="CONSOLE" />
</appender>
<root level="INFO">
<appender-ref ref="ASYNC-FILE"/>
<appender-ref ref="ASYNC-CONSOLE"/>
</root>
</configuration>

Some files were not shown because too many files have changed in this diff Show More