mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90625736e9 | ||
|
|
eff254747f | ||
|
|
b8b22f7faa | ||
|
|
6376576e9e | ||
|
|
f0c2de829a | ||
|
|
08fcd7a87d | ||
|
|
f39c7a15c7 | ||
|
|
1c239d435b | ||
|
|
d8cba97d05 | ||
|
|
a362a3fa7f | ||
|
|
4163f2a53f | ||
|
|
e556dd1804 | ||
|
|
96ad55b930 | ||
|
|
9dc1a10255 | ||
|
|
db4a041bc4 | ||
|
|
661f591bf5 | ||
|
|
e81bcfbfee | ||
|
|
e8ba07aebd | ||
|
|
9930226dc0 | ||
|
|
48491767cb | ||
|
|
49229b9dac | ||
|
|
ecf3287e61 | ||
|
|
206b305ae6 | ||
|
|
70e7a87189 | ||
|
|
5aef1c0a89 | ||
|
|
7745abbb8a | ||
|
|
e577dba7c9 | ||
|
|
ed63d5c029 | ||
|
|
2aa82a73a0 | ||
|
|
cbe5800c08 | ||
|
|
b200226060 | ||
|
|
0d22b054c9 | ||
|
|
9d18dc8897 | ||
|
|
f42d412b86 | ||
|
|
f8370801c2 | ||
|
|
51dcaa1946 | ||
|
|
a833a0b1b2 | ||
|
|
79739b80f9 | ||
|
|
26cf60b741 | ||
|
|
bc45deed2a | ||
|
|
b1e3353a1d | ||
|
|
c018033d2f | ||
|
|
b0f5a15943 | ||
|
|
8db4d406ad | ||
|
|
47f1705abb | ||
|
|
816fb84549 | ||
|
|
5213ed7129 | ||
|
|
2483c5fa00 | ||
|
|
dfc5810fd3 | ||
|
|
fad418134e | ||
|
|
9dd91bfc07 | ||
|
|
5bd42e2ce5 | ||
|
|
e18832b154 | ||
|
|
41feb53a83 | ||
|
|
6f166b42c4 | ||
|
|
e8ee579a37 | ||
|
|
41ce99995b |
@@ -0,0 +1,55 @@
|
||||
name: Package
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B install --file pom.xml
|
||||
|
||||
- name: Rename GUI artifact
|
||||
run: mv vripper-gui/target/vripper-gui-*.jar vripper-gui/target/vripper-gui.jar
|
||||
|
||||
- name: Rename WEB artifact
|
||||
run: mv vripper-web/target/vripper-web-*.jar vripper-web/target/vripper-web.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Package Linux binaries
|
||||
run: |
|
||||
cd jpackage
|
||||
cp ../vripper-gui/target/vripper-gui.jar jar/vripper-gui.jar
|
||||
jpackage --type deb "@jpackage.cfg" "@jpackage-linux.cfg"
|
||||
jpackage --type rpm "@jpackage.cfg" "@jpackage-linux.cfg"
|
||||
ls -la dist
|
||||
|
||||
- if: matrix.os == 'windows-latest'
|
||||
name: Package Windows binaries
|
||||
run: |
|
||||
cd jpackage
|
||||
cp ../vripper-gui/target/vripper-gui.jar jar/vripper-gui.jar
|
||||
jpackage "@jpackage.cfg" "@jpackage-windows.cfg"
|
||||
dir dist
|
||||
|
||||
- if: matrix.os == 'macos-latest'
|
||||
name: Package macOS binaries
|
||||
run: |
|
||||
cd jpackage
|
||||
cp ../vripper-gui/target/vripper-gui.jar jar/vripper-gui.jar
|
||||
jpackage "@jpackage.cfg" "@jpackage-macos.cfg"
|
||||
ls -la dist
|
||||
@@ -0,0 +1,147 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Build parent project
|
||||
run: mvn -N -q install --file pom.xml
|
||||
|
||||
- name: Build Core Jar
|
||||
run: mvn -B -q install --file vripper-core/pom.xml
|
||||
|
||||
- name: Build GUI Jar
|
||||
run: mvn -B -q install --file vripper-gui/pom.xml
|
||||
|
||||
- name: Rename GUI Jar
|
||||
run: mv vripper-gui/target/vripper-gui-${{ github.event.release.tag_name }}-jar-with-dependencies.jar vripper-gui/target/vripper-noarch-gui-${{ github.event.release.tag_name }}.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Release GUI Jar
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: vripper-gui/target/vripper-noarch-gui-${{ github.event.release.tag_name }}.jar
|
||||
|
||||
# Start building WEB jar in ubuntu only
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Build WEB Jar
|
||||
run: |
|
||||
mvn -B -q install --file vripper-web-ui/pom.xml
|
||||
mvn -B -q install --file vripper-web/pom.xml
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Rename WEB Jar
|
||||
run: mv vripper-web/target/vripper-web-${{ github.event.release.tag_name }}.jar vripper-web/target/vripper-noarch-web-${{ github.event.release.tag_name }}.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Release WEB Jar
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: vripper-web/target/vripper-noarch-web-${{ github.event.release.tag_name }}.jar
|
||||
# End building WEB jar in ubuntu only
|
||||
|
||||
- name: Prepare Packaging
|
||||
run: |
|
||||
cp vripper-gui/target/vripper-noarch-gui-${{ github.event.release.tag_name }}.jar jpackage/jar/vripper-gui.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Package Linux
|
||||
run: |
|
||||
cd jpackage
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-app-image.cfg" --icon icon.png
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-linux.cfg" --type deb
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-linux.cfg" --type rpm
|
||||
mv dist/vripper-${{ github.event.release.tag_name }}-1.x86_64.rpm dist/vripper-linux-${{ github.event.release.tag_name }}.x86_64.rpm
|
||||
mv dist/vripper_${{ github.event.release.tag_name }}-1_amd64.deb dist/vripper-linux-${{ github.event.release.tag_name }}_amd64.deb
|
||||
|
||||
- if: matrix.os == 'windows-latest'
|
||||
name: Package Windows
|
||||
run: |
|
||||
cd jpackage
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-app-image.cfg" --icon icon.ico
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-windows.cfg" --type msi
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-windows.cfg" --type exe
|
||||
cd dist
|
||||
ren VRipper-${{ github.event.release.tag_name }}.msi vripper-windows-installer-${{ github.event.release.tag_name }}.msi
|
||||
ren VRipper-${{ github.event.release.tag_name }}.exe vripper-windows-installer-${{ github.event.release.tag_name }}.exe
|
||||
|
||||
- if: matrix.os == 'macos-latest'
|
||||
name: Package macOS
|
||||
run: |
|
||||
cd jpackage
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-app-image.cfg" --icon icon.icns
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-macos.cfg" --type pkg
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-macos.cfg" --type dmg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.pkg dist/vripper-macos-${{ github.event.release.tag_name }}.pkg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.dmg dist/vripper-macos-${{ github.event.release.tag_name }}.dmg
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Zip Ubuntu portable
|
||||
uses: thedoctor0/zip-release@0.7.1
|
||||
with:
|
||||
type: 'zip'
|
||||
directory: 'jpackage/dist'
|
||||
path: 'VRipper'
|
||||
filename: 'vripper-linux-portable-${{ github.event.release.tag_name }}.zip'
|
||||
|
||||
- if: matrix.os == 'windows-latest'
|
||||
name: Zip Windows portable
|
||||
uses: thedoctor0/zip-release@0.7.1
|
||||
with:
|
||||
type: 'zip'
|
||||
directory: 'jpackage/dist'
|
||||
path: 'VRipper'
|
||||
filename: 'vripper-windows-portable-${{ github.event.release.tag_name }}.zip'
|
||||
|
||||
- if: matrix.os == 'macos-latest'
|
||||
name: Zip MacOS portable
|
||||
uses: thedoctor0/zip-release@0.7.1
|
||||
with:
|
||||
type: 'zip'
|
||||
directory: 'jpackage/dist'
|
||||
path: 'VRipper.app'
|
||||
filename: 'vripper-macos-portable-${{ github.event.release.tag_name }}.zip'
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Release packages for Linux
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
jpackage/dist/vripper-linux-${{ github.event.release.tag_name }}.x86_64.rpm
|
||||
jpackage/dist/vripper-linux-${{ github.event.release.tag_name }}_amd64.deb
|
||||
jpackage/dist/vripper-linux-portable-${{ github.event.release.tag_name }}.zip
|
||||
|
||||
- if: matrix.os == 'windows-latest'
|
||||
name: Release packages for Windows
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
jpackage/dist/vripper-windows-installer-${{ github.event.release.tag_name }}.msi
|
||||
jpackage/dist/vripper-windows-installer-${{ github.event.release.tag_name }}.exe
|
||||
jpackage/dist/vripper-windows-portable-${{ github.event.release.tag_name }}.zip
|
||||
|
||||
- if: matrix.os == 'macos-latest'
|
||||
name: Release packages for macOS
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.pkg
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.dmg
|
||||
jpackage/dist/vripper-macos-portable-${{ github.event.release.tag_name }}.zip
|
||||
-726
@@ -1,726 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## [3.4.2] - 2021-05-10
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix potential issue with imagebam host
|
||||
- Enhance download queue logic
|
||||
- Code source enhancements
|
||||
- Fix app icons
|
||||
- Fix race condition bug
|
||||
|
||||
## [3.3.8] - 2021-05-05
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix imagebam host
|
||||
- Fix font path
|
||||
|
||||
## [3.3.6] - 2021-03-20
|
||||
|
||||
### Changed
|
||||
|
||||
- Optimize build size
|
||||
|
||||
## [3.3.5] - 2021-03-18
|
||||
|
||||
### Changed
|
||||
|
||||
- Bug fixe
|
||||
|
||||
## [3.3.4] - 2021-03-18
|
||||
|
||||
### Changed
|
||||
|
||||
- Bug fixes
|
||||
|
||||
## [3.3.3] - 2021-03-13
|
||||
|
||||
### Changed
|
||||
|
||||
- Remove unnecessary event logs
|
||||
|
||||
## [3.3.2] - 2021-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix a bug with event logs
|
||||
- Change event names and add some icons
|
||||
|
||||
## [3.3.1] - 2021-02-18
|
||||
|
||||
### Added
|
||||
|
||||
- Add about menu
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix README.md
|
||||
|
||||
## [3.3.0] - 2021-02-16
|
||||
|
||||
### Changed
|
||||
|
||||
- Add support for proxies
|
||||
- Add a Event Logs
|
||||
- Fix bugs with the database
|
||||
|
||||
## [3.2.3] - 2021-01-13
|
||||
|
||||
### Changed
|
||||
|
||||
- Finished posts are not cleared from the UI
|
||||
|
||||
## [3.2.2] - 2021-01-13
|
||||
|
||||
### Changed
|
||||
|
||||
- Set total download to max value
|
||||
|
||||
## [3.2.1] - 2021-01-12
|
||||
|
||||
### Added
|
||||
|
||||
- Add settings for connection timeout
|
||||
- Add settings for maximum attempts
|
||||
|
||||
### Changed
|
||||
|
||||
- Enhance posts rename logic
|
||||
- Dependencies update
|
||||
- Switch reactive from rx-java to reactor
|
||||
|
||||
## [3.2.0] - 2020-11-16
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix build issue
|
||||
|
||||
## [3.1.0] - 2020-11-16
|
||||
|
||||
### Changed
|
||||
|
||||
- UI revamp
|
||||
- Fix bugs
|
||||
|
||||
## [3.0.11] - 2020-10-31
|
||||
|
||||
### Added
|
||||
|
||||
- Support for vipr.im
|
||||
|
||||
## [3.0.10] - 2020-10-04
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix bug on settings update
|
||||
|
||||
## [3.0.9] - 2020-09-27
|
||||
|
||||
### Changed
|
||||
|
||||
- Revert to appending post id to download folders
|
||||
- Fix a bug that lead to adding duplicate posts
|
||||
- Remove old unused settings
|
||||
|
||||
## [3.0.8] - 2020-08-22
|
||||
|
||||
### Changed
|
||||
|
||||
- Bug fix which breaks concurrent downloads
|
||||
|
||||
## [3.0.7] - 2020-08-22
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix MacOs build
|
||||
|
||||
## [3.0.6] - 2020-08-18
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix TurboImageHost
|
||||
|
||||
## [3.0.5] - 2020-08-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Update packages
|
||||
- Host class refactoring
|
||||
|
||||
## [3.0.4] - 2020-08-16
|
||||
|
||||
### Changed
|
||||
|
||||
- Improve rename UI
|
||||
|
||||
## [3.0.3] - 2020-08-16
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix bugs with electron app
|
||||
|
||||
## [3.0.2] - 2020-08-15
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix bugs with download queue
|
||||
|
||||
## [3.0.1] - 2020-08-03
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix bugs with download queue
|
||||
|
||||
## [3.0.0] - 2020-08-03
|
||||
|
||||
### Changed
|
||||
|
||||
- Major rewrites
|
||||
- Introducing a proper database for persistence
|
||||
|
||||
## [2.12.1] - 2020-05-22
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix alternative name bug
|
||||
|
||||
## [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
|
||||
@@ -1,30 +1,19 @@
|
||||
# VRipper!
|
||||
|
||||
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.
|
||||
This is my spin for a cross-platform gallery ripper for [vipergirls.to](https://vipergirls.to).
|
||||
|
||||
## 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.
|
||||
You need JDK 17 and a recent version of maven 3.6.1+
|
||||
|
||||
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 run the following:
|
||||
|
||||
To build the server app:
|
||||
mvn clean install
|
||||
|
||||
mvn clean install -DskipTests
|
||||
Build artifact is located under
|
||||
|
||||
To build the desktop app:
|
||||
vripper-project\vripper-gui\target\vripper-gui-{{version}}.jar
|
||||
|
||||
mvn clean install -Pelectron -DskipTests
|
||||
Copy the artifact into any other folder and run:
|
||||
|
||||
Maven will automatically handle front end compilation. However, for development, you will need to install a recent
|
||||
version of nodejs on your system.
|
||||
|
||||
If you feel generous and want to support me, you can donate some coins, and I would be very grateful 🙏
|
||||
|
||||
I accept Bitcoin (BTC) for donations, following is my address
|
||||
|
||||
bc1q9jzzw3st49r9vmxgtylq4vrd67cl7zfclf3lsq
|
||||
java -jar vripper-gui-{{version}}.jar
|
||||
|
||||
|
Before Width: | Height: | Size: 303 KiB After Width: | Height: | Size: 303 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,2 @@
|
||||
--type app-image
|
||||
--java-options "-Dvripper.portable=true"
|
||||
@@ -0,0 +1,7 @@
|
||||
--icon icon.png
|
||||
--java-options "-Dvripper.portable=false"
|
||||
--linux-package-name vripper
|
||||
--linux-app-release 1
|
||||
--linux-menu-group Utility
|
||||
--linux-app-category java
|
||||
--linux-shortcut
|
||||
@@ -0,0 +1,4 @@
|
||||
--icon icon.icns
|
||||
--java-options "-Dvripper.portable=false"
|
||||
--mac-package-identifier me.mnlr.vripper.vripper-gui
|
||||
--mac-package-name VRipper
|
||||
@@ -0,0 +1,8 @@
|
||||
--icon icon.ico
|
||||
--java-options "-Dvripper.portable=false"
|
||||
--win-dir-chooser
|
||||
--win-menu
|
||||
--win-per-user-install
|
||||
--win-shortcut
|
||||
--win-shortcut-prompt
|
||||
--win-update-url https://github.com/death-claw/vripper-project/releases
|
||||
@@ -0,0 +1,8 @@
|
||||
--input jar
|
||||
--main-jar vripper-gui.jar
|
||||
--add-modules java.base,java.desktop,java.sql,jdk.unsupported,jdk.crypto.ec,java.security.jgss
|
||||
--jlink-options "--strip-native-commands --strip-debug --no-man-pages --no-header-files --compress=zip-6"
|
||||
--name VRipper
|
||||
--description "Image ripper tool for vipergirls"
|
||||
--dest dist
|
||||
--vendor "death-claw"
|
||||
@@ -1,20 +1,150 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.4.2</version>
|
||||
<packaging>pom</packaging>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.5</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<modules>
|
||||
<module>vripper-server</module>
|
||||
<module>vripper-ui</module>
|
||||
<module>vripper-electron</module>
|
||||
</modules>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.vripper</groupId>
|
||||
<artifactId>vripper-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>5.0.0</version>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<kotlin.version>1.9.20</kotlin.version>
|
||||
<maven.deploy.skip>false</maven.deploy.skip>
|
||||
<timestamp>${maven.build.timestamp}</timestamp>
|
||||
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<modules>
|
||||
<module>vripper-core</module>
|
||||
<module>vripper-web-ui</module>
|
||||
<module>vripper-web</module>
|
||||
<module>vripper-gui</module>
|
||||
</modules>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<version>1.4.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
|
||||
<version>1.7.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.exposed</groupId>
|
||||
<artifactId>exposed-jdbc</artifactId>
|
||||
<version>0.41.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.exposed</groupId>
|
||||
<artifactId>exposed-java-time</artifactId>
|
||||
<version>0.41.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
<version>3.5.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.insert-koin</groupId>
|
||||
<artifactId>koin-core-jvm</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jackson-module-kotlin</artifactId>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>h2</artifactId>
|
||||
<groupId>com.h2database</groupId>
|
||||
<version>2.2.224</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<version>4.5.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>htmlcleaner</artifactId>
|
||||
<groupId>net.sourceforge.htmlcleaner</groupId>
|
||||
<version>2.26</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>failsafe</artifactId>
|
||||
<groupId>net.jodah</groupId>
|
||||
<version>2.4.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<version>3.1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna-platform</artifactId>
|
||||
<version>5.13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<version>1.7.32</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<version>5.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
<version>1.16.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<version>4.24.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>liquibase-slf4j</artifactId>
|
||||
<groupId>com.mattbertolini</groupId>
|
||||
<version>5.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
Vendored
@@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>me.vripper</groupId>
|
||||
<artifactId>vripper-project</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>vripper-core</artifactId>
|
||||
<name>vripper-core</name>
|
||||
<description>vripper-core</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.exposed</groupId>
|
||||
<artifactId>exposed-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.exposed</groupId>
|
||||
<artifactId>exposed-java-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.insert-koin</groupId>
|
||||
<artifactId>koin-core-jvm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jackson-module-kotlin</artifactId>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>h2</artifactId>
|
||||
<groupId>com.h2database</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<groupId>org.slf4j</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>htmlcleaner</artifactId>
|
||||
<groupId>net.sourceforge.htmlcleaner</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>failsafe</artifactId>
|
||||
<groupId>net.jodah</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna-platform</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<groupId>org.liquibase</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>liquibase-slf4j</artifactId>
|
||||
<groupId>com.mattbertolini</groupId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<source>src/main/kotlin</source>
|
||||
<source>target/generated-sources/annotations</source>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Build-Time>${maven.build.timestamp}</Build-Time>
|
||||
<Built-By>${user.name}</Built-By>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,106 @@
|
||||
package me.vripper
|
||||
|
||||
import me.vripper.download.DownloadService
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.host.*
|
||||
import me.vripper.repositories.*
|
||||
import me.vripper.repositories.impl.*
|
||||
import me.vripper.services.*
|
||||
import org.koin.dsl.bind
|
||||
import org.koin.dsl.module
|
||||
|
||||
val coreModule = module {
|
||||
single<EventBus> {
|
||||
EventBus
|
||||
}
|
||||
single<SettingsService> {
|
||||
SettingsService(get())
|
||||
}
|
||||
single<ImageRepository> {
|
||||
ImageRepositoryImpl()
|
||||
}
|
||||
single<PostDownloadStateRepository> {
|
||||
PostDownloadStateRepositoryImpl()
|
||||
}
|
||||
single<MetadataRepository> {
|
||||
MetadataRepositoryImpl()
|
||||
}
|
||||
single<ThreadRepository> {
|
||||
ThreadRepositoryImpl()
|
||||
}
|
||||
single<LogRepository> {
|
||||
LogRepositoryImpl(get())
|
||||
}
|
||||
single<DataTransaction> {
|
||||
DataTransaction(get(), get(), get(), get(), get(), get(), get())
|
||||
}
|
||||
single<RetryPolicyService> {
|
||||
RetryPolicyService(get(), get())
|
||||
}
|
||||
single<HTTPService> {
|
||||
HTTPService(get(), get())
|
||||
}
|
||||
single<VGAuthService> {
|
||||
VGAuthService(get(), get(), get())
|
||||
}
|
||||
single<ThreadCacheService> {
|
||||
ThreadCacheService(get())
|
||||
}
|
||||
single<DownloadService> {
|
||||
DownloadService(get(), get(), get(), get(), get())
|
||||
}
|
||||
single<DownloadSpeedService> {
|
||||
DownloadSpeedService(get())
|
||||
}
|
||||
single<AppEndpointService> {
|
||||
AppEndpointService(get(), get(), get(), get())
|
||||
}
|
||||
single {
|
||||
AcidimgHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
DPicMeHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ImageBamHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ImageTwistHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ImageVenueHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ImageZillaHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ImgboxHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ImgSpiceHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ImxHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
PimpandhostHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
PixhostHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
PixRouteHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
PixxxelsHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
PostImgHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
TurboImageHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
single {
|
||||
ViprImHost(get(), get(), get())
|
||||
} bind Host::class
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package me.vripper.delegate
|
||||
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class LoggerDelegate : ReadOnlyProperty<Any?, Logger> {
|
||||
private var logger: Logger? = null
|
||||
override operator fun getValue(thisRef: Any?, property: KProperty<*>): Logger {
|
||||
if (logger == null) {
|
||||
logger = LoggerFactory.getLogger(thisRef!!.javaClass)
|
||||
}
|
||||
return logger!!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package me.vripper.download
|
||||
|
||||
import kotlinx.coroutines.Runnable
|
||||
import me.vripper.entities.Image
|
||||
import me.vripper.entities.LogEntry
|
||||
import me.vripper.entities.Post
|
||||
import me.vripper.entities.domain.Status
|
||||
import me.vripper.event.ErrorCountEvent
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.QueueStateEvent
|
||||
import me.vripper.host.Host
|
||||
import me.vripper.model.ErrorCount
|
||||
import me.vripper.model.QueueState
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.RetryPolicyService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.VGAuthService
|
||||
import me.vripper.utilities.GLOBAL_EXECUTOR
|
||||
import me.vripper.utilities.formatToString
|
||||
import net.jodah.failsafe.Failsafe
|
||||
import net.jodah.failsafe.RetryPolicy
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
class DownloadService(
|
||||
private val settingsService: SettingsService,
|
||||
private val dataTransaction: DataTransaction,
|
||||
private val retryPolicyService: RetryPolicyService,
|
||||
private val vgAuthService: VGAuthService,
|
||||
private val eventBus: EventBus
|
||||
) {
|
||||
private val maxPoolSize: Int = 24
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private val running: MutableMap<Byte, MutableList<ImageDownloadRunnable>> = mutableMapOf()
|
||||
private val pending: MutableMap<Byte, MutableList<ImageDownloadRunnable>> = mutableMapOf()
|
||||
private val lock = ReentrantLock()
|
||||
private val condition = lock.newCondition()
|
||||
|
||||
fun init() {
|
||||
Thread.ofVirtual().name("Download Loop").unstarted(Runnable {
|
||||
val accepted: MutableList<ImageDownloadRunnable> = mutableListOf()
|
||||
val candidates: MutableList<ImageDownloadRunnable> = mutableListOf()
|
||||
while (!Thread.currentThread().isInterrupted) {
|
||||
lock.withLock {
|
||||
candidates.addAll(getCandidates(candidateCount()))
|
||||
candidates.forEach {
|
||||
if (canRun(it.context.image.host)) {
|
||||
accepted.add(it)
|
||||
running[it.context.image.host]!!.add(it)
|
||||
log.debug("${it.context.image.url} accepted to run")
|
||||
}
|
||||
}
|
||||
accepted.forEach {
|
||||
pending[it.context.image.host]?.remove(it)
|
||||
scheduleForDownload(it)
|
||||
}
|
||||
accepted.clear()
|
||||
candidates.clear()
|
||||
try {
|
||||
condition.await()
|
||||
} catch (e: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
||||
fun stop(postIds: List<Long> = emptyList()) {
|
||||
if (postIds.isNotEmpty()) {
|
||||
stopInternal(postIds)
|
||||
} else {
|
||||
stopAll()
|
||||
}
|
||||
}
|
||||
|
||||
fun restartAll(postIds: List<Post> = emptyList()) {
|
||||
if (postIds.isNotEmpty()) {
|
||||
restart(postIds.associateWith { dataTransaction.findByPostIdAndIsNotCompleted(it.postId) })
|
||||
} else {
|
||||
restart(dataTransaction.findAllPosts()
|
||||
.associateWith { dataTransaction.findByPostIdAndIsNotCompleted(it.postId) })
|
||||
}
|
||||
}
|
||||
|
||||
private fun restart(posts: Map<Post, List<Image>>) {
|
||||
lock.withLock {
|
||||
val toProcess = mutableMapOf<Post, List<Image>>()
|
||||
|
||||
for ((post, images) in posts) {
|
||||
if (images.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
if (isPending(post.postId)) {
|
||||
log.warn("Cannot restart, jobs are currently running for post id $posts")
|
||||
continue
|
||||
}
|
||||
toProcess[post] = images
|
||||
}
|
||||
|
||||
toProcess.forEach { (post, images) ->
|
||||
post.status = Status.PENDING
|
||||
images.forEach { image ->
|
||||
with(image) {
|
||||
this.status = Status.PENDING
|
||||
this.downloaded = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transaction {
|
||||
dataTransaction.updatePosts(
|
||||
toProcess.keys.toList()
|
||||
)
|
||||
dataTransaction.updateImages(
|
||||
toProcess.values.flatten()
|
||||
)
|
||||
}
|
||||
|
||||
toProcess.keys.forEach {
|
||||
vgAuthService.leaveThanks(it)
|
||||
}
|
||||
|
||||
|
||||
toProcess.entries.forEach { (post, images) ->
|
||||
images.forEach { image ->
|
||||
log.debug("Enqueuing a job for ${image.url}")
|
||||
val imageDownloadRunnable = ImageDownloadRunnable(
|
||||
image, post.rank, settingsService.settings
|
||||
)
|
||||
pending.computeIfAbsent(
|
||||
image.host
|
||||
) { mutableListOf() }
|
||||
pending[image.host]!!.add(imageDownloadRunnable)
|
||||
}
|
||||
}
|
||||
|
||||
condition.signal()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isPending(postId: Long): Boolean {
|
||||
return pending.values.flatten().any { it.context.image.postId == postId }
|
||||
}
|
||||
|
||||
private fun isRunning(postId: Long): Boolean {
|
||||
return running.values.flatten().any { it.context.image.postId == postId }
|
||||
}
|
||||
|
||||
private fun stopAll() {
|
||||
lock.withLock {
|
||||
pending.values.clear()
|
||||
running.values.flatten().forEach { obj: ImageDownloadRunnable -> obj.stop() }
|
||||
dataTransaction.findAllNonCompletedPostIds().forEach {
|
||||
dataTransaction.stopImagesByPostIdAndIsNotCompleted(it)
|
||||
dataTransaction.finishPost(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopInternal(postIds: List<Long>) {
|
||||
lock.withLock {
|
||||
for (postId in postIds) {
|
||||
pending.values.forEach { pending ->
|
||||
pending.removeIf { it.context.image.postId == postId }
|
||||
}
|
||||
running.values.flatten().filter { p: ImageDownloadRunnable -> p.context.image.postId == postId }
|
||||
.forEach { obj: ImageDownloadRunnable -> obj.stop() }
|
||||
}
|
||||
postIds.forEach {
|
||||
dataTransaction.stopImagesByPostIdAndIsNotCompleted(it)
|
||||
dataTransaction.finishPost(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun canRun(host: Byte): Boolean {
|
||||
val totalRunning = running.values.sumOf { it.size }
|
||||
return (running[host]!!.size < settingsService.settings.connectionSettings.maxConcurrentPerHost && if (settingsService.settings.connectionSettings.maxGlobalConcurrent == 0) totalRunning < maxPoolSize else totalRunning < settingsService.settings.connectionSettings.maxGlobalConcurrent)
|
||||
}
|
||||
|
||||
private fun candidateCount(): Map<Byte, Int> {
|
||||
val map: MutableMap<Byte, Int> = mutableMapOf()
|
||||
Host.getHosts().values.forEach { host: Byte ->
|
||||
val imageDownloadRunnableList: List<ImageDownloadRunnable> = running.computeIfAbsent(
|
||||
host
|
||||
) { mutableListOf() }
|
||||
val count: Int =
|
||||
settingsService.settings.connectionSettings.maxConcurrentPerHost - imageDownloadRunnableList.size
|
||||
log.debug("Download slots for $host: $count")
|
||||
map[host] = count
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
private fun getCandidates(candidateCount: Map<Byte, Int>): List<ImageDownloadRunnable> {
|
||||
val hostIntegerMap: MutableMap<Byte, Int> = candidateCount.toMutableMap()
|
||||
val candidates: MutableList<ImageDownloadRunnable> = mutableListOf()
|
||||
hosts@ for (host in pending.keys) {
|
||||
|
||||
val list: List<ImageDownloadRunnable> =
|
||||
pending[host]!!.sortedWith(Comparator.comparingInt<ImageDownloadRunnable> { it.postRank }
|
||||
.thenComparingInt { it.context.image.index })
|
||||
|
||||
for (imageDownloadRunnable in list) {
|
||||
val count = hostIntegerMap[host] ?: 0
|
||||
if (count > 0) {
|
||||
candidates.add(imageDownloadRunnable)
|
||||
hostIntegerMap[host] = count - 1
|
||||
} else {
|
||||
continue@hosts
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidates
|
||||
}
|
||||
|
||||
private fun scheduleForDownload(imageDownloadRunnable: ImageDownloadRunnable) {
|
||||
log.debug("Scheduling a job for ${imageDownloadRunnable.context.image.url}")
|
||||
eventBus.publishEvent(QueueStateEvent(QueueState(runningCount(), pendingCount())))
|
||||
Failsafe.with<Any, RetryPolicy<Any>>(retryPolicyService.buildRetryPolicyForDownload()).with(GLOBAL_EXECUTOR)
|
||||
.onFailure {
|
||||
try {
|
||||
dataTransaction.saveLog(
|
||||
LogEntry(
|
||||
type = LogEntry.Type.DOWNLOAD,
|
||||
status = LogEntry.Status.ERROR,
|
||||
message = "Failed to download ${imageDownloadRunnable.context.image.url}\n ${it.failure.formatToString()}"
|
||||
)
|
||||
)
|
||||
} catch (exp: Exception) {
|
||||
log.error("Failed to save event", exp)
|
||||
}
|
||||
log.error(
|
||||
"Failed to download ${imageDownloadRunnable.context.image.url} after ${it.attemptCount} tries",
|
||||
it.failure
|
||||
)
|
||||
val image = imageDownloadRunnable.context.image
|
||||
image.status = Status.ERROR
|
||||
dataTransaction.updateImage(image)
|
||||
}.onComplete {
|
||||
afterJobFinish(imageDownloadRunnable)
|
||||
eventBus.publishEvent(
|
||||
QueueStateEvent(
|
||||
QueueState(
|
||||
runningCount(), pendingCount()
|
||||
)
|
||||
)
|
||||
)
|
||||
eventBus.publishEvent(ErrorCountEvent(ErrorCount(dataTransaction.countImagesInError())))
|
||||
log.debug(
|
||||
"Finished downloading ${imageDownloadRunnable.context.image.url}"
|
||||
)
|
||||
}.runAsync(imageDownloadRunnable::run)
|
||||
}
|
||||
|
||||
private fun afterJobFinish(imageDownloadRunnable: ImageDownloadRunnable) {
|
||||
lock.withLock {
|
||||
val image = imageDownloadRunnable.context.image
|
||||
running[image.host]!!.remove(imageDownloadRunnable)
|
||||
if (!isPending(image.postId) && !isRunning(
|
||||
image.postId
|
||||
) && !imageDownloadRunnable.context.stopped
|
||||
) {
|
||||
dataTransaction.finishPost(image.postId, true)
|
||||
}
|
||||
condition.signal()
|
||||
}
|
||||
}
|
||||
|
||||
private fun pendingCount(): Int {
|
||||
return pending.values.sumOf { it.size }
|
||||
}
|
||||
|
||||
private fun runningCount(): Int {
|
||||
return running.values.sumOf { it.size }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.vripper.download
|
||||
|
||||
import me.vripper.entities.Image
|
||||
import me.vripper.model.Settings
|
||||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase
|
||||
import org.apache.hc.client5.http.cookie.BasicCookieStore
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext
|
||||
import org.koin.core.component.KoinComponent
|
||||
|
||||
class ImageDownloadContext(val image: Image, val settings: Settings) : KoinComponent {
|
||||
|
||||
val httpContext: HttpClientContext =
|
||||
HttpClientContext.create().apply { cookieStore = BasicCookieStore() }
|
||||
val requests = mutableListOf<HttpUriRequestBase>()
|
||||
val postId = image.postIdRef
|
||||
var stopped = false
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package me.vripper.download
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.entities.Image
|
||||
import me.vripper.entities.domain.Status
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.host.DownloadedImage
|
||||
import me.vripper.host.Host
|
||||
import me.vripper.host.ImageMimeType
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.PathUtils
|
||||
import me.vripper.utilities.PathUtils.getExtension
|
||||
import net.jodah.failsafe.function.CheckedRunnable
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.util.*
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
class ImageDownloadRunnable(
|
||||
private val image: Image, val postRank: Int, private val settings: Settings
|
||||
) : KoinComponent, CheckedRunnable {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
private val hosts: List<Host> = getKoin().getAll()
|
||||
|
||||
val context: ImageDownloadContext = ImageDownloadContext(image, settings)
|
||||
private var stopped: Boolean
|
||||
get() = context.stopped
|
||||
set(value) {
|
||||
context.stopped = value
|
||||
}
|
||||
|
||||
@Throws(DownloadException::class)
|
||||
fun download() {
|
||||
try {
|
||||
image.status = Status.DOWNLOADING
|
||||
image.downloaded = 0
|
||||
dataTransaction.updateImage(image)
|
||||
val downloadDirectory: String
|
||||
synchronized(image.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId).orElseThrow()
|
||||
downloadDirectory = post.downloadDirectory
|
||||
if (post.status != Status.DOWNLOADING) {
|
||||
post.status = Status.DOWNLOADING
|
||||
dataTransaction.updatePost(post)
|
||||
}
|
||||
}
|
||||
log.debug("Getting image url and name from ${image.url} using ${image.host}")
|
||||
val host = hosts.first { it.isSupported(image.url) }
|
||||
val downloadedImage = host.downloadInternal(image.url, context)
|
||||
log.debug("Resolved name for ${image.url}: ${downloadedImage.name}")
|
||||
log.debug("Downloaded image {} to {}", image.url, downloadedImage.path)
|
||||
val sanitizedFileName = PathUtils.sanitize(downloadedImage.name)
|
||||
log.debug(
|
||||
"Sanitizing image name from ${downloadedImage.name} to $sanitizedFileName"
|
||||
)
|
||||
checkImageTypeAndRename(
|
||||
downloadDirectory, downloadedImage, image.index
|
||||
)
|
||||
synchronized(image.postId.toString().intern()) {
|
||||
if (image.downloaded == image.size && image.size > 0) {
|
||||
image.status = Status.FINISHED
|
||||
val post = dataTransaction.findPostById(context.postId).orElseThrow()
|
||||
post.done += 1
|
||||
post.downloaded += image.size
|
||||
dataTransaction.updatePost(post)
|
||||
} else {
|
||||
image.status = Status.ERROR
|
||||
}
|
||||
dataTransaction.updateImage(image)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (stopped) {
|
||||
return
|
||||
}
|
||||
image.status = Status.ERROR
|
||||
dataTransaction.updateImage(image)
|
||||
throw DownloadException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(HostException::class)
|
||||
private fun checkImageTypeAndRename(
|
||||
downloadDirectory: String, downloadedImage: DownloadedImage, index: Int
|
||||
) {
|
||||
val existingExtension = getExtension(downloadedImage.name).lowercase()
|
||||
val extension = when (downloadedImage.type) {
|
||||
ImageMimeType.IMAGE_BMP -> "BMP"
|
||||
ImageMimeType.IMAGE_GIF -> "GIF"
|
||||
ImageMimeType.IMAGE_JPEG -> "JPG"
|
||||
ImageMimeType.IMAGE_PNG -> "PNG"
|
||||
ImageMimeType.IMAGE_WEBP -> "WEBP"
|
||||
}
|
||||
val filename =
|
||||
if (existingExtension.isBlank()) "${downloadedImage.name}.$extension" else downloadedImage.name
|
||||
try {
|
||||
val downloadDestinationFolder = Path.of(downloadDirectory)
|
||||
synchronized(downloadDestinationFolder.pathString.intern()) {
|
||||
Files.createDirectories(downloadDestinationFolder)
|
||||
}
|
||||
val image = downloadDestinationFolder.resolve(
|
||||
"${
|
||||
if (settings.downloadSettings.forceOrder) String.format(
|
||||
"%03d_", index + 1
|
||||
) else ""
|
||||
}$filename"
|
||||
)
|
||||
Files.copy(downloadedImage.path, image, StandardCopyOption.REPLACE_EXISTING)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Failed to rename the image", e)
|
||||
} finally {
|
||||
try {
|
||||
Files.delete(downloadedImage.path)
|
||||
} catch (e: IOException) {
|
||||
log.warn(
|
||||
"Failed to delete temporary file ${downloadedImage.path}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
override fun run() {
|
||||
if (stopped) {
|
||||
return
|
||||
}
|
||||
download()
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other == null || javaClass != other.javaClass) return false
|
||||
val that = other as ImageDownloadRunnable
|
||||
return image.id == that.image.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(image.id)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
context.requests.forEach { it.abort() }
|
||||
stopped = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package me.vripper.entities
|
||||
|
||||
import me.vripper.entities.domain.Status
|
||||
|
||||
data class Image(
|
||||
var id: Long = -1,
|
||||
val postId: Long,
|
||||
val url: String,
|
||||
val thumbUrl: String,
|
||||
val host: Byte,
|
||||
val index: Int,
|
||||
val postIdRef: Long = -1,
|
||||
var size: Long = -1,
|
||||
var downloaded: Long = 0,
|
||||
var status: Status = Status.STOPPED,
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Image
|
||||
|
||||
if (url != other.url) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return url.hashCode()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package me.vripper.entities
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class LogEntry(
|
||||
val id: Long = -1,
|
||||
val type: Type,
|
||||
val status: Status,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") val time: LocalDateTime = LocalDateTime.now(),
|
||||
val message: String,
|
||||
) {
|
||||
|
||||
enum class Type(val stringValue: String) {
|
||||
POST("Post"), THREAD("Thread"), THANKS("Thanks"), METADATA("Metadata"), SCAN("Scan"), DOWNLOAD(
|
||||
"Download"
|
||||
)
|
||||
}
|
||||
|
||||
enum class Status(val stringValue: String) {
|
||||
PENDING("Pending"), PROCESSING("Processing"), DONE("Done"), ERROR("Error")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.vripper.entities
|
||||
|
||||
class Metadata {
|
||||
var postIdRef: Long? = null
|
||||
var postId: String? = null
|
||||
var postedBy: String? = null
|
||||
var resolvedNames = emptyList<String>()
|
||||
|
||||
companion object {
|
||||
fun from(metadata: Metadata): Metadata {
|
||||
val copy = Metadata()
|
||||
copy.postIdRef = metadata.postIdRef
|
||||
copy.postId = metadata.postId
|
||||
copy.postedBy = metadata.postedBy
|
||||
copy.resolvedNames = metadata.resolvedNames
|
||||
return copy
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package me.vripper.entities
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat
|
||||
import me.vripper.entities.domain.Status
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class Post(
|
||||
var id: Long = -1,
|
||||
val postTitle: String,
|
||||
val threadTitle: String,
|
||||
val forum: String,
|
||||
val url: String,
|
||||
val token: String,
|
||||
val postId: Long,
|
||||
val threadId: Long,
|
||||
val total: Int,
|
||||
val hosts: Set<String>,
|
||||
val downloadDirectory: String,
|
||||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") val addedOn: LocalDateTime = LocalDateTime.now(),
|
||||
var status: Status = Status.STOPPED,
|
||||
var done: Int = 0,
|
||||
var rank: Int = Int.MAX_VALUE,
|
||||
var size: Long = -1,
|
||||
var downloaded: Long = 0,
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Post
|
||||
|
||||
return postId == other.postId
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return postId.hashCode()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.vripper.entities
|
||||
|
||||
data class Thread(
|
||||
val id: Long = -1,
|
||||
val title: String,
|
||||
val link: String,
|
||||
val threadId: Long,
|
||||
var total: Int = 0,
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Thread
|
||||
|
||||
return threadId == other.threadId
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return threadId.hashCode()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.vripper.entities.domain
|
||||
|
||||
enum class Status(val stringValue: String) {
|
||||
PENDING("Pending"), DOWNLOADING("Downloading"), FINISHED("Finished"), ERROR("Error"), STOPPED("Stopped")
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package me.vripper.event
|
||||
|
||||
import me.vripper.entities.Image
|
||||
import me.vripper.entities.LogEntry
|
||||
import me.vripper.entities.Post
|
||||
import me.vripper.entities.Thread
|
||||
import me.vripper.model.DownloadSpeed
|
||||
import me.vripper.model.ErrorCount
|
||||
import me.vripper.model.QueueState
|
||||
import me.vripper.model.Settings
|
||||
|
||||
data class PostEvent(
|
||||
val add: List<Post> = emptyList(),
|
||||
val update: List<Post> = emptyList(),
|
||||
val delete: List<Long> = emptyList()
|
||||
)
|
||||
|
||||
data class ImageEvent(val images: List<Image>)
|
||||
data class ThreadCreateEvent(val thread: Thread)
|
||||
data class ThreadDeleteEvent(val threadId: Long)
|
||||
class ThreadClearEvent
|
||||
data class VGUserLoginEvent(val username: String)
|
||||
data class DownloadSpeedEvent(val downloadSpeed: DownloadSpeed)
|
||||
data class QueueStateEvent(val queueState: QueueState)
|
||||
data class ErrorCountEvent(val errorCount: ErrorCount)
|
||||
data class SettingsUpdateEvent(val settings: Settings)
|
||||
|
||||
data class LogCreateEvent(val logEntry: LogEntry)
|
||||
data class LogUpdateEvent(val logEntry: LogEntry)
|
||||
data class LogDeleteEvent(val deleted: List<Long>)
|
||||
|
||||
data class LoadingTasks(val loading: Boolean)
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.vripper.event
|
||||
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Sinks
|
||||
import reactor.core.scheduler.Scheduler
|
||||
import reactor.core.scheduler.Schedulers
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
object EventBus {
|
||||
|
||||
private val Scheduler: Scheduler = Schedulers.fromExecutor(Executors.newSingleThreadExecutor())
|
||||
private val _events = Sinks.many().multicast().onBackpressureBuffer<Any>()
|
||||
val events: Flux<Any> = _events.asFlux().publishOn(Scheduler)
|
||||
fun publishEvent(event: Any) {
|
||||
_events.tryEmitNext(event)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class DownloadException : Exception {
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(e: Throwable?) : super(e)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class HostException : Exception {
|
||||
constructor(e: Throwable?) : super(e)
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(message: String?, e: Throwable?) : super(message, e)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class HtmlProcessorException(e: Throwable?) : Exception(e)
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class PostParseException : Exception {
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(message: String?, e: Throwable?) : super(message, e)
|
||||
constructor(e: Throwable?) : super(e)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class QueueException : Exception {
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(message: String?, e: Throwable?) : super(message, e)
|
||||
constructor(e: Throwable?) : super(e)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class RenameException(message: String?, e: Exception?) : Exception(message, e)
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class ValidationException(message: String) : Exception(message)
|
||||
@@ -0,0 +1,6 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class VripperException : Exception {
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(e: Throwable?) : super(e)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.exception
|
||||
|
||||
class XpathException(e: Throwable?) : Exception(e)
|
||||
@@ -0,0 +1,86 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class AcidimgHost(
|
||||
private val httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("acidimg.cc", 0, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String, document: Document, context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
try {
|
||||
log.debug(
|
||||
String.format(
|
||||
"Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url
|
||||
)
|
||||
)
|
||||
XpathUtils.getAsNode(document, CONTINUE_BUTTON_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
}
|
||||
log.debug(String.format("Click button found for %s", url))
|
||||
val httpPost = HttpPost(url).also {
|
||||
it.addHeader("Referer", url)
|
||||
it.entity = UrlEncodedFormEntity(
|
||||
listOf(
|
||||
BasicNameValuePair(
|
||||
"imgContinue",
|
||||
"Continue to your image"
|
||||
)
|
||||
)
|
||||
)
|
||||
}.also { context.requests.add(it) }
|
||||
log.debug(String.format("Requesting %s", httpPost))
|
||||
val doc = try {
|
||||
httpService.client.execute(
|
||||
httpPost, context.httpContext
|
||||
)
|
||||
{ response ->
|
||||
log.debug(String.format("Cleaning response for %s", httpPost))
|
||||
HtmlUtils.clean(response.entity.content)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw HostException(e)
|
||||
}
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(doc, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'", IMG_XPATH, url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = imgNode.attributes.getNamedItem("alt").textContent.trim()
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim()
|
||||
Pair(
|
||||
imgTitle.ifEmpty { getDefaultImageName(imgUrl) }, imgUrl
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CONTINUE_BUTTON_XPATH = "//input[@id='continuebutton']"
|
||||
private const val IMG_XPATH = "//img[@class='centred']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
import java.util.*
|
||||
|
||||
class DPicMeHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("dpic.me", 1, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle =
|
||||
Optional.ofNullable(imgNode.attributes.getNamedItem("alt"))
|
||||
.map { e: Node -> e.textContent.trim() }
|
||||
.orElse("")
|
||||
val imgUrl =
|
||||
Optional.ofNullable(imgNode.attributes.getNamedItem("src"))
|
||||
.map { e: Node -> e.textContent.trim() }
|
||||
.orElse("")
|
||||
var defaultName: String = UUID.randomUUID().toString()
|
||||
val index = imgUrl.lastIndexOf('/')
|
||||
if (index != -1 && index < imgUrl.length) {
|
||||
defaultName = imgUrl.substring(imgUrl.lastIndexOf('/') + 1)
|
||||
}
|
||||
Pair((imgTitle.ifEmpty { defaultName })!!, imgUrl)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[@id='pic']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.PathUtils.getFileNameWithoutExtension
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet
|
||||
import org.apache.hc.client5.http.classic.methods.HttpHead
|
||||
import org.apache.hc.core5.http.ClassicHttpResponse
|
||||
import org.apache.hc.core5.http.Header
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.w3c.dom.Document
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
|
||||
abstract class Host(
|
||||
val hostName: String,
|
||||
val hostId: Byte,
|
||||
private val httpService: HTTPService,
|
||||
private val dataTransaction: DataTransaction,
|
||||
private val downloadSpeedService: DownloadSpeedService
|
||||
) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
companion object {
|
||||
private const val READ_BUFFER_SIZE = 8192
|
||||
private val hosts: MutableMap<String, Byte> = mutableMapOf()
|
||||
|
||||
fun getHosts(): Map<String, Byte> {
|
||||
return hosts.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
hosts[hostName] = hostId
|
||||
}
|
||||
|
||||
@Throws(HostException::class)
|
||||
abstract fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String>
|
||||
|
||||
@Throws(HostException::class)
|
||||
fun downloadInternal(url: String, context: ImageDownloadContext): DownloadedImage {
|
||||
val headers = head(url, context)
|
||||
// is the body of type image ?
|
||||
val imageMimeType = getImageMimeType(headers)
|
||||
val downloadedImage = if (imageMimeType != null) {
|
||||
// a direct link, awesome
|
||||
val downloadedImage = fetch(url, context) {
|
||||
handleImageDownload(it, context)
|
||||
}
|
||||
DownloadedImage(getDefaultImageName(url), downloadedImage.first, downloadedImage.second)
|
||||
} else {
|
||||
// linked image ?
|
||||
val value = headers.find { it.name.contains("content-type", true) }?.value
|
||||
if (value != null) {
|
||||
if (value.contains("text/html")) {
|
||||
val document = fetch(url, context) {
|
||||
HtmlUtils.clean(it.entity.content)
|
||||
}
|
||||
if (log.isDebugEnabled) {
|
||||
log.debug("Cleaning $url response", url)
|
||||
}
|
||||
val resolvedImage = resolve(url, document, context)
|
||||
val downloadImage: Pair<Path, ImageMimeType> =
|
||||
fetch(resolvedImage.second, context) {
|
||||
handleImageDownload(it, context)
|
||||
}
|
||||
DownloadedImage(resolvedImage.first, downloadImage.first, downloadImage.second)
|
||||
} else {
|
||||
throw HostException("Unable to download $url, can't process content type $value")
|
||||
}
|
||||
} else {
|
||||
throw HostException("Unexpected server response for $url, response have no content type")
|
||||
}
|
||||
}
|
||||
return downloadedImage
|
||||
}
|
||||
|
||||
private fun handleImageDownload(
|
||||
response: ClassicHttpResponse,
|
||||
context: ImageDownloadContext
|
||||
): Pair<Path, ImageMimeType> {
|
||||
val mimeType = getImageMimeType(response.headers)
|
||||
?: throw HostException("Unsupported image type ${response.getFirstHeader("content-type")}")
|
||||
|
||||
val tempImage = Files.createTempFile(
|
||||
Path.of(context.settings.systemSettings.tempPath),
|
||||
"vripper_",
|
||||
".tmp"
|
||||
)
|
||||
return Files.newOutputStream(tempImage).use { fos ->
|
||||
val image = context.image
|
||||
synchronized(image.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId).orElseThrow()
|
||||
val size = if (image.size < 0) {
|
||||
response.entity.contentLength
|
||||
} else {
|
||||
0
|
||||
}
|
||||
image.size = response.entity.contentLength
|
||||
post.size += size
|
||||
transaction {
|
||||
dataTransaction.updateImage(image)
|
||||
dataTransaction.updatePost(post)
|
||||
}
|
||||
}
|
||||
log.debug(
|
||||
"Length is ${image.size}"
|
||||
)
|
||||
log.debug(
|
||||
"Starting data transfer"
|
||||
)
|
||||
val buffer = ByteArray(READ_BUFFER_SIZE)
|
||||
var read: Int
|
||||
while (response.entity.content.read(buffer, 0, READ_BUFFER_SIZE)
|
||||
.also { read = it } != -1 && !context.stopped
|
||||
) {
|
||||
fos.write(buffer, 0, read)
|
||||
image.downloaded += read
|
||||
dataTransaction.updateImage(image)
|
||||
downloadSpeedService.reportDownloadedBytes(read.toLong())
|
||||
}
|
||||
Pair(tempImage, mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
fun isSupported(url: String): Boolean {
|
||||
return url.contains(hostName)
|
||||
}
|
||||
|
||||
@Throws(HostException::class)
|
||||
fun head(url: String, context: ImageDownloadContext): Array<Header> {
|
||||
val httpHead = HttpHead(url).also { context.requests.add(it) }
|
||||
log.debug(String.format("Requesting %s", url))
|
||||
return httpService.client.execute(
|
||||
httpHead,
|
||||
context.httpContext
|
||||
) {
|
||||
if (it.code / 100 != 2) {
|
||||
throw HostException("Unexpected response code: ${it.code}")
|
||||
}
|
||||
it.headers
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(HostException::class)
|
||||
fun <T> fetch(
|
||||
url: String,
|
||||
context: ImageDownloadContext,
|
||||
transformer: (ClassicHttpResponse) -> T
|
||||
): T {
|
||||
val httpGet = HttpGet(url).also { it.addHeader("Referer", context.image.url) }.also { context.requests.add(it) }
|
||||
log.debug(String.format("Requesting %s", url))
|
||||
return httpService.client.execute(httpGet, context.httpContext) {
|
||||
if (it.code / 100 != 2) {
|
||||
throw DownloadException("Server returned code ${it.code}")
|
||||
}
|
||||
transformer(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getImageMimeType(headers: Array<Header>): ImageMimeType? {
|
||||
|
||||
// first check if content type header exists
|
||||
val value = headers.find { it.name.contains("content-type", true) }?.value
|
||||
|
||||
// header found, check the type
|
||||
return if (value != null) {
|
||||
ImageMimeType.entries.find {
|
||||
value.contains(it.strValue, true)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun getDefaultImageName(imgUrl: String): String {
|
||||
val imageTitle = imgUrl.substring(imgUrl.lastIndexOf('/') + 1)
|
||||
log.debug(String.format("Extracting name from url %s: %s", imgUrl, imageTitle))
|
||||
return getFileNameWithoutExtension(imageTitle)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Host
|
||||
|
||||
return hostName == other.hostName
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return hostName.hashCode()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return hostName
|
||||
}
|
||||
}
|
||||
|
||||
data class DownloadedImage(val name: String, val path: Path, val type: ImageMimeType)
|
||||
|
||||
enum class ImageMimeType(val strValue: String) {
|
||||
IMAGE_BMP("image/bmp"),
|
||||
IMAGE_GIF("image/gif"),
|
||||
IMAGE_JPEG("image/jpeg"),
|
||||
IMAGE_PNG("image/png"),
|
||||
IMAGE_WEBP("image/webp"),
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.apache.hc.client5.http.impl.cookie.BasicClientCookie
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
import java.sql.Date
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.util.*
|
||||
|
||||
class ImageBamHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("imagebam.com", 2, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val doc = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_XPATH, url))
|
||||
if (XpathUtils.getAsNode(document, CONTINUE_XPATH) != null) {
|
||||
val clientCookie = BasicClientCookie("nsfw_inter", "1")
|
||||
clientCookie.domain = "www.imagebam.com"
|
||||
clientCookie.path = "/"
|
||||
clientCookie.expiryDate =
|
||||
Date.from(
|
||||
LocalDateTime.now().plusDays(3).atZone(ZoneId.systemDefault()).toInstant()
|
||||
)
|
||||
context.httpContext.cookieStore.addCookie(clientCookie)
|
||||
fetch(url, context) {
|
||||
HtmlUtils.clean(it.entity.content)
|
||||
}
|
||||
} else {
|
||||
document
|
||||
}
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
}
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(doc, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = Optional.ofNullable(imgNode.attributes.getNamedItem("alt"))
|
||||
.map { e: Node -> e.textContent.trim { it <= ' ' } }
|
||||
.orElse("")
|
||||
val imgUrl = Optional.ofNullable(imgNode.attributes.getNamedItem("src"))
|
||||
.map { e: Node -> e.textContent.trim { it <= ' ' } }
|
||||
.orElse("")
|
||||
var defaultName: String = UUID.randomUUID().toString()
|
||||
val index = imgUrl.lastIndexOf('/')
|
||||
if (index != -1 && index < imgUrl.length) {
|
||||
defaultName = imgUrl.substring(imgUrl.lastIndexOf('/') + 1)
|
||||
}
|
||||
Pair((imgTitle.ifEmpty { defaultName })!!, imgUrl)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[contains(@class,'main-image')]"
|
||||
private const val CONTINUE_XPATH = "//*[contains(text(), 'Continue')]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
import java.util.*
|
||||
|
||||
class ImageTwistHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("imagetwist.com", 3, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle =
|
||||
Optional.ofNullable(imgNode.attributes.getNamedItem("alt"))
|
||||
.map { obj: Node -> obj.textContent }
|
||||
.map { obj: String -> obj.trim { it <= ' ' } }.orElse(null)
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' }
|
||||
Pair(imgTitle!!, imgUrl)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[contains(@class, 'img')]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class ImageVenueHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("imagevenue.com", 4, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val doc = try {
|
||||
log.debug(
|
||||
String.format(
|
||||
"Looking for xpath expression %s in %s",
|
||||
CONTINUE_BUTTON_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
if (XpathUtils.getAsNode(document, CONTINUE_BUTTON_XPATH) != null) {
|
||||
// Button detected. No need to actually click it, just make the call again.
|
||||
fetch(url, context) {
|
||||
HtmlUtils.clean(it.entity.content)
|
||||
}
|
||||
} else {
|
||||
document
|
||||
}
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
}
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(doc, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = imgNode.attributes.getNamedItem("alt").textContent.trim { it <= ' ' }
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' }
|
||||
Pair(
|
||||
if (imgTitle.isEmpty()) imgUrl.substring(imgUrl.lastIndexOf('/') + 1) else imgTitle,
|
||||
imgUrl
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CONTINUE_BUTTON_XPATH = "//a[@title='Continue to ImageVenue']"
|
||||
private const val IMG_XPATH = "//a[@data-toggle='full']/img"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
class ImageZillaHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("imagezilla.net", 5, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val titleNode = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
log.debug(String.format("Resolving name for %s", url))
|
||||
var title = titleNode.attributes.getNamedItem("title").textContent.trim()
|
||||
titleNode.textContent.trim()
|
||||
if (title.isEmpty()) {
|
||||
title = getDefaultImageName(url)
|
||||
}
|
||||
return try {
|
||||
Pair(title, url.replace("show", "images"))
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[@id='photo']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class ImgSpiceHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("imgspice.com", 7, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = imgNode.attributes.getNamedItem("alt").textContent.trim { it <= ' ' }
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' }
|
||||
Pair(
|
||||
imgTitle.ifEmpty { imgUrl.substring(imgUrl.lastIndexOf('/') + 1) }, imgUrl
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[@id='imgpreview']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class ImgboxHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("imgbox.com", 6, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = imgNode.attributes.getNamedItem("title").textContent.trim { it <= ' ' }
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' }
|
||||
Pair(imgTitle, imgUrl)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[@id='img']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.HtmlProcessorException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
import java.io.IOException
|
||||
|
||||
class ImxHost(
|
||||
private val httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("imx.to", 8, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val httpsUrl = url.replace("http:", "https:")
|
||||
var value: String? = null
|
||||
try {
|
||||
log.debug("Looking for xpath expression $CONTINUE_BUTTON_XPATH in $httpsUrl")
|
||||
val contDiv = XpathUtils.getAsNode(document, CONTINUE_BUTTON_XPATH)
|
||||
?: throw HostException("$CONTINUE_BUTTON_XPATH cannot be found")
|
||||
val node = contDiv.attributes.getNamedItem("value")
|
||||
if (node != null) {
|
||||
value = node.textContent
|
||||
}
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
}
|
||||
if (value == null) {
|
||||
throw HostException("Failed to obtain value attribute from continue input")
|
||||
}
|
||||
log.debug("Click button found for $httpsUrl")
|
||||
val httpPost: HttpPost = HttpPost(httpsUrl).also {
|
||||
it.entity = UrlEncodedFormEntity(listOf(BasicNameValuePair("imgContinue", value)))
|
||||
}.also { context.requests.add(it) }
|
||||
log.debug("Requesting {}", httpPost)
|
||||
val doc = try {
|
||||
httpService.client.execute(
|
||||
httpPost, context.httpContext
|
||||
) { response ->
|
||||
log.debug("Cleaning response for {}", httpPost)
|
||||
HtmlUtils.clean(response.entity.content)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
throw HostException(e)
|
||||
} catch (e: HtmlProcessorException) {
|
||||
throw HostException(e)
|
||||
}
|
||||
val imgNode: Node = try {
|
||||
log.debug("Looking for xpath expression $IMG_XPATH in $httpsUrl")
|
||||
XpathUtils.getAsNode(doc, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
"Xpath $IMG_XPATH cannot be found in $httpsUrl"
|
||||
)
|
||||
return try {
|
||||
log.debug("Resolving name and image url for $httpsUrl")
|
||||
val imgTitle = imgNode.attributes.getNamedItem("alt").textContent.trim { it <= ' ' }
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' }
|
||||
Pair(
|
||||
imgTitle.ifEmpty { getDefaultImageName(imgUrl) }, imgUrl
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CONTINUE_BUTTON_XPATH = "//*[@name='imgContinue']"
|
||||
private const val IMG_XPATH = "//img[@class='centred']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
import java.net.URI
|
||||
import java.net.URISyntaxException
|
||||
|
||||
class PimpandhostHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("pimpandhost.com", 9, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val newUrl: String
|
||||
try {
|
||||
newUrl = appendUri(url.replace("http://", "https://").replace("-medium(\\.html)?".toRegex(), ""), "size=original")
|
||||
} catch (e: Exception) {
|
||||
throw HostException(e)
|
||||
}
|
||||
val doc = fetch(newUrl, context) {
|
||||
HtmlUtils.clean(it.entity.content)
|
||||
}
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, newUrl))
|
||||
XpathUtils.getAsNode(doc, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", newUrl))
|
||||
val imgTitle = imgNode.attributes.getNamedItem("alt").textContent.trim { it <= ' ' }
|
||||
val imgUrl =
|
||||
"https:" + imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' }
|
||||
Pair(
|
||||
imgTitle.ifEmpty { imgUrl.substring(imgUrl.lastIndexOf('/') + 1) }, imgUrl
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(URISyntaxException::class)
|
||||
fun appendUri(uri: String, appendQuery: String): String {
|
||||
val oldUri = URI(uri)
|
||||
var newQuery = oldUri.query
|
||||
if (newQuery == null) {
|
||||
newQuery = appendQuery
|
||||
} else {
|
||||
newQuery += "&$appendQuery"
|
||||
}
|
||||
return URI(
|
||||
oldUri.scheme, oldUri.authority, oldUri.path, newQuery, oldUri.fragment
|
||||
).toString()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[contains(@class, 'original')]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class PixRouteHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("pixroute.com", 11, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
Pair(imgNode.attributes.getNamedItem("alt").textContent.trim { it <= ' ' },
|
||||
imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' })
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[@id='imgpreview']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class PixhostHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("pixhost.to", 10, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = imgNode.attributes.getNamedItem("alt").textContent.trim { it <= ' ' }
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' }
|
||||
Pair(imgTitle.substring(imgTitle.indexOf('_') + 1), imgUrl)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[@id='image']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
class PixxxelsHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("pixxxels.cc", 12, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
val titleNode = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", TITLE_XPATH, url))
|
||||
XpathUtils.getAsNode(document, TITLE_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
TITLE_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = titleNode.textContent.trim { it <= ' ' }
|
||||
val imgUrl = imgNode.attributes.getNamedItem("href").textContent.trim { it <= ' ' }
|
||||
Pair(
|
||||
imgTitle.ifEmpty { imgUrl.substring(imgUrl.lastIndexOf('/') + 1) }, imgUrl
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//*[@id='download']"
|
||||
private const val TITLE_XPATH = "//*[contains(@class,'imagename')]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
import java.util.*
|
||||
|
||||
class PostImgHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("postimg.cc", 13, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val titleNode = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", TITLE_XPATH, url))
|
||||
XpathUtils.getAsNode(document, TITLE_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
TITLE_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
val urlNode = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle = Optional.ofNullable(titleNode)
|
||||
.map { node: Node -> node.textContent.trim { it <= ' ' } }
|
||||
.orElseGet { getDefaultImageName(url) }
|
||||
Pair(imgTitle, urlNode.attributes.getNamedItem("href").textContent.trim { it <= ' ' })
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TITLE_XPATH = "//span[contains(@class,'imagename')]"
|
||||
private const val IMG_XPATH = "//a[@id='download']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class TurboImageHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("turboimagehost.com", 14, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
var title: String?
|
||||
title = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", TITLE_XPATH, url))
|
||||
val titleNode: Node? = XpathUtils.getAsNode(document, TITLE_XPATH)
|
||||
log.debug(String.format("Resolving name for %s", url))
|
||||
titleNode?.textContent?.trim { it <= ' ' }
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
}
|
||||
if (title.isNullOrEmpty()) {
|
||||
title = getDefaultImageName(url)
|
||||
}
|
||||
val urlNode: Node = XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return Pair(title, urlNode.attributes.getNamedItem("src").textContent.trim { it <= ' ' })
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TITLE_XPATH = "//div[contains(@class,'titleFullS')]/h1"
|
||||
private const val IMG_XPATH = "//img[@id='imageid']"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Node
|
||||
import java.util.*
|
||||
|
||||
class ViprImHost(
|
||||
httpService: HTTPService,
|
||||
dataTransaction: DataTransaction,
|
||||
downloadSpeedService: DownloadSpeedService,
|
||||
) : Host("vipr.im", 15, httpService, dataTransaction, downloadSpeedService) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Throws(HostException::class)
|
||||
override fun resolve(
|
||||
url: String,
|
||||
document: Document,
|
||||
context: ImageDownloadContext
|
||||
): Pair<String, String> {
|
||||
val imgNode: Node = try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url))
|
||||
XpathUtils.getAsNode(document, IMG_XPATH)
|
||||
} catch (e: XpathException) {
|
||||
throw HostException(e)
|
||||
} ?: throw HostException(
|
||||
String.format(
|
||||
"Xpath '%s' cannot be found in '%s'",
|
||||
IMG_XPATH,
|
||||
url
|
||||
)
|
||||
)
|
||||
return try {
|
||||
log.debug(String.format("Resolving name and image url for %s", url))
|
||||
val imgTitle =
|
||||
Optional.ofNullable(imgNode.attributes.getNamedItem("alt"))
|
||||
.map { obj: Node -> obj.textContent }
|
||||
.map { obj: String -> obj.trim() }.orElse(null)
|
||||
val imgUrl = imgNode.attributes.getNamedItem("src").textContent.trim()
|
||||
Pair(imgTitle!!, imgUrl)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Unexpected error occurred", e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val IMG_XPATH = "//img[contains(@class, 'img')]"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.vripper.listeners
|
||||
|
||||
import me.vripper.utilities.ApplicationProperties.VRIPPER_DIR
|
||||
import java.io.RandomAccessFile
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.pathString
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
object AppLock {
|
||||
fun exclusiveLock() {
|
||||
val lock = VRIPPER_DIR.resolve("lock")
|
||||
try {
|
||||
val randomFile = RandomAccessFile(lock.pathString, "rw")
|
||||
val channel = randomFile.channel
|
||||
val fileLock = channel.tryLock()
|
||||
if (fileLock == null) {
|
||||
System.err.println("Another instance is already running in ${lock.parent.pathString}")
|
||||
exitProcess(-1)
|
||||
} else {
|
||||
Runtime.getRuntime().addShutdownHook(Thread {
|
||||
fileLock.release()
|
||||
channel.close()
|
||||
Files.deleteIfExists(lock)
|
||||
})
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println(e.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.vripper.listeners
|
||||
|
||||
import me.vripper.download.DownloadService
|
||||
import me.vripper.services.*
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
open class OnStartupListener : KoinComponent {
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
private val downloadService: DownloadService by inject()
|
||||
private val httpService: HTTPService by inject()
|
||||
private val retryPolicyService: RetryPolicyService by inject()
|
||||
private val vgAuthService: VGAuthService by inject()
|
||||
private val downloadSpeedService: DownloadSpeedService by inject()
|
||||
|
||||
open fun run() {
|
||||
dataTransaction.setDownloadingToStopped()
|
||||
httpService.init()
|
||||
retryPolicyService.init()
|
||||
vgAuthService.init()
|
||||
downloadService.init()
|
||||
downloadSpeedService.init()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class DownloadSpeed(val speed: Long)
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class ErrorCount(val count: Int)
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.vripper.model
|
||||
|
||||
import me.vripper.host.Host
|
||||
|
||||
data class ImageItem(val mainLink: String, val thumbLink: String, val host: Host)
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class LoggedUser(val user: String)
|
||||
@@ -0,0 +1,15 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class PostItem(
|
||||
val threadId: Long,
|
||||
val threadTitle: String,
|
||||
val postId: Long,
|
||||
val number: Int,
|
||||
val title: String,
|
||||
val imageCount: Int,
|
||||
val url: String,
|
||||
val hosts: List<Pair<String, Int>>,
|
||||
val securityToken: String,
|
||||
val forum: String,
|
||||
val imageItemList: List<ImageItem>
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class QueueState(
|
||||
val running: Int,
|
||||
val remaining: Int
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class Settings(
|
||||
var connectionSettings: ConnectionSettings = ConnectionSettings(),
|
||||
var downloadSettings: DownloadSettings = DownloadSettings(),
|
||||
var viperSettings: ViperSettings = ViperSettings(),
|
||||
var systemSettings: SystemSettings = SystemSettings()
|
||||
)
|
||||
|
||||
data class ViperSettings(
|
||||
var login: Boolean = false,
|
||||
var username: String = "",
|
||||
var password: String = "",
|
||||
var thanks: Boolean = false,
|
||||
var host: String = "https://vipergirls.to",
|
||||
)
|
||||
|
||||
data class DownloadSettings(
|
||||
var downloadPath: String = System.getProperty("user.home"),
|
||||
var autoStart: Boolean = true,
|
||||
var autoQueueThreshold: Int = 1,
|
||||
var forceOrder: Boolean = false,
|
||||
var forumSubDirectory: Boolean = false,
|
||||
var threadSubLocation: Boolean = false,
|
||||
var clearCompleted: Boolean = false,
|
||||
var appendPostId: Boolean = false
|
||||
)
|
||||
|
||||
data class ConnectionSettings(
|
||||
var maxConcurrentPerHost: Int = 2,
|
||||
var maxGlobalConcurrent: Int = 0,
|
||||
var timeout: Long = 30,
|
||||
var maxAttempts: Int = 3,
|
||||
)
|
||||
|
||||
data class SystemSettings(
|
||||
var tempPath: String = System.getProperty("java.io.tmpdir"),
|
||||
var cachePath: String = System.getProperty("java.io.tmpdir"),
|
||||
var enableClipboardMonitoring: Boolean = false,
|
||||
var clipboardPollingRate: Int = 500,
|
||||
var maxEventLog: Int = 1_000,
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class ThreadItem(
|
||||
val threadId: Long,
|
||||
val title: String,
|
||||
val securityToken: String,
|
||||
val forum: String,
|
||||
val postItemList: List<PostItem>
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.vripper.model
|
||||
|
||||
data class ThreadPostId(val threadId: Long, val postId: Long)
|
||||
@@ -0,0 +1,67 @@
|
||||
package me.vripper.parser
|
||||
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.PostParseException
|
||||
import me.vripper.model.ThreadItem
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.services.RetryPolicyService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.VGAuthService
|
||||
import net.jodah.failsafe.Failsafe
|
||||
import net.jodah.failsafe.function.CheckedSupplier
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet
|
||||
import org.apache.hc.core5.net.URIBuilder
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.BufferedInputStream
|
||||
import java.util.*
|
||||
import javax.xml.parsers.SAXParserFactory
|
||||
|
||||
class ThreadLookupAPIParser(private val threadId: Long) : KoinComponent {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private val cm: HTTPService by inject()
|
||||
private val retryPolicyService: RetryPolicyService by inject()
|
||||
private val vgAuthService: VGAuthService by inject()
|
||||
private val settingsService: SettingsService by inject()
|
||||
|
||||
@Throws(PostParseException::class)
|
||||
fun parse(): ThreadItem {
|
||||
log.debug("Parsing thread $threadId")
|
||||
val httpGet =
|
||||
HttpGet(URIBuilder(settingsService.settings.viperSettings.host + "/vr.php").also {
|
||||
it.setParameter(
|
||||
"t",
|
||||
threadId.toString()
|
||||
)
|
||||
}.build())
|
||||
val threadLookupAPIResponseHandler = ThreadLookupAPIResponseHandler()
|
||||
log.debug("Requesting {}", httpGet)
|
||||
return try {
|
||||
Failsafe.with(retryPolicyService.buildGenericRetryPolicy<Any>()).onFailure {
|
||||
log.error(
|
||||
"parsing failed for thread $threadId",
|
||||
it.failure
|
||||
)
|
||||
}.get(CheckedSupplier {
|
||||
cm.client.execute(
|
||||
httpGet, vgAuthService.context
|
||||
) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${response.code}' for $httpGet")
|
||||
}
|
||||
factory.newSAXParser().parse(
|
||||
BufferedInputStream(response.entity.content),
|
||||
threadLookupAPIResponseHandler
|
||||
)
|
||||
threadLookupAPIResponseHandler.result
|
||||
}
|
||||
})
|
||||
} catch (e: Exception) {
|
||||
throw PostParseException(e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val factory = SAXParserFactory.newInstance()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.vripper.parser
|
||||
|
||||
import me.vripper.host.Host
|
||||
import me.vripper.model.ImageItem
|
||||
import me.vripper.model.PostItem
|
||||
import me.vripper.model.ThreadItem
|
||||
import me.vripper.services.SettingsService
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import org.xml.sax.Attributes
|
||||
import org.xml.sax.helpers.DefaultHandler
|
||||
|
||||
class ThreadLookupAPIResponseHandler : KoinComponent, DefaultHandler() {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private val supportedHosts: List<Host> = getKoin().getAll()
|
||||
private val settingsService: SettingsService by inject()
|
||||
private var error: String = ""
|
||||
private val hostMap: MutableMap<Host, Int> = mutableMapOf()
|
||||
private val postItemList: MutableList<PostItem> = mutableListOf()
|
||||
private val imageItemList: MutableList<ImageItem> = mutableListOf()
|
||||
private lateinit var threadItem: ThreadItem
|
||||
private var threadId: Long = -1
|
||||
private lateinit var threadTitle: String
|
||||
private lateinit var forum: String
|
||||
private lateinit var securityToken: String
|
||||
private var postId: Long = -1
|
||||
private lateinit var postTitle: String
|
||||
private var postCounter: Int = 0
|
||||
|
||||
val result: ThreadItem
|
||||
get() = threadItem
|
||||
|
||||
override fun startDocument() {}
|
||||
override fun startElement(
|
||||
uri: String, localName: String, qName: String, attributes: Attributes
|
||||
) {
|
||||
when (qName.lowercase()) {
|
||||
"error" -> error = attributes.getValue("details")
|
||||
"thread" -> {
|
||||
threadId = attributes.getValue("id")?.trim()?.toLong() ?: -1
|
||||
threadTitle = attributes.getValue("title")?.trim() ?: ""
|
||||
}
|
||||
|
||||
"forum" -> forum = attributes.getValue("title")?.trim() ?: ""
|
||||
"user" -> securityToken = attributes.getValue("hash")?.trim() ?: ""
|
||||
"post" -> {
|
||||
postId = attributes.getValue("id")?.trim()?.toLong() ?: -1
|
||||
postCounter = attributes.getValue("number")?.trim()?.toInt() ?: 0
|
||||
val title = attributes.getValue("title")?.trim() ?: ""
|
||||
postTitle = title.ifBlank { threadTitle }
|
||||
}
|
||||
|
||||
"image" -> {
|
||||
val mainLink = attributes.getValue("main_url")?.trim() ?: ""
|
||||
val thumbLink = attributes.getValue("thumb_url")?.trim() ?: ""
|
||||
val type = attributes.getValue("type")?.trim() ?: ""
|
||||
if (type == "linked") {
|
||||
supportedHosts.firstOrNull {
|
||||
it.isSupported(mainLink)
|
||||
}?.also { host ->
|
||||
hostMap.computeIfAbsent(host) { 0 }
|
||||
hostMap[host] = hostMap[host]!! + 1
|
||||
imageItemList.add(ImageItem(mainLink, thumbLink, host))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun endElement(uri: String, localName: String, qName: String) {
|
||||
if ("post".equals(qName, true)) {
|
||||
if (imageItemList.isNotEmpty()) {
|
||||
postItemList.add(
|
||||
PostItem(
|
||||
threadId,
|
||||
threadTitle,
|
||||
postId,
|
||||
postCounter,
|
||||
postTitle,
|
||||
imageItemList.size,
|
||||
"${settingsService.settings.viperSettings.host}/threads/?p=$postId&viewfull=1#post$postId",
|
||||
hostMap.toMap().map { Pair(it.key.hostName, it.value) },
|
||||
securityToken,
|
||||
forum,
|
||||
imageItemList.toList()
|
||||
)
|
||||
)
|
||||
}
|
||||
imageItemList.clear()
|
||||
hostMap.clear()
|
||||
}
|
||||
}
|
||||
|
||||
override fun endDocument() {
|
||||
threadItem = ThreadItem(threadId, threadTitle, securityToken, forum, postItemList.toList())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package me.vripper.repositories
|
||||
|
||||
import me.vripper.entities.Image
|
||||
import java.util.*
|
||||
|
||||
interface ImageRepository {
|
||||
fun save(image: Image): Image
|
||||
fun save(imageList: List<Image>)
|
||||
fun deleteAllByPostId(postId: Long)
|
||||
fun findByPostId(postId: Long): List<Image>
|
||||
fun countError(): Int
|
||||
fun findByPostIdAndIsNotCompleted(postId: Long): List<Image>
|
||||
fun stopByPostIdAndIsNotCompleted(postId: Long): Int
|
||||
fun stopByPostIdAndIsNotCompleted(): Int
|
||||
fun findByPostIdAndIsError(postId: Long): List<Image>
|
||||
fun findById(id: Long): Optional<Image>
|
||||
fun update(image: Image)
|
||||
fun update(images: List<Image>)
|
||||
fun deleteAllByPostId(postIds: List<Long>)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package me.vripper.repositories
|
||||
|
||||
import me.vripper.entities.LogEntry
|
||||
import java.util.*
|
||||
|
||||
interface LogRepository {
|
||||
fun save(logEntry: LogEntry): LogEntry
|
||||
fun update(logEntry: LogEntry)
|
||||
fun findAll(): List<LogEntry>
|
||||
fun findById(id: Long): Optional<LogEntry>
|
||||
|
||||
fun deleteOldest(): List<Long>
|
||||
fun deleteAll()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.vripper.repositories
|
||||
|
||||
import me.vripper.entities.Metadata
|
||||
import java.util.*
|
||||
|
||||
interface MetadataRepository {
|
||||
fun save(metadata: Metadata): Metadata
|
||||
fun findByPostId(postId: Long): Optional<Metadata>
|
||||
fun deleteByPostId(postId: Long): Int
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package me.vripper.repositories
|
||||
|
||||
import me.vripper.entities.Post
|
||||
import java.util.*
|
||||
|
||||
interface PostDownloadStateRepository {
|
||||
fun save(posts: List<Post>): List<Post>
|
||||
fun findByPostId(postId: Long): Optional<Post>
|
||||
fun findById(id: Long): Optional<Post>
|
||||
fun findCompleted(): List<Long>
|
||||
fun findAll(): List<Post>
|
||||
fun existByPostId(postId: Long): Boolean
|
||||
fun setDownloadingToStopped(): Int
|
||||
fun deleteByPostId(postId: Long): Int
|
||||
fun update(post: Post)
|
||||
fun update(posts: List<Post>)
|
||||
fun findMaxRank(): Int?
|
||||
fun deleteAll(postIds: List<Long>)
|
||||
fun stopAll()
|
||||
fun findAllNonCompletedPostIds(): List<Long>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package me.vripper.repositories
|
||||
|
||||
import me.vripper.entities.Thread
|
||||
import java.util.*
|
||||
|
||||
interface ThreadRepository {
|
||||
fun save(thread: Thread): Thread
|
||||
fun findByThreadId(threadId: Long): Optional<Thread>
|
||||
fun findAll(): List<Thread>
|
||||
fun findById(id: Long): Optional<Thread>
|
||||
fun deleteByThreadId(threadId: Long): Int
|
||||
fun deleteAll()
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package me.vripper.repositories.impl
|
||||
|
||||
import me.vripper.entities.Image
|
||||
import me.vripper.entities.domain.Status
|
||||
import me.vripper.repositories.ImageRepository
|
||||
import me.vripper.tables.ImageTable
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||
import java.sql.Connection
|
||||
import java.util.*
|
||||
|
||||
class ImageRepositoryImpl : ImageRepository {
|
||||
override fun save(image: Image): Image {
|
||||
val id = ImageTable.insertAndGetId {
|
||||
it[downloaded] = image.downloaded
|
||||
it[host] = image.host
|
||||
it[index] = image.index
|
||||
it[postId] = image.postId
|
||||
it[status] = image.status.name
|
||||
it[size] = image.size
|
||||
it[url] = image.url
|
||||
it[thumbUrl] = image.thumbUrl
|
||||
it[postIdRef] = image.postIdRef
|
||||
}.value
|
||||
return image.copy(id = id)
|
||||
}
|
||||
|
||||
override fun save(imageList: List<Image>) {
|
||||
ImageTable.batchInsert(imageList, shouldReturnGeneratedValues = false) {
|
||||
this[ImageTable.downloaded] = it.downloaded
|
||||
this[ImageTable.host] = it.host
|
||||
this[ImageTable.index] = it.index
|
||||
this[ImageTable.postId] = it.postId
|
||||
this[ImageTable.status] = it.status.name
|
||||
this[ImageTable.size] = it.size
|
||||
this[ImageTable.url] = it.url
|
||||
this[ImageTable.thumbUrl] = it.thumbUrl
|
||||
this[ImageTable.postIdRef] = it.postIdRef
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteAllByPostId(postId: Long) {
|
||||
ImageTable.deleteWhere { ImageTable.postId eq postId }
|
||||
}
|
||||
|
||||
override fun findByPostId(postId: Long): List<Image> {
|
||||
return ImageTable.select {
|
||||
ImageTable.postId eq postId
|
||||
}.map(this::transform)
|
||||
}
|
||||
|
||||
override fun countError(): Int {
|
||||
return ImageTable
|
||||
.slice(ImageTable.id)
|
||||
.select { ImageTable.status eq Status.ERROR.name }
|
||||
.count().toInt()
|
||||
}
|
||||
|
||||
override fun findByPostIdAndIsNotCompleted(postId: Long): List<Image> {
|
||||
return ImageTable
|
||||
.select {
|
||||
(ImageTable.postId eq postId) and (ImageTable.status neq Status.FINISHED.name)
|
||||
}.map(this::transform)
|
||||
}
|
||||
|
||||
override fun stopByPostIdAndIsNotCompleted(postId: Long): Int {
|
||||
return ImageTable.update({ (ImageTable.postId eq postId) and (ImageTable.status neq Status.FINISHED.name) }) {
|
||||
it[status] = Status.STOPPED.name
|
||||
}
|
||||
}
|
||||
|
||||
override fun stopByPostIdAndIsNotCompleted(): Int {
|
||||
return ImageTable.update({ (ImageTable.status neq Status.FINISHED.name) }) {
|
||||
it[status] = Status.STOPPED.name
|
||||
}
|
||||
}
|
||||
|
||||
override fun findByPostIdAndIsError(postId: Long): List<Image> {
|
||||
return ImageTable.select {
|
||||
(ImageTable.postId eq postId) and (ImageTable.status eq Status.ERROR.name)
|
||||
}.map(this::transform)
|
||||
}
|
||||
|
||||
override fun findById(id: Long): Optional<Image> {
|
||||
val result = ImageTable.select {
|
||||
ImageTable.id eq id
|
||||
}.map(this::transform)
|
||||
return if (result.isEmpty()) {
|
||||
Optional.empty()
|
||||
} else {
|
||||
Optional.of(result.first())
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(image: Image) {
|
||||
ImageTable.update({ ImageTable.id eq image.id }) {
|
||||
it[status] = image.status.name
|
||||
it[downloaded] = image.downloaded
|
||||
it[size] = image.size
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(images: List<Image>) {
|
||||
ImageTable.batchReplace(images, shouldReturnGeneratedValues = false) {
|
||||
this[ImageTable.id] = it.id
|
||||
this[ImageTable.downloaded] = it.downloaded
|
||||
this[ImageTable.host] = it.host
|
||||
this[ImageTable.index] = it.index
|
||||
this[ImageTable.postId] = it.postId
|
||||
this[ImageTable.status] = it.status.name
|
||||
this[ImageTable.size] = it.size
|
||||
this[ImageTable.url] = it.url
|
||||
this[ImageTable.thumbUrl] = it.thumbUrl
|
||||
this[ImageTable.postIdRef] = it.postIdRef
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteAllByPostId(postIds: List<Long>) {
|
||||
val conn = TransactionManager.current().connection.connection as Connection
|
||||
conn.prepareStatement("CREATE LOCAL TEMPORARY TABLE IMAGES_DELETE(POST_ID BIGINT PRIMARY KEY)")
|
||||
.use {
|
||||
it.execute()
|
||||
}
|
||||
|
||||
conn.prepareStatement("INSERT INTO IMAGES_DELETE VALUES ( ? )").use { ps ->
|
||||
postIds.forEach {
|
||||
ps.setLong(1, it)
|
||||
ps.addBatch()
|
||||
}
|
||||
ps.executeBatch()
|
||||
}
|
||||
|
||||
conn.prepareStatement("DELETE FROM IMAGE WHERE POST_ID IN (SELECT POST_ID FROM IMAGES_DELETE)")
|
||||
.use {
|
||||
it.execute()
|
||||
}
|
||||
|
||||
conn.prepareStatement("TRUNCATE TABLE IMAGES_DELETE")
|
||||
}
|
||||
|
||||
private fun transform(resultRow: ResultRow): Image {
|
||||
val id = resultRow[ImageTable.id].value
|
||||
val postId = resultRow[ImageTable.postId]
|
||||
val url = resultRow[ImageTable.url]
|
||||
val thumbUrl = resultRow[ImageTable.thumbUrl]
|
||||
val host = resultRow[ImageTable.host]
|
||||
val index = resultRow[ImageTable.index]
|
||||
val current = resultRow[ImageTable.downloaded]
|
||||
val total = resultRow[ImageTable.size]
|
||||
val status = Status.valueOf(resultRow[ImageTable.status])
|
||||
val postIdRef = resultRow[ImageTable.postIdRef]
|
||||
return Image(
|
||||
id,
|
||||
postId,
|
||||
url,
|
||||
thumbUrl,
|
||||
host,
|
||||
index,
|
||||
postIdRef,
|
||||
total,
|
||||
current,
|
||||
status
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package me.vripper.repositories.impl
|
||||
|
||||
import me.vripper.entities.LogEntry
|
||||
import me.vripper.repositories.LogRepository
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.tables.LogTable
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.notInSubQuery
|
||||
import java.util.*
|
||||
|
||||
class LogRepositoryImpl(val settingsService: SettingsService) : LogRepository {
|
||||
|
||||
@Synchronized
|
||||
override fun save(logEntry: LogEntry): LogEntry {
|
||||
val id = LogTable.insertAndGetId {
|
||||
it[type] = logEntry.type.name
|
||||
it[status] = logEntry.status.name
|
||||
it[time] = logEntry.time
|
||||
it[message] = logEntry.message.take(500)
|
||||
}.value
|
||||
return logEntry.copy(id = id)
|
||||
}
|
||||
|
||||
override fun update(logEntry: LogEntry) {
|
||||
LogTable.update({ LogTable.id eq logEntry.id }) {
|
||||
it[type] = logEntry.type.name
|
||||
it[status] = logEntry.status.name
|
||||
it[message] = logEntry.message.take(500)
|
||||
}
|
||||
}
|
||||
|
||||
override fun findById(id: Long): Optional<LogEntry> {
|
||||
val result = LogTable.select {
|
||||
LogTable.id eq id
|
||||
}.map(::transform)
|
||||
|
||||
return if (result.isEmpty()) {
|
||||
Optional.empty()
|
||||
} else {
|
||||
Optional.of(result.first())
|
||||
}
|
||||
}
|
||||
|
||||
override fun findAll(): List<LogEntry> {
|
||||
return LogTable.selectAll().map(::transform)
|
||||
}
|
||||
|
||||
override fun deleteOldest(): List<Long> {
|
||||
val sub = LogTable.slice(LogTable.id).selectAll().orderBy(LogTable.time to SortOrder.DESC)
|
||||
.limit(settingsService.settings.systemSettings.maxEventLog)
|
||||
val ids = LogTable.select { LogTable.id notInSubQuery sub }.map { it[LogTable.id].value }
|
||||
LogTable.deleteWhere { LogTable.id notInSubQuery sub }
|
||||
return ids
|
||||
}
|
||||
|
||||
override fun deleteAll() {
|
||||
LogTable.deleteAll()
|
||||
}
|
||||
|
||||
private fun transform(resultRow: ResultRow): LogEntry {
|
||||
val id = resultRow[LogTable.id].value
|
||||
val type = LogEntry.Type.valueOf(resultRow[LogTable.type])
|
||||
val status = LogEntry.Status.valueOf(resultRow[LogTable.status])
|
||||
val time = resultRow[LogTable.time]
|
||||
val message = resultRow[LogTable.message]
|
||||
return LogEntry(
|
||||
id,
|
||||
type,
|
||||
status,
|
||||
time,
|
||||
message
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package me.vripper.repositories.impl
|
||||
|
||||
import me.vripper.entities.Metadata
|
||||
import me.vripper.repositories.MetadataRepository
|
||||
import java.util.*
|
||||
|
||||
class MetadataRepositoryImpl: MetadataRepository {
|
||||
|
||||
override fun save(metadata: Metadata): Metadata {
|
||||
return metadata
|
||||
}
|
||||
|
||||
override fun findByPostId(postId: Long): Optional<Metadata> {
|
||||
return Optional.empty()
|
||||
}
|
||||
|
||||
override fun deleteByPostId(postId: Long): Int {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
package me.vripper.repositories.impl
|
||||
|
||||
import me.vripper.entities.Post
|
||||
import me.vripper.entities.domain.Status
|
||||
import me.vripper.repositories.PostDownloadStateRepository
|
||||
import me.vripper.tables.PostTable
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||
import java.sql.Connection
|
||||
import java.util.*
|
||||
|
||||
class PostDownloadStateRepositoryImpl :
|
||||
PostDownloadStateRepository {
|
||||
|
||||
private val delimiter = ";"
|
||||
|
||||
override fun save(posts: List<Post>): List<Post> {
|
||||
return PostTable.batchInsert(posts, shouldReturnGeneratedValues = true) { post ->
|
||||
this[PostTable.status] = post.status.name
|
||||
this[PostTable.done] = post.done
|
||||
this[PostTable.total] = post.total
|
||||
this[PostTable.rank] = post.rank
|
||||
this[PostTable.hosts] = post.hosts.joinToString(delimiter)
|
||||
this[PostTable.outputPath] = post.downloadDirectory
|
||||
this[PostTable.postId] = post.postId
|
||||
this[PostTable.threadId] = post.threadId
|
||||
this[PostTable.postTitle] = post.postTitle
|
||||
this[PostTable.threadTitle] = post.threadTitle
|
||||
this[PostTable.forum] = post.forum
|
||||
this[PostTable.url] = post.url
|
||||
this[PostTable.token] = post.token
|
||||
this[PostTable.addedAt] = post.addedOn
|
||||
this[PostTable.size] = post.size
|
||||
this[PostTable.downloaded] = post.downloaded
|
||||
}.map(::transform)
|
||||
}
|
||||
|
||||
override fun findByPostId(postId: Long): Optional<Post> {
|
||||
val result = PostTable.select {
|
||||
PostTable.postId eq postId
|
||||
}.map(::transform)
|
||||
return if (result.isEmpty()) {
|
||||
Optional.empty()
|
||||
} else {
|
||||
Optional.of(result.first())
|
||||
}
|
||||
}
|
||||
|
||||
override fun findCompleted(): List<Long> {
|
||||
return PostTable.slice(PostTable.postId).select {
|
||||
(PostTable.status eq Status.FINISHED.name) and (PostTable.done greaterEq PostTable.total)
|
||||
}.map { it[PostTable.postId] }
|
||||
}
|
||||
|
||||
override fun findById(id: Long): Optional<Post> {
|
||||
val result = PostTable.select {
|
||||
PostTable.id eq id
|
||||
}.map { transform(it) }
|
||||
|
||||
return if (result.isEmpty()) {
|
||||
Optional.empty()
|
||||
} else {
|
||||
Optional.of(result.first())
|
||||
}
|
||||
}
|
||||
|
||||
override fun findAll(): List<Post> {
|
||||
return PostTable.selectAll().map { transform(it) }
|
||||
}
|
||||
|
||||
override fun existByPostId(postId: Long): Boolean {
|
||||
return PostTable.slice(PostTable.id).select { PostTable.postId eq postId }.count() > 0
|
||||
}
|
||||
|
||||
override fun setDownloadingToStopped(): Int {
|
||||
return PostTable.update({ (PostTable.status eq Status.DOWNLOADING.name) or (PostTable.status eq Status.PENDING.name) }) {
|
||||
it[status] = Status.STOPPED.name
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteByPostId(postId: Long): Int {
|
||||
return PostTable.deleteWhere { PostTable.postId eq postId }
|
||||
}
|
||||
|
||||
override fun update(post: Post) {
|
||||
PostTable.update({ PostTable.id eq post.id }) {
|
||||
it[status] = post.status.name
|
||||
it[done] = post.done
|
||||
it[rank] = post.rank
|
||||
it[size] = post.size
|
||||
it[downloaded] = post.downloaded
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(posts: List<Post>) {
|
||||
PostTable.batchReplace(posts, shouldReturnGeneratedValues = false) { post ->
|
||||
this[PostTable.id] = post.id
|
||||
this[PostTable.status] = post.status.name
|
||||
this[PostTable.done] = post.done
|
||||
this[PostTable.total] = post.total
|
||||
this[PostTable.rank] = post.rank
|
||||
this[PostTable.hosts] = post.hosts.joinToString(delimiter)
|
||||
this[PostTable.outputPath] = post.downloadDirectory
|
||||
this[PostTable.postId] = post.postId
|
||||
this[PostTable.threadId] = post.threadId
|
||||
this[PostTable.postTitle] = post.postTitle
|
||||
this[PostTable.threadTitle] = post.threadTitle
|
||||
this[PostTable.forum] = post.forum
|
||||
this[PostTable.url] = post.url
|
||||
this[PostTable.token] = post.token
|
||||
this[PostTable.size] = post.size
|
||||
this[PostTable.downloaded] = post.downloaded
|
||||
}
|
||||
}
|
||||
|
||||
override fun findMaxRank(): Int? {
|
||||
return PostTable.slice(PostTable.rank.max())
|
||||
.selectAll()
|
||||
.firstOrNull()
|
||||
?.get(PostTable.rank.max())
|
||||
}
|
||||
|
||||
override fun deleteAll(postIds: List<Long>) {
|
||||
val conn = TransactionManager.current().connection.connection as Connection
|
||||
conn.prepareStatement("CREATE LOCAL TEMPORARY TABLE POSTS_DELETE(POST_ID BIGINT PRIMARY KEY)")
|
||||
.use {
|
||||
it.execute()
|
||||
}
|
||||
|
||||
conn.prepareStatement("INSERT INTO POSTS_DELETE VALUES ( ? )").use { ps ->
|
||||
postIds.forEach {
|
||||
ps.setLong(1, it)
|
||||
ps.addBatch()
|
||||
}
|
||||
ps.executeBatch()
|
||||
}
|
||||
|
||||
conn.prepareStatement("DELETE FROM POST WHERE POST_ID IN (SELECT POST_ID FROM POSTS_DELETE)")
|
||||
.use {
|
||||
it.execute()
|
||||
}
|
||||
|
||||
conn.prepareStatement("TRUNCATE TABLE POSTS_DELETE")
|
||||
}
|
||||
|
||||
override fun stopAll() {
|
||||
PostTable.update {
|
||||
it[status] = Status.STOPPED.name
|
||||
}
|
||||
}
|
||||
|
||||
override fun findAllNonCompletedPostIds(): List<Long> {
|
||||
return PostTable.slice(PostTable.postId).select {
|
||||
PostTable.status neq Status.FINISHED.name
|
||||
}.map { it[PostTable.postId] }
|
||||
}
|
||||
|
||||
private fun transform(resultRow: ResultRow): Post {
|
||||
val id = resultRow[PostTable.id].value
|
||||
val status = Status.valueOf(resultRow[PostTable.status])
|
||||
val postId = resultRow[PostTable.postId]
|
||||
val threadId = resultRow[PostTable.threadId]
|
||||
val postTitle = resultRow[PostTable.postTitle]
|
||||
val threadTitle = resultRow[PostTable.threadTitle]
|
||||
val forum = resultRow[PostTable.forum]
|
||||
val url = resultRow[PostTable.url]
|
||||
val token = resultRow[PostTable.token]
|
||||
val done = resultRow[PostTable.done]
|
||||
val total = resultRow[PostTable.total]
|
||||
val hosts =
|
||||
resultRow[PostTable.hosts].split(delimiter).dropLastWhile { it.isEmpty() }.toSet()
|
||||
val downloadDirectory = resultRow[PostTable.outputPath]
|
||||
val addedOn = resultRow[PostTable.addedAt]
|
||||
val rank = resultRow[PostTable.rank]
|
||||
val size = resultRow[PostTable.size]
|
||||
val downloaded = resultRow[PostTable.downloaded]
|
||||
return Post(
|
||||
id,
|
||||
postTitle,
|
||||
threadTitle,
|
||||
forum,
|
||||
url,
|
||||
token,
|
||||
postId,
|
||||
threadId,
|
||||
total,
|
||||
hosts,
|
||||
downloadDirectory,
|
||||
addedOn,
|
||||
status,
|
||||
done,
|
||||
rank,
|
||||
size,
|
||||
downloaded
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package me.vripper.repositories.impl
|
||||
|
||||
import me.vripper.entities.Thread
|
||||
import me.vripper.repositories.ThreadRepository
|
||||
import me.vripper.tables.ThreadTable
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import java.util.*
|
||||
|
||||
class ThreadRepositoryImpl : ThreadRepository {
|
||||
|
||||
override fun save(thread: Thread): Thread {
|
||||
val id = ThreadTable.insertAndGetId {
|
||||
it[title] = thread.title
|
||||
it[total] = thread.total
|
||||
it[url] = thread.link
|
||||
it[threadId] = thread.threadId
|
||||
}.value
|
||||
return thread.copy(id = id)
|
||||
}
|
||||
|
||||
override fun findByThreadId(threadId: Long): Optional<Thread> {
|
||||
val result = ThreadTable.select {
|
||||
ThreadTable.threadId eq threadId
|
||||
}.map(this::transform)
|
||||
return if (result.isEmpty()) {
|
||||
Optional.empty()
|
||||
} else {
|
||||
Optional.of(result.first())
|
||||
}
|
||||
}
|
||||
|
||||
override fun findAll(): List<Thread> {
|
||||
return ThreadTable.selectAll().map(this::transform)
|
||||
}
|
||||
|
||||
override fun findById(id: Long): Optional<Thread> {
|
||||
val result = ThreadTable.select {
|
||||
ThreadTable.id eq id
|
||||
}.map(this::transform)
|
||||
return if (result.isEmpty()) {
|
||||
Optional.empty()
|
||||
} else {
|
||||
Optional.of(result.first())
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteByThreadId(threadId: Long): Int {
|
||||
return ThreadTable.deleteWhere { ThreadTable.threadId eq threadId }
|
||||
}
|
||||
|
||||
override fun deleteAll() {
|
||||
ThreadTable.deleteAll()
|
||||
}
|
||||
|
||||
private fun transform(resultRow: ResultRow): Thread {
|
||||
val id = resultRow[ThreadTable.id].value
|
||||
val title = resultRow[ThreadTable.title]
|
||||
val url = resultRow[ThreadTable.url]
|
||||
val threadId = resultRow[ThreadTable.threadId]
|
||||
val total = resultRow[ThreadTable.total]
|
||||
return Thread(id, title, url, threadId, total)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package me.vripper.services
|
||||
|
||||
import me.vripper.download.DownloadService
|
||||
import me.vripper.exception.PostParseException
|
||||
import me.vripper.model.PostItem
|
||||
import me.vripper.model.ThreadPostId
|
||||
import me.vripper.services.*
|
||||
import me.vripper.tasks.AddPostRunnable
|
||||
import me.vripper.tasks.ThreadLookupRunnable
|
||||
import me.vripper.utilities.GLOBAL_EXECUTOR
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class AppEndpointService(
|
||||
private val downloadService: DownloadService,
|
||||
private val dataTransaction: DataTransaction,
|
||||
private val threadCacheService: ThreadCacheService,
|
||||
private val settingsService: SettingsService
|
||||
) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
|
||||
@Synchronized
|
||||
fun scanLinks(postLinks: String) {
|
||||
if (postLinks.isBlank()) {
|
||||
log.warn("Nothing to scan")
|
||||
return
|
||||
}
|
||||
val urlList = postLinks.split(Pattern.compile("\\r?\\n")).dropLastWhile { it.isEmpty() }.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
for (link in urlList) {
|
||||
log.debug("Starting to process thread: $link")
|
||||
if (!link.startsWith(settingsService.settings.viperSettings.host)) {
|
||||
continue
|
||||
}
|
||||
var threadId: Long
|
||||
var postId: Long?
|
||||
val m = Pattern.compile(
|
||||
Pattern.quote(settingsService.settings.viperSettings.host) + "/threads/(\\d+)((.*p=)(\\d+))?"
|
||||
).matcher(link)
|
||||
if (m.find()) {
|
||||
threadId = m.group(1).toLong()
|
||||
postId = m.group(4)?.toLong()
|
||||
if (postId == null) {
|
||||
CompletableFuture.runAsync(
|
||||
ThreadLookupRunnable(
|
||||
threadId, settingsService.settings
|
||||
),
|
||||
GLOBAL_EXECUTOR
|
||||
)
|
||||
} else {
|
||||
CompletableFuture.runAsync(
|
||||
AddPostRunnable(
|
||||
listOf(ThreadPostId(threadId, postId))
|
||||
),
|
||||
GLOBAL_EXECUTOR
|
||||
)
|
||||
}
|
||||
} else {
|
||||
log.error("Cannot retrieve thread id from URL $link")
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun restartAll(posIds: List<Long> = listOf()) {
|
||||
downloadService.restartAll(posIds.map { dataTransaction.findPostsByPostId(it) }.filter { it.isPresent }
|
||||
.map { it.get() })
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun download(posts: List<ThreadPostId>) {
|
||||
CompletableFuture.runAsync(
|
||||
AddPostRunnable(posts), GLOBAL_EXECUTOR
|
||||
)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun stopAll(postIdList: List<Long> = emptyList()) {
|
||||
downloadService.stop(postIdList)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun remove(postIdList: List<Long>) {
|
||||
downloadService.stop(postIdList)
|
||||
dataTransaction.removeAll(postIdList)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun clearCompleted(): List<Long> {
|
||||
return dataTransaction.clearCompleted()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@Throws(PostParseException::class)
|
||||
fun grab(threadId: Long): List<PostItem> {
|
||||
return try {
|
||||
val thread = dataTransaction.findThreadByThreadId(threadId).orElseThrow {
|
||||
PostParseException(
|
||||
String.format(
|
||||
"Unable to find links for threadId = %s", threadId
|
||||
)
|
||||
)
|
||||
}
|
||||
val threadLookupResult = threadCacheService[thread.threadId]
|
||||
threadLookupResult.postItemList.ifEmpty {
|
||||
log.error(
|
||||
String.format(
|
||||
"Failed to get links for threadId = %s", threadId
|
||||
)
|
||||
)
|
||||
throw PostParseException(
|
||||
String.format(
|
||||
"Failed to get links for threadId = %s", threadId
|
||||
)
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw PostParseException(
|
||||
String.format(
|
||||
"Failed to get links for threadId = %s, %s", threadId, e.message
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun threadRemove(threadIdList: List<Long>) {
|
||||
threadIdList.forEach {
|
||||
dataTransaction.removeThread(it)
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun threadClear() {
|
||||
dataTransaction.clearQueueLinks()
|
||||
}
|
||||
|
||||
fun logClear() {
|
||||
dataTransaction.deleteAllLogs()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package me.vripper.services
|
||||
|
||||
import me.vripper.entities.*
|
||||
import me.vripper.entities.domain.Status
|
||||
import me.vripper.event.*
|
||||
import me.vripper.model.ErrorCount
|
||||
import me.vripper.model.PostItem
|
||||
import me.vripper.repositories.*
|
||||
import me.vripper.utilities.PathUtils
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import java.util.*
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
class DataTransaction(
|
||||
private val settingsService: SettingsService,
|
||||
private val postDownloadStateRepository: PostDownloadStateRepository,
|
||||
private val imageRepository: ImageRepository,
|
||||
private val threadRepository: ThreadRepository,
|
||||
private val metadataRepository: MetadataRepository,
|
||||
private val logRepository: LogRepository,
|
||||
private val eventBus: EventBus,
|
||||
) {
|
||||
|
||||
private fun save(posts: List<Post>): List<Post> {
|
||||
return transaction { postDownloadStateRepository.save(posts) }
|
||||
}
|
||||
|
||||
fun updatePosts(posts: List<Post>) {
|
||||
transaction { postDownloadStateRepository.update(posts) }
|
||||
eventBus.publishEvent(PostEvent(update = posts))
|
||||
}
|
||||
|
||||
fun updatePost(posts: Post) {
|
||||
transaction { postDownloadStateRepository.update(posts) }
|
||||
eventBus.publishEvent(PostEvent(update = listOf(posts)))
|
||||
}
|
||||
|
||||
fun save(thread: Thread) {
|
||||
val savedThread = transaction { threadRepository.save(thread) }
|
||||
eventBus.publishEvent(ThreadCreateEvent(savedThread))
|
||||
}
|
||||
|
||||
fun updateImages(images: List<Image>) {
|
||||
transaction { imageRepository.update(images) }
|
||||
eventBus.publishEvent(ImageEvent(images))
|
||||
}
|
||||
|
||||
fun updateImage(image: Image) {
|
||||
transaction { imageRepository.update(image) }
|
||||
eventBus.publishEvent(ImageEvent(listOf(image)))
|
||||
}
|
||||
|
||||
fun exists(postId: Long): Boolean {
|
||||
return transaction { postDownloadStateRepository.existByPostId(postId) }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun newPosts(postItems: List<PostItem>): List<Post> {
|
||||
var queuePosition = transaction {
|
||||
getQueuePosition()?.plus(1) ?: 0
|
||||
}
|
||||
|
||||
val posts = postItems.associate { postItem ->
|
||||
val post = Post(
|
||||
postTitle = postItem.title,
|
||||
url = postItem.url,
|
||||
token = postItem.securityToken,
|
||||
postId = postItem.postId,
|
||||
threadId = postItem.threadId,
|
||||
total = postItem.imageCount,
|
||||
hosts = postItem.hosts.map { "${it.first} (${it.second})" }.toSet(),
|
||||
threadTitle = postItem.threadTitle,
|
||||
forum = postItem.forum,
|
||||
rank = queuePosition++,
|
||||
downloadDirectory = PathUtils.calculateDownloadPath(
|
||||
postItem.forum,
|
||||
postItem.threadTitle,
|
||||
postItem.title,
|
||||
postItem.postId,
|
||||
settingsService.settings
|
||||
).pathString
|
||||
)
|
||||
val images = postItem.imageItemList.mapIndexed { index, imageItem ->
|
||||
Image(
|
||||
postId = postItem.postId,
|
||||
url = imageItem.mainLink,
|
||||
thumbUrl = imageItem.thumbLink,
|
||||
host = imageItem.host.hostId,
|
||||
index = index,
|
||||
)
|
||||
}
|
||||
Pair(post, images)
|
||||
}
|
||||
|
||||
|
||||
val savedPosts = transaction {
|
||||
val savedPosts = save(posts.keys.toList())
|
||||
savedPosts.associateWith {
|
||||
posts[it]!!
|
||||
}.forEach { (key, value) ->
|
||||
save(value.map { it.copy(postIdRef = key.id) })
|
||||
}
|
||||
savedPosts
|
||||
}
|
||||
eventBus.publishEvent(PostEvent(add = savedPosts))
|
||||
return savedPosts
|
||||
}
|
||||
|
||||
private fun getQueuePosition(): Int? {
|
||||
return postDownloadStateRepository.findMaxRank()
|
||||
}
|
||||
|
||||
private fun save(images: List<Image>) {
|
||||
transaction { imageRepository.save(images) }
|
||||
}
|
||||
|
||||
fun finishPost(postId: Long, automatic: Boolean = false) {
|
||||
val post = findPostsByPostId(postId).orElseThrow()
|
||||
val imagesInErrorStatus = findByPostIdAndIsError(post.postId)
|
||||
if (imagesInErrorStatus.isNotEmpty()) {
|
||||
post.status = Status.ERROR
|
||||
updatePost(post)
|
||||
} else {
|
||||
if (post.done < post.total) {
|
||||
post.status = Status.STOPPED
|
||||
updatePost(post)
|
||||
} else {
|
||||
post.status = Status.FINISHED
|
||||
transaction {
|
||||
updatePost(post)
|
||||
if (settingsService.settings.downloadSettings.clearCompleted && automatic) {
|
||||
remove(listOf(post.postId))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun findByPostIdAndIsError(postId: Long): List<Image> {
|
||||
return transaction { imageRepository.findByPostIdAndIsError(postId) }
|
||||
|
||||
}
|
||||
|
||||
private fun remove(postIds: List<Long>) {
|
||||
|
||||
transaction {
|
||||
imageRepository.deleteAllByPostId(postIds)
|
||||
postDownloadStateRepository.deleteAll(postIds)
|
||||
sortPostsByRank()
|
||||
}
|
||||
|
||||
|
||||
eventBus.publishEvent(PostEvent(delete = postIds))
|
||||
eventBus.publishEvent(ErrorCountEvent(ErrorCount(countImagesInError())))
|
||||
}
|
||||
|
||||
fun removeThread(threadId: Long) {
|
||||
transaction { threadRepository.deleteByThreadId(threadId) }
|
||||
|
||||
eventBus.publishEvent(ThreadDeleteEvent(threadId))
|
||||
|
||||
}
|
||||
|
||||
fun clearCompleted(): List<Long> {
|
||||
val completed = transaction { postDownloadStateRepository.findCompleted() }
|
||||
remove(completed)
|
||||
return completed
|
||||
}
|
||||
|
||||
fun removeAll(postIds: List<Long> = emptyList()) {
|
||||
if (postIds.isNotEmpty()) {
|
||||
remove(postIds)
|
||||
} else {
|
||||
remove(findAllPosts().map(Post::postId))
|
||||
}
|
||||
}
|
||||
|
||||
fun stopImagesByPostIdAndIsNotCompleted(postId: Long) {
|
||||
transaction { imageRepository.stopByPostIdAndIsNotCompleted(postId) }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun setMetadata(post: Post, metadata: Metadata) {
|
||||
if (metadataRepository.findByPostId(post.postId).isEmpty) {
|
||||
metadata.postIdRef = post.id
|
||||
metadataRepository.save(metadata)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearQueueLinks() {
|
||||
transaction { threadRepository.deleteAll() }
|
||||
eventBus.publishEvent(ThreadClearEvent())
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun sortPostsByRank() {
|
||||
val posts = findAllPosts().sortedWith(Comparator.comparing(Post::addedOn))
|
||||
for (i in posts.indices) {
|
||||
posts[i].rank = i
|
||||
}
|
||||
updatePosts(posts)
|
||||
}
|
||||
|
||||
fun setDownloadingToStopped() {
|
||||
transaction { postDownloadStateRepository.setDownloadingToStopped() }
|
||||
}
|
||||
|
||||
fun findAllPosts(): List<Post> {
|
||||
return transaction { postDownloadStateRepository.findAll() }
|
||||
}
|
||||
|
||||
fun findPostById(id: Long): Optional<Post> {
|
||||
return transaction { postDownloadStateRepository.findById(id) }
|
||||
}
|
||||
|
||||
fun findImagesByPostId(postId: Long): List<Image> {
|
||||
return transaction { imageRepository.findByPostId(postId) }
|
||||
}
|
||||
|
||||
fun findImageById(id: Long): Optional<Image> {
|
||||
return transaction { imageRepository.findById(id) }
|
||||
}
|
||||
|
||||
fun findAllThreads(): List<Thread> {
|
||||
return transaction { threadRepository.findAll() }
|
||||
}
|
||||
|
||||
fun findThreadById(id: Long): Optional<Thread> {
|
||||
return transaction {
|
||||
threadRepository.findById(id)
|
||||
}
|
||||
}
|
||||
|
||||
fun findByPostIdAndIsNotCompleted(postId: Long): List<Image> {
|
||||
return transaction { imageRepository.findByPostIdAndIsNotCompleted(postId) }
|
||||
}
|
||||
|
||||
fun countImagesInError(): Int {
|
||||
return transaction { imageRepository.countError() }
|
||||
}
|
||||
|
||||
fun findPostsByPostId(postId: Long): Optional<Post> {
|
||||
return transaction { postDownloadStateRepository.findByPostId(postId) }
|
||||
}
|
||||
|
||||
fun findThreadByThreadId(threadId: Long): Optional<Thread> {
|
||||
return transaction { threadRepository.findByThreadId(threadId) }
|
||||
}
|
||||
|
||||
fun saveLog(logEntry: LogEntry): LogEntry {
|
||||
val pair = transaction {
|
||||
val saved = logRepository.save(logEntry)
|
||||
val deleted = logRepository.deleteOldest()
|
||||
Pair(saved, deleted)
|
||||
}
|
||||
eventBus.publishEvent(LogCreateEvent(pair.first))
|
||||
eventBus.publishEvent(LogDeleteEvent(pair.second))
|
||||
return pair.first
|
||||
}
|
||||
|
||||
fun updateLog(logEntry: LogEntry) {
|
||||
transaction { logRepository.update(logEntry) }
|
||||
eventBus.publishEvent(LogUpdateEvent(logEntry))
|
||||
}
|
||||
|
||||
fun deleteAllLogs() {
|
||||
transaction { logRepository.deleteAll() }
|
||||
}
|
||||
|
||||
fun findAllLogs(): List<LogEntry> {
|
||||
return transaction { logRepository.findAll() }
|
||||
}
|
||||
|
||||
fun findAllNonCompletedPostIds(): List<Long> {
|
||||
return transaction { postDownloadStateRepository.findAllNonCompletedPostIds() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.vripper.services
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.event.DownloadSpeedEvent
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.QueueStateEvent
|
||||
import me.vripper.model.DownloadSpeed
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
|
||||
class DownloadSpeedService(
|
||||
private val eventBus: EventBus,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
const val DOWNLOAD_POLL_RATE = 2500
|
||||
}
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
private val bytesCount = AtomicLong(0)
|
||||
private var job: Job? = null
|
||||
|
||||
fun init() {
|
||||
coroutineScope.launch {
|
||||
eventBus.events.ofType(QueueStateEvent::class.java).subscribe {
|
||||
if (it.queueState.running + it.queueState.remaining > 0) {
|
||||
if (job == null || job?.isActive == false) {
|
||||
job = coroutineScope.launch {
|
||||
eventBus.publishEvent(DownloadSpeedEvent(DownloadSpeed(0L)))
|
||||
while (isActive) {
|
||||
delay(DOWNLOAD_POLL_RATE.toLong())
|
||||
val newValue = bytesCount.getAndSet(0)
|
||||
|
||||
eventBus.publishEvent(DownloadSpeedEvent(DownloadSpeed(((newValue * 1000) / DOWNLOAD_POLL_RATE))))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
job?.cancel()
|
||||
coroutineScope.launch {
|
||||
delay(DOWNLOAD_POLL_RATE + 500L)
|
||||
eventBus.publishEvent(DownloadSpeedEvent(DownloadSpeed(0L)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun reportDownloadedBytes(count: Long) {
|
||||
bytesCount.addAndGet(count)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.vripper.services
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.SettingsUpdateEvent
|
||||
import org.apache.hc.client5.http.config.ConnectionConfig
|
||||
import org.apache.hc.client5.http.config.RequestConfig
|
||||
import org.apache.hc.client5.http.cookie.StandardCookieSpec
|
||||
import org.apache.hc.client5.http.impl.DefaultRedirectStrategy
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder
|
||||
import org.apache.hc.core5.pool.PoolConcurrencyPolicy
|
||||
import org.apache.hc.core5.pool.PoolReusePolicy
|
||||
import org.apache.hc.core5.util.TimeValue
|
||||
import org.apache.hc.core5.util.Timeout
|
||||
|
||||
class HTTPService(
|
||||
val eventBus: EventBus,
|
||||
settingsService: SettingsService
|
||||
) {
|
||||
|
||||
companion object {
|
||||
const val USER_AGENT =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0"
|
||||
}
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
private lateinit var pcm: PoolingHttpClientConnectionManager
|
||||
private lateinit var rc: RequestConfig
|
||||
private lateinit var cc: ConnectionConfig
|
||||
lateinit var client: CloseableHttpClient
|
||||
private var connectionTimeout: Long = settingsService.settings.connectionSettings.timeout
|
||||
|
||||
fun init() {
|
||||
buildRequestConfig()
|
||||
buildConnectionConfig()
|
||||
buildConnectionPool()
|
||||
buildClientBuilder()
|
||||
coroutineScope.launch {
|
||||
pcm.closeIdle(TimeValue.ofSeconds(60))
|
||||
delay(15000)
|
||||
}
|
||||
eventBus
|
||||
.events
|
||||
.ofType(SettingsUpdateEvent::class.java)
|
||||
.subscribe {
|
||||
if (connectionTimeout != it.settings.connectionSettings.timeout) {
|
||||
connectionTimeout = it.settings.connectionSettings.timeout
|
||||
client.close()
|
||||
pcm.close()
|
||||
buildRequestConfig()
|
||||
buildConnectionConfig()
|
||||
buildConnectionPool()
|
||||
buildClientBuilder()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildConnectionPool() {
|
||||
pcm = PoolingHttpClientConnectionManagerBuilder.create()
|
||||
.setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT)
|
||||
.setConnPoolPolicy(PoolReusePolicy.LIFO)
|
||||
.setDefaultConnectionConfig(cc)
|
||||
.setMaxConnTotal(Int.MAX_VALUE)
|
||||
.setMaxConnPerRoute(Int.MAX_VALUE)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun buildRequestConfig() {
|
||||
rc = RequestConfig.custom()
|
||||
.setConnectionRequestTimeout(Timeout.ofSeconds(connectionTimeout))
|
||||
.setCookieSpec(StandardCookieSpec.RELAXED)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun buildConnectionConfig() {
|
||||
cc = ConnectionConfig.custom()
|
||||
.setConnectTimeout(Timeout.ofSeconds(connectionTimeout))
|
||||
.setSocketTimeout(Timeout.ofSeconds(connectionTimeout))
|
||||
.setTimeToLive(TimeValue.ofMinutes(10))
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun buildClientBuilder() {
|
||||
client = HttpClients.custom()
|
||||
.setConnectionManager(pcm)
|
||||
.setRedirectStrategy(DefaultRedirectStrategy.INSTANCE)
|
||||
.setUserAgent(USER_AGENT)
|
||||
.disableAutomaticRetries()
|
||||
.setDefaultRequestConfig(rc)
|
||||
.build()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.vripper.services
|
||||
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.SettingsUpdateEvent
|
||||
import net.jodah.failsafe.RetryPolicy
|
||||
import net.jodah.failsafe.event.ExecutionAttemptedEvent
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
class RetryPolicyService(
|
||||
val eventBus: EventBus, settingsService: SettingsService
|
||||
) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private var maxAttempts: Int = settingsService.settings.connectionSettings.maxAttempts
|
||||
|
||||
fun init() {
|
||||
eventBus.events.ofType(SettingsUpdateEvent::class.java).subscribe {
|
||||
if (maxAttempts != it.settings.connectionSettings.maxAttempts) {
|
||||
maxAttempts = it.settings.connectionSettings.maxAttempts
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun <T> buildRetryPolicyForDownload(): RetryPolicy<T> {
|
||||
return RetryPolicy<T>().withDelay(2, 5, ChronoUnit.SECONDS).withMaxAttempts(maxAttempts).onFailedAttempt {
|
||||
log.warn("#${it.attemptCount} tries failed", it.lastFailure)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> buildGenericRetryPolicy(): RetryPolicy<T> {
|
||||
return RetryPolicy<T>().withDelay(2, 5, ChronoUnit.SECONDS).withMaxAttempts(maxAttempts)
|
||||
.onFailedAttempt { e: ExecutionAttemptedEvent<T> ->
|
||||
log.warn("#${e.attemptCount} tries failed", e.lastFailure)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package me.vripper.services
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.SettingsUpdateEvent
|
||||
import me.vripper.exception.ValidationException
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.utilities.ApplicationProperties.VRIPPER_DIR
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import java.io.FileWriter
|
||||
import java.nio.file.*
|
||||
|
||||
class SettingsService(private val eventBus: EventBus) {
|
||||
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private val configPath = VRIPPER_DIR.resolve("config.yml")
|
||||
private val customProxiesPath = VRIPPER_DIR.resolve("proxies.json")
|
||||
private val om = ObjectMapper(YAMLFactory())
|
||||
private val proxies: MutableSet<String> = HashSet()
|
||||
|
||||
|
||||
var settings = Settings()
|
||||
|
||||
init {
|
||||
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.findAndRegisterModules().registerKotlinModule()
|
||||
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
loadViperProxies()
|
||||
restore()
|
||||
eventBus.publishEvent(SettingsUpdateEvent(settings))
|
||||
|
||||
}
|
||||
|
||||
private fun loadViperProxies() {
|
||||
try {
|
||||
SettingsService::class.java.getResourceAsStream("/proxies.json")?.use {
|
||||
val defaultProxies: List<String> = om.readValue(it)
|
||||
val customProxies: List<String> = if (customProxiesPath.toFile()
|
||||
.exists() && Files.isRegularFile(customProxiesPath)
|
||||
) {
|
||||
try {
|
||||
om.readValue(
|
||||
customProxiesPath.toFile()
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
FileWriter(customProxiesPath.toFile()).use { fw ->
|
||||
fw.append("[]").append(System.lineSeparator())
|
||||
fw.flush()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.warn(
|
||||
"Unable to create " + customProxiesPath.toFile().absolutePath, e
|
||||
)
|
||||
}
|
||||
emptyList()
|
||||
}
|
||||
|
||||
proxies.addAll(defaultProxies)
|
||||
proxies.addAll(customProxies)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error("Failed to load vipergirls proxies list", e)
|
||||
}
|
||||
proxies.add("https://vipergirls.to")
|
||||
}
|
||||
|
||||
fun getProxies(): List<String> {
|
||||
return ArrayList(proxies)
|
||||
}
|
||||
|
||||
fun newSettings(settings: Settings) {
|
||||
if (settings.viperSettings.login) {
|
||||
if (this.settings.viperSettings.password != settings.viperSettings.password) {
|
||||
settings.viperSettings.password =
|
||||
DigestUtils.md5Hex(settings.viperSettings.password)
|
||||
}
|
||||
} else {
|
||||
settings.viperSettings.username = ""
|
||||
settings.viperSettings.password = ""
|
||||
settings.viperSettings.thanks = false
|
||||
settings.viperSettings.login = false
|
||||
}
|
||||
check(settings)
|
||||
this.settings = settings
|
||||
save()
|
||||
|
||||
eventBus.publishEvent(SettingsUpdateEvent(settings))
|
||||
|
||||
}
|
||||
|
||||
private fun restore() {
|
||||
try {
|
||||
if (configPath.toFile().exists()) {
|
||||
settings = om.readValue(configPath.toFile())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error("Failed restore user settings", e)
|
||||
settings = Settings()
|
||||
}
|
||||
if (!proxies.contains(settings.viperSettings.host)) {
|
||||
settings.viperSettings.host = "https://vipergirls.to"
|
||||
}
|
||||
try {
|
||||
check(settings)
|
||||
} catch (e: ValidationException) {
|
||||
log.error("Your settings are invalid, using default settings", e)
|
||||
settings = Settings()
|
||||
}
|
||||
save()
|
||||
}
|
||||
|
||||
fun save() {
|
||||
try {
|
||||
Files.write(
|
||||
configPath,
|
||||
om.writeValueAsBytes(settings),
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.WRITE,
|
||||
StandardOpenOption.TRUNCATE_EXISTING,
|
||||
StandardOpenOption.SYNC
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
log.error("Failed to store user settings", e)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(ValidationException::class)
|
||||
fun check(settings: Settings) {
|
||||
val path: Path = try {
|
||||
Paths.get(settings.downloadSettings.downloadPath)
|
||||
} catch (e: InvalidPathException) {
|
||||
throw ValidationException(
|
||||
String.format(
|
||||
"%s is invalid", settings.downloadSettings.downloadPath
|
||||
)
|
||||
)
|
||||
}
|
||||
if (!Files.exists(path)) {
|
||||
throw ValidationException(
|
||||
String.format(
|
||||
"%s does not exist", settings.downloadSettings.downloadPath
|
||||
)
|
||||
)
|
||||
} else if (!Files.isDirectory(path)) {
|
||||
throw ValidationException(
|
||||
String.format(
|
||||
"%s is not a directory", settings.downloadSettings.downloadPath
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (settings.downloadSettings.autoQueueThreshold < 0) {
|
||||
throw ValidationException("Invalid auto queue settings, value must be a positive integer")
|
||||
}
|
||||
|
||||
if (settings.connectionSettings.maxGlobalConcurrent < 0 || settings.connectionSettings.maxGlobalConcurrent > 24) {
|
||||
throw ValidationException(
|
||||
"Invalid max global concurrent download settings, values must be in [0,24]"
|
||||
)
|
||||
}
|
||||
if (settings.connectionSettings.maxConcurrentPerHost < 1 || settings.connectionSettings.maxConcurrentPerHost > 4) {
|
||||
throw ValidationException("Invalid max concurrent download settings, values must be in [1,4]")
|
||||
}
|
||||
if (settings.connectionSettings.timeout < 1 || settings.connectionSettings.timeout > 300) {
|
||||
throw ValidationException(
|
||||
"Invalid connection timeout settings, values must be in [1,300]"
|
||||
)
|
||||
}
|
||||
if (settings.connectionSettings.maxAttempts < 1 || settings.connectionSettings.maxAttempts > 10) {
|
||||
throw ValidationException("Invalid maximum attempts settings, values must be in [1,10]")
|
||||
}
|
||||
if (settings.systemSettings.maxEventLog < 10 || settings.systemSettings.maxEventLog > 10000) {
|
||||
throw ValidationException(
|
||||
"Invalid maximum event log record settings, values must be in [100,10000]"
|
||||
)
|
||||
}
|
||||
if (settings.systemSettings.clipboardPollingRate < 500) {
|
||||
throw ValidationException(
|
||||
"Invalid clipboard monitoring polling rate settings, values must be >= 500"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.vripper.services
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.SettingsUpdateEvent
|
||||
import me.vripper.model.ThreadItem
|
||||
import me.vripper.parser.ThreadLookupAPIParser
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class ThreadCacheService(val eventBus: EventBus) {
|
||||
|
||||
fun init() {
|
||||
eventBus.events.ofType(SettingsUpdateEvent::class.java).subscribe {
|
||||
cache.invalidateAll()
|
||||
}
|
||||
}
|
||||
|
||||
private val cache: LoadingCache<Long, ThreadItem> =
|
||||
Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build { threadId ->
|
||||
ThreadLookupAPIParser(threadId).parse()
|
||||
}
|
||||
|
||||
@Throws(ExecutionException::class)
|
||||
operator fun get(threadId: Long): ThreadItem {
|
||||
return cache[threadId] ?: throw NoSuchElementException("$threadId does not exist")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package me.vripper.services
|
||||
|
||||
import me.vripper.entities.Post
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.SettingsUpdateEvent
|
||||
import me.vripper.event.VGUserLoginEvent
|
||||
import me.vripper.exception.VripperException
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.tasks.LeaveThanksRunnable
|
||||
import me.vripper.utilities.GLOBAL_EXECUTOR
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost
|
||||
import org.apache.hc.client5.http.cookie.BasicCookieStore
|
||||
import org.apache.hc.client5.http.cookie.Cookie
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class VGAuthService(
|
||||
private val cm: HTTPService, private val settingsService: SettingsService, private val eventBus: EventBus
|
||||
) {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
val context: HttpClientContext = HttpClientContext.create()
|
||||
var loggedUser = ""
|
||||
|
||||
private var authenticated = false
|
||||
|
||||
fun init() {
|
||||
context.cookieStore = BasicCookieStore()
|
||||
eventBus.events.ofType(SettingsUpdateEvent::class.java).subscribe {
|
||||
authenticate(it.settings)
|
||||
}
|
||||
authenticate(settingsService.settings)
|
||||
}
|
||||
|
||||
private fun authenticate(settings: Settings) {
|
||||
authenticated = false
|
||||
if (!settings.viperSettings.login) {
|
||||
log.debug("Authentication option is disabled")
|
||||
context.cookieStore.clear()
|
||||
loggedUser = ""
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
|
||||
return
|
||||
}
|
||||
val username = settings.viperSettings.username
|
||||
val password = settings.viperSettings.password
|
||||
if (username.isEmpty() || password.isEmpty()) {
|
||||
log.error("Cannot authenticate with ViperGirls credentials, username or password is empty")
|
||||
context.cookieStore.clear()
|
||||
loggedUser = ""
|
||||
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
|
||||
return
|
||||
}
|
||||
val postAuth = HttpPost(settings.viperSettings.host + "/login.php?do=login").also {
|
||||
it.entity = UrlEncodedFormEntity(
|
||||
listOf(
|
||||
BasicNameValuePair("vb_login_username", username),
|
||||
BasicNameValuePair("cookieuser", "1"),
|
||||
BasicNameValuePair("do", "login"),
|
||||
BasicNameValuePair("vb_login_md5password", password)
|
||||
)
|
||||
)
|
||||
it.addHeader("Referer", settings.viperSettings.host)
|
||||
it.addHeader(
|
||||
"Host", settings.viperSettings.host.replace("https://", "").replace("http://", "")
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
cm.client.execute(postAuth, context) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw VripperException("Unexpected response code returned ${response.code}")
|
||||
}
|
||||
val responseBody = EntityUtils.toString(response.entity)
|
||||
log.debug("Authentication with ViperGirls response body:{}", responseBody)
|
||||
}
|
||||
if (context.cookieStore.cookies.stream().map { obj: Cookie -> obj.name }
|
||||
.noneMatch { e: String -> e == "vg_userid" }) {
|
||||
log.error(
|
||||
"Failed to authenticate user with {}, missing vg_userid cookie", settings.viperSettings.host
|
||||
)
|
||||
return
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.cookieStore.clear()
|
||||
loggedUser = ""
|
||||
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
|
||||
log.error(
|
||||
"Failed to authenticate user with " + settings.viperSettings.host, e
|
||||
)
|
||||
return
|
||||
}
|
||||
authenticated = true
|
||||
loggedUser = username
|
||||
log.info(String.format("Authenticated: %s", username))
|
||||
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
|
||||
}
|
||||
|
||||
fun leaveThanks(post: Post) {
|
||||
CompletableFuture.runAsync(LeaveThanksRunnable(post, authenticated, context), GLOBAL_EXECUTOR)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package me.vripper.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||
|
||||
object ImageTable : LongIdTable(name = "IMAGE", columnName = "ID") {
|
||||
val downloaded = long("DOWNLOADED")
|
||||
val host = byte("HOST")
|
||||
val index = integer("INDEX")
|
||||
val postId = long("POST_ID")
|
||||
val status = varchar("STATUS", 15)
|
||||
val size = long("SIZE")
|
||||
val url = varchar("URL", 200)
|
||||
val thumbUrl = varchar("THUMB_URL", 200)
|
||||
val postIdRef = long("POST_ID_REF").references(PostTable.id, fkName = "IMAGE_POST_ID_REF_POST_ID_FK")
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.vripper.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||
import org.jetbrains.exposed.sql.javatime.datetime
|
||||
|
||||
object LogTable : LongIdTable(name = "LOG", columnName = "ID") {
|
||||
val type = varchar("TYPE", 8)
|
||||
val status = varchar("STATUS", 10)
|
||||
val time = datetime("TIME")
|
||||
val message = varchar("MESSAGE", 500)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.vripper.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||
import org.jetbrains.exposed.sql.javatime.datetime
|
||||
import java.time.LocalDateTime
|
||||
|
||||
object PostTable : LongIdTable(name = "POST", columnName = "ID") {
|
||||
val done = integer("DONE")
|
||||
val hosts = varchar("HOSTS", 255)
|
||||
val outputPath = varchar("OUTPUT_PATH", 260)
|
||||
val postId = long("POST_ID")
|
||||
val status = varchar("STATUS", 15)
|
||||
val threadId = long("THREAD_ID")
|
||||
val postTitle = varchar("POST_TITLE", 255)
|
||||
val threadTitle = varchar("THREAD_TITLE", 255)
|
||||
val forum = varchar("FORUM", 255)
|
||||
val total = integer("TOTAL")
|
||||
val url = varchar("URL", 200)
|
||||
val token = varchar("TOKEN", 51)
|
||||
val addedAt = datetime("ADDED_AT").default(LocalDateTime.now())
|
||||
val rank = integer("RANK").default(0)
|
||||
val downloaded = long("DOWNLOADED")
|
||||
val size = long("SIZE")
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.vripper.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||
|
||||
object ThreadTable : LongIdTable("THREAD", columnName = "ID") {
|
||||
val total = integer("TOTAL").default(0)
|
||||
val url = varchar("URL", 200)
|
||||
val threadId = long("THREAD_ID")
|
||||
val title = varchar("TITLE", 255)
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package me.vripper.tasks
|
||||
|
||||
import me.vripper.download.DownloadService
|
||||
import me.vripper.entities.LogEntry.Status.*
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.PostParseException
|
||||
import me.vripper.model.PostItem
|
||||
import me.vripper.model.ThreadPostId
|
||||
import me.vripper.parser.ThreadLookupAPIResponseHandler
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.Tasks
|
||||
import net.jodah.failsafe.Failsafe
|
||||
import net.jodah.failsafe.function.CheckedSupplier
|
||||
import org.apache.hc.client5.http.classic.HttpClient
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet
|
||||
import org.apache.hc.core5.net.URIBuilder
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.util.*
|
||||
import javax.xml.parsers.SAXParserFactory
|
||||
|
||||
class AddPostRunnable(private val items: List<ThreadPostId>) : KoinComponent, Runnable {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
private val settingsService: SettingsService by inject()
|
||||
private val vgAuthService: VGAuthService by inject()
|
||||
private val httpService: HTTPService by inject()
|
||||
private val retryPolicyService: RetryPolicyService by inject()
|
||||
private val downloadService: DownloadService by inject()
|
||||
private val cacheService: ThreadCacheService by inject()
|
||||
// private val logEntry: LogEntry
|
||||
|
||||
init {
|
||||
// logEntry = dataTransaction.saveLog(
|
||||
// LogEntry(
|
||||
// type = LogEntry.Type.POST, status = PENDING, message = "Processing $link"
|
||||
// )
|
||||
// )
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
try {
|
||||
Tasks.increment()
|
||||
val toProcess = mutableListOf<PostItem>()
|
||||
for ((threadId, postId) in items) {
|
||||
// dataTransaction.updateLog(logEntry.copy(status = PROCESSING))
|
||||
if (dataTransaction.exists(postId)) {
|
||||
log.warn(String.format("skipping %s, already loaded", postId))
|
||||
continue
|
||||
}
|
||||
|
||||
val threadItem = cacheService[threadId]
|
||||
// val postItem: PostItem = try {
|
||||
val postItem: PostItem =
|
||||
threadItem.postItemList.find { it.postId == postId } ?: parse(postId, threadId)
|
||||
// } catch (e: PostParseException) {
|
||||
// val error = String.format("parsing failed for gallery %s", link)
|
||||
// log.error(error, e)
|
||||
// dataTransaction.updateLog(
|
||||
// logEntry.copy(
|
||||
// status = ERROR, message = """
|
||||
// $error
|
||||
// ${e.formatToString()}
|
||||
// """.trimIndent()
|
||||
// )
|
||||
// )
|
||||
// return@map
|
||||
// }
|
||||
// if (postItem.imageItemList.isEmpty()) {
|
||||
// val error = "Post $link contains no images to download"
|
||||
// log.error(error)
|
||||
// dataTransaction.updateLog(logEntry.copy(status = ERROR, message = error))
|
||||
// return@map
|
||||
// }
|
||||
|
||||
|
||||
// dataTransaction.updateLog(
|
||||
// logEntry.copy(
|
||||
// status = DONE, message = String.format(
|
||||
// "Post $link has been successfully added to download queue"
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
toProcess.add(postItem)
|
||||
}
|
||||
|
||||
val posts = dataTransaction.newPosts(toProcess.toList())
|
||||
// metadataService.startFetchingMetadata(post)
|
||||
if (settingsService.settings.downloadSettings.autoStart) {
|
||||
log.debug("Auto start downloads option is enabled")
|
||||
downloadService.restartAll(posts)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val error = String.format("Error when adding galleries")
|
||||
log.error(error, e)
|
||||
// dataTransaction.updateLog(
|
||||
// logEntry.copy(
|
||||
// status = ERROR, message = """
|
||||
// $error
|
||||
// ${e.formatToString()}
|
||||
// """.trimIndent()
|
||||
// )
|
||||
// )
|
||||
} finally {
|
||||
Tasks.decrement()
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(PostParseException::class)
|
||||
fun parse(postId: Long, threadId: Long): PostItem {
|
||||
log.debug("Parsing post $postId")
|
||||
val httpGet =
|
||||
HttpGet(URIBuilder("${settingsService.settings.viperSettings.host}/vr.php").also {
|
||||
it.setParameter(
|
||||
"p", postId.toString()
|
||||
)
|
||||
}.build())
|
||||
val threadLookupAPIResponseHandler = ThreadLookupAPIResponseHandler()
|
||||
log.debug("Requesting {}", httpGet)
|
||||
return try {
|
||||
Failsafe.with(retryPolicyService.buildGenericRetryPolicy<Any>()).onFailure {
|
||||
log.error(
|
||||
"parsing failed for thread $threadId, post $postId", it.failure
|
||||
)
|
||||
}.get(CheckedSupplier {
|
||||
val connection: HttpClient = httpService.client
|
||||
connection.execute(
|
||||
httpGet, vgAuthService.context
|
||||
) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${response.code}' for $httpGet")
|
||||
}
|
||||
factory.newSAXParser()
|
||||
.parse(response.entity.content, threadLookupAPIResponseHandler)
|
||||
threadLookupAPIResponseHandler.result.postItemList.first()
|
||||
}
|
||||
})
|
||||
} catch (e: Exception) {
|
||||
throw PostParseException(e)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val factory = SAXParserFactory.newInstance()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package me.vripper.tasks
|
||||
|
||||
import me.vripper.entities.LogEntry
|
||||
import me.vripper.entities.LogEntry.Status.*
|
||||
import me.vripper.entities.Post
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.utilities.Tasks
|
||||
import me.vripper.utilities.formatToString
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class LeaveThanksRunnable(
|
||||
private val post: Post,
|
||||
private val authenticated: Boolean,
|
||||
private val context: HttpClientContext
|
||||
) : KoinComponent, Runnable {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private val cm: HTTPService by inject()
|
||||
private val settingsService: SettingsService by inject()
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
private val logEntry: LogEntry
|
||||
|
||||
init {
|
||||
logEntry = dataTransaction.saveLog(
|
||||
LogEntry(
|
||||
type = LogEntry.Type.THANKS,
|
||||
status = PENDING,
|
||||
message = "Leaving thanks for ${post.url}"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
try {
|
||||
Tasks.increment()
|
||||
dataTransaction.updateLog(logEntry.copy(status = PROCESSING))
|
||||
if (!settingsService.settings.viperSettings.login) {
|
||||
dataTransaction.updateLog(
|
||||
logEntry.copy(
|
||||
status = DONE,
|
||||
message = "Will not send a like for ${post.url}\nAuthentication with ViperGirls option is disabled"
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
if (!settingsService.settings.viperSettings.thanks) {
|
||||
dataTransaction.updateLog(
|
||||
logEntry.copy(
|
||||
status = DONE,
|
||||
message = "Will not send a like for ${post.url}\nLeave thanks option is disabled"
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
if (!authenticated) {
|
||||
dataTransaction.updateLog(
|
||||
logEntry.copy(
|
||||
status = DONE,
|
||||
message = "Will not send a like for ${post.url}\nYou are not authenticated"
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
val postThanks =
|
||||
HttpPost("${settingsService.settings.viperSettings.host}/post_thanks.php").also {
|
||||
it.entity = UrlEncodedFormEntity(
|
||||
listOf(
|
||||
BasicNameValuePair("do", "post_thanks_add"),
|
||||
BasicNameValuePair("using_ajax", "1"),
|
||||
BasicNameValuePair("p", post.postId.toString()),
|
||||
BasicNameValuePair("securitytoken", post.token)
|
||||
)
|
||||
)
|
||||
it.addHeader("Referer", settingsService.settings.viperSettings.host)
|
||||
it.addHeader(
|
||||
"Host",
|
||||
settingsService.settings.viperSettings.host.replace("https://", "")
|
||||
.replace("http://", "")
|
||||
)
|
||||
}
|
||||
cm.client.execute(postThanks, context) { }
|
||||
dataTransaction.updateLog(logEntry.copy(status = DONE))
|
||||
} catch (e: Exception) {
|
||||
val error = "Failed to leave a thanks for $post"
|
||||
log.error(error, e)
|
||||
dataTransaction.updateLog(
|
||||
logEntry.copy(
|
||||
status = ERROR, message = """
|
||||
$error
|
||||
${e.formatToString()}
|
||||
""".trimIndent()
|
||||
)
|
||||
)
|
||||
} finally {
|
||||
Tasks.decrement()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package me.vripper.tasks
|
||||
|
||||
import me.vripper.entities.LogEntry
|
||||
import me.vripper.entities.LogEntry.Status.*
|
||||
import me.vripper.entities.Thread
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.model.ThreadItem
|
||||
import me.vripper.model.ThreadPostId
|
||||
import me.vripper.services.AppEndpointService
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.ThreadCacheService
|
||||
import me.vripper.utilities.GLOBAL_EXECUTOR
|
||||
import me.vripper.utilities.Tasks
|
||||
import me.vripper.utilities.formatToString
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class ThreadLookupRunnable(private val threadId: Long, private val settings: Settings) :
|
||||
KoinComponent, Runnable {
|
||||
private val log by me.vripper.delegate.LoggerDelegate()
|
||||
private val dataTransaction by inject<DataTransaction>()
|
||||
private val settingsService by inject<SettingsService>()
|
||||
private val threadCacheService by inject<ThreadCacheService>()
|
||||
private val appEndpointService by inject<AppEndpointService>()
|
||||
private val link: String = "${settingsService.settings.viperSettings.host}/threads/$threadId"
|
||||
private val logEntry: LogEntry
|
||||
|
||||
init {
|
||||
logEntry = dataTransaction.saveLog(
|
||||
LogEntry(
|
||||
type = LogEntry.Type.THREAD,
|
||||
status = LogEntry.Status.PENDING,
|
||||
message = "Processing multi-post link $link"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
try {
|
||||
Tasks.increment()
|
||||
dataTransaction.updateLog(logEntry.copy(status = PROCESSING))
|
||||
if (dataTransaction.findThreadByThreadId(threadId).isEmpty) {
|
||||
val threadLookupResult = threadCacheService[threadId]
|
||||
if (threadLookupResult.postItemList.isEmpty()) {
|
||||
val message = "Nothing found for $link"
|
||||
dataTransaction.updateLog(logEntry.copy(status = ERROR, message = message))
|
||||
return
|
||||
}
|
||||
dataTransaction.save(
|
||||
Thread(
|
||||
title = threadLookupResult.title,
|
||||
link = link,
|
||||
threadId = threadId,
|
||||
total = threadLookupResult.postItemList.size
|
||||
)
|
||||
)
|
||||
dataTransaction.updateLog(
|
||||
logEntry.copy(
|
||||
status = DONE,
|
||||
message = "Thread scan completed, found ${threadLookupResult.postItemList.size} posts"
|
||||
)
|
||||
)
|
||||
autostart(threadLookupResult)
|
||||
} else {
|
||||
log.info("Link $link is already loaded")
|
||||
dataTransaction.updateLog(
|
||||
logEntry.copy(
|
||||
status = DONE, message = "$link has already been scanned"
|
||||
)
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
val error = "Error when adding multi-post link $link"
|
||||
log.error(error, e)
|
||||
dataTransaction.updateLog(
|
||||
logEntry.copy(
|
||||
status = ERROR, message = """
|
||||
$error
|
||||
${e.formatToString()}
|
||||
""".trimIndent()
|
||||
)
|
||||
)
|
||||
} finally {
|
||||
Tasks.decrement()
|
||||
}
|
||||
}
|
||||
|
||||
private fun autostart(lookupResult: ThreadItem) {
|
||||
if (lookupResult.postItemList.size <= settings.downloadSettings.autoQueueThreshold) {
|
||||
appEndpointService.threadRemove(listOf(lookupResult.threadId))
|
||||
CompletableFuture.runAsync(
|
||||
AddPostRunnable(
|
||||
lookupResult.postItemList.map { ThreadPostId(it.threadId, it.postId) }
|
||||
),
|
||||
GLOBAL_EXECUTOR
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
object ApplicationProperties {
|
||||
const val VERSION: String = "5.0.0"
|
||||
private const val BASE_DIR_NAME: String = "vripper"
|
||||
private val portable = System.getProperty("vripper.portable", "true").toBoolean()
|
||||
private val BASE_DIR: String = getBaseDir()
|
||||
val VRIPPER_DIR: Path = Path(BASE_DIR, BASE_DIR_NAME)
|
||||
|
||||
init {
|
||||
Files.createDirectories(VRIPPER_DIR)
|
||||
System.setProperty("VRIPPER_DIR", VRIPPER_DIR.toRealPath().pathString)
|
||||
}
|
||||
|
||||
private fun getBaseDir(): String {
|
||||
return if (portable) {
|
||||
System.getProperty("user.dir")
|
||||
} else {
|
||||
val os = System.getProperty("os.name")
|
||||
if (os.contains("Windows")) {
|
||||
System.getProperty("user.home")
|
||||
} else if (os.contains("Linux")) {
|
||||
"${System.getProperty("user.home")}/.config"
|
||||
} else if (os.contains("Mac")) {
|
||||
"${System.getProperty("user.home")}/.config"
|
||||
} else {
|
||||
System.getProperty("user.dir")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import liquibase.Contexts
|
||||
import liquibase.LabelExpression
|
||||
import liquibase.Liquibase
|
||||
import liquibase.database.Database
|
||||
import liquibase.database.DatabaseFactory
|
||||
import liquibase.database.jvm.JdbcConnection
|
||||
import liquibase.resource.ClassLoaderResourceAccessor
|
||||
import me.vripper.utilities.ApplicationProperties.VRIPPER_DIR
|
||||
import java.sql.DriverManager
|
||||
|
||||
object DbUtils {
|
||||
|
||||
fun update() {
|
||||
val connection =
|
||||
DriverManager.getConnection("jdbc:h2:file:$VRIPPER_DIR/vripper;DB_CLOSE_DELAY=-1;")
|
||||
|
||||
connection.use { cn ->
|
||||
val database: Database = DatabaseFactory.getInstance()
|
||||
.findCorrectDatabaseImplementation(JdbcConnection(cn))
|
||||
Liquibase(
|
||||
"db.changelog-master.xml", ClassLoaderResourceAccessor(), database
|
||||
).use { liquibase ->
|
||||
liquibase.update(Contexts(), LabelExpression())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import java.security.MessageDigest
|
||||
|
||||
fun Throwable.formatToString(): String {
|
||||
return StringWriter().use { stringWriter ->
|
||||
PrintWriter(stringWriter).use { printWriter ->
|
||||
this.printStackTrace(printWriter)
|
||||
printWriter.flush()
|
||||
stringWriter.flush()
|
||||
stringWriter.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Long.formatSI(): String {
|
||||
if (this < 0) {
|
||||
return "? Bytes"
|
||||
}
|
||||
return humanReadableByteCount(this, false)
|
||||
}
|
||||
|
||||
private fun humanReadableByteCount(bytes: Long, si: Boolean): String {
|
||||
val unit = if (si) 1000 else 1024
|
||||
if (bytes < unit) return "$bytes Bytes"
|
||||
val exp = (Math.log(bytes.toDouble()) / Math.log(unit.toDouble())).toInt()
|
||||
val pre = (if (si) "kMGTPE" else "KMGTPE")[exp - 1].toString() + if (si) "" else "i"
|
||||
return String.format("%.1f %sB", bytes / Math.pow(unit.toDouble(), exp.toDouble()), pre)
|
||||
}
|
||||
|
||||
fun String.hash256(): String {
|
||||
val bytes = this.toByteArray()
|
||||
val md = MessageDigest.getInstance("SHA-256")
|
||||
val digest = md.digest(bytes)
|
||||
return digest.fold("") { str, it -> str + "%02x".format(it) }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user