Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85983ec490 | ||
|
|
7abf6bcade | ||
|
|
854581f0bf | ||
|
|
c79a92f3b2 | ||
|
|
4d6c3a67b1 | ||
|
|
83abb5a825 | ||
|
|
d618771125 | ||
|
|
45c9fd308d | ||
|
|
0c00ee1320 |
+3
-4
@@ -1,10 +1,9 @@
|
|||||||
target/
|
target/
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
.vscode
|
.vscode
|
||||||
*.ui~
|
*.ui~
|
||||||
resources.gresource
|
resources.gresource
|
||||||
_build/
|
_build
|
||||||
build/
|
|
||||||
vendor/
|
vendor/
|
||||||
.criterion/
|
.criterion
|
||||||
org.gnome.*.json~
|
|
||||||
|
|||||||
+43
-80
@@ -1,12 +1,31 @@
|
|||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- lint
|
- lint
|
||||||
- review
|
|
||||||
|
|
||||||
variables:
|
.cargo_test_template: &cargo_test
|
||||||
BUNDLE: "gnome-podcasts-dev.flatpak"
|
stage: test
|
||||||
|
|
||||||
|
# variables:
|
||||||
|
# RUSTFLAGS: "-C link-dead-code"
|
||||||
|
# RUST_BACKTRACE: "FULL"
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- apt-get update -yqq
|
||||||
|
- apt-get install -yqq --no-install-recommends build-essential libgtk-3-dev meson
|
||||||
|
|
||||||
|
- mkdir -p .cargo_cache
|
||||||
|
# Only stuff inside the repo directory can be cached
|
||||||
|
# Override the CARGO_HOME variable to force it location
|
||||||
|
- export CARGO_HOME="${PWD}/.cargo_cache"
|
||||||
|
script:
|
||||||
|
- rustc -Vv && cargo -Vv
|
||||||
|
# Force regeneration of gresources regardless of artifacts chage
|
||||||
|
- cd hammond-gtk/resources/ && glib-compile-resources --generate resources.xml && cd ../../
|
||||||
|
|
||||||
|
- cargo build
|
||||||
|
- cargo test -- --test-threads=1
|
||||||
|
- cargo test -- --test-threads=1 --ignored
|
||||||
|
|
||||||
.cargo_cache_template: &cargo_cache
|
|
||||||
cache:
|
cache:
|
||||||
# JOB_NAME - Each job will have it's own cache
|
# JOB_NAME - Each job will have it's own cache
|
||||||
# COMMIT_REF_SLUG = Lowercase name of the branch
|
# COMMIT_REF_SLUG = Lowercase name of the branch
|
||||||
@@ -16,37 +35,12 @@ variables:
|
|||||||
- target/
|
- target/
|
||||||
- .cargo_cache/
|
- .cargo_cache/
|
||||||
|
|
||||||
.cargo_test_template: &cargo_test
|
rust:stable:
|
||||||
stage: test
|
|
||||||
|
|
||||||
variables:
|
|
||||||
RUSTFLAGS: "--cfg rayon_unstable"
|
|
||||||
RUST_BACKTRACE: "FULL"
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- apt-get update -yqq
|
|
||||||
- apt-get install -yqq --no-install-recommends build-essential libgtk-3-dev meson libgstreamer1.0-dev
|
|
||||||
|
|
||||||
- mkdir -p .cargo_cache
|
|
||||||
# Only stuff inside the repo directory can be cached
|
|
||||||
# Override the CARGO_HOME variable to force it location
|
|
||||||
- export CARGO_HOME="${PWD}/.cargo_cache"
|
|
||||||
script:
|
|
||||||
- rustc -Vv && cargo -Vv
|
|
||||||
# Force regeneration of gresources regardless of artifacts chage
|
|
||||||
- cd podcasts-gtk/resources/ && glib-compile-resources --generate resources.xml && cd ../../
|
|
||||||
|
|
||||||
- cargo build
|
|
||||||
- cargo test -- --test-threads=1
|
|
||||||
- cargo test -- --test-threads=1 --ignored
|
|
||||||
<<: *cargo_cache
|
|
||||||
|
|
||||||
.rust:stable:
|
|
||||||
# https://hub.docker.com/_/rust/
|
# https://hub.docker.com/_/rust/
|
||||||
image: "rust"
|
image: "rust"
|
||||||
<<: *cargo_test
|
<<: *cargo_test
|
||||||
|
|
||||||
.rust:nightly:
|
rust:nightly:
|
||||||
# https://hub.docker.com/r/rustlang/rust/
|
# https://hub.docker.com/r/rustlang/rust/
|
||||||
image: "rustlang/rust:nightly"
|
image: "rustlang/rust:nightly"
|
||||||
<<: *cargo_test
|
<<: *cargo_test
|
||||||
@@ -55,30 +49,30 @@ variables:
|
|||||||
- web
|
- web
|
||||||
|
|
||||||
flatpak:
|
flatpak:
|
||||||
image: registry.gitlab.gnome.org/gnome/gnome-runtime-images/rust_bundle:3.28
|
image: registry.gitlab.com/alatiera/gnome-nightly-oci/rust-bundle:latest
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- flatpak-builder --stop-at=gnome-podcasts app org.gnome.Podcasts.json
|
- flatpak-builder --stop-at=hammond app org.gnome.Hammond.json
|
||||||
# https://gitlab.gnome.org/World/podcasts/issues/55
|
# https://gitlab.gnome.org/alatiera/Hammond/issues/55
|
||||||
# Force regeneration of gresources regardless of artifacts chage
|
# Force regeneration of gresources regardless of artifacts chage
|
||||||
- flatpak-builder --run app org.gnome.Podcasts.json glib-compile-resources --sourcedir=podcasts-gtk/resources/ podcasts-gtk/resources/resources.xml
|
- flatpak-builder --run app org.gnome.Hammond.json glib-compile-resources --sourcedir=hammond-gtk/resources/ hammond-gtk/resources/resources.xml
|
||||||
|
|
||||||
# Build the flatpak repo
|
# Build the flatpak repo
|
||||||
- flatpak-builder --run app org.gnome.Podcasts.json meson --prefix=/app --libdir=/app/lib _build
|
- flatpak-builder --run app org.gnome.Hammond.json meson --prefix=/app --libdir=/app/lib _build
|
||||||
- flatpak-builder --run app org.gnome.Podcasts.json ninja -C _build install
|
- flatpak-builder --run app org.gnome.Hammond.json ninja -C _build install
|
||||||
- flatpak-builder --finish-only app org.gnome.Podcasts.json
|
- flatpak-builder --finish-only app org.gnome.Hammond.json
|
||||||
- flatpak build-export repo app
|
- flatpak build-export repo app
|
||||||
|
|
||||||
# Create a flatpak bundle
|
# Create a flatpak bundle
|
||||||
- flatpak build-bundle repo ${BUNDLE} org.gnome.Podcasts
|
- flatpak build-bundle repo hammond-dev.flatpak org.gnome.Hammond
|
||||||
# Run the tests
|
# Run the tests
|
||||||
# - flatpak-builder --run app org.gnome.Podcasts.json cargo test -- --test-threads=1
|
# - flatpak-builder --run app org.gnome.Hammond.json cargo test -- --test-threads=1
|
||||||
# - flatpak-builder --run app org.gnome.Podcasts.json cargo test -- --test-threads=1 --ignored
|
# - flatpak-builder --run app org.gnome.Hammond.json cargo test -- --test-threads=1 --ignored
|
||||||
|
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- $BUNDLE
|
- hammond-dev.flatpak
|
||||||
expire_in: 30 days
|
expire_in: 2 days
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
# JOB_NAME - Each job will have it's own cache
|
# JOB_NAME - Each job will have it's own cache
|
||||||
@@ -89,34 +83,6 @@ flatpak:
|
|||||||
- .flatpak-builder/cache/
|
- .flatpak-builder/cache/
|
||||||
- target/
|
- target/
|
||||||
|
|
||||||
review:
|
|
||||||
stage: review
|
|
||||||
dependencies:
|
|
||||||
- flatpak
|
|
||||||
script:
|
|
||||||
- echo "Generating flatpak deployment"
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- $BUNDLE
|
|
||||||
expire_in: 30 days
|
|
||||||
environment:
|
|
||||||
name: review/$CI_COMMIT_REF_NAME
|
|
||||||
url: https://gitlab.gnome.org/$CI_PROJECT_PATH/-/jobs/$CI_JOB_ID/artifacts/raw/${BUNDLE}
|
|
||||||
on_stop: stop_review
|
|
||||||
except:
|
|
||||||
- master@World/podcasts
|
|
||||||
|
|
||||||
stop_review:
|
|
||||||
stage: review
|
|
||||||
script:
|
|
||||||
- echo "Stopping flatpak deployment"
|
|
||||||
when: manual
|
|
||||||
environment:
|
|
||||||
name: review/$CI_COMMIT_REF_NAME
|
|
||||||
action: stop
|
|
||||||
except:
|
|
||||||
- master@World/podcasts
|
|
||||||
|
|
||||||
# Configure and run rustfmt on nightly
|
# Configure and run rustfmt on nightly
|
||||||
# Exits and builds fails if on bad format
|
# Exits and builds fails if on bad format
|
||||||
rustfmt:
|
rustfmt:
|
||||||
@@ -125,20 +91,17 @@ rustfmt:
|
|||||||
script:
|
script:
|
||||||
- rustc -Vv && cargo -Vv
|
- rustc -Vv && cargo -Vv
|
||||||
- cargo fmt --version
|
- cargo fmt --version
|
||||||
- cargo fmt --all -- --check
|
- cargo fmt --all -- --write-mode=diff
|
||||||
|
|
||||||
# Configure and run clippy on nightly
|
# Configure and run clippy on nightly
|
||||||
# Only fails on errors atm.
|
# Only fails on errors atm.
|
||||||
.clippy:
|
clippy:
|
||||||
image: "registry.gitlab.gnome.org/alatiera/hammond-container-images/clippy:nightly"
|
image: "rustlang/rust:nightly"
|
||||||
stage: lint
|
stage: lint
|
||||||
variables:
|
|
||||||
RUSTFLAGS: "--cfg rayon_unstable"
|
|
||||||
CARGO_HOME: ".cargo_cache"
|
|
||||||
script:
|
script:
|
||||||
- rustc --version && cargo --version
|
- rustc --version && cargo --version
|
||||||
- cargo clippy --version
|
- cargo install clippy --force
|
||||||
# Force regeneration of gresources regardless of artifacts chage
|
# Force regeneration of gresources regardless of artifacts chage
|
||||||
- cd podcasts-gtk/resources/ && glib-compile-resources --generate resources.xml && cd ../../
|
- cd hammond-gtk/resources/ && glib-compile-resources --generate resources.xml && cd ../../
|
||||||
- cargo clippy --all
|
- cargo clippy --all
|
||||||
<<: *cargo_cache
|
when: manual
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Some common cases might be:
|
|||||||
|
|
||||||
Steps to reproduce:
|
Steps to reproduce:
|
||||||
|
|
||||||
1. Open GNOME Podcasts
|
1. Open Hammond
|
||||||
2. Do an action
|
2. Do an action
|
||||||
3. ...
|
3. ...
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +1,9 @@
|
|||||||
# Steps to reproduce
|
Detailed description of the issue. Put as much information as you can, potentially
|
||||||
<!--
|
with images showing the issue.
|
||||||
Explain in detail the steps on how the issue can be reproduced.
|
|
||||||
-->
|
|
||||||
1.
|
|
||||||
2.
|
|
||||||
3.
|
|
||||||
|
|
||||||
Reproducible in:
|
Steps to reproduce:
|
||||||
<!--
|
|
||||||
Please test if the issue was already fixed in the unstable version of the app.
|
|
||||||
For that, follow these steps:
|
|
||||||
1. Make sure Flatpak is installed or install it following these steps https://flatpak.org/setup
|
|
||||||
2. Install the unstable version of the app following this link
|
|
||||||
https://gitlab.gnome.org/GNOME/gnome-apps-nightly/raw/master/nautilus.flatpakref and save
|
|
||||||
it as a ".flatpakref" file
|
|
||||||
|
|
||||||
If these steps failed, write in 'Other' the distribution you’re using and
|
1. Open Hammond
|
||||||
the version of the app.
|
2. Do an action
|
||||||
-->
|
3. ...
|
||||||
- Flatpak unstable: (yes or no) <!-- Write "yes" or "no" after the semicolon. -->
|
|
||||||
- Other:
|
|
||||||
|
|
||||||
# Current behavior
|
|
||||||
<!-- Describe the current behavior. -->
|
|
||||||
|
|
||||||
|
|
||||||
# Expected behavior
|
|
||||||
<!-- Describe the expected behavior. -->
|
|
||||||
|
|
||||||
|
|
||||||
# Additional information
|
|
||||||
<!--
|
|
||||||
Provide more information that could be relevant.
|
|
||||||
|
|
||||||
If the issue is a crash, provide a stack trace following the steps in:
|
|
||||||
https://wiki.gnome.org/Community/GettingInTouch/Bugzilla/GettingTraces
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Ignore the text under this line. -->
|
|
||||||
/label ~"Bug"
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
# Current problems
|
|
||||||
<!--
|
|
||||||
What are the problems that the current project has?
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* User cannot use the keyboard to perform most common actions
|
|
||||||
or
|
|
||||||
* User cannot see documents from cloud services
|
|
||||||
-->
|
|
||||||
|
|
||||||
# Goals & use cases
|
|
||||||
<!--
|
|
||||||
What are the use cases that this proposal will cover? What are the end goals?
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* User needs to share a file with their friends.
|
|
||||||
or
|
|
||||||
* It should be easy to edit a picture within the app.
|
|
||||||
-->
|
|
||||||
|
|
||||||
# Requirements
|
|
||||||
<!--
|
|
||||||
What does the solution needs to ensure for being succesful?
|
|
||||||
|
|
||||||
For example:
|
|
||||||
* Work on small form factors and touch
|
|
||||||
or
|
|
||||||
* Use the Meson build system and integrate with it
|
|
||||||
-->
|
|
||||||
|
|
||||||
# Relevant art
|
|
||||||
<!--
|
|
||||||
Is there any product that has implemented something similar? Put links to other
|
|
||||||
projects, pictures, links to other code, etc.
|
|
||||||
-->
|
|
||||||
|
|
||||||
# Proposal & plan
|
|
||||||
<!-- What's the solution and how should be achieved? It can be split in smaller
|
|
||||||
tasks of minimum change, so they can be delivered across several releases. -->
|
|
||||||
|
|
||||||
/label ~"Epic"
|
|
||||||
@@ -1,24 +1,17 @@
|
|||||||
### Use cases
|
Detailed description of the feature. Put as much information as you can.
|
||||||
<!--
|
|
||||||
Describe what problem(s) the user is experiencing and that this request
|
|
||||||
is trying to solve.
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
Proposed Mockups:
|
||||||
|
|
||||||
### Desired behavior
|
(Add mockups of the proposed feature)
|
||||||
<!-- Describe the desired functionality. -->
|
|
||||||
|
|
||||||
|
## Design Tasks
|
||||||
|
|
||||||
### Benefits of the solution
|
* [ ] design tasks
|
||||||
<!-- List the possible benefits of the solution and how it fits in the project. -->
|
|
||||||
|
|
||||||
|
## Development Tasks
|
||||||
|
|
||||||
### Possible drawbacks
|
* [ ] development tasks
|
||||||
<!--
|
|
||||||
Describe possible drawbacks of the feature and list how it could affect
|
|
||||||
the project i.e. UI discoverability, complexity, impact in more or less
|
|
||||||
number of users, etc.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Ignore the text under this line. -->
|
## QA Tasks
|
||||||
/label ~"Feature"
|
|
||||||
|
* [ ] qa (quality assurance) tasks
|
||||||
|
|||||||
+38
-138
@@ -5,153 +5,53 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added:
|
|
||||||
|
|
||||||
### Changed:
|
* Downlaoding and loading images now is done asynchronously and is not blocking programs execution.
|
||||||
|
[#7](https://gitlab.gnome.org/alatiera/Hammond/issues/7)
|
||||||
### Fixed:
|
* Bold, italics links and some other `html` tags can now be rendered in the Show Description.
|
||||||
|
[#25](https://gitlab.gnome.org/alatiera/Hammond/issues/25)
|
||||||
### Removed:
|
|
||||||
|
|
||||||
## [0.4.3] - 2018-07-27
|
|
||||||
|
|
||||||
### Fixed:
|
|
||||||
|
|
||||||
- Fix the cargo vendor config for the tarball releash script. (Jorda Petridis) a2440c19e11ca4dcdbcb67cd85259a41fe3754d6
|
|
||||||
|
|
||||||
## [0.4.2] - 2018-07-27
|
|
||||||
|
|
||||||
### Changed:
|
|
||||||
|
|
||||||
- Minimum size requested by the Views. (Jorda Petridis) 7c96152f3f53f271247230dccf1c9cd5947b685f
|
|
||||||
|
|
||||||
### Fixed:
|
|
||||||
|
|
||||||
- Screenshot metadata in appstream data. (Jorda Petridis) a2440c19e11ca4dcdbcb67cd85259a41fe3754d6
|
|
||||||
|
|
||||||
## [0.4.1] - 2018-07-26
|
|
||||||
### Added:
|
|
||||||
|
|
||||||
- Custom icons for the fast-forward and rewind actions in the Player were added. (Tobias Bernard) e77000076b3d78b8625f4c7ef367376d0130ece6
|
|
||||||
- Hicolor and symbolic icons for the Application. (Tobias Bernard and Sam Hewitt) edae1b04801dba9d91d5d4145db79b287f0eec2c
|
|
||||||
- Basic prefferences dialog (Zander Brown). [34](https://gitlab.gnome.org/World/podcasts/merge_requests/34)
|
|
||||||
- Dbus service preperation. Not used till the MPRIS2 integration has landed. (Zander Brown) [42](https://gitlab.gnome.org/World/podcasts/merge_requests/42)
|
|
||||||
- Episodes and Images will only get drawn when needed. Big Performance impact. (Jordan Petridis) [43](https://gitlab.gnome.org/World/podcasts/merge_requests/43)
|
|
||||||
|
|
||||||
### Changed:
|
|
||||||
|
|
||||||
- The `ShowWidget` control button were moved to a secondary menu in the Headerbar. (Jordan Petridis) 536805791e336a3e112799be554706bb804d2bef
|
|
||||||
- EmptyView layout improvements. (Jorda Petridis) 3c3d6c1e7f15b88308a9054b15a6ca0d8fa233ce 518ea9c8b57885c44bda9c418b19fef26ae0e55d
|
|
||||||
- Improved the `AddButton` behavior. (Jorda Petridis) 67ab54f8203f19aad198dc49e935127d25432b41
|
|
||||||
|
|
||||||
### Fixed:
|
|
||||||
|
|
||||||
- A couple reffence cycles where fixed. (Jorda Petridis)
|
|
||||||
|
|
||||||
### Removed:
|
|
||||||
|
|
||||||
- The delay between the application startup and the `update_on_startup` action. (Jorda Petridis) 7569465a612ee5ef84d0e58f4e1010c8d14080d4
|
|
||||||
|
|
||||||
## [0.4.0] - 2018-07-04
|
|
||||||
### Added:
|
|
||||||
- Keyboard Shortcuts and a Shortcuts dialog were implemented. (ZanderBrown)
|
|
||||||
[!33](https://gitlab.gnome.org/World/podcasts/merge_requests/33)
|
|
||||||
|
|
||||||
### Changed:
|
|
||||||
- The `FileChooser` of the OPML import was changed to use the `FileChooserNative` widget/API. (ZanderBrown)
|
|
||||||
[!33](https://gitlab.gnome.org/World/podcasts/merge_requests/33)
|
|
||||||
- The `EpisdeWidget` was refactored.
|
|
||||||
[!38](https://gitlab.gnome.org/World/podcasts/merge_requests/38)
|
|
||||||
- `EpisdeWidget`'s progressbar was changed to be non-blocking and should feel way more responsive now. 9b0ac5b83dadecdff51cd398293afdf0d5276012
|
|
||||||
- An embeded audio player was implemented!
|
|
||||||
[!40](https://gitlab.gnome.org/World/podcasts/merge_requests/40)
|
|
||||||
- Various Database changes.
|
|
||||||
[!41](https://gitlab.gnome.org/World/podcasts/merge_requests/41)
|
|
||||||
|
|
||||||
### Fixed:
|
|
||||||
- Fixed a bug whre the about dialog would be unclosable. (ZanderBrown) [!37](https://gitlab.gnome.org/World/podcasts/merge_requests/37)
|
|
||||||
|
|
||||||
## [0.3.4] - 2018-05-20
|
|
||||||
### Fixed:
|
|
||||||
- Flatpak can now access the Home folder. This fixes the OPML import feature from
|
|
||||||
not being able to access any file.
|
|
||||||
|
|
||||||
## [0.3.3] - 2018-05-19
|
|
||||||
### Added:
|
|
||||||
- Initial functionality for importing shows from an OPML file was implemented.
|
|
||||||
- ShowsView now rembmers the vertical alignment of the scrollbar between refreshes. 4d2b64e79d8518454b3677612664cd32044cf837
|
|
||||||
|
|
||||||
### Changed:
|
|
||||||
- Minimum `rustc` version requirment was bumped to `1.26`
|
|
||||||
- Some animations should be smoother now. 7d598bb1d08b05fd5ab532657acdad967c0afbc3
|
|
||||||
- InAppNotification now can be used to propagate some erros to the user. 7035fe05c4741b3e7ccce6827f72766226d5fc0a and 118dac5a1ab79c0b4ebe78e88256a4a38b138c04
|
|
||||||
|
|
||||||
### Fixed:
|
|
||||||
- Fixed a of by one bug in the `ShowsView` where the last show was never shown. bd12b09cbc8132fd39a266fd091e24bc6c3c040f
|
|
||||||
|
|
||||||
## [0.3.2] - 2018-05-07
|
|
||||||
### Added:
|
|
||||||
- Vies now have a new fancy scrolling animation when they are refereshed.
|
|
||||||
|
|
||||||
### Changed:
|
|
||||||
- Downlaoding and loading images now is done asynchronously and is not blocking programs execution.
|
|
||||||
[#7](https://gitlab.gnome.org/World/podcasts/issues/7)
|
|
||||||
- Bold, italics links and some other `html` tags can now be rendered in the Show Description.
|
|
||||||
[#25](https://gitlab.gnome.org/World/podcasts/issues/25)
|
|
||||||
- `Rayon` Threadpools are now used instead of unlimited one-off threads.
|
|
||||||
- `EpisdeWidget`s are now loaded asynchronously accross views.
|
|
||||||
- `EpisodeWidget`s no longer trigger a `View` refresh for trivial stuff 03bd95184808ccab3e0ea0e3713a52ee6b7c9ab4
|
|
||||||
- `ShowWidget` layout was changed 9a5cc1595d982f3232ee7595b83b6512ac8f6c88
|
|
||||||
- `ShowWidget` Description is inside a scrolled window now
|
|
||||||
|
|
||||||
### Fixed:
|
|
||||||
- `EpisodeWidget` Height now is consistent accros views [#57](https://gitlab.gnome.org/World/podcasts/issues/57)
|
|
||||||
- Implemented a tail-recursion loop to follow-up when a feed redirects to another url. c6a24e839a8ba77d09673f299cfc1e64ba7078f3
|
|
||||||
|
|
||||||
### Removed:
|
|
||||||
- Removed the custom configuration file and replaced instructions to just use meson. 1f1d4af8ba7db8f56435d13a1c191ecff3d4a85b
|
|
||||||
|
|
||||||
## [0.3.1] - 2018-03-28
|
## [0.3.1] - 2018-03-28
|
||||||
### Added:
|
|
||||||
- Ability to mark all episodes of a Show as watched.
|
|
||||||
[#47](https://gitlab.gnome.org/World/podcasts/issues/47)
|
|
||||||
- Now you are able to subscribe to itunes™ podcasts by using the itunes link of the show.
|
|
||||||
[#49](https://gitlab.gnome.org/World/podcasts/issues/49)
|
|
||||||
- Hammond now remembers the window size and position. (Rowan Lewis)
|
|
||||||
[#50](https://gitlab.gnome.org/World/podcasts/issues/50)
|
|
||||||
- Implemnted the initial work for integrating with GSettings and storing preferences. (Rowan Lewis)
|
|
||||||
[!22](https://gitlab.gnome.org/World/podcasts/merge_requests/22) [!23](https://gitlab.gnome.org/World/podcasts/merge_requests/23)
|
|
||||||
- Shows without episodes now display an empty message similar to EmptyView.
|
|
||||||
[#44](https://gitlab.gnome.org/World/podcasts/issues/44)
|
|
||||||
|
|
||||||
### Changed:
|
* Ability to mark all episodes of a Show as watched.
|
||||||
- EpisdeWidget has been reimplemented as a compile time state machine.
|
[#47](https://gitlab.gnome.org/alatiera/Hammond/issues/47)
|
||||||
[!18](https://gitlab.gnome.org/World/podcasts/merge_requests/18)
|
* Now you are able to subscribe to itunes™ podcasts by using the itunes link of the show.
|
||||||
- Content Views no longer scroll horizontally when shrunk bellow their minimum size.
|
[#49](https://gitlab.gnome.org/alatiera/Hammond/issues/49)
|
||||||
[#35](https://gitlab.gnome.org/World/podcasts/issues/35)
|
* EpisdeWidget has been reimplemented as a compile time state machine.
|
||||||
- Some requests now use the Tor Browser's user agent. (Rowan Lewis)
|
[!18](https://gitlab.gnome.org/alatiera/Hammond/merge_requests/18)
|
||||||
[#53](https://gitlab.gnome.org/World/podcasts/issues/53)
|
* Content Views no longer scroll horizontally when shrunk bellow their minimum size.
|
||||||
|
[#35](https://gitlab.gnome.org/alatiera/Hammond/issues/35)
|
||||||
### Fixed:
|
* Double border aroun the main window was fixed. (Rowan Lewis)
|
||||||
- Double border aroun the main window was fixed. (Rowan Lewis)
|
[#52](https://gitlab.gnome.org/alatiera/Hammond/issues/52)
|
||||||
[#52](https://gitlab.gnome.org/World/podcasts/issues/52)
|
* Some requests now use the Tor Browser's user agent. (Rowan Lewis)
|
||||||
|
[#53](https://gitlab.gnome.org/alatiera/Hammond/issues/53)
|
||||||
|
* Hammond now remembers the window size and position. (Rowan Lewis)
|
||||||
|
[#50](https://gitlab.gnome.org/alatiera/Hammond/issues/50)
|
||||||
|
* Implemnted the initial work for integrating with GSettings and storing preferences. (Rowan Lewis)
|
||||||
|
[!22](https://gitlab.gnome.org/alatiera/Hammond/merge_requests/22) [!23](https://gitlab.gnome.org/alatiera/Hammond/merge_requests/23)
|
||||||
|
* Shows without episodes now display an empty message similar to EmptyView.
|
||||||
|
[#44](https://gitlab.gnome.org/alatiera/Hammond/issues/44)
|
||||||
|
|
||||||
## [0.3.0] - 2018-02-11
|
## [0.3.0] - 2018-02-11
|
||||||
- Tobias Bernard Redesigned the whole Gtk+ client.
|
|
||||||
- Complete re-write of hammond-data and hammond-gtk modules.
|
* Tobias Bernard Redesigned the whole Gtk+ client.
|
||||||
- Error handling for all crates was migrated from error-chain to Failure.
|
* Complete re-write of hammond-data and hammond-gtk modules.
|
||||||
- Hammond-data now uses futures to parse feeds.
|
* Error handling for all crates was migrated from error-chain to Failure.
|
||||||
- Custom gtk-widgets are now composed structs as opposed to functions returning Gtk widgets.
|
* Hammond-data now uses futures to parse feeds.
|
||||||
|
* Custom gtk-widgets are now composed structs as opposed to functions returning Gtk widgets.
|
||||||
|
|
||||||
## [0.2.0] - 2017-11-28
|
## [0.2.0] - 2017-11-28
|
||||||
- Database Schema Breaking Changes.
|
|
||||||
- Added url sanitization. #4.
|
* Database Schema Breaking Changes.
|
||||||
- Reworked and refactored of the hammond-data API.
|
* Added url sanitization. #4.
|
||||||
- Added some more unit tests
|
* Reworked and refactored of the hammond-data API.
|
||||||
- Documented hammond-data public API.
|
* Added some more unit tests
|
||||||
|
* Documented hammond-data public API.
|
||||||
|
|
||||||
## [0.1.1] - 2017-11-13
|
## [0.1.1] - 2017-11-13
|
||||||
- Added appdata.xml file
|
|
||||||
|
* Added appdata.xml file
|
||||||
|
|
||||||
## [0.1.0] - 2017-11-13
|
## [0.1.0] - 2017-11-13
|
||||||
- Initial Release
|
|
||||||
|
Initial Release
|
||||||
+8
-8
@@ -1,18 +1,18 @@
|
|||||||
## Contributing to GNOME Podcasts
|
## Contributing to Hammond
|
||||||
|
|
||||||
Thank you for looking in this file!
|
Thank you for looking in this file!
|
||||||
|
|
||||||
When contributing to the development of GNOME Podcasts, please first discuss the change you wish to make via issue, email, or any other method with the maintainers before making a change.
|
When contributing to the development of Hammond, please first discuss the change you wish to make via issue, email, or any other method with the maintainers before making a change.
|
||||||
|
|
||||||
If you have any questions regarding the use or development of GNOME Podcasts,
|
If you have any questions regarding the use or development of Hammond,
|
||||||
want to discuss design or simply hang out, please join us in [#hammond on irc.gnome.org.](irc://irc.gnome.org/#hammond)
|
want to discuss design or simply hang out, please join us in [#hammond on irc.gnome.org.](irc://irc.gnome.org/#hammond)
|
||||||
|
|
||||||
Please note we have a [code of conduct](https://wiki.gnome.org/Foundation/CodeOfConduc), please follow it in all your interactions with the project.
|
Please note we have a [code of conduct](https://wiki.gnome.org/Foundation/CodeOfConduc), please follow it in all your interactions with the project.
|
||||||
|
|
||||||
## Source repository
|
## Source repository
|
||||||
|
|
||||||
GNOME Podcasts's main source repository is at gitlab.gnome.org. You can view
|
Hammond's main source repository is at gitlab.gnome.org. You can view
|
||||||
the web interface [here](https://gitlab.gnome.org/World/podcasts)
|
the web interface [here](https://gitlab.gnome.org/alatiera/hammond)
|
||||||
|
|
||||||
Development happens in the master branch.
|
Development happens in the master branch.
|
||||||
|
|
||||||
@@ -50,8 +50,8 @@ In order to run the test suite use the following: `cargo test -- --test-threads=
|
|||||||
|
|
||||||
# Issues, issues and more issues!
|
# Issues, issues and more issues!
|
||||||
|
|
||||||
There are many ways you can contribute to GNOME Podcasts, and all of them involve creating issues
|
There are many ways you can contribute to Hammond, and all of them involve creating issues
|
||||||
in [GNOME Podcasts issue tracker](https://gitlab.gnome.org/World/podcasts/issues). This is the entry point for your contribution.
|
in [Hammond issue tracker](https://gitlab.gnome.org/alatiera/Hammond/issues). This is the entry point for your contribution.
|
||||||
|
|
||||||
To create an effective and high quality ticket, try to put the following information on your
|
To create an effective and high quality ticket, try to put the following information on your
|
||||||
ticket:
|
ticket:
|
||||||
@@ -74,7 +74,7 @@ If it's an issue, add the steps to reproduce like this:
|
|||||||
|
|
||||||
Steps to reproduce:
|
Steps to reproduce:
|
||||||
|
|
||||||
1. Open GNOME Podcasts
|
1. Open Hammond
|
||||||
2. Do an Action
|
2. Do an Action
|
||||||
3. ...
|
3. ...
|
||||||
|
|
||||||
|
|||||||
Generated
+640
-1139
File diff suppressed because it is too large
Load Diff
+4
-3
@@ -1,9 +1,10 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"podcasts-data",
|
"hammond-data",
|
||||||
"podcasts-downloader",
|
"hammond-downloader",
|
||||||
"podcasts-gtk"
|
"hammond-gtk"
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = false
|
debug = false
|
||||||
|
|
||||||
|
|||||||
@@ -631,7 +631,7 @@ to attach them to the start of each source file to most effectively
|
|||||||
state the exclusion of warranty; and each file should have at least
|
state the exclusion of warranty; and each file should have at least
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
GNOME Podcasts
|
Hammond
|
||||||
Copyright (C) 2017 Jordan Petridis
|
Copyright (C) 2017 Jordan Petridis
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|||||||
If the program does terminal interaction, make it output a short
|
If the program does terminal interaction, make it output a short
|
||||||
notice like this when it starts in an interactive mode:
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
GNOME Podcasts Copyright (C) 2017 Jordan Petridis
|
Hammond Copyright (C) 2017 Jordan Petridis
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
|||||||
@@ -1,28 +1,33 @@
|
|||||||
# GNOME Podcasts
|
# Hammond
|
||||||
|
|
||||||
### A Podcast application for GNOME.
|
## A Podcast Client for the GNOME Desktop written in Rust.
|
||||||
Listen to your favorite podcasts, right from your desktop.
|
|
||||||
|
|
||||||

|
[](https://gitlab.gnome.org/alatiera/Hammond/commits/master)
|
||||||
|
[](https://dependencyci.com/github/alatiera/Hammond)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* TBA
|
||||||
|
|
||||||
|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
GNOME Podcasts can be built and run with [Gnome Builder](https://wiki.gnome.org/Apps/Builder) >= 3.28.
|
Hammond can be built and run with [Gnome Builder](https://wiki.gnome.org/Apps/Builder) >= 3.28.
|
||||||
|
|
||||||
Get Builder [here](https://wiki.gnome.org/Apps/Builder/Downloads)
|
Get Builder [here](https://wiki.gnome.org/Apps/Builder/Downloads)
|
||||||
|
|
||||||
## Broken Feeds
|
## Broken Feeds
|
||||||
|
|
||||||
Found a feed that does not work in GNOME Podcasts?
|
Found a feed that does not work in Hammond?
|
||||||
Please [open an issue](https://gitlab.gnome.org/World/podcasts/issues/new) and choose the `BrokenFeed` template so we will know and fix it!
|
Please [open an issue](https://gitlab.gnome.org/alatiera/Hammond/issues/new) and choose the `BrokenFeed` template so we will know and fix it!
|
||||||
|
|
||||||
## Getting in Touch
|
## Getting in Touch
|
||||||
|
|
||||||
If you have any questions regarding the use or development of GNOME Podcasts,
|
If you have any questions regarding the use or development of Hammond,
|
||||||
want to discuss design or simply hang out, please join us in `#hammond` on
|
want to discuss design or simply hang out, please join us in [#hammond on irc.gnome.org.](irc://irc.gnome.org/#hammond)
|
||||||
[irc.gnome.org.][irc] or [matrix][matrix].
|
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
|
||||||
@@ -32,11 +37,11 @@ There isn't much documentation yet, so you will probably have question about par
|
|||||||
|
|
||||||
### Flatpak
|
### Flatpak
|
||||||
|
|
||||||
Flatpak is the reccomended way of building and installing GNOME Podcasts.
|
Flatpak is the reccomended way of building and installing Hammond.
|
||||||
|
|
||||||
#### Building a Flatpak
|
#### Building a Flatpak
|
||||||
|
|
||||||
Download the `org.gnome.Podcasts.json` flatpak manifest from this repo.
|
Download the `org.gnome.Hammond.json` flatpak manifest from this repo.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Add flathub repo
|
# Add flathub repo
|
||||||
@@ -47,31 +52,27 @@ flatpak --user remote-add gnome-nightly --if-not-exists https://sdk.gnome.org/gn
|
|||||||
flatpak --user install gnome-nightly org.gnome.Sdk org.gnome.Platform
|
flatpak --user install gnome-nightly org.gnome.Sdk org.gnome.Platform
|
||||||
# Install the required rust-stable extension from flathub
|
# Install the required rust-stable extension from flathub
|
||||||
flatpak --user install flathub org.freedesktop.Sdk.Extension.rust-stable
|
flatpak --user install flathub org.freedesktop.Sdk.Extension.rust-stable
|
||||||
flatpak-builder --user --repo=repo podcasts org.gnome.Podcasts.json --force-clean
|
flatpak-builder --user --repo=repo hammond org.gnome.Hammond.json --force-clean
|
||||||
```
|
flatpak build-bundle repo hammond org.gnome.Hammond
|
||||||
|
|
||||||
To install the resulting flatpak you can do:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
flatpak build-bundle repo gnome-podcasts.flatpak org.gnome.Podcasts
|
|
||||||
flatpak install --user --bundle gnome-podcasts.flatpak
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Building from soure
|
### Building from soure
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://gitlab.gnome.org/World/podcasts.git
|
git clone https://gitlab.gnome.org/alatiera/hammond.git
|
||||||
cd gnome-podcasts/
|
cd hammond/
|
||||||
meson --prefix=/usr build
|
./configure --prefix=/usr/local
|
||||||
ninja -C build
|
make && sudo make install
|
||||||
sudo ninja -C build install
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Additional:**
|
||||||
|
|
||||||
|
You can run `sudo make uninstall` for removal
|
||||||
|
|
||||||
#### Dependencies
|
#### Dependencies
|
||||||
|
|
||||||
* Rust stable 1.27 or later along with cargo.
|
* Rust stable 1.22 or later along with cargo.
|
||||||
* Gtk+ 3.22 or later
|
* Gtk+ 3.22 or later
|
||||||
* Gstreamer 1.12 or later
|
|
||||||
* Meson
|
* Meson
|
||||||
* A network connection
|
* A network connection
|
||||||
|
|
||||||
@@ -80,23 +81,15 @@ Offline build are possible too, but [`cargo-vendor`][vendor] would have to be se
|
|||||||
**Debian/Ubuntu**
|
**Debian/Ubuntu**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
apt-get install -yqq cargo rustc libsqlite3-dev libssl-dev libgtk-3-dev meson \
|
apt-get update -yqq
|
||||||
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
|
apt-get install -yqq --no-install-recommends build-essential
|
||||||
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
|
apt-get install -yqq --no-install-recommends rustc cargo libgtk-3-dev meson
|
||||||
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
|
|
||||||
gstreamer1.0-libav libgstrtspserver-1.0-dev ibgstreamer-plugins-bad1.0-dev
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Fedora**
|
**Fedora**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dnf install -y rust cargo gtk3-devel glib2-devel openssl-devel sqlite-devel meson \
|
dnf install -y rust cargo gtk3-devel glib2-devel openssl-devel sqlite-devel meson
|
||||||
gstreamer1-devel gstreamer1-plugins-base-tools gstreamer1-devel-docs \
|
|
||||||
gstreamer1-plugins-base-devel gstreamer1-plugins-base-devel-docs \
|
|
||||||
gstreamer1-plugins-good gstreamer1-plugins-good-extras \
|
|
||||||
gstreamer1-plugins-bad-free gstreamer1-plugins-bad-free-devel \
|
|
||||||
gstreamer1-plugins-bad-free-extras
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If you happen to build it on other distributions please let me know the names
|
If you happen to build it on other distributions please let me know the names
|
||||||
@@ -108,11 +101,11 @@ There alot of thins yet to be done.
|
|||||||
|
|
||||||
If you want to contribute, please check the [Contributions Guidelines][contribution-guidelines].
|
If you want to contribute, please check the [Contributions Guidelines][contribution-guidelines].
|
||||||
|
|
||||||
You can start by taking a look at [Issues](https://gitlab.gnome.org/World/podcasts/issues) or by opening a [New issue](https://gitlab.gnome.org/World/podcasts/issues/new?issue%5Bassignee_id%5D=&issue%5Bmilestone_id%5D=).
|
You can start by taking a look at [Issues](https://gitlab.gnome.org/alatiera/Hammond/issues) or by opening a [New issue](https://gitlab.gnome.org/alatiera/Hammond/issues/new?issue%5Bassignee_id%5D=&issue%5Bmilestone_id%5D=).
|
||||||
|
|
||||||
There are also some minor tasks tagged with `TODO:` and `FIXME:` in the source code.
|
There are also some minor tasks tagged with `TODO:` and `FIXME:` in the source code.
|
||||||
|
|
||||||
[contribution-guidelines]: https://gitlab.gnome.org/World/podcasts/blob/master/CONTRIBUTING.md
|
[contribution-guidelines]: https://gitlab.gnome.org/alatiera/Hammond/blob/master/CONTRIBUTING.md
|
||||||
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
@@ -120,35 +113,34 @@ There are also some minor tasks tagged with `TODO:` and `FIXME:` in the source c
|
|||||||
```sh
|
```sh
|
||||||
$ tree -d
|
$ tree -d
|
||||||
├── screenshots # png's used in the README.md
|
├── screenshots # png's used in the README.md
|
||||||
├── podcasts-data # Storate related stuff, SQLite, XDG setup, RSS Parser.
|
├── hammond-data # Storate related stuff, SQLite, XDG setup, RSS Parser.
|
||||||
│ ├── migrations # Diesel SQL migrations.
|
│ ├── migrations # Diesel SQL migrations.
|
||||||
│ │ └── ...
|
│ │ └── ...
|
||||||
│ ├── src
|
│ ├── src
|
||||||
│ └── tests
|
│ └── tests
|
||||||
│ └── feeds # Raw RSS Feeds used for tests.
|
│ └── feeds # Raw RSS Feeds used for tests.
|
||||||
├── podcasts-downloader # Really basic, Really crappy downloader.
|
├── hammond-downloader # Really basic, Really crappy downloader.
|
||||||
│ └── src
|
│ └── src
|
||||||
├── podcasts-gtk # The Gtk+ Client
|
├── hammond-gtk # The Gtk+ Client
|
||||||
│ ├── resources # GResources folder
|
│ ├── resources # GResources folder
|
||||||
│ │ └── gtk # Contains the glade.ui files.
|
│ │ └── gtk # Contains the glade.ui files.
|
||||||
│ └── src
|
│ └── src
|
||||||
│ ├── stacks # Contains the gtk Stacks that hold all the different views.
|
│ ├── views # Contains the Empty, Episodes and Shows view.
|
||||||
│ └── widgets # Contains custom widgets such as Show and Episode.
|
│ └── widgets # Contains custom widgets such as Show and Episode.
|
||||||
```
|
```
|
||||||
|
|
||||||
## A note about the project's name
|
## A note about the project's name
|
||||||
|
|
||||||
The project used to be called Hammond, after Allan Moore's character [Evey Hammond](https://en.wikipedia.org/wiki/Evey_Hammond) from the graphic novel V for Vendetta.
|
The project was named after Allan Moore's character [Evey Hammond](https://en.wikipedia.org/wiki/Evey_Hammond) from the graphic novel V for Vendetta.
|
||||||
It was renamed to GNOME Podcasts on 2018/07/24 shortly before its first public release.
|
|
||||||
|
It has nothing to do with the horrible headlines on the news.
|
||||||
|
|
||||||
## Acknowledgments
|
## Acknowledgments
|
||||||
|
|
||||||
GNOME Podcasts's design is heavily insired by [GNOME Music](https://wiki.gnome.org/Design/Apps/Music) and [Vocal](http://vocalproject.net/).
|
Hammond's design is heavily insired by [GNOME Music](https://wiki.gnome.org/Design/Apps/Music) and [Vocal](http://vocalproject.net/).
|
||||||
|
|
||||||
We also copied some elements from [GNOME News](https://wiki.gnome.org/Design/Apps/Potential/News).
|
We also copied some elements from [GNOME News](https://wiki.gnome.org/Design/Apps/Potential/News).
|
||||||
|
|
||||||
And almost the entirety of the build system is copied from the [Fractal](https://gitlab.gnome.org/danigm/fractal) project.
|
And almost the entirety of the build system is copied from the [Fractal](https://gitlab.gnome.org/danigm/fractal) project.
|
||||||
|
|
||||||
[vendor]: https://github.com/alexcrichton/cargo-vendor
|
[vendor]: https://github.com/alexcrichton/cargo-vendor
|
||||||
[irc]: irc://irc.gnome.org/#hammond
|
|
||||||
[matrix]: https://matrix.to/#/#gnome-podcasts:matrix.org
|
|
||||||
@@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
## Priorities
|
## Priorities
|
||||||
|
|
||||||
|
- [ ] Unplayed Only and Downloaded only view.
|
||||||
- [ ] OPML import/export // Probably need to create a crate.
|
- [ ] OPML import/export // Probably need to create a crate.
|
||||||
|
|
||||||
## Second
|
## Second
|
||||||
|
|
||||||
- [ ] Make use of file metadas?, [This](https://github.com/GuillaumeGomez/audio-video-metadata) might be helpfull.
|
- [ ] Make use of file metadas, [This](https://github.com/GuillaumeGomez/audio-video-metadata) might be helpfull.
|
||||||
- [ ] Episode queue
|
- [ ] Episode queue
|
||||||
- [ ] Embedded player
|
- [ ] Embedded player
|
||||||
- [ ] MPRIS integration
|
- [ ] MPRIS integration
|
||||||
@@ -18,8 +19,14 @@
|
|||||||
|
|
||||||
- [ ] Download Queue
|
- [ ] Download Queue
|
||||||
- [ ] Ability to Stream content on demand
|
- [ ] Ability to Stream content on demand
|
||||||
- [ ] rss feeds from soundcloud urls? // [This](http://getrssfeed.com) seems intresting.
|
- [ ] soundcloud and itunes feeds // [This](http://getrssfeed.com) seems intresting.
|
||||||
- [ ] Integrate with Itunes API for various crap?
|
- [ ] Integrate with Itunes API for various crap?
|
||||||
- [ ] YoutubeFeeds?
|
- [ ] YoutubeFeeds?
|
||||||
|
|
||||||
## Rest Tasks
|
## Rest Tasks
|
||||||
|
|
||||||
|
**Would be nice:**
|
||||||
|
|
||||||
|
- [ ] Make Podcast cover fetchng and loading not block the execution of the program at startup.
|
||||||
|
- [ ] Lazy evaluate episode loading based on the show_widget's scrolling.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,186 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Adapted from:
|
||||||
|
# https://gitlab.gnome.org/danigm/libgepub/blob/27f0d374e0c8f6fa972dbd111d4ce0c0f3096914/configure_meson
|
||||||
|
|
||||||
|
# configure script adapter for Meson
|
||||||
|
# Based on build-api: https://github.com/cgwalters/build-api
|
||||||
|
# Copyright 2010, 2011, 2013 Colin Walters <walters@verbum.org>
|
||||||
|
# Copyright 2016, 2017 Emmanuele Bassi
|
||||||
|
# Copyright 2017 Iñigo Martínez <inigomartinez@gmail.com>
|
||||||
|
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
|
# Build API variables:
|
||||||
|
|
||||||
|
# Little helper function for reading args from the commandline.
|
||||||
|
# it automatically handles -a b and -a=b variants, and returns 1 if
|
||||||
|
# we need to shift $3.
|
||||||
|
read_arg() {
|
||||||
|
# $1 = arg name
|
||||||
|
# $2 = arg value
|
||||||
|
# $3 = arg parameter
|
||||||
|
local rematch='^[^=]*=(.*)$'
|
||||||
|
if [[ $2 =~ $rematch ]]; then
|
||||||
|
read "$1" <<< "${BASH_REMATCH[1]}"
|
||||||
|
else
|
||||||
|
read "$1" <<< "$3"
|
||||||
|
# There is no way to shift our callers args, so
|
||||||
|
# return 1 to indicate they should do it instead.
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
sanitycheck() {
|
||||||
|
# $1 = arg name
|
||||||
|
# $1 = arg command
|
||||||
|
# $2 = arg alternates
|
||||||
|
local cmd=$( which $2 2>/dev/null )
|
||||||
|
|
||||||
|
if [ -x "$cmd" ]; then
|
||||||
|
read "$1" <<< "$cmd"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
test -z $3 || {
|
||||||
|
for alt in $3; do
|
||||||
|
cmd=$( which $alt 2>/dev/null )
|
||||||
|
|
||||||
|
if [ -x "$cmd" ]; then
|
||||||
|
read "$1" <<< "$cmd"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
echo -e "\e[1;31mERROR\e[0m: Command '$2' not found"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
checkoption() {
|
||||||
|
# $1 = arg
|
||||||
|
option="${1#*--}"
|
||||||
|
action="${option%%-*}"
|
||||||
|
name="${option#*-}"
|
||||||
|
if [ ${default_options[$name]+_} ]; then
|
||||||
|
case "$action" in
|
||||||
|
enable) meson_options[$name]=true;;
|
||||||
|
disable) meson_options[$name]=false;;
|
||||||
|
*) echo -e "\e[1;33mINFO\e[0m: Ignoring unknown action '$action'";;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo -e "\e[1;33mINFO\e[0m: Ignoring unknown option '$option'"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echooption() {
|
||||||
|
# $1 = option
|
||||||
|
if [ ${meson_options[$1]+_} ]; then
|
||||||
|
echo ${meson_options[$1]}
|
||||||
|
elif [ ${default_options[$1]+_} ]; then
|
||||||
|
echo ${default_options[$1]}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
sanitycheck MESON 'meson'
|
||||||
|
sanitycheck MESONTEST 'mesontest'
|
||||||
|
sanitycheck NINJA 'ninja' 'ninja-build'
|
||||||
|
|
||||||
|
declare -A meson_options
|
||||||
|
|
||||||
|
while (($# > 0)); do
|
||||||
|
case "${1%%=*}" in
|
||||||
|
--prefix) read_arg prefix "$@" || shift;;
|
||||||
|
--bindir) read_arg bindir "$@" || shift;;
|
||||||
|
--sbindir) read_arg sbindir "$@" || shift;;
|
||||||
|
--libexecdir) read_arg libexecdir "$@" || shift;;
|
||||||
|
--datarootdir) read_arg datarootdir "$@" || shift;;
|
||||||
|
--datadir) read_arg datadir "$@" || shift;;
|
||||||
|
--sysconfdir) read_arg sysconfdir "$@" || shift;;
|
||||||
|
--libdir) read_arg libdir "$@" || shift;;
|
||||||
|
--mandir) read_arg mandir "$@" || shift;;
|
||||||
|
--includedir) read_arg includedir "$@" || shift;;
|
||||||
|
*) checkoption $1;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# Defaults
|
||||||
|
test -z ${prefix} && prefix="/usr/local"
|
||||||
|
test -z ${bindir} && bindir=${prefix}/bin
|
||||||
|
test -z ${sbindir} && sbindir=${prefix}/sbin
|
||||||
|
test -z ${libexecdir} && libexecdir=${prefix}/bin
|
||||||
|
test -z ${datarootdir} && datarootdir=${prefix}/share
|
||||||
|
test -z ${datadir} && datadir=${datarootdir}
|
||||||
|
test -z ${sysconfdir} && sysconfdir=${prefix}/etc
|
||||||
|
test -z ${libdir} && libdir=${prefix}/lib
|
||||||
|
test -z ${mandir} && mandir=${prefix}/share/man
|
||||||
|
test -z ${includedir} && includedir=${prefix}/include
|
||||||
|
|
||||||
|
# The source directory is the location of this file
|
||||||
|
srcdir=$(dirname $0)
|
||||||
|
|
||||||
|
# The build directory is the current location
|
||||||
|
builddir=`pwd`
|
||||||
|
|
||||||
|
# If we're calling this file from the source directory then
|
||||||
|
# we automatically create a build directory and ensure that
|
||||||
|
# both Meson and Ninja invocations are relative to that
|
||||||
|
# location
|
||||||
|
if [[ -f "${builddir}/meson.build" ]]; then
|
||||||
|
mkdir -p _build
|
||||||
|
builddir="${builddir}/_build"
|
||||||
|
NINJA_OPT="-C ${builddir}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Wrapper Makefile for Ninja
|
||||||
|
cat > Makefile <<END
|
||||||
|
# Generated by configure; do not edit
|
||||||
|
|
||||||
|
all: rebuild
|
||||||
|
${NINJA} ${NINJA_OPT}
|
||||||
|
|
||||||
|
rebuild:
|
||||||
|
rm -f ${builddir}/hammond
|
||||||
|
|
||||||
|
install:
|
||||||
|
DESTDIR="\$(DESTDIR)" ${NINJA} ${NINJA_OPT} install
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
${NINJA} ${NINJA_OPT} uninstall
|
||||||
|
|
||||||
|
release:
|
||||||
|
${NINJA} ${NINJA_OPT} release
|
||||||
|
|
||||||
|
check:
|
||||||
|
${MESONTEST} ${NINJA_OPT}
|
||||||
|
END
|
||||||
|
|
||||||
|
echo "
|
||||||
|
|
||||||
|
hammond
|
||||||
|
=======
|
||||||
|
|
||||||
|
meson: ${MESON}
|
||||||
|
ninja: ${NINJA}
|
||||||
|
prefix: ${prefix}
|
||||||
|
|
||||||
|
Now type 'make' to build
|
||||||
|
"
|
||||||
|
|
||||||
|
cmd_options=""
|
||||||
|
for key in "${!meson_options[@]}"; do
|
||||||
|
cmd_options="$cmd_options -Denable-$key=${meson_options[$key]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
exec ${MESON} \
|
||||||
|
--prefix=${prefix} \
|
||||||
|
--libdir=${libdir} \
|
||||||
|
--libexecdir=${libexecdir} \
|
||||||
|
--datadir=${datadir} \
|
||||||
|
--sysconfdir=${sysconfdir} \
|
||||||
|
--bindir=${bindir} \
|
||||||
|
--includedir=${includedir} \
|
||||||
|
--mandir=${mandir} \
|
||||||
|
${cmd_options} \
|
||||||
|
${builddir} \
|
||||||
|
${srcdir}
|
||||||
@@ -1,25 +1,24 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||||
name = "podcasts-data"
|
name = "hammond-data"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
workspace = "../"
|
workspace = "../"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ammonia = "1.2.0"
|
ammonia = "1.1.0"
|
||||||
chrono = "0.4.4"
|
chrono = "0.4.1"
|
||||||
derive_builder = "0.5.1"
|
derive_builder = "0.5.1"
|
||||||
lazy_static = "1.0.2"
|
itertools = "0.7.8"
|
||||||
log = "0.4.3"
|
lazy_static = "1.0.0"
|
||||||
rayon = "1.0.2"
|
log = "0.4.1"
|
||||||
rayon-futures = "0.1.0"
|
rayon = "1.0.1"
|
||||||
rfc822_sanitizer = "0.3.3"
|
rfc822_sanitizer = "0.3.3"
|
||||||
rss = "1.5.0"
|
rss = "1.4.0"
|
||||||
url = "1.7.1"
|
url = "1.7.0"
|
||||||
xdg = "2.1.0"
|
xdg = "2.1.0"
|
||||||
xml-rs = "0.8.0"
|
futures = "0.1.21"
|
||||||
futures = "0.1.23"
|
hyper = "0.11.24"
|
||||||
hyper = "0.11.27"
|
tokio-core = "0.1.16"
|
||||||
tokio-core = "0.1.17"
|
|
||||||
hyper-tls = "0.1.3"
|
hyper-tls = "0.1.3"
|
||||||
native-tls = "0.1.5"
|
native-tls = "0.1.5"
|
||||||
num_cpus = "1.8.0"
|
num_cpus = "1.8.0"
|
||||||
@@ -28,18 +27,17 @@ failure_derive = "0.1.1"
|
|||||||
|
|
||||||
[dependencies.diesel]
|
[dependencies.diesel]
|
||||||
features = ["sqlite", "r2d2"]
|
features = ["sqlite", "r2d2"]
|
||||||
version = "1.3.2"
|
version = "1.1.1"
|
||||||
|
|
||||||
[dependencies.diesel_migrations]
|
[dependencies.diesel_migrations]
|
||||||
features = ["sqlite"]
|
features = ["sqlite"]
|
||||||
version = "1.3.0"
|
version = "1.1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.5.4"
|
rand = "0.4.2"
|
||||||
tempdir = "0.3.7"
|
tempdir = "0.3.7"
|
||||||
criterion = "0.2.4"
|
criterion = "0.2.2"
|
||||||
pretty_assertions = "0.5.1"
|
pretty_assertions = "0.5.1"
|
||||||
maplit = "1.0.1"
|
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "bench"
|
name = "bench"
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
#![allow(unused)]
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate criterion;
|
extern crate criterion;
|
||||||
use criterion::Criterion;
|
use criterion::Criterion;
|
||||||
|
|
||||||
// extern crate futures;
|
// extern crate futures;
|
||||||
|
extern crate hammond_data;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate hyper_tls;
|
extern crate hyper_tls;
|
||||||
extern crate podcasts_data;
|
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate tokio_core;
|
extern crate tokio_core;
|
||||||
// extern crate rayon;
|
// extern crate rayon;
|
||||||
@@ -18,11 +16,11 @@ extern crate rss;
|
|||||||
// use futures::future::*;
|
// use futures::future::*;
|
||||||
use tokio_core::reactor::Core;
|
use tokio_core::reactor::Core;
|
||||||
|
|
||||||
use podcasts_data::database::truncate_db;
|
use hammond_data::FeedBuilder;
|
||||||
use podcasts_data::pipeline;
|
use hammond_data::Source;
|
||||||
use podcasts_data::FeedBuilder;
|
use hammond_data::database::truncate_db;
|
||||||
use podcasts_data::Source;
|
use hammond_data::pipeline;
|
||||||
// use podcasts_data::errors::*;
|
// use hammond_data::errors::*;
|
||||||
|
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
|
||||||
@@ -58,6 +56,22 @@ static FEEDS: &[(&[u8], &str)] = &[
|
|||||||
(STARS, STARS_URL),
|
(STARS, STARS_URL),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// This is broken and I don't know why.
|
||||||
|
fn bench_pipeline(c: &mut Criterion) {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
FEEDS.iter().for_each(|&(_, url)| {
|
||||||
|
Source::from_url(url).unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
|
c.bench_function("pipline", move |b| {
|
||||||
|
b.iter(|| {
|
||||||
|
let sources = hammond_data::dbqueries::get_sources().unwrap();
|
||||||
|
pipeline::run(sources, true).unwrap();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
truncate_db().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn bench_index_large_feed(c: &mut Criterion) {
|
fn bench_index_large_feed(c: &mut Criterion) {
|
||||||
truncate_db().unwrap();
|
truncate_db().unwrap();
|
||||||
let url = "https://www.greaterthancode.com/feed/podcast";
|
let url = "https://www.greaterthancode.com/feed/podcast";
|
||||||
@@ -100,5 +114,10 @@ fn bench_index_small_feed(c: &mut Criterion) {
|
|||||||
truncate_db().unwrap();
|
truncate_db().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, bench_index_large_feed, bench_index_small_feed);
|
criterion_group!(
|
||||||
|
benches,
|
||||||
|
bench_pipeline,
|
||||||
|
bench_index_large_feed,
|
||||||
|
bench_index_small_feed
|
||||||
|
);
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
//! Database Setup. This is only public to help with some unit tests.
|
//! Database Setup. This is only public to help with some unit tests.
|
||||||
// Diesel embed_migrations! triggers the lint
|
|
||||||
#![allow(unused_imports)]
|
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel::r2d2;
|
use diesel::r2d2;
|
||||||
@@ -24,9 +22,7 @@ lazy_static! {
|
|||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref DB_PATH: PathBuf = xdg_dirs::PODCASTS_XDG
|
static ref DB_PATH: PathBuf = xdg_dirs::HAMMOND_XDG.place_data_file("hammond.db").unwrap();
|
||||||
.place_data_file("podcasts.db")
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -34,8 +30,8 @@ extern crate tempdir;
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TEMPDIR: tempdir::TempDir = { tempdir::TempDir::new("podcasts_unit_test").unwrap() };
|
static ref TEMPDIR: tempdir::TempDir = { tempdir::TempDir::new("hammond_unit_test").unwrap() };
|
||||||
static ref DB_PATH: PathBuf = TEMPDIR.path().join("podcasts.db");
|
static ref DB_PATH: PathBuf = TEMPDIR.path().join("hammond.db");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an r2d2 `SqliteConnection`.
|
/// Get an r2d2 `SqliteConnection`.
|
||||||
@@ -70,8 +66,8 @@ fn run_migration_on(connection: &SqliteConnection) -> Result<(), DataError> {
|
|||||||
pub fn truncate_db() -> Result<(), DataError> {
|
pub fn truncate_db() -> Result<(), DataError> {
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
con.execute("DELETE FROM episodes")?;
|
con.execute("DELETE FROM episode")?;
|
||||||
con.execute("DELETE FROM shows")?;
|
con.execute("DELETE FROM podcast")?;
|
||||||
con.execute("DELETE FROM source")?;
|
con.execute("DELETE FROM source")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@ use diesel::prelude::*;
|
|||||||
|
|
||||||
use diesel;
|
use diesel;
|
||||||
use diesel::dsl::exists;
|
use diesel::dsl::exists;
|
||||||
use diesel::query_builder::AsQuery;
|
|
||||||
use diesel::select;
|
use diesel::select;
|
||||||
|
|
||||||
use database::connection;
|
use database::connection;
|
||||||
@@ -23,106 +22,92 @@ pub fn get_sources() -> Result<Vec<Source>, DataError> {
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_podcasts() -> Result<Vec<Show>, DataError> {
|
pub fn get_podcasts() -> Result<Vec<Podcast>, DataError> {
|
||||||
use schema::shows::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
shows
|
podcast
|
||||||
.order(title.asc())
|
.order(title.asc())
|
||||||
.load::<Show>(&con)
|
.load::<Podcast>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Show>, DataError> {
|
pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Podcast>, DataError> {
|
||||||
use schema::shows::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
shows
|
podcast
|
||||||
.order(title.asc())
|
.order(title.asc())
|
||||||
.filter(id.ne_all(filter_ids))
|
.filter(id.ne_any(filter_ids))
|
||||||
.load::<Show>(&con)
|
.load::<Podcast>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_episodes() -> Result<Vec<Episode>, DataError> {
|
pub fn get_episodes() -> Result<Vec<Episode>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
episodes
|
episode
|
||||||
.order(epoch.desc())
|
.order(epoch.desc())
|
||||||
.load::<Episode>(&con)
|
.load::<Episode>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_downloaded_episodes() -> Result<Vec<EpisodeCleanerModel>, DataError> {
|
pub(crate) fn get_downloaded_episodes() -> Result<Vec<EpisodeCleanerQuery>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
episodes
|
episode
|
||||||
.select((rowid, local_uri, played))
|
.select((rowid, local_uri, played))
|
||||||
.filter(local_uri.is_not_null())
|
.filter(local_uri.is_not_null())
|
||||||
.load::<EpisodeCleanerModel>(&con)
|
.load::<EpisodeCleanerQuery>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub(crate) fn get_played_episodes() -> Result<Vec<Episode>, DataError> {
|
// pub(crate) fn get_played_episodes() -> Result<Vec<Episode>, DataError> {
|
||||||
// use schema::episodes::dsl::*;
|
// use schema::episode::dsl::*;
|
||||||
|
|
||||||
// let db = connection();
|
// let db = connection();
|
||||||
// let con = db.get()?;
|
// let con = db.get()?;
|
||||||
// episodes
|
// episode
|
||||||
// .filter(played.is_not_null())
|
// .filter(played.is_not_null())
|
||||||
// .load::<Episode>(&con)
|
// .load::<Episode>(&con)
|
||||||
// .map_err(From::from)
|
// .map_err(From::from)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub(crate) fn get_played_cleaner_episodes() -> Result<Vec<EpisodeCleanerModel>, DataError> {
|
pub(crate) fn get_played_cleaner_episodes() -> Result<Vec<EpisodeCleanerQuery>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
episodes
|
episode
|
||||||
.select((rowid, local_uri, played))
|
.select((rowid, local_uri, played))
|
||||||
.filter(played.is_not_null())
|
.filter(played.is_not_null())
|
||||||
.load::<EpisodeCleanerModel>(&con)
|
.load::<EpisodeCleanerQuery>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_episode_from_rowid(ep_id: i32) -> Result<Episode, DataError> {
|
pub fn get_episode_from_rowid(ep_id: i32) -> Result<Episode, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
episodes
|
episode
|
||||||
.filter(rowid.eq(ep_id))
|
.filter(rowid.eq(ep_id))
|
||||||
.get_result::<Episode>(&con)
|
.get_result::<Episode>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_episode_widget_from_rowid(ep_id: i32) -> Result<EpisodeWidgetModel, DataError> {
|
|
||||||
use schema::episodes::dsl::*;
|
|
||||||
let db = connection();
|
|
||||||
let con = db.get()?;
|
|
||||||
|
|
||||||
episodes
|
|
||||||
.select((
|
|
||||||
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
|
|
||||||
))
|
|
||||||
.filter(rowid.eq(ep_id))
|
|
||||||
.get_result::<EpisodeWidgetModel>(&con)
|
|
||||||
.map_err(From::from)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result<Option<String>, DataError> {
|
pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result<Option<String>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
episodes
|
episode
|
||||||
.filter(rowid.eq(ep_id))
|
.filter(rowid.eq(ep_id))
|
||||||
.select(local_uri)
|
.select(local_uri)
|
||||||
.get_result::<Option<String>>(&con)
|
.get_result::<Option<String>>(&con)
|
||||||
@@ -132,48 +117,55 @@ pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result<Option<String>, DataE
|
|||||||
pub fn get_episodes_widgets_filter_limit(
|
pub fn get_episodes_widgets_filter_limit(
|
||||||
filter_ids: &[i32],
|
filter_ids: &[i32],
|
||||||
limit: u32,
|
limit: u32,
|
||||||
) -> Result<Vec<EpisodeWidgetModel>, DataError> {
|
) -> Result<Vec<EpisodeWidgetQuery>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
let columns = (
|
|
||||||
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
episodes
|
episode::table
|
||||||
.select(columns)
|
.select((
|
||||||
.order(epoch.desc())
|
episode::rowid,
|
||||||
.filter(show_id.ne_all(filter_ids))
|
episode::title,
|
||||||
|
episode::uri,
|
||||||
|
episode::local_uri,
|
||||||
|
episode::epoch,
|
||||||
|
episode::length,
|
||||||
|
episode::duration,
|
||||||
|
episode::played,
|
||||||
|
episode::podcast_id,
|
||||||
|
))
|
||||||
|
.order(episode::epoch.desc())
|
||||||
|
.filter(episode::podcast_id.ne_any(filter_ids))
|
||||||
.limit(i64::from(limit))
|
.limit(i64::from(limit))
|
||||||
.load::<EpisodeWidgetModel>(&con)
|
.load::<EpisodeWidgetQuery>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_podcast_from_id(pid: i32) -> Result<Show, DataError> {
|
pub fn get_podcast_from_id(pid: i32) -> Result<Podcast, DataError> {
|
||||||
use schema::shows::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
shows
|
podcast
|
||||||
.filter(id.eq(pid))
|
.filter(id.eq(pid))
|
||||||
.get_result::<Show>(&con)
|
.get_result::<Podcast>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_podcast_cover_from_id(pid: i32) -> Result<ShowCoverModel, DataError> {
|
pub fn get_podcast_cover_from_id(pid: i32) -> Result<PodcastCoverQuery, DataError> {
|
||||||
use schema::shows::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
shows
|
podcast
|
||||||
.select((id, title, image_uri))
|
.select((id, title, image_uri))
|
||||||
.filter(id.eq(pid))
|
.filter(id.eq(pid))
|
||||||
.get_result::<ShowCoverModel>(&con)
|
.get_result::<PodcastCoverQuery>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pd_episodes(parent: &Show) -> Result<Vec<Episode>, DataError> {
|
pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
@@ -183,7 +175,7 @@ pub fn get_pd_episodes(parent: &Show) -> Result<Vec<Episode>, DataError> {
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pd_episodes_count(parent: &Show) -> Result<i64, DataError> {
|
pub fn get_pd_episodes_count(parent: &Podcast) -> Result<i64, DataError> {
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
@@ -193,24 +185,21 @@ pub fn get_pd_episodes_count(parent: &Show) -> Result<i64, DataError> {
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pd_episodeswidgets(parent: &Show) -> Result<Vec<EpisodeWidgetModel>, DataError> {
|
pub fn get_pd_episodeswidgets(_parent: &Podcast) -> Result<Vec<EpisodeWidgetQuery>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
let columns = (
|
|
||||||
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
episodes
|
episode.select((rowid, title, uri, local_uri, epoch, length, duration, played, podcast_id))
|
||||||
.select(columns)
|
// .filter(podcast_id.eq(parent.id()))
|
||||||
.filter(show_id.eq(parent.id()))
|
// .group_by(epoch)
|
||||||
.order(epoch.desc())
|
.order(epoch.desc())
|
||||||
.load::<EpisodeWidgetModel>(&con)
|
.load::<EpisodeWidgetQuery>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pd_unplayed_episodes(parent: &Show) -> Result<Vec<Episode>, DataError> {
|
pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
@@ -221,8 +210,8 @@ pub fn get_pd_unplayed_episodes(parent: &Show) -> Result<Vec<Episode>, DataError
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub(crate) fn get_pd_episodes_limit(parent: &Show, limit: u32) ->
|
// pub(crate) fn get_pd_episodes_limit(parent: &Podcast, limit: u32) ->
|
||||||
// Result<Vec<Episode>, DataError> { use schema::episodes::dsl::*;
|
// Result<Vec<Episode>, DataError> { use schema::episode::dsl::*;
|
||||||
|
|
||||||
// let db = connection();
|
// let db = connection();
|
||||||
// let con = db.get()?;
|
// let con = db.get()?;
|
||||||
@@ -256,25 +245,25 @@ pub fn get_source_from_id(id_: i32) -> Result<Source, DataError> {
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_podcast_from_source_id(sid: i32) -> Result<Show, DataError> {
|
pub fn get_podcast_from_source_id(sid: i32) -> Result<Podcast, DataError> {
|
||||||
use schema::shows::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
shows
|
podcast
|
||||||
.filter(source_id.eq(sid))
|
.filter(source_id.eq(sid))
|
||||||
.get_result::<Show>(&con)
|
.get_result::<Podcast>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_episode_from_pk(title_: &str, pid: i32) -> Result<Episode, DataError> {
|
pub fn get_episode_from_pk(title_: &str, pid: i32) -> Result<Episode, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
episodes
|
episode
|
||||||
.filter(title.eq(title_))
|
.filter(title.eq(title_))
|
||||||
.filter(show_id.eq(pid))
|
.filter(podcast_id.eq(pid))
|
||||||
.get_result::<Episode>(&con)
|
.get_result::<Episode>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
@@ -283,19 +272,19 @@ pub(crate) fn get_episode_minimal_from_pk(
|
|||||||
title_: &str,
|
title_: &str,
|
||||||
pid: i32,
|
pid: i32,
|
||||||
) -> Result<EpisodeMinimal, DataError> {
|
) -> Result<EpisodeMinimal, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
episodes
|
episode
|
||||||
.select((rowid, title, uri, epoch, length, duration, guid, show_id))
|
.select((rowid, title, uri, epoch, duration, guid, podcast_id))
|
||||||
.filter(title.eq(title_))
|
.filter(title.eq(title_))
|
||||||
.filter(show_id.eq(pid))
|
.filter(podcast_id.eq(pid))
|
||||||
.get_result::<EpisodeMinimal>(&con)
|
.get_result::<EpisodeMinimal>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn remove_feed(pd: &Show) -> Result<(), DataError> {
|
pub(crate) fn remove_feed(pd: &Podcast) -> Result<(), DataError> {
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
@@ -314,16 +303,16 @@ fn delete_source(con: &SqliteConnection, source_id: i32) -> QueryResult<usize> {
|
|||||||
diesel::delete(source.filter(id.eq(source_id))).execute(con)
|
diesel::delete(source.filter(id.eq(source_id))).execute(con)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_podcast(con: &SqliteConnection, show_id: i32) -> QueryResult<usize> {
|
fn delete_podcast(con: &SqliteConnection, podcast_id: i32) -> QueryResult<usize> {
|
||||||
use schema::shows::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
|
|
||||||
diesel::delete(shows.filter(id.eq(show_id))).execute(con)
|
diesel::delete(podcast.filter(id.eq(podcast_id))).execute(con)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_podcast_episodes(con: &SqliteConnection, parent_id: i32) -> QueryResult<usize> {
|
fn delete_podcast_episodes(con: &SqliteConnection, parent_id: i32) -> QueryResult<usize> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
diesel::delete(episodes.filter(show_id.eq(parent_id))).execute(con)
|
diesel::delete(episode.filter(podcast_id.eq(parent_id))).execute(con)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn source_exists(url: &str) -> Result<bool, DataError> {
|
pub fn source_exists(url: &str) -> Result<bool, DataError> {
|
||||||
@@ -338,70 +327,42 @@ pub fn source_exists(url: &str) -> Result<bool, DataError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn podcast_exists(source_id_: i32) -> Result<bool, DataError> {
|
pub(crate) fn podcast_exists(source_id_: i32) -> Result<bool, DataError> {
|
||||||
use schema::shows::dsl::*;
|
use schema::podcast::dsl::*;
|
||||||
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
select(exists(shows.filter(source_id.eq(source_id_))))
|
select(exists(podcast.filter(source_id.eq(source_id_))))
|
||||||
.get_result(&con)
|
.get_result(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
pub(crate) fn episode_exists(title_: &str, show_id_: i32) -> Result<bool, DataError> {
|
pub(crate) fn episode_exists(title_: &str, podcast_id_: i32) -> Result<bool, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
select(exists(episodes.filter(show_id.eq(show_id_)).filter(title.eq(title_))))
|
select(exists(episode.filter(podcast_id.eq(podcast_id_)).filter(title.eq(title_))))
|
||||||
.get_result(&con)
|
|
||||||
.map_err(From::from)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if the `episodes table contains any rows
|
|
||||||
///
|
|
||||||
/// Return true if `episodes` table is populated.
|
|
||||||
pub fn is_episodes_populated() -> Result<bool, DataError> {
|
|
||||||
use schema::episodes::dsl::*;
|
|
||||||
|
|
||||||
let db = connection();
|
|
||||||
let con = db.get()?;
|
|
||||||
|
|
||||||
select(exists(episodes.as_query()))
|
|
||||||
.get_result(&con)
|
|
||||||
.map_err(From::from)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if the `shows` table contains any rows
|
|
||||||
///
|
|
||||||
/// Return true if `shows table is populated.
|
|
||||||
pub fn is_podcasts_populated(filter_ids: &[i32]) -> Result<bool, DataError> {
|
|
||||||
use schema::shows::dsl::*;
|
|
||||||
|
|
||||||
let db = connection();
|
|
||||||
let con = db.get()?;
|
|
||||||
|
|
||||||
select(exists(shows.filter(id.ne_all(filter_ids))))
|
|
||||||
.get_result(&con)
|
.get_result(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
|
pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
diesel::insert_into(episodes)
|
diesel::insert_into(episode)
|
||||||
.values(eps)
|
.values(eps)
|
||||||
.execute(&*con)
|
.execute(&*con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_none_to_played_now(parent: &Show) -> Result<usize, DataError> {
|
pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
@@ -418,7 +379,7 @@ pub fn update_none_to_played_now(parent: &Show) -> Result<usize, DataError> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use database::*;
|
use database::*;
|
||||||
use pipeline;
|
use pipeline::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_update_none_to_played_now() {
|
fn test_update_none_to_played_now() {
|
||||||
@@ -428,7 +389,7 @@ mod tests {
|
|||||||
com/InterceptedWithJeremyScahill";
|
com/InterceptedWithJeremyScahill";
|
||||||
let source = Source::from_url(url).unwrap();
|
let source = Source::from_url(url).unwrap();
|
||||||
let id = source.id();
|
let id = source.id();
|
||||||
pipeline::run(vec![source], true).unwrap();
|
index_single_source(source, true).unwrap();
|
||||||
let pd = get_podcast_from_source_id(id).unwrap();
|
let pd = get_podcast_from_source_id(id).unwrap();
|
||||||
|
|
||||||
let eps_num = get_pd_unplayed_episodes(&pd).unwrap().len();
|
let eps_num = get_pd_unplayed_episodes(&pd).unwrap().len();
|
||||||
@@ -5,35 +5,9 @@ use hyper;
|
|||||||
use native_tls;
|
use native_tls;
|
||||||
use rss;
|
use rss;
|
||||||
use url;
|
use url;
|
||||||
use xml;
|
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use models::Source;
|
|
||||||
|
|
||||||
#[fail(
|
|
||||||
display = "Request to {} returned {}. Context: {}",
|
|
||||||
url,
|
|
||||||
status_code,
|
|
||||||
context
|
|
||||||
)]
|
|
||||||
#[derive(Fail, Debug)]
|
|
||||||
pub struct HttpStatusError {
|
|
||||||
url: String,
|
|
||||||
status_code: hyper::StatusCode,
|
|
||||||
context: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HttpStatusError {
|
|
||||||
pub fn new(url: String, code: hyper::StatusCode, context: String) -> Self {
|
|
||||||
HttpStatusError {
|
|
||||||
url,
|
|
||||||
status_code: code,
|
|
||||||
context,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Fail, Debug)]
|
#[derive(Fail, Debug)]
|
||||||
pub enum DataError {
|
pub enum DataError {
|
||||||
#[fail(display = "SQL Query failed: {}", _0)]
|
#[fail(display = "SQL Query failed: {}", _0)]
|
||||||
@@ -55,19 +29,18 @@ pub enum DataError {
|
|||||||
IOError(#[cause] io::Error),
|
IOError(#[cause] io::Error),
|
||||||
#[fail(display = "RSS Error: {}", _0)]
|
#[fail(display = "RSS Error: {}", _0)]
|
||||||
RssError(#[cause] rss::Error),
|
RssError(#[cause] rss::Error),
|
||||||
#[fail(display = "XML Reader Error: {}", _0)]
|
|
||||||
XmlReaderError(#[cause] xml::reader::Error),
|
|
||||||
#[fail(display = "Error: {}", _0)]
|
#[fail(display = "Error: {}", _0)]
|
||||||
Bail(String),
|
Bail(String),
|
||||||
#[fail(display = "{}", _0)]
|
#[fail(display = "Request to {} returned {}. Context: {}", url, status_code, context)]
|
||||||
HttpStatusGeneral(HttpStatusError),
|
HttpStatusError {
|
||||||
#[fail(display = "FIXME: This should be better")]
|
url: String,
|
||||||
F301(Source),
|
status_code: hyper::StatusCode,
|
||||||
#[fail(
|
context: String,
|
||||||
display = "Error occured while Parsing an Episode. Reason: {}",
|
},
|
||||||
reason
|
#[fail(display = "Error occured while Parsing an Episode. Reason: {}", reason)]
|
||||||
)]
|
|
||||||
ParseEpisodeError { reason: String, parent_id: i32 },
|
ParseEpisodeError { reason: String, parent_id: i32 },
|
||||||
|
#[fail(display = "No Futures where produced to be run.")]
|
||||||
|
EmptyFuturesList,
|
||||||
#[fail(display = "Episode was not changed and thus skipped.")]
|
#[fail(display = "Episode was not changed and thus skipped.")]
|
||||||
EpisodeNotChanged,
|
EpisodeNotChanged,
|
||||||
}
|
}
|
||||||
@@ -126,12 +99,6 @@ impl From<rss::Error> for DataError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<xml::reader::Error> for DataError {
|
|
||||||
fn from(err: xml::reader::Error) -> Self {
|
|
||||||
DataError::XmlReaderError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<String> for DataError {
|
impl From<String> for DataError {
|
||||||
fn from(err: String) -> Self {
|
fn from(err: String) -> Self {
|
||||||
DataError::Bail(err)
|
DataError::Bail(err)
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
//! Index Feeds.
|
||||||
|
|
||||||
|
use futures::future::*;
|
||||||
|
use itertools::{Either, Itertools};
|
||||||
|
use rss;
|
||||||
|
|
||||||
|
use dbqueries;
|
||||||
|
use errors::DataError;
|
||||||
|
use models::{Index, IndexState, Update};
|
||||||
|
use models::{NewEpisode, NewPodcast, Podcast};
|
||||||
|
use pipeline::*;
|
||||||
|
|
||||||
|
type InsertUpdate = (Vec<NewEpisode>, Vec<Option<(NewEpisode, i32)>>);
|
||||||
|
|
||||||
|
/// Wrapper struct that hold a `Source` id and the `rss::Channel`
|
||||||
|
/// that corresponds to the `Source.uri` field.
|
||||||
|
#[derive(Debug, Clone, Builder, PartialEq)]
|
||||||
|
#[builder(derive(Debug))]
|
||||||
|
#[builder(setter(into))]
|
||||||
|
pub struct Feed {
|
||||||
|
/// The `rss::Channel` parsed from the `Source` uri.
|
||||||
|
channel: rss::Channel,
|
||||||
|
/// The `Source` id where the xml `rss::Channel` came from.
|
||||||
|
source_id: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Feed {
|
||||||
|
/// Index the contents of the RSS `Feed` into the database.
|
||||||
|
pub fn index(self) -> Box<Future<Item = (), Error = DataError> + Send> {
|
||||||
|
let fut = self.parse_podcast_async()
|
||||||
|
.and_then(|pd| pd.to_podcast())
|
||||||
|
.and_then(move |pd| self.index_channel_items(&pd));
|
||||||
|
|
||||||
|
Box::new(fut)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_podcast(&self) -> NewPodcast {
|
||||||
|
NewPodcast::new(&self.channel, self.source_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_podcast_async(&self) -> Box<Future<Item = NewPodcast, Error = DataError> + Send> {
|
||||||
|
Box::new(ok(self.parse_podcast()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn index_channel_items(
|
||||||
|
&self,
|
||||||
|
pd: &Podcast,
|
||||||
|
) -> Box<Future<Item = (), Error = DataError> + Send> {
|
||||||
|
let fut = self.get_stuff(pd)
|
||||||
|
.and_then(|(insert, update)| {
|
||||||
|
if !insert.is_empty() {
|
||||||
|
info!("Indexing {} episodes.", insert.len());
|
||||||
|
if let Err(err) = dbqueries::index_new_episodes(insert.as_slice()) {
|
||||||
|
error!("Failed batch indexng, Fallign back to individual indexing.");
|
||||||
|
error!("{}", err);
|
||||||
|
insert.iter().for_each(|ep| {
|
||||||
|
if let Err(err) = ep.index() {
|
||||||
|
error!("Failed to index episode: {:?}.", ep.title());
|
||||||
|
error!("{}", err);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok((insert, update))
|
||||||
|
})
|
||||||
|
.map(|(_, update)| {
|
||||||
|
if !update.is_empty() {
|
||||||
|
info!("Updating {} episodes.", update.len());
|
||||||
|
// see get_stuff for more
|
||||||
|
update
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|x| x)
|
||||||
|
.for_each(|(ref ep, rowid)| {
|
||||||
|
if let Err(err) = ep.update(rowid) {
|
||||||
|
error!("Failed to index episode: {:?}.", ep.title());
|
||||||
|
error!("{}", err);
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Box::new(fut)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_stuff(
|
||||||
|
&self,
|
||||||
|
pd: &Podcast,
|
||||||
|
) -> Box<Future<Item = InsertUpdate, Error = DataError> + Send> {
|
||||||
|
let (insert, update): (Vec<_>, Vec<_>) = self.channel
|
||||||
|
.items()
|
||||||
|
.into_iter()
|
||||||
|
.map(|item| glue_async(item, pd.id()))
|
||||||
|
// This is sort of ugly but I think it's cheaper than pushing None
|
||||||
|
// to updated and filtering it out later.
|
||||||
|
// Even though we already map_filter in index_channel_items.
|
||||||
|
// I am not sure what the optimizations are on match vs allocating None.
|
||||||
|
.map(|fut| {
|
||||||
|
fut.and_then(|x| match x {
|
||||||
|
IndexState::NotChanged => Err(DataError::EpisodeNotChanged),
|
||||||
|
_ => Ok(x),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.flat_map(|fut| fut.wait())
|
||||||
|
.partition_map(|state| match state {
|
||||||
|
IndexState::Index(e) => Either::Left(e),
|
||||||
|
IndexState::Update(e) => Either::Right(Some(e)),
|
||||||
|
// This should never occur
|
||||||
|
IndexState::NotChanged => Either::Right(None),
|
||||||
|
});
|
||||||
|
|
||||||
|
Box::new(ok((insert, update)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use rss::Channel;
|
||||||
|
use tokio_core::reactor::Core;
|
||||||
|
|
||||||
|
use Source;
|
||||||
|
use database::truncate_db;
|
||||||
|
use dbqueries;
|
||||||
|
use utils::get_feed;
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
use std::io::BufReader;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
// (path, url) tuples.
|
||||||
|
const URLS: &[(&str, &str)] = {
|
||||||
|
&[
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-Intercepted.xml",
|
||||||
|
"https://web.archive.org/web/20180120083840if_/https://feeds.feedburner.\
|
||||||
|
com/InterceptedWithJeremyScahill",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-LinuxUnplugged.xml",
|
||||||
|
"https://web.archive.org/web/20180120110314if_/https://feeds.feedburner.\
|
||||||
|
com/linuxunplugged",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-TheTipOff.xml",
|
||||||
|
"https://web.archive.org/web/20180120110727if_/https://rss.acast.com/thetipoff",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-StealTheStars.xml",
|
||||||
|
"https://web.archive.org/web/20180120104957if_/https://rss.art19.\
|
||||||
|
com/steal-the-stars",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-GreaterThanCode.xml",
|
||||||
|
"https://web.archive.org/web/20180120104741if_/https://www.greaterthancode.\
|
||||||
|
com/feed/podcast",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_complete_index() {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
|
||||||
|
let feeds: Vec<_> = URLS.iter()
|
||||||
|
.map(|&(path, url)| {
|
||||||
|
// Create and insert a Source into db
|
||||||
|
let s = Source::from_url(url).unwrap();
|
||||||
|
get_feed(path, s.id())
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut core = Core::new().unwrap();
|
||||||
|
// Index the channels
|
||||||
|
let list: Vec<_> = feeds.into_iter().map(|x| x.index()).collect();
|
||||||
|
let _foo = core.run(join_all(list));
|
||||||
|
|
||||||
|
// Assert the index rows equal the controlled results
|
||||||
|
assert_eq!(dbqueries::get_sources().unwrap().len(), 5);
|
||||||
|
assert_eq!(dbqueries::get_podcasts().unwrap().len(), 5);
|
||||||
|
assert_eq!(dbqueries::get_episodes().unwrap().len(), 354);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_feed_parse_podcast() {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
|
||||||
|
let path = "tests/feeds/2018-01-20-Intercepted.xml";
|
||||||
|
let feed = get_feed(path, 42);
|
||||||
|
|
||||||
|
let file = fs::File::open(path).unwrap();
|
||||||
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
|
let pd = NewPodcast::new(&channel, 42);
|
||||||
|
assert_eq!(feed.parse_podcast(), pd);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_feed_index_channel_items() {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
|
||||||
|
let path = "tests/feeds/2018-01-20-Intercepted.xml";
|
||||||
|
let feed = get_feed(path, 42);
|
||||||
|
let pd = feed.parse_podcast().to_podcast().unwrap();
|
||||||
|
|
||||||
|
feed.index_channel_items(&pd).wait().unwrap();
|
||||||
|
assert_eq!(dbqueries::get_podcasts().unwrap().len(), 1);
|
||||||
|
assert_eq!(dbqueries::get_episodes().unwrap().len(), 43);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_feed_get_stuff() {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
|
||||||
|
let path = "tests/feeds/2018-01-20-Intercepted.xml";
|
||||||
|
let feed = get_feed(path, 42);
|
||||||
|
let pd = feed.parse_podcast().to_podcast().unwrap();
|
||||||
|
|
||||||
|
let (insert, update) = feed.get_stuff(&pd).wait().unwrap();
|
||||||
|
assert_eq!(43, insert.len());
|
||||||
|
assert_eq!(0, update.len());
|
||||||
|
|
||||||
|
feed.index().wait().unwrap();
|
||||||
|
|
||||||
|
let path = "tests/feeds/2018-02-03-Intercepted.xml";
|
||||||
|
let feed = get_feed(path, 42);
|
||||||
|
let pd = feed.parse_podcast().to_podcast().unwrap();
|
||||||
|
|
||||||
|
let (insert, update) = feed.get_stuff(&pd).wait().unwrap();
|
||||||
|
assert_eq!(4, insert.len());
|
||||||
|
assert_eq!(43, update.len());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
#![recursion_limit = "1024"]
|
||||||
|
#![cfg_attr(all(test, feature = "clippy"), allow(option_unwrap_used, result_unwrap_used))]
|
||||||
|
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name))]
|
||||||
|
#![cfg_attr(feature = "clippy",
|
||||||
|
warn(option_unwrap_used, result_unwrap_used, print_stdout,
|
||||||
|
wrong_pub_self_convention, mut_mut, non_ascii_literal, similar_names,
|
||||||
|
unicode_not_nfc, enum_glob_use, if_not_else, items_after_statements,
|
||||||
|
used_underscore_binding))]
|
||||||
|
#![allow(unknown_lints)]
|
||||||
|
#![deny(bad_style, const_err, dead_code, improper_ctypes, legacy_directory_ownership,
|
||||||
|
non_shorthand_field_patterns, no_mangle_generic_items, overflowing_literals,
|
||||||
|
path_statements, patterns_in_fns_without_body, plugin_as_library, private_in_public,
|
||||||
|
private_no_mangle_fns, private_no_mangle_statics, safe_extern_statics,
|
||||||
|
unconditional_recursion, unions_with_drop_fields, unused_allocation, unused_comparisons,
|
||||||
|
unused_parens, while_true)]
|
||||||
|
#![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)]
|
||||||
|
#![deny(unused_extern_crates, unused)]
|
||||||
|
|
||||||
|
// #![feature(conservative_impl_trait)]
|
||||||
|
|
||||||
|
//! FIXME: Docs
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate pretty_assertions;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate derive_builder;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel_migrations;
|
||||||
|
// #[macro_use]
|
||||||
|
extern crate failure;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate failure_derive;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
|
||||||
|
extern crate ammonia;
|
||||||
|
extern crate chrono;
|
||||||
|
extern crate futures;
|
||||||
|
extern crate hyper;
|
||||||
|
extern crate hyper_tls;
|
||||||
|
extern crate itertools;
|
||||||
|
extern crate native_tls;
|
||||||
|
extern crate num_cpus;
|
||||||
|
extern crate rayon;
|
||||||
|
extern crate rfc822_sanitizer;
|
||||||
|
extern crate rss;
|
||||||
|
extern crate tokio_core;
|
||||||
|
extern crate url;
|
||||||
|
extern crate xdg;
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub mod dbqueries;
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub mod errors;
|
||||||
|
pub mod utils;
|
||||||
|
pub mod database;
|
||||||
|
pub mod pipeline;
|
||||||
|
pub(crate) mod models;
|
||||||
|
mod feed;
|
||||||
|
mod parser;
|
||||||
|
mod schema;
|
||||||
|
|
||||||
|
pub use feed::{Feed, FeedBuilder};
|
||||||
|
pub use models::{Episode, EpisodeWidgetQuery, Podcast, PodcastCoverQuery, Source};
|
||||||
|
pub use models::Save;
|
||||||
|
|
||||||
|
/// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths.
|
||||||
|
#[allow(missing_debug_implementations)]
|
||||||
|
pub mod xdg_dirs {
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use xdg;
|
||||||
|
|
||||||
|
lazy_static!{
|
||||||
|
pub(crate) static ref HAMMOND_XDG: xdg::BaseDirectories = {
|
||||||
|
xdg::BaseDirectories::with_prefix("hammond").unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
/// XDG_DATA Directory `Pathbuf`.
|
||||||
|
pub static ref HAMMOND_DATA: PathBuf = {
|
||||||
|
HAMMOND_XDG.create_data_directory(HAMMOND_XDG.get_data_home()).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
/// XDG_CONFIG Directory `Pathbuf`.
|
||||||
|
pub static ref HAMMOND_CONFIG: PathBuf = {
|
||||||
|
HAMMOND_XDG.create_config_directory(HAMMOND_XDG.get_config_home()).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
/// XDG_CACHE Directory `Pathbuf`.
|
||||||
|
pub static ref HAMMOND_CACHE: PathBuf = {
|
||||||
|
HAMMOND_XDG.create_cache_directory(HAMMOND_XDG.get_cache_home()).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Hammond Download Direcotry `PathBuf`.
|
||||||
|
pub static ref DL_DIR: PathBuf = {
|
||||||
|
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use diesel;
|
use diesel;
|
||||||
use diesel::prelude::*;
|
|
||||||
use diesel::SaveChangesDsl;
|
use diesel::SaveChangesDsl;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
|
||||||
use database::connection;
|
use database::connection;
|
||||||
use errors::DataError;
|
use errors::DataError;
|
||||||
use models::{Save, Show};
|
use models::{Podcast, Save};
|
||||||
use schema::episodes;
|
use schema::episode;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
||||||
#[table_name = "episodes"]
|
#[table_name = "episode"]
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
#[primary_key(title, show_id)]
|
#[primary_key(title, podcast_id)]
|
||||||
#[belongs_to(Show, foreign_key = "show_id")]
|
#[belongs_to(Podcast, foreign_key = "podcast_id")]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/// Diesel Model of the episode table.
|
/// Diesel Model of the episode table.
|
||||||
pub struct Episode {
|
pub struct Episode {
|
||||||
@@ -26,15 +26,15 @@ pub struct Episode {
|
|||||||
duration: Option<i32>,
|
duration: Option<i32>,
|
||||||
guid: Option<String>,
|
guid: Option<String>,
|
||||||
played: Option<i32>,
|
played: Option<i32>,
|
||||||
show_id: i32,
|
favorite: bool,
|
||||||
|
archive: bool,
|
||||||
|
podcast_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Save<Episode> for Episode {
|
impl Save<Episode, DataError> for Episode {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
/// Helper method to easily save/"sync" current state of self to the
|
/// Helper method to easily save/"sync" current state of self to the
|
||||||
/// Database.
|
/// Database.
|
||||||
fn save(&self) -> Result<Episode, Self::Error> {
|
fn save(&self) -> Result<Episode, DataError> {
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let tempdb = db.get()?;
|
let tempdb = db.get()?;
|
||||||
|
|
||||||
@@ -152,9 +152,32 @@ impl Episode {
|
|||||||
self.played = value;
|
self.played = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Show` table foreign key.
|
/// Represents the archiving policy for the episode.
|
||||||
pub fn show_id(&self) -> i32 {
|
pub fn archive(&self) -> bool {
|
||||||
self.show_id
|
self.archive
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the `archive` policy.
|
||||||
|
///
|
||||||
|
/// If true, the download cleanr will ignore the episode
|
||||||
|
/// and the corresponding media value will never be automaticly deleted.
|
||||||
|
pub fn set_archive(&mut self, b: bool) {
|
||||||
|
self.archive = b
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the `favorite` status of the `Episode`.
|
||||||
|
pub fn favorite(&self) -> bool {
|
||||||
|
self.favorite
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set `favorite` status.
|
||||||
|
pub fn set_favorite(&mut self, b: bool) {
|
||||||
|
self.favorite = b
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `Podcast` table foreign key.
|
||||||
|
pub fn podcast_id(&self) -> i32 {
|
||||||
|
self.podcast_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `played` value with the current `epoch` timestap and save it.
|
/// Sets the `played` value with the current `epoch` timestap and save it.
|
||||||
@@ -166,12 +189,12 @@ impl Episode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, AsChangeset, PartialEq)]
|
#[derive(Queryable, AsChangeset, PartialEq)]
|
||||||
#[table_name = "episodes"]
|
#[table_name = "episode"]
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
#[primary_key(title, show_id)]
|
#[primary_key(title, podcast_id)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/// Diesel Model to be used for constructing `EpisodeWidgets`.
|
/// Diesel Model to be used for constructing `EpisodeWidgets`.
|
||||||
pub struct EpisodeWidgetModel {
|
pub struct EpisodeWidgetQuery {
|
||||||
rowid: i32,
|
rowid: i32,
|
||||||
title: String,
|
title: String,
|
||||||
uri: Option<String>,
|
uri: Option<String>,
|
||||||
@@ -180,12 +203,14 @@ pub struct EpisodeWidgetModel {
|
|||||||
length: Option<i32>,
|
length: Option<i32>,
|
||||||
duration: Option<i32>,
|
duration: Option<i32>,
|
||||||
played: Option<i32>,
|
played: Option<i32>,
|
||||||
show_id: i32,
|
// favorite: bool,
|
||||||
|
// archive: bool,
|
||||||
|
podcast_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Episode> for EpisodeWidgetModel {
|
impl From<Episode> for EpisodeWidgetQuery {
|
||||||
fn from(e: Episode) -> EpisodeWidgetModel {
|
fn from(e: Episode) -> EpisodeWidgetQuery {
|
||||||
EpisodeWidgetModel {
|
EpisodeWidgetQuery {
|
||||||
rowid: e.rowid,
|
rowid: e.rowid,
|
||||||
title: e.title,
|
title: e.title,
|
||||||
uri: e.uri,
|
uri: e.uri,
|
||||||
@@ -194,30 +219,28 @@ impl From<Episode> for EpisodeWidgetModel {
|
|||||||
length: e.length,
|
length: e.length,
|
||||||
duration: e.duration,
|
duration: e.duration,
|
||||||
played: e.played,
|
played: e.played,
|
||||||
show_id: e.show_id,
|
podcast_id: e.podcast_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Save<usize> for EpisodeWidgetModel {
|
impl Save<usize, DataError> for EpisodeWidgetQuery {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
/// Helper method to easily save/"sync" current state of self to the
|
/// Helper method to easily save/"sync" current state of self to the
|
||||||
/// Database.
|
/// Database.
|
||||||
fn save(&self) -> Result<usize, Self::Error> {
|
fn save(&self) -> Result<usize, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let tempdb = db.get()?;
|
let tempdb = db.get()?;
|
||||||
|
|
||||||
diesel::update(episodes.filter(rowid.eq(self.rowid)))
|
diesel::update(episode.filter(rowid.eq(self.rowid)))
|
||||||
.set(self)
|
.set(self)
|
||||||
.execute(&*tempdb)
|
.execute(&*tempdb)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodeWidgetModel {
|
impl EpisodeWidgetQuery {
|
||||||
/// Get the value of the sqlite's `ROW_ID`
|
/// Get the value of the sqlite's `ROW_ID`
|
||||||
pub fn rowid(&self) -> i32 {
|
pub fn rowid(&self) -> i32 {
|
||||||
self.rowid
|
self.rowid
|
||||||
@@ -292,9 +315,32 @@ impl EpisodeWidgetModel {
|
|||||||
self.played = value;
|
self.played = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Show` table foreign key.
|
// /// Represents the archiving policy for the episode.
|
||||||
pub fn show_id(&self) -> i32 {
|
// pub fn archive(&self) -> bool {
|
||||||
self.show_id
|
// self.archive
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /// Set the `archive` policy.
|
||||||
|
// ///
|
||||||
|
// /// If true, the download cleanr will ignore the episode
|
||||||
|
// /// and the corresponding media value will never be automaticly deleted.
|
||||||
|
// pub fn set_archive(&mut self, b: bool) {
|
||||||
|
// self.archive = b
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /// Get the `favorite` status of the `Episode`.
|
||||||
|
// pub fn favorite(&self) -> bool {
|
||||||
|
// self.favorite
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /// Set `favorite` status.
|
||||||
|
// pub fn set_favorite(&mut self, b: bool) {
|
||||||
|
// self.favorite = b
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// `Podcast` table foreign key.
|
||||||
|
pub fn podcast_id(&self) -> i32 {
|
||||||
|
self.podcast_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `played` value with the current `epoch` timestap and save it.
|
/// Sets the `played` value with the current `epoch` timestap and save it.
|
||||||
@@ -306,38 +352,36 @@ impl EpisodeWidgetModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, AsChangeset, PartialEq)]
|
#[derive(Queryable, AsChangeset, PartialEq)]
|
||||||
#[table_name = "episodes"]
|
#[table_name = "episode"]
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
#[primary_key(title, show_id)]
|
#[primary_key(title, podcast_id)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/// Diesel Model to be used internal with the `utils::checkup` function.
|
/// Diesel Model to be used internal with the `utils::checkup` function.
|
||||||
pub struct EpisodeCleanerModel {
|
pub struct EpisodeCleanerQuery {
|
||||||
rowid: i32,
|
rowid: i32,
|
||||||
local_uri: Option<String>,
|
local_uri: Option<String>,
|
||||||
played: Option<i32>,
|
played: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Save<usize> for EpisodeCleanerModel {
|
impl Save<usize, DataError> for EpisodeCleanerQuery {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
/// Helper method to easily save/"sync" current state of self to the
|
/// Helper method to easily save/"sync" current state of self to the
|
||||||
/// Database.
|
/// Database.
|
||||||
fn save(&self) -> Result<usize, Self::Error> {
|
fn save(&self) -> Result<usize, DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let tempdb = db.get()?;
|
let tempdb = db.get()?;
|
||||||
|
|
||||||
diesel::update(episodes.filter(rowid.eq(self.rowid)))
|
diesel::update(episode.filter(rowid.eq(self.rowid)))
|
||||||
.set(self)
|
.set(self)
|
||||||
.execute(&*tempdb)
|
.execute(&*tempdb)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Episode> for EpisodeCleanerModel {
|
impl From<Episode> for EpisodeCleanerQuery {
|
||||||
fn from(e: Episode) -> EpisodeCleanerModel {
|
fn from(e: Episode) -> EpisodeCleanerQuery {
|
||||||
EpisodeCleanerModel {
|
EpisodeCleanerQuery {
|
||||||
rowid: e.rowid(),
|
rowid: e.rowid(),
|
||||||
local_uri: e.local_uri,
|
local_uri: e.local_uri,
|
||||||
played: e.played,
|
played: e.played,
|
||||||
@@ -345,7 +389,7 @@ impl From<Episode> for EpisodeCleanerModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodeCleanerModel {
|
impl EpisodeCleanerQuery {
|
||||||
/// Get the value of the sqlite's `ROW_ID`
|
/// Get the value of the sqlite's `ROW_ID`
|
||||||
pub fn rowid(&self) -> i32 {
|
pub fn rowid(&self) -> i32 {
|
||||||
self.rowid
|
self.rowid
|
||||||
@@ -378,9 +422,9 @@ impl EpisodeCleanerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, AsChangeset, PartialEq)]
|
#[derive(Queryable, AsChangeset, PartialEq)]
|
||||||
#[table_name = "episodes"]
|
#[table_name = "episode"]
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
#[primary_key(title, show_id)]
|
#[primary_key(title, podcast_id)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/// Diesel Model to be used for FIXME.
|
/// Diesel Model to be used for FIXME.
|
||||||
pub struct EpisodeMinimal {
|
pub struct EpisodeMinimal {
|
||||||
@@ -388,10 +432,9 @@ pub struct EpisodeMinimal {
|
|||||||
title: String,
|
title: String,
|
||||||
uri: Option<String>,
|
uri: Option<String>,
|
||||||
epoch: i32,
|
epoch: i32,
|
||||||
length: Option<i32>,
|
|
||||||
duration: Option<i32>,
|
duration: Option<i32>,
|
||||||
guid: Option<String>,
|
guid: Option<String>,
|
||||||
show_id: i32,
|
podcast_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Episode> for EpisodeMinimal {
|
impl From<Episode> for EpisodeMinimal {
|
||||||
@@ -400,11 +443,10 @@ impl From<Episode> for EpisodeMinimal {
|
|||||||
rowid: e.rowid,
|
rowid: e.rowid,
|
||||||
title: e.title,
|
title: e.title,
|
||||||
uri: e.uri,
|
uri: e.uri,
|
||||||
length: e.length,
|
|
||||||
guid: e.guid,
|
guid: e.guid,
|
||||||
epoch: e.epoch,
|
epoch: e.epoch,
|
||||||
duration: e.duration,
|
duration: e.duration,
|
||||||
show_id: e.show_id,
|
podcast_id: e.podcast_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -440,18 +482,6 @@ impl EpisodeMinimal {
|
|||||||
self.epoch
|
self.epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the `length`.
|
|
||||||
///
|
|
||||||
/// The number represents the size of the file in bytes.
|
|
||||||
pub fn length(&self) -> Option<i32> {
|
|
||||||
self.length
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the `length`.
|
|
||||||
pub fn set_length(&mut self, value: Option<i32>) {
|
|
||||||
self.length = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the `duration` value.
|
/// Get the `duration` value.
|
||||||
///
|
///
|
||||||
/// The number represents the duration of the item/episode in seconds.
|
/// The number represents the duration of the item/episode in seconds.
|
||||||
@@ -459,8 +489,8 @@ impl EpisodeMinimal {
|
|||||||
self.duration
|
self.duration
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Show` table foreign key.
|
/// `Podcast` table foreign key.
|
||||||
pub fn show_id(&self) -> i32 {
|
pub fn podcast_id(&self) -> i32 {
|
||||||
self.show_id
|
self.podcast_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
mod new_episode;
|
||||||
|
mod new_podcast;
|
||||||
|
mod new_source;
|
||||||
|
|
||||||
|
mod episode;
|
||||||
|
mod podcast;
|
||||||
|
mod source;
|
||||||
|
|
||||||
|
// use futures::prelude::*;
|
||||||
|
// use futures::future::*;
|
||||||
|
|
||||||
|
pub(crate) use self::episode::EpisodeCleanerQuery;
|
||||||
|
pub(crate) use self::new_episode::{NewEpisode, NewEpisodeMinimal};
|
||||||
|
pub(crate) use self::new_podcast::NewPodcast;
|
||||||
|
pub(crate) use self::new_source::NewSource;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) use self::new_episode::NewEpisodeBuilder;
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) use self::new_podcast::NewPodcastBuilder;
|
||||||
|
|
||||||
|
pub use self::episode::{Episode, EpisodeMinimal, EpisodeWidgetQuery};
|
||||||
|
pub use self::podcast::{Podcast, PodcastCoverQuery};
|
||||||
|
pub use self::source::Source;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
pub enum IndexState<T> {
|
||||||
|
Index(T),
|
||||||
|
Update((T, i32)),
|
||||||
|
NotChanged,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Insert<T, E> {
|
||||||
|
fn insert(&self) -> Result<T, E>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Update<T, E> {
|
||||||
|
fn update(&self, i32) -> Result<T, E>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This might need to change in the future
|
||||||
|
pub trait Index<T, E>: Insert<T, E> + Update<T, E> {
|
||||||
|
fn index(&self) -> Result<T, E>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// FIXME: DOCS
|
||||||
|
pub trait Save<T, E> {
|
||||||
|
/// Helper method to easily save/"sync" current state of a diesel model to
|
||||||
|
/// the Database.
|
||||||
|
fn save(&self) -> Result<T, E>;
|
||||||
|
}
|
||||||
@@ -9,11 +9,11 @@ use dbqueries;
|
|||||||
use errors::DataError;
|
use errors::DataError;
|
||||||
use models::{Episode, EpisodeMinimal, Index, Insert, Update};
|
use models::{Episode, EpisodeMinimal, Index, Insert, Update};
|
||||||
use parser;
|
use parser;
|
||||||
use schema::episodes;
|
use schema::episode;
|
||||||
use utils::url_cleaner;
|
use utils::url_cleaner;
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "episodes"]
|
#[table_name = "episode"]
|
||||||
#[derive(Debug, Clone, Default, Builder, PartialEq)]
|
#[derive(Debug, Clone, Default, Builder, PartialEq)]
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
#[builder(derive(Debug))]
|
#[builder(derive(Debug))]
|
||||||
@@ -26,7 +26,7 @@ pub(crate) struct NewEpisode {
|
|||||||
duration: Option<i32>,
|
duration: Option<i32>,
|
||||||
guid: Option<String>,
|
guid: Option<String>,
|
||||||
epoch: i32,
|
epoch: i32,
|
||||||
show_id: i32,
|
podcast_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<NewEpisodeMinimal> for NewEpisode {
|
impl From<NewEpisodeMinimal> for NewEpisode {
|
||||||
@@ -36,23 +36,21 @@ impl From<NewEpisodeMinimal> for NewEpisode {
|
|||||||
.uri(e.uri)
|
.uri(e.uri)
|
||||||
.duration(e.duration)
|
.duration(e.duration)
|
||||||
.epoch(e.epoch)
|
.epoch(e.epoch)
|
||||||
.show_id(e.show_id)
|
.podcast_id(e.podcast_id)
|
||||||
.guid(e.guid)
|
.guid(e.guid)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Insert<()> for NewEpisode {
|
impl Insert<(), DataError> for NewEpisode {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
fn insert(&self) -> Result<(), DataError> {
|
fn insert(&self) -> Result<(), DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
info!("Inserting {:?}", self.title);
|
info!("Inserting {:?}", self.title);
|
||||||
diesel::insert_into(episodes)
|
diesel::insert_into(episode)
|
||||||
.values(self)
|
.values(self)
|
||||||
.execute(&con)
|
.execute(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
@@ -60,16 +58,14 @@ impl Insert<()> for NewEpisode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Update<()> for NewEpisode {
|
impl Update<(), DataError> for NewEpisode {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
fn update(&self, episode_id: i32) -> Result<(), DataError> {
|
fn update(&self, episode_id: i32) -> Result<(), DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
info!("Updating {:?}", self.title);
|
info!("Updating {:?}", self.title);
|
||||||
diesel::update(episodes.filter(rowid.eq(episode_id)))
|
diesel::update(episode.filter(rowid.eq(episode_id)))
|
||||||
.set(self)
|
.set(self)
|
||||||
.execute(&con)
|
.execute(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
@@ -77,16 +73,14 @@ impl Update<()> for NewEpisode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<()> for NewEpisode {
|
impl Index<(), DataError> for NewEpisode {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
// Does not update the episode description if it's the only thing that has
|
// Does not update the episode description if it's the only thing that has
|
||||||
// changed.
|
// changed.
|
||||||
fn index(&self) -> Result<(), DataError> {
|
fn index(&self) -> Result<(), DataError> {
|
||||||
let exists = dbqueries::episode_exists(self.title(), self.show_id())?;
|
let exists = dbqueries::episode_exists(self.title(), self.podcast_id())?;
|
||||||
|
|
||||||
if exists {
|
if exists {
|
||||||
let other = dbqueries::get_episode_minimal_from_pk(self.title(), self.show_id())?;
|
let other = dbqueries::get_episode_minimal_from_pk(self.title(), self.podcast_id())?;
|
||||||
|
|
||||||
if self != &other {
|
if self != &other {
|
||||||
self.update(other.rowid())
|
self.update(other.rowid())
|
||||||
@@ -101,23 +95,17 @@ impl Index<()> for NewEpisode {
|
|||||||
|
|
||||||
impl PartialEq<EpisodeMinimal> for NewEpisode {
|
impl PartialEq<EpisodeMinimal> for NewEpisode {
|
||||||
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
||||||
(self.title() == other.title())
|
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||||
&& (self.uri() == other.uri())
|
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||||
&& (self.duration() == other.duration())
|
&& (self.guid() == other.guid()) && (self.podcast_id() == other.podcast_id())
|
||||||
&& (self.epoch() == other.epoch())
|
|
||||||
&& (self.guid() == other.guid())
|
|
||||||
&& (self.show_id() == other.show_id())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<Episode> for NewEpisode {
|
impl PartialEq<Episode> for NewEpisode {
|
||||||
fn eq(&self, other: &Episode) -> bool {
|
fn eq(&self, other: &Episode) -> bool {
|
||||||
(self.title() == other.title())
|
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||||
&& (self.uri() == other.uri())
|
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||||
&& (self.duration() == other.duration())
|
&& (self.guid() == other.guid()) && (self.podcast_id() == other.podcast_id())
|
||||||
&& (self.epoch() == other.epoch())
|
|
||||||
&& (self.guid() == other.guid())
|
|
||||||
&& (self.show_id() == other.show_id())
|
|
||||||
&& (self.description() == other.description())
|
&& (self.description() == other.description())
|
||||||
&& (self.length() == other.length())
|
&& (self.length() == other.length())
|
||||||
}
|
}
|
||||||
@@ -126,14 +114,14 @@ impl PartialEq<Episode> for NewEpisode {
|
|||||||
impl NewEpisode {
|
impl NewEpisode {
|
||||||
/// Parses an `rss::Item` into a `NewEpisode` Struct.
|
/// Parses an `rss::Item` into a `NewEpisode` Struct.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn new(item: &rss::Item, show_id: i32) -> Result<Self, DataError> {
|
pub(crate) fn new(item: &rss::Item, podcast_id: i32) -> Result<Self, DataError> {
|
||||||
NewEpisodeMinimal::new(item, show_id).map(|ep| ep.into_new_episode(item))
|
NewEpisodeMinimal::new(item, podcast_id).map(|ep| ep.into_new_episode(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn to_episode(&self) -> Result<Episode, DataError> {
|
pub(crate) fn to_episode(&self) -> Result<Episode, DataError> {
|
||||||
self.index()?;
|
self.index()?;
|
||||||
dbqueries::get_episode_from_pk(&self.title, self.show_id).map_err(From::from)
|
dbqueries::get_episode_from_pk(&self.title, self.podcast_id).map_err(From::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,34 +155,30 @@ impl NewEpisode {
|
|||||||
self.length
|
self.length
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn show_id(&self) -> i32 {
|
pub(crate) fn podcast_id(&self) -> i32 {
|
||||||
self.show_id
|
self.podcast_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "episodes"]
|
#[table_name = "episode"]
|
||||||
#[derive(Debug, Clone, Builder, PartialEq)]
|
#[derive(Debug, Clone, Builder, PartialEq)]
|
||||||
#[builder(derive(Debug))]
|
#[builder(derive(Debug))]
|
||||||
#[builder(setter(into))]
|
#[builder(setter(into))]
|
||||||
pub(crate) struct NewEpisodeMinimal {
|
pub(crate) struct NewEpisodeMinimal {
|
||||||
title: String,
|
title: String,
|
||||||
uri: Option<String>,
|
uri: Option<String>,
|
||||||
length: Option<i32>,
|
|
||||||
duration: Option<i32>,
|
duration: Option<i32>,
|
||||||
epoch: i32,
|
epoch: i32,
|
||||||
guid: Option<String>,
|
guid: Option<String>,
|
||||||
show_id: i32,
|
podcast_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<EpisodeMinimal> for NewEpisodeMinimal {
|
impl PartialEq<EpisodeMinimal> for NewEpisodeMinimal {
|
||||||
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
||||||
(self.title() == other.title())
|
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||||
&& (self.uri() == other.uri())
|
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||||
&& (self.duration() == other.duration())
|
&& (self.guid() == other.guid()) && (self.podcast_id() == other.podcast_id())
|
||||||
&& (self.epoch() == other.epoch())
|
|
||||||
&& (self.guid() == other.guid())
|
|
||||||
&& (self.show_id() == other.show_id())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,19 +196,12 @@ impl NewEpisodeMinimal {
|
|||||||
let title = item.title().unwrap().trim().to_owned();
|
let title = item.title().unwrap().trim().to_owned();
|
||||||
let guid = item.guid().map(|s| s.value().trim().to_owned());
|
let guid = item.guid().map(|s| s.value().trim().to_owned());
|
||||||
|
|
||||||
// Get the mime type, the `http` url and the length from the enclosure
|
let uri = item.enclosure()
|
||||||
// http://www.rssboard.org/rss-specification#ltenclosuregtSubelementOfLtitemgt
|
.map(|s| url_cleaner(s.url()))
|
||||||
let enc = item.enclosure();
|
|
||||||
|
|
||||||
// Get the url
|
|
||||||
let uri = enc.map(|s| url_cleaner(s.url().trim()))
|
|
||||||
// Fallback to Rss.Item.link if enclosure is None.
|
// Fallback to Rss.Item.link if enclosure is None.
|
||||||
.or_else(|| item.link().map(|s| url_cleaner(s.trim())));
|
.or_else(|| item.link().map(|s| url_cleaner(s)));
|
||||||
|
|
||||||
// Get the size of the content, it should be in bytes
|
// If url is still None return an Error as this behaviour is
|
||||||
let length = enc.and_then(|x| x.length().parse().ok());
|
|
||||||
|
|
||||||
// If url is still None return an Error as this behaviour is not
|
|
||||||
// compliant with the RSS Spec.
|
// compliant with the RSS Spec.
|
||||||
if uri.is_none() {
|
if uri.is_none() {
|
||||||
let err = DataError::ParseEpisodeError {
|
let err = DataError::ParseEpisodeError {
|
||||||
@@ -246,35 +223,27 @@ impl NewEpisodeMinimal {
|
|||||||
NewEpisodeMinimalBuilder::default()
|
NewEpisodeMinimalBuilder::default()
|
||||||
.title(title)
|
.title(title)
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.length(length)
|
|
||||||
.duration(duration)
|
.duration(duration)
|
||||||
.epoch(epoch)
|
.epoch(epoch)
|
||||||
.guid(guid)
|
.guid(guid)
|
||||||
.show_id(parent_id)
|
.podcast_id(parent_id)
|
||||||
.build()
|
.build()
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: TryInto is stabilizing in rustc v1.26!
|
// TODO: TryInto is stabilizing in rustc v1.26!
|
||||||
// ^ Jokes on you past self!
|
|
||||||
pub(crate) fn into_new_episode(self, item: &rss::Item) -> NewEpisode {
|
pub(crate) fn into_new_episode(self, item: &rss::Item) -> NewEpisode {
|
||||||
let description = item.description().and_then(|s| {
|
let length = item.enclosure().and_then(|x| x.length().parse().ok());
|
||||||
let sanitized_html = ammonia::Builder::new()
|
let description = item.description().map(|s| ammonia::clean(s));
|
||||||
// Remove `rel` attributes from `<a>` tags
|
|
||||||
.link_rel(None)
|
|
||||||
.clean(s.trim())
|
|
||||||
.to_string();
|
|
||||||
Some(sanitized_html)
|
|
||||||
});
|
|
||||||
|
|
||||||
NewEpisodeBuilder::default()
|
NewEpisodeBuilder::default()
|
||||||
.title(self.title)
|
.title(self.title)
|
||||||
.uri(self.uri)
|
.uri(self.uri)
|
||||||
.duration(self.duration)
|
.duration(self.duration)
|
||||||
.epoch(self.epoch)
|
.epoch(self.epoch)
|
||||||
.show_id(self.show_id)
|
.podcast_id(self.podcast_id)
|
||||||
.guid(self.guid)
|
.guid(self.guid)
|
||||||
.length(self.length)
|
.length(length)
|
||||||
.description(description)
|
.description(description)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -303,17 +272,16 @@ impl NewEpisodeMinimal {
|
|||||||
self.epoch
|
self.epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn show_id(&self) -> i32 {
|
pub(crate) fn podcast_id(&self) -> i32 {
|
||||||
self.show_id
|
self.podcast_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use database::truncate_db;
|
use database::truncate_db;
|
||||||
use dbqueries;
|
use dbqueries;
|
||||||
use models::new_episode::{NewEpisodeMinimal, NewEpisodeMinimalBuilder};
|
|
||||||
use models::*;
|
use models::*;
|
||||||
|
use models::new_episode::{NewEpisodeMinimal, NewEpisodeMinimalBuilder};
|
||||||
|
|
||||||
use rss::Channel;
|
use rss::Channel;
|
||||||
|
|
||||||
@@ -333,9 +301,8 @@ mod tests {
|
|||||||
)))
|
)))
|
||||||
.guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
|
.guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24")))
|
||||||
.epoch(1505296800)
|
.epoch(1505296800)
|
||||||
.length(Some(66738886))
|
|
||||||
.duration(Some(4171))
|
.duration(Some(4171))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -347,9 +314,8 @@ mod tests {
|
|||||||
)))
|
)))
|
||||||
.guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
|
.guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d")))
|
||||||
.epoch(1502272800)
|
.epoch(1502272800)
|
||||||
.length(Some(67527575))
|
|
||||||
.duration(Some(4415))
|
.duration(Some(4415))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -370,7 +336,7 @@ mod tests {
|
|||||||
.length(Some(66738886))
|
.length(Some(66738886))
|
||||||
.epoch(1505296800)
|
.epoch(1505296800)
|
||||||
.duration(Some(4171))
|
.duration(Some(4171))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -394,7 +360,7 @@ mod tests {
|
|||||||
.length(Some(67527575))
|
.length(Some(67527575))
|
||||||
.epoch(1502272800)
|
.epoch(1502272800)
|
||||||
.duration(Some(4415))
|
.duration(Some(4415))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -409,7 +375,7 @@ mod tests {
|
|||||||
.length(Some(66738886))
|
.length(Some(66738886))
|
||||||
.epoch(1505296800)
|
.epoch(1505296800)
|
||||||
.duration(Some(424242))
|
.duration(Some(424242))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -420,10 +386,9 @@ mod tests {
|
|||||||
"http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3",
|
"http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3",
|
||||||
)))
|
)))
|
||||||
.guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
|
.guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D")))
|
||||||
.length(Some(46479789))
|
|
||||||
.epoch(1505280282)
|
.epoch(1505280282)
|
||||||
.duration(Some(5733))
|
.duration(Some(5733))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -435,9 +400,8 @@ mod tests {
|
|||||||
)))
|
)))
|
||||||
.guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
|
.guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B")))
|
||||||
.epoch(1504670247)
|
.epoch(1504670247)
|
||||||
.length(Some(36544272))
|
|
||||||
.duration(Some(4491))
|
.duration(Some(4491))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -457,7 +421,7 @@ mod tests {
|
|||||||
.length(Some(46479789))
|
.length(Some(46479789))
|
||||||
.epoch(1505280282)
|
.epoch(1505280282)
|
||||||
.duration(Some(5733))
|
.duration(Some(5733))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -479,7 +443,7 @@ mod tests {
|
|||||||
.length(Some(36544272))
|
.length(Some(36544272))
|
||||||
.epoch(1504670247)
|
.epoch(1504670247)
|
||||||
.duration(Some(4491))
|
.duration(Some(4491))
|
||||||
.show_id(42)
|
.podcast_id(42)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
@@ -553,10 +517,6 @@ mod tests {
|
|||||||
let ep = EXPECTED_MINIMAL_INTERCEPTED_1
|
let ep = EXPECTED_MINIMAL_INTERCEPTED_1
|
||||||
.clone()
|
.clone()
|
||||||
.into_new_episode(&item);
|
.into_new_episode(&item);
|
||||||
println!(
|
|
||||||
"EPISODE: {:#?}\nEXPECTED: {:#?}",
|
|
||||||
ep, *EXPECTED_INTERCEPTED_1
|
|
||||||
);
|
|
||||||
assert_eq!(ep, *EXPECTED_INTERCEPTED_1);
|
assert_eq!(ep, *EXPECTED_INTERCEPTED_1);
|
||||||
|
|
||||||
let item = channel.items().iter().nth(15).unwrap();
|
let item = channel.items().iter().nth(15).unwrap();
|
||||||
@@ -576,7 +536,7 @@ mod tests {
|
|||||||
let episode = channel.items().iter().nth(14).unwrap();
|
let episode = channel.items().iter().nth(14).unwrap();
|
||||||
let new_ep = NewEpisode::new(&episode, 42).unwrap();
|
let new_ep = NewEpisode::new(&episode, 42).unwrap();
|
||||||
new_ep.insert().unwrap();
|
new_ep.insert().unwrap();
|
||||||
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.show_id()).unwrap();
|
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.podcast_id()).unwrap();
|
||||||
|
|
||||||
assert_eq!(new_ep, ep);
|
assert_eq!(new_ep, ep);
|
||||||
assert_eq!(&new_ep, &*EXPECTED_INTERCEPTED_1);
|
assert_eq!(&new_ep, &*EXPECTED_INTERCEPTED_1);
|
||||||
@@ -585,7 +545,7 @@ mod tests {
|
|||||||
let episode = channel.items().iter().nth(15).unwrap();
|
let episode = channel.items().iter().nth(15).unwrap();
|
||||||
let new_ep = NewEpisode::new(&episode, 42).unwrap();
|
let new_ep = NewEpisode::new(&episode, 42).unwrap();
|
||||||
new_ep.insert().unwrap();
|
new_ep.insert().unwrap();
|
||||||
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.show_id()).unwrap();
|
let ep = dbqueries::get_episode_from_pk(new_ep.title(), new_ep.podcast_id()).unwrap();
|
||||||
|
|
||||||
assert_eq!(new_ep, ep);
|
assert_eq!(new_ep, ep);
|
||||||
assert_eq!(&new_ep, &*EXPECTED_INTERCEPTED_2);
|
assert_eq!(&new_ep, &*EXPECTED_INTERCEPTED_2);
|
||||||
@@ -599,15 +559,21 @@ mod tests {
|
|||||||
|
|
||||||
let updated = &*UPDATED_DURATION_INTERCEPTED_1;
|
let updated = &*UPDATED_DURATION_INTERCEPTED_1;
|
||||||
updated.update(old.rowid()).unwrap();
|
updated.update(old.rowid()).unwrap();
|
||||||
let new = dbqueries::get_episode_from_pk(old.title(), old.show_id()).unwrap();
|
let mut new = dbqueries::get_episode_from_pk(old.title(), old.podcast_id()).unwrap();
|
||||||
|
|
||||||
// Assert that updating does not change the rowid and show_id
|
// Assert that updating does not change the rowid and podcast_id
|
||||||
assert_ne!(old, new);
|
assert_ne!(old, new);
|
||||||
assert_eq!(old.rowid(), new.rowid());
|
assert_eq!(old.rowid(), new.rowid());
|
||||||
assert_eq!(old.show_id(), new.show_id());
|
assert_eq!(old.podcast_id(), new.podcast_id());
|
||||||
|
|
||||||
assert_eq!(updated, &new);
|
assert_eq!(updated, &new);
|
||||||
assert_ne!(updated, &old);
|
assert_ne!(updated, &old);
|
||||||
|
|
||||||
|
new.set_archive(true);
|
||||||
|
new.save().unwrap();
|
||||||
|
|
||||||
|
let new2 = dbqueries::get_episode_from_pk(old.title(), old.podcast_id()).unwrap();
|
||||||
|
assert_eq!(true, new2.archive());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -620,7 +586,7 @@ mod tests {
|
|||||||
// Second identical, This should take the early return path
|
// Second identical, This should take the early return path
|
||||||
assert!(expected.index().is_ok());
|
assert!(expected.index().is_ok());
|
||||||
// Get the episode
|
// Get the episode
|
||||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
let old = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||||
// Assert that NewPodcast is equal to the Indexed one
|
// Assert that NewPodcast is equal to the Indexed one
|
||||||
assert_eq!(*expected, old);
|
assert_eq!(*expected, old);
|
||||||
|
|
||||||
@@ -629,22 +595,23 @@ mod tests {
|
|||||||
// Update the podcast
|
// Update the podcast
|
||||||
assert!(updated.index().is_ok());
|
assert!(updated.index().is_ok());
|
||||||
// Get the new Podcast
|
// Get the new Podcast
|
||||||
let new = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
let new = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||||
// Assert it's diff from the old one.
|
// Assert it's diff from the old one.
|
||||||
assert_ne!(new, old);
|
assert_ne!(new, old);
|
||||||
assert_eq!(*updated, new);
|
assert_eq!(*updated, new);
|
||||||
assert_eq!(new.rowid(), old.rowid());
|
assert_eq!(new.rowid(), old.rowid());
|
||||||
assert_eq!(new.show_id(), old.show_id());
|
assert_eq!(new.podcast_id(), old.podcast_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new_episode_to_episode() {
|
fn test_new_episode_to_episode() {
|
||||||
let expected = &*EXPECTED_INTERCEPTED_1;
|
let expected = &*EXPECTED_INTERCEPTED_1;
|
||||||
|
let updated = &*UPDATED_DURATION_INTERCEPTED_1;
|
||||||
|
|
||||||
// Assert insert() produces the same result that you would get with to_podcast()
|
// Assert insert() produces the same result that you would get with to_podcast()
|
||||||
truncate_db().unwrap();
|
truncate_db().unwrap();
|
||||||
expected.insert().unwrap();
|
expected.insert().unwrap();
|
||||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
let old = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||||
let ep = expected.to_episode().unwrap();
|
let ep = expected.to_episode().unwrap();
|
||||||
assert_eq!(old, ep);
|
assert_eq!(old, ep);
|
||||||
|
|
||||||
@@ -653,7 +620,17 @@ mod tests {
|
|||||||
let ep = expected.to_episode().unwrap();
|
let ep = expected.to_episode().unwrap();
|
||||||
// This should error as a unique constrain violation
|
// This should error as a unique constrain violation
|
||||||
assert!(expected.insert().is_err());
|
assert!(expected.insert().is_err());
|
||||||
let old = dbqueries::get_episode_from_pk(expected.title(), expected.show_id()).unwrap();
|
let mut old =
|
||||||
|
dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||||
assert_eq!(old, ep);
|
assert_eq!(old, ep);
|
||||||
|
|
||||||
|
old.set_archive(true);
|
||||||
|
old.save().unwrap();
|
||||||
|
|
||||||
|
// Assert that it does not mess with user preferences
|
||||||
|
let ep = updated.to_episode().unwrap();
|
||||||
|
let old = dbqueries::get_episode_from_pk(expected.title(), expected.podcast_id()).unwrap();
|
||||||
|
assert_eq!(old, ep);
|
||||||
|
assert_eq!(old.archive(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,21 +4,21 @@ use diesel::prelude::*;
|
|||||||
use rss;
|
use rss;
|
||||||
|
|
||||||
use errors::DataError;
|
use errors::DataError;
|
||||||
use models::Show;
|
|
||||||
use models::{Index, Insert, Update};
|
use models::{Index, Insert, Update};
|
||||||
use schema::shows;
|
use models::Podcast;
|
||||||
|
use schema::podcast;
|
||||||
|
|
||||||
use database::connection;
|
use database::connection;
|
||||||
use dbqueries;
|
use dbqueries;
|
||||||
use utils::url_cleaner;
|
use utils::url_cleaner;
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "shows"]
|
#[table_name = "podcast"]
|
||||||
#[derive(Debug, Clone, Default, Builder, PartialEq)]
|
#[derive(Debug, Clone, Default, Builder, PartialEq)]
|
||||||
#[builder(default)]
|
#[builder(default)]
|
||||||
#[builder(derive(Debug))]
|
#[builder(derive(Debug))]
|
||||||
#[builder(setter(into))]
|
#[builder(setter(into))]
|
||||||
pub(crate) struct NewShow {
|
pub(crate) struct NewPodcast {
|
||||||
title: String,
|
title: String,
|
||||||
link: String,
|
link: String,
|
||||||
description: String,
|
description: String,
|
||||||
@@ -26,15 +26,13 @@ pub(crate) struct NewShow {
|
|||||||
source_id: i32,
|
source_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Insert<()> for NewShow {
|
impl Insert<(), DataError> for NewPodcast {
|
||||||
type Error = DataError;
|
fn insert(&self) -> Result<(), DataError> {
|
||||||
|
use schema::podcast::dsl::*;
|
||||||
fn insert(&self) -> Result<(), Self::Error> {
|
|
||||||
use schema::shows::dsl::*;
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
diesel::insert_into(shows)
|
diesel::insert_into(podcast)
|
||||||
.values(self)
|
.values(self)
|
||||||
.execute(&con)
|
.execute(&con)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
@@ -42,16 +40,14 @@ impl Insert<()> for NewShow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Update<()> for NewShow {
|
impl Update<(), DataError> for NewPodcast {
|
||||||
type Error = DataError;
|
fn update(&self, podcast_id: i32) -> Result<(), DataError> {
|
||||||
|
use schema::podcast::dsl::*;
|
||||||
fn update(&self, show_id: i32) -> Result<(), Self::Error> {
|
|
||||||
use schema::shows::dsl::*;
|
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
info!("Updating {}", self.title);
|
info!("Updating {}", self.title);
|
||||||
diesel::update(shows.filter(id.eq(show_id)))
|
diesel::update(podcast.filter(id.eq(podcast_id)))
|
||||||
.set(self)
|
.set(self)
|
||||||
.execute(&con)
|
.execute(&con)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
@@ -61,9 +57,7 @@ impl Update<()> for NewShow {
|
|||||||
|
|
||||||
// TODO: Maybe return an Enum<Action(Resut)> Instead.
|
// TODO: Maybe return an Enum<Action(Resut)> Instead.
|
||||||
// It would make unti testing better too.
|
// It would make unti testing better too.
|
||||||
impl Index<()> for NewShow {
|
impl Index<(), DataError> for NewPodcast {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
fn index(&self) -> Result<(), DataError> {
|
fn index(&self) -> Result<(), DataError> {
|
||||||
let exists = dbqueries::podcast_exists(self.source_id)?;
|
let exists = dbqueries::podcast_exists(self.source_id)?;
|
||||||
|
|
||||||
@@ -81,37 +75,31 @@ impl Index<()> for NewShow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<Show> for NewShow {
|
impl PartialEq<Podcast> for NewPodcast {
|
||||||
fn eq(&self, other: &Show) -> bool {
|
fn eq(&self, other: &Podcast) -> bool {
|
||||||
(self.link() == other.link())
|
(self.link() == other.link()) && (self.title() == other.title())
|
||||||
&& (self.title() == other.title())
|
|
||||||
&& (self.image_uri() == other.image_uri())
|
&& (self.image_uri() == other.image_uri())
|
||||||
&& (self.description() == other.description())
|
&& (self.description() == other.description())
|
||||||
&& (self.source_id() == other.source_id())
|
&& (self.source_id() == other.source_id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewShow {
|
impl NewPodcast {
|
||||||
/// Parses a `rss::Channel` into a `NewShow` Struct.
|
/// Parses a `rss::Channel` into a `NewPodcast` Struct.
|
||||||
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewShow {
|
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewPodcast {
|
||||||
let title = chan.title().trim();
|
let title = chan.title().trim();
|
||||||
let link = url_cleaner(chan.link().trim());
|
|
||||||
|
|
||||||
let description = ammonia::Builder::new()
|
let description = ammonia::clean(chan.description().trim());
|
||||||
// Remove `rel` attributes from `<a>` tags
|
let link = url_cleaner(chan.link());
|
||||||
.link_rel(None)
|
|
||||||
.clean(chan.description().trim())
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
// Try to get the itunes img first
|
// Try to get the itunes img first
|
||||||
let itunes_img = chan
|
let itunes_img = chan.itunes_ext()
|
||||||
.itunes_ext()
|
.and_then(|s| s.image())
|
||||||
.and_then(|s| s.image().map(|url| url.trim()))
|
|
||||||
.map(|s| s.to_owned());
|
.map(|s| s.to_owned());
|
||||||
// If itunes is None, try to get the channel.image from the rss spec
|
// If itunes is None, try to get the channel.image from the rss spec
|
||||||
let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().trim().to_owned()));
|
let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().to_owned()));
|
||||||
|
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title(title)
|
.title(title)
|
||||||
.description(description)
|
.description(description)
|
||||||
.link(link)
|
.link(link)
|
||||||
@@ -122,14 +110,14 @@ impl NewShow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Look out for when tryinto lands into stable.
|
// Look out for when tryinto lands into stable.
|
||||||
pub(crate) fn to_podcast(&self) -> Result<Show, DataError> {
|
pub(crate) fn to_podcast(&self) -> Result<Podcast, DataError> {
|
||||||
self.index()?;
|
self.index()?;
|
||||||
dbqueries::get_podcast_from_source_id(self.source_id).map_err(From::from)
|
dbqueries::get_podcast_from_source_id(self.source_id).map_err(From::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore the following geters. They are used in unit tests mainly.
|
// Ignore the following geters. They are used in unit tests mainly.
|
||||||
impl NewShow {
|
impl NewPodcast {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn source_id(&self) -> i32 {
|
pub(crate) fn source_id(&self) -> i32 {
|
||||||
self.source_id
|
self.source_id
|
||||||
@@ -160,14 +148,14 @@ mod tests {
|
|||||||
use rss::Channel;
|
use rss::Channel;
|
||||||
|
|
||||||
use database::truncate_db;
|
use database::truncate_db;
|
||||||
use models::NewShowBuilder;
|
use models::{NewPodcastBuilder, Save};
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
|
||||||
// Pre-built expected NewShow structs.
|
// Pre-built expected NewPodcast structs.
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref EXPECTED_INTERCEPTED: NewShow = {
|
static ref EXPECTED_INTERCEPTED: NewPodcast = {
|
||||||
let descr = "The people behind The Intercept’s fearless reporting and incisive \
|
let descr = "The people behind The Intercept’s fearless reporting and incisive \
|
||||||
commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and \
|
commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and \
|
||||||
others—discuss the crucial issues of our time: national security, civil \
|
others—discuss the crucial issues of our time: national security, civil \
|
||||||
@@ -175,7 +163,7 @@ mod tests {
|
|||||||
artists, thinkers, and newsmakers who challenge our preconceptions about \
|
artists, thinkers, and newsmakers who challenge our preconceptions about \
|
||||||
the world we live in.";
|
the world we live in.";
|
||||||
|
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title("Intercepted with Jeremy Scahill")
|
.title("Intercepted with Jeremy Scahill")
|
||||||
.link("https://theintercept.com/podcasts")
|
.link("https://theintercept.com/podcasts")
|
||||||
.description(descr)
|
.description(descr)
|
||||||
@@ -188,12 +176,12 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
static ref EXPECTED_LUP: NewShow = {
|
static ref EXPECTED_LUP: NewPodcast = {
|
||||||
let descr = "An open show powered by community LINUX Unplugged takes the best \
|
let descr = "An open show powered by community LINUX Unplugged takes the best \
|
||||||
attributes of open collaboration and focuses them into a weekly \
|
attributes of open collaboration and focuses them into a weekly \
|
||||||
lifestyle show about Linux.";
|
lifestyle show about Linux.";
|
||||||
|
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title("LINUX Unplugged Podcast")
|
.title("LINUX Unplugged Podcast")
|
||||||
.link("http://www.jupiterbroadcasting.com/")
|
.link("http://www.jupiterbroadcasting.com/")
|
||||||
.description(descr)
|
.description(descr)
|
||||||
@@ -204,7 +192,7 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
static ref EXPECTED_TIPOFF: NewShow = {
|
static ref EXPECTED_TIPOFF: NewPodcast = {
|
||||||
let desc = "<p>Welcome to The Tip Off- the podcast where we take you behind the \
|
let desc = "<p>Welcome to The Tip Off- the podcast where we take you behind the \
|
||||||
scenes of some of the best investigative journalism from recent years. \
|
scenes of some of the best investigative journalism from recent years. \
|
||||||
Each episode we’ll be digging into an investigative scoop- hearing from \
|
Each episode we’ll be digging into an investigative scoop- hearing from \
|
||||||
@@ -215,7 +203,7 @@ mod tests {
|
|||||||
complicated detective work that goes into doing great investigative \
|
complicated detective work that goes into doing great investigative \
|
||||||
journalism- then this is the podcast for you.</p>";
|
journalism- then this is the podcast for you.</p>";
|
||||||
|
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title("The Tip Off")
|
.title("The Tip Off")
|
||||||
.link("http://www.acast.com/thetipoff")
|
.link("http://www.acast.com/thetipoff")
|
||||||
.description(desc)
|
.description(desc)
|
||||||
@@ -227,7 +215,7 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
static ref EXPECTED_STARS: NewShow = {
|
static ref EXPECTED_STARS: NewPodcast = {
|
||||||
let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars \
|
let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars \
|
||||||
is a gripping noir science fiction thriller in 14 episodes: Forbidden \
|
is a gripping noir science fiction thriller in 14 episodes: Forbidden \
|
||||||
love, a crashed UFO, an alien body, and an impossible heist unlike any \
|
love, a crashed UFO, an alien body, and an impossible heist unlike any \
|
||||||
@@ -237,7 +225,7 @@ mod tests {
|
|||||||
b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\
|
b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\
|
||||||
923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg";
|
923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg";
|
||||||
|
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title("Steal the Stars")
|
.title("Steal the Stars")
|
||||||
.link("http://tor-labs.com/")
|
.link("http://tor-labs.com/")
|
||||||
.description(descr)
|
.description(descr)
|
||||||
@@ -246,12 +234,12 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
static ref EXPECTED_CODE: NewShow = {
|
static ref EXPECTED_CODE: NewPodcast = {
|
||||||
let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, \
|
let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, \
|
||||||
David Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam \
|
David Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam \
|
||||||
Livingston-Gray. Brought to you by @therubyrep.";
|
Livingston-Gray. Brought to you by @therubyrep.";
|
||||||
|
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title("Greater Than Code")
|
.title("Greater Than Code")
|
||||||
.link("https://www.greaterthancode.com/")
|
.link("https://www.greaterthancode.com/")
|
||||||
.description(descr)
|
.description(descr)
|
||||||
@@ -262,8 +250,8 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
static ref EXPECTED_ELLINOFRENEIA: NewShow = {
|
static ref EXPECTED_ELLINOFRENEIA: NewPodcast = {
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title("Ελληνοφρένεια")
|
.title("Ελληνοφρένεια")
|
||||||
.link("https://ellinofreneia.sealabs.net/feed.rss")
|
.link("https://ellinofreneia.sealabs.net/feed.rss")
|
||||||
.description("Ανεπίσημο feed της Ελληνοφρένειας")
|
.description("Ανεπίσημο feed της Ελληνοφρένειας")
|
||||||
@@ -272,8 +260,8 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
static ref UPDATED_DESC_INTERCEPTED: NewShow = {
|
static ref UPDATED_DESC_INTERCEPTED: NewPodcast = {
|
||||||
NewShowBuilder::default()
|
NewPodcastBuilder::default()
|
||||||
.title("Intercepted with Jeremy Scahill")
|
.title("Intercepted with Jeremy Scahill")
|
||||||
.link("https://theintercept.com/podcasts")
|
.link("https://theintercept.com/podcasts")
|
||||||
.description("New Description")
|
.description("New Description")
|
||||||
@@ -293,7 +281,7 @@ mod tests {
|
|||||||
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let pd = NewShow::new(&channel, 42);
|
let pd = NewPodcast::new(&channel, 42);
|
||||||
assert_eq!(*EXPECTED_INTERCEPTED, pd);
|
assert_eq!(*EXPECTED_INTERCEPTED, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +290,7 @@ mod tests {
|
|||||||
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap();
|
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap();
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let pd = NewShow::new(&channel, 42);
|
let pd = NewPodcast::new(&channel, 42);
|
||||||
assert_eq!(*EXPECTED_LUP, pd);
|
assert_eq!(*EXPECTED_LUP, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +299,7 @@ mod tests {
|
|||||||
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap();
|
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap();
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let pd = NewShow::new(&channel, 42);
|
let pd = NewPodcast::new(&channel, 42);
|
||||||
assert_eq!(*EXPECTED_TIPOFF, pd);
|
assert_eq!(*EXPECTED_TIPOFF, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +308,7 @@ mod tests {
|
|||||||
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap();
|
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap();
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let pd = NewShow::new(&channel, 42);
|
let pd = NewPodcast::new(&channel, 42);
|
||||||
assert_eq!(*EXPECTED_STARS, pd);
|
assert_eq!(*EXPECTED_STARS, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +317,7 @@ mod tests {
|
|||||||
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap();
|
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap();
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let pd = NewShow::new(&channel, 42);
|
let pd = NewPodcast::new(&channel, 42);
|
||||||
assert_eq!(*EXPECTED_CODE, pd);
|
assert_eq!(*EXPECTED_CODE, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +326,7 @@ mod tests {
|
|||||||
let file = File::open("tests/feeds/2018-03-28-Ellinofreneia.xml").unwrap();
|
let file = File::open("tests/feeds/2018-03-28-Ellinofreneia.xml").unwrap();
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let pd = NewShow::new(&channel, 42);
|
let pd = NewPodcast::new(&channel, 42);
|
||||||
assert_eq!(*EXPECTED_ELLINOFRENEIA, pd);
|
assert_eq!(*EXPECTED_ELLINOFRENEIA, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +337,7 @@ mod tests {
|
|||||||
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||||
|
|
||||||
let npd = NewShow::new(&channel, 42);
|
let npd = NewPodcast::new(&channel, 42);
|
||||||
npd.insert().unwrap();
|
npd.insert().unwrap();
|
||||||
let pd = dbqueries::get_podcast_from_source_id(42).unwrap();
|
let pd = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||||
|
|
||||||
@@ -369,13 +357,20 @@ mod tests {
|
|||||||
|
|
||||||
let updated = &*UPDATED_DESC_INTERCEPTED;
|
let updated = &*UPDATED_DESC_INTERCEPTED;
|
||||||
updated.update(old.id()).unwrap();
|
updated.update(old.id()).unwrap();
|
||||||
let new = dbqueries::get_podcast_from_source_id(42).unwrap();
|
let mut new = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||||
|
|
||||||
assert_ne!(old, new);
|
assert_ne!(old, new);
|
||||||
assert_eq!(old.id(), new.id());
|
assert_eq!(old.id(), new.id());
|
||||||
assert_eq!(old.source_id(), new.source_id());
|
assert_eq!(old.source_id(), new.source_id());
|
||||||
assert_eq!(updated, &new);
|
assert_eq!(updated, &new);
|
||||||
assert_ne!(updated, &old);
|
assert_ne!(updated, &old);
|
||||||
|
|
||||||
|
// Chech that the update does not override user preferences.
|
||||||
|
new.set_archive(true);
|
||||||
|
new.save().unwrap();
|
||||||
|
|
||||||
|
let new2 = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||||
|
assert_eq!(true, new2.archive());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -388,14 +383,14 @@ mod tests {
|
|||||||
assert!(EXPECTED_INTERCEPTED.index().is_ok());
|
assert!(EXPECTED_INTERCEPTED.index().is_ok());
|
||||||
// Get the podcast
|
// Get the podcast
|
||||||
let old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
let old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||||
// Assert that NewShow is equal to the Indexed one
|
// Assert that NewPodcast is equal to the Indexed one
|
||||||
assert_eq!(&*EXPECTED_INTERCEPTED, &old);
|
assert_eq!(&*EXPECTED_INTERCEPTED, &old);
|
||||||
|
|
||||||
let updated = &*UPDATED_DESC_INTERCEPTED;
|
let updated = &*UPDATED_DESC_INTERCEPTED;
|
||||||
|
|
||||||
// Update the podcast
|
// Update the podcast
|
||||||
assert!(updated.index().is_ok());
|
assert!(updated.index().is_ok());
|
||||||
// Get the new Show
|
// Get the new Podcast
|
||||||
let new = dbqueries::get_podcast_from_source_id(42).unwrap();
|
let new = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||||
// Assert it's diff from the old one.
|
// Assert it's diff from the old one.
|
||||||
assert_ne!(new, old);
|
assert_ne!(new, old);
|
||||||
@@ -417,7 +412,16 @@ mod tests {
|
|||||||
let pd = EXPECTED_INTERCEPTED.to_podcast().unwrap();
|
let pd = EXPECTED_INTERCEPTED.to_podcast().unwrap();
|
||||||
// This should error as a unique constrain violation
|
// This should error as a unique constrain violation
|
||||||
assert!(EXPECTED_INTERCEPTED.insert().is_err());
|
assert!(EXPECTED_INTERCEPTED.insert().is_err());
|
||||||
|
let mut old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||||
|
assert_eq!(old, pd);
|
||||||
|
|
||||||
|
old.set_archive(true);
|
||||||
|
old.save().unwrap();
|
||||||
|
|
||||||
|
// Assert that it does not mess with user preferences
|
||||||
|
let pd = UPDATED_DESC_INTERCEPTED.to_podcast().unwrap();
|
||||||
let old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
let old = dbqueries::get_podcast_from_source_id(42).unwrap();
|
||||||
assert_eq!(old, pd);
|
assert_eq!(old, pd);
|
||||||
|
assert_eq!(old.archive(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![allow(unused_mut)]
|
||||||
|
|
||||||
use diesel;
|
use diesel;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@@ -3,37 +3,40 @@ use diesel::SaveChangesDsl;
|
|||||||
use database::connection;
|
use database::connection;
|
||||||
use errors::DataError;
|
use errors::DataError;
|
||||||
use models::{Save, Source};
|
use models::{Save, Source};
|
||||||
use schema::shows;
|
use schema::podcast;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
||||||
#[belongs_to(Source, foreign_key = "source_id")]
|
#[belongs_to(Source, foreign_key = "source_id")]
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
#[table_name = "shows"]
|
#[table_name = "podcast"]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/// Diesel Model of the shows table.
|
/// Diesel Model of the podcast table.
|
||||||
pub struct Show {
|
pub struct Podcast {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: String,
|
title: String,
|
||||||
link: String,
|
link: String,
|
||||||
description: String,
|
description: String,
|
||||||
image_uri: Option<String>,
|
image_uri: Option<String>,
|
||||||
|
favorite: bool,
|
||||||
|
archive: bool,
|
||||||
|
always_dl: bool,
|
||||||
source_id: i32,
|
source_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Save<Show> for Show {
|
impl Save<Podcast, DataError> for Podcast {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
/// Helper method to easily save/"sync" current state of self to the
|
/// Helper method to easily save/"sync" current state of self to the
|
||||||
/// Database.
|
/// Database.
|
||||||
fn save(&self) -> Result<Show, Self::Error> {
|
fn save(&self) -> Result<Podcast, DataError> {
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let tempdb = db.get()?;
|
let tempdb = db.get()?;
|
||||||
|
|
||||||
self.save_changes::<Show>(&*tempdb).map_err(From::from)
|
self.save_changes::<Podcast>(&*tempdb).map_err(From::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Show {
|
impl Podcast {
|
||||||
/// Get the Feed `id`.
|
/// Get the Feed `id`.
|
||||||
pub fn id(&self) -> i32 {
|
pub fn id(&self) -> i32 {
|
||||||
self.id
|
self.id
|
||||||
@@ -51,7 +54,7 @@ impl Show {
|
|||||||
&self.link
|
&self.link
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the Show/Feed `link`.
|
/// Set the Podcast/Feed `link`.
|
||||||
pub fn set_link(&mut self, value: &str) {
|
pub fn set_link(&mut self, value: &str) {
|
||||||
self.link = value.to_string();
|
self.link = value.to_string();
|
||||||
}
|
}
|
||||||
@@ -78,6 +81,41 @@ impl Show {
|
|||||||
self.image_uri = value.map(|x| x.to_string());
|
self.image_uri = value.map(|x| x.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents the archiving policy for the episode.
|
||||||
|
pub fn archive(&self) -> bool {
|
||||||
|
self.archive
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the `archive` policy.
|
||||||
|
pub fn set_archive(&mut self, b: bool) {
|
||||||
|
self.archive = b
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the `favorite` status of the `Podcast` Feed.
|
||||||
|
pub fn favorite(&self) -> bool {
|
||||||
|
self.favorite
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set `favorite` status.
|
||||||
|
pub fn set_favorite(&mut self, b: bool) {
|
||||||
|
self.favorite = b
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Represents the download policy for the `Podcast` Feed.
|
||||||
|
///
|
||||||
|
/// Reserved for the use with a Download manager, yet to be implemented.
|
||||||
|
///
|
||||||
|
/// If true Podcast Episode should be downloaded automaticly/skipping
|
||||||
|
/// the selection queue.
|
||||||
|
pub fn always_download(&self) -> bool {
|
||||||
|
self.always_dl
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the download policy.
|
||||||
|
pub fn set_always_download(&mut self, b: bool) {
|
||||||
|
self.always_dl = b
|
||||||
|
}
|
||||||
|
|
||||||
/// `Source` table foreign key.
|
/// `Source` table foreign key.
|
||||||
pub fn source_id(&self) -> i32 {
|
pub fn source_id(&self) -> i32 {
|
||||||
self.source_id
|
self.source_id
|
||||||
@@ -85,17 +123,17 @@ impl Show {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Debug, Clone)]
|
#[derive(Queryable, Debug, Clone)]
|
||||||
/// Diesel Model of the Show cover query.
|
/// Diesel Model of the podcast cover query.
|
||||||
/// Used for fetching information about a Show's cover.
|
/// Used for fetching information about a Podcast's cover.
|
||||||
pub struct ShowCoverModel {
|
pub struct PodcastCoverQuery {
|
||||||
id: i32,
|
id: i32,
|
||||||
title: String,
|
title: String,
|
||||||
image_uri: Option<String>,
|
image_uri: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Show> for ShowCoverModel {
|
impl From<Podcast> for PodcastCoverQuery {
|
||||||
fn from(p: Show) -> ShowCoverModel {
|
fn from(p: Podcast) -> PodcastCoverQuery {
|
||||||
ShowCoverModel {
|
PodcastCoverQuery {
|
||||||
id: p.id(),
|
id: p.id(),
|
||||||
title: p.title,
|
title: p.title,
|
||||||
image_uri: p.image_uri,
|
image_uri: p.image_uri,
|
||||||
@@ -103,7 +141,17 @@ impl From<Show> for ShowCoverModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShowCoverModel {
|
impl From<Arc<Podcast>> for PodcastCoverQuery {
|
||||||
|
fn from(p: Arc<Podcast>) -> PodcastCoverQuery {
|
||||||
|
PodcastCoverQuery {
|
||||||
|
id: p.id(),
|
||||||
|
title: p.title.clone(),
|
||||||
|
image_uri: p.image_uri.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PodcastCoverQuery {
|
||||||
/// Get the Feed `id`.
|
/// Get the Feed `id`.
|
||||||
pub fn id(&self) -> i32 {
|
pub fn id(&self) -> i32 {
|
||||||
self.id
|
self.id
|
||||||
@@ -3,23 +3,20 @@ use diesel::SaveChangesDsl;
|
|||||||
use rss::Channel;
|
use rss::Channel;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use hyper::client::HttpConnector;
|
|
||||||
use hyper::header::{
|
|
||||||
ETag, EntityTag, HttpDate, IfModifiedSince, IfNoneMatch, LastModified, Location, UserAgent,
|
|
||||||
};
|
|
||||||
use hyper::{Client, Method, Request, Response, StatusCode, Uri};
|
use hyper::{Client, Method, Request, Response, StatusCode, Uri};
|
||||||
|
use hyper::client::HttpConnector;
|
||||||
|
use hyper::header::{ETag, EntityTag, HttpDate, IfModifiedSince, IfNoneMatch, LastModified,
|
||||||
|
Location, UserAgent};
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
// use futures::future::ok;
|
// use futures::future::ok;
|
||||||
use futures::future::{loop_fn, Future, Loop};
|
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
|
|
||||||
use database::connection;
|
use database::connection;
|
||||||
use errors::*;
|
use errors::DataError;
|
||||||
use feed::{Feed, FeedBuilder};
|
use feed::{Feed, FeedBuilder};
|
||||||
use models::{NewSource, Save};
|
use models::{NewSource, Save};
|
||||||
use schema::source;
|
use schema::source;
|
||||||
use USER_AGENT;
|
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
@@ -35,12 +32,10 @@ pub struct Source {
|
|||||||
http_etag: Option<String>,
|
http_etag: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Save<Source> for Source {
|
impl Save<Source, DataError> for Source {
|
||||||
type Error = DataError;
|
|
||||||
|
|
||||||
/// Helper method to easily save/"sync" current state of self to the
|
/// Helper method to easily save/"sync" current state of self to the
|
||||||
/// Database.
|
/// Database.
|
||||||
fn save(&self) -> Result<Source, Self::Error> {
|
fn save(&self) -> Result<Source, DataError> {
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
|
|
||||||
@@ -107,7 +102,11 @@ impl Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn make_err(self, context: &str, code: StatusCode) -> DataError {
|
fn make_err(self, context: &str, code: StatusCode) -> DataError {
|
||||||
DataError::HttpStatusGeneral(HttpStatusError::new(self.uri, code, context.into()))
|
DataError::HttpStatusError {
|
||||||
|
url: self.uri,
|
||||||
|
status_code: code,
|
||||||
|
context: context.into(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO match on more stuff
|
// TODO match on more stuff
|
||||||
@@ -120,7 +119,7 @@ impl Source {
|
|||||||
// 408: Timeout
|
// 408: Timeout
|
||||||
// 410: Feed deleted
|
// 410: Feed deleted
|
||||||
// TODO: Rething this api,
|
// TODO: Rething this api,
|
||||||
fn match_status(mut self, res: Response) -> Result<Response, DataError> {
|
fn match_status(mut self, res: Response) -> Result<(Self, Response), DataError> {
|
||||||
self.update_etag(&res)?;
|
self.update_etag(&res)?;
|
||||||
let code = res.status();
|
let code = res.status();
|
||||||
|
|
||||||
@@ -129,7 +128,7 @@ impl Source {
|
|||||||
StatusCode::MovedPermanently => {
|
StatusCode::MovedPermanently => {
|
||||||
error!("Feed was moved permanently.");
|
error!("Feed was moved permanently.");
|
||||||
self.handle_301(&res)?;
|
self.handle_301(&res)?;
|
||||||
return Err(DataError::F301(self));
|
return Err(self.make_err("301: Feed was moved permanently.", code));
|
||||||
}
|
}
|
||||||
StatusCode::TemporaryRedirect => debug!("307: Temporary Redirect."),
|
StatusCode::TemporaryRedirect => debug!("307: Temporary Redirect."),
|
||||||
StatusCode::PermanentRedirect => warn!("308: Permanent Redirect."),
|
StatusCode::PermanentRedirect => warn!("308: Permanent Redirect."),
|
||||||
@@ -140,7 +139,7 @@ impl Source {
|
|||||||
StatusCode::Gone => return Err(self.make_err("410: Feed was deleted..", code)),
|
StatusCode::Gone => return Err(self.make_err("410: Feed was deleted..", code)),
|
||||||
_ => info!("HTTP StatusCode: {}", code),
|
_ => info!("HTTP StatusCode: {}", code),
|
||||||
};
|
};
|
||||||
Ok(res)
|
Ok((self, res))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_301(&mut self, res: &Response) -> Result<(), DataError> {
|
fn handle_301(&mut self, res: &Response) -> Result<(), DataError> {
|
||||||
@@ -152,6 +151,8 @@ impl Source {
|
|||||||
self.last_modified = None;
|
self.last_modified = None;
|
||||||
self.save()?;
|
self.save()?;
|
||||||
info!("Feed url was updated succesfully.");
|
info!("Feed url was updated succesfully.");
|
||||||
|
// TODO: Refresh in place instead of next time, Not a priority.
|
||||||
|
info!("New content will be fetched with the next refesh.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -176,34 +177,21 @@ impl Source {
|
|||||||
// Refactor into TryInto once it lands on stable.
|
// Refactor into TryInto once it lands on stable.
|
||||||
pub fn into_feed(
|
pub fn into_feed(
|
||||||
self,
|
self,
|
||||||
client: Client<HttpsConnector<HttpConnector>>,
|
client: &Client<HttpsConnector<HttpConnector>>,
|
||||||
ignore_etags: bool,
|
ignore_etags: bool,
|
||||||
) -> impl Future<Item = Feed, Error = DataError> {
|
) -> Box<Future<Item = Feed, Error = DataError>> {
|
||||||
let id = self.id();
|
let id = self.id();
|
||||||
let response = loop_fn(self, move |source| {
|
let feed = self.request_constructor(client, ignore_etags)
|
||||||
source
|
.and_then(move |(_, res)| response_to_channel(res))
|
||||||
.request_constructor(&client.clone(), ignore_etags)
|
|
||||||
.then(|res| match res {
|
|
||||||
Ok(response) => Ok(Loop::Break(response)),
|
|
||||||
Err(err) => match err {
|
|
||||||
DataError::F301(s) => {
|
|
||||||
info!("Following redirect...");
|
|
||||||
Ok(Loop::Continue(s))
|
|
||||||
}
|
|
||||||
e => Err(e),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
response
|
|
||||||
.and_then(response_to_channel)
|
|
||||||
.and_then(move |chan| {
|
.and_then(move |chan| {
|
||||||
FeedBuilder::default()
|
FeedBuilder::default()
|
||||||
.channel(chan)
|
.channel(chan)
|
||||||
.source_id(id)
|
.source_id(id)
|
||||||
.build()
|
.build()
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
})
|
});
|
||||||
|
|
||||||
|
Box::new(feed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make ignore_etags an Enum for better ergonomics.
|
// TODO: make ignore_etags an Enum for better ergonomics.
|
||||||
@@ -212,43 +200,51 @@ impl Source {
|
|||||||
self,
|
self,
|
||||||
client: &Client<HttpsConnector<HttpConnector>>,
|
client: &Client<HttpsConnector<HttpConnector>>,
|
||||||
ignore_etags: bool,
|
ignore_etags: bool,
|
||||||
) -> impl Future<Item = Response, Error = DataError> {
|
) -> Box<Future<Item = (Self, Response), Error = DataError>> {
|
||||||
// FIXME: remove unwrap somehow
|
// FIXME: remove unwrap somehow
|
||||||
let uri = Uri::from_str(self.uri()).unwrap();
|
let uri = Uri::from_str(self.uri()).unwrap();
|
||||||
let mut req = Request::new(Method::Get, uri);
|
let mut req = Request::new(Method::Get, uri);
|
||||||
|
|
||||||
// Set the UserAgent cause ppl still seem to check it for some reason...
|
// Set the user agent as a fix for issue #53
|
||||||
req.headers_mut().set(UserAgent::new(USER_AGENT));
|
// TODO: keep this in sync with tor-browser releases
|
||||||
|
req.headers_mut().set(UserAgent::new(
|
||||||
|
"Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0",
|
||||||
|
));
|
||||||
|
|
||||||
if !ignore_etags {
|
if !ignore_etags {
|
||||||
if let Some(etag) = self.http_etag() {
|
if let Some(foo) = self.http_etag() {
|
||||||
let tag = vec![EntityTag::new(true, etag.to_owned())];
|
req.headers_mut().set(IfNoneMatch::Items(vec![
|
||||||
req.headers_mut().set(IfNoneMatch::Items(tag));
|
EntityTag::new(true, foo.to_owned()),
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(lmod) = self.last_modified() {
|
if let Some(foo) = self.last_modified() {
|
||||||
if let Ok(date) = lmod.parse::<HttpDate>() {
|
if let Ok(x) = foo.parse::<HttpDate>() {
|
||||||
req.headers_mut().set(IfModifiedSince(date));
|
req.headers_mut().set(IfModifiedSince(x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client
|
let work = client
|
||||||
.request(req)
|
.request(req)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
.and_then(move |res| self.match_status(res))
|
// TODO: tail recursion loop that would follow redirects directly
|
||||||
|
.and_then(move |res| self.match_status(res));
|
||||||
|
Box::new(work)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(needless_pass_by_value)]
|
#[allow(needless_pass_by_value)]
|
||||||
fn response_to_channel(res: Response) -> impl Future<Item = Channel, Error = DataError> + Send {
|
fn response_to_channel(res: Response) -> Box<Future<Item = Channel, Error = DataError> + Send> {
|
||||||
res.body()
|
let chan = res.body()
|
||||||
.concat2()
|
.concat2()
|
||||||
.map(|x| x.into_iter())
|
.map(|x| x.into_iter())
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
.map(|iter| iter.collect::<Vec<u8>>())
|
.map(|iter| iter.collect::<Vec<u8>>())
|
||||||
.map(|utf_8_bytes| String::from_utf8_lossy(&utf_8_bytes).into_owned())
|
.map(|utf_8_bytes| String::from_utf8_lossy(&utf_8_bytes).into_owned())
|
||||||
.and_then(|buf| Channel::from_str(&buf).map_err(From::from))
|
.and_then(|buf| Channel::from_str(&buf).map_err(From::from));
|
||||||
|
|
||||||
|
Box::new(chan)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -273,7 +269,7 @@ mod tests {
|
|||||||
let source = Source::from_url(url).unwrap();
|
let source = Source::from_url(url).unwrap();
|
||||||
let id = source.id();
|
let id = source.id();
|
||||||
|
|
||||||
let feed = source.into_feed(client, true);
|
let feed = source.into_feed(&client, true);
|
||||||
let feed = core.run(feed).unwrap();
|
let feed = core.run(feed).unwrap();
|
||||||
|
|
||||||
let expected = get_feed("tests/feeds/2018-01-20-Intercepted.xml", id);
|
let expected = get_feed("tests/feeds/2018-01-20-Intercepted.xml", id);
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
// FIXME:
|
||||||
|
//! Docs.
|
||||||
|
|
||||||
|
use futures::future::*;
|
||||||
|
// use futures::prelude::*;
|
||||||
|
|
||||||
|
use hyper::Client;
|
||||||
|
use hyper::client::HttpConnector;
|
||||||
|
use hyper_tls::HttpsConnector;
|
||||||
|
use tokio_core::reactor::Core;
|
||||||
|
|
||||||
|
use num_cpus;
|
||||||
|
use rss;
|
||||||
|
|
||||||
|
use Source;
|
||||||
|
use dbqueries;
|
||||||
|
use errors::DataError;
|
||||||
|
use models::{IndexState, NewEpisode, NewEpisodeMinimal};
|
||||||
|
|
||||||
|
// use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
/// The pipline to be run for indexing and updating a Podcast feed that originates from
|
||||||
|
/// `Source.uri`.
|
||||||
|
///
|
||||||
|
/// Messy temp diagram:
|
||||||
|
/// Source -> GET Request -> Update Etags -> Check Status -> Parse xml/Rss ->
|
||||||
|
/// Convert `rss::Channel` into Feed -> Index Podcast -> Index Episodes.
|
||||||
|
pub fn pipeline<S: IntoIterator<Item = Source>>(
|
||||||
|
sources: S,
|
||||||
|
ignore_etags: bool,
|
||||||
|
tokio_core: &mut Core,
|
||||||
|
client: Client<HttpsConnector<HttpConnector>>,
|
||||||
|
) -> Result<(), DataError> {
|
||||||
|
let list: Vec<_> = sources
|
||||||
|
.into_iter()
|
||||||
|
.map(move |s| s.into_feed(&client, ignore_etags))
|
||||||
|
.map(|fut| fut.and_then(|feed| feed.index()))
|
||||||
|
.map(|fut| fut.map(|_| ()).map_err(|err| error!("Error: {}", err)))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if list.is_empty() {
|
||||||
|
return Err(DataError::EmptyFuturesList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thats not really concurrent yet I think.
|
||||||
|
tokio_core.run(collect_futures(list))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a tokio `reactor::Core`, and a `hyper::Client` and
|
||||||
|
/// runs the pipeline.
|
||||||
|
pub fn run(sources: Vec<Source>, ignore_etags: bool) -> Result<(), DataError> {
|
||||||
|
if sources.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut core = Core::new()?;
|
||||||
|
let handle = core.handle();
|
||||||
|
let client = Client::configure()
|
||||||
|
.connector(HttpsConnector::new(num_cpus::get(), &handle)?)
|
||||||
|
.build(&handle);
|
||||||
|
|
||||||
|
pipeline(sources, ignore_etags, &mut core, client)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Docs
|
||||||
|
pub fn index_single_source(s: Source, ignore_etags: bool) -> Result<(), DataError> {
|
||||||
|
let mut core = Core::new()?;
|
||||||
|
let handle = core.handle();
|
||||||
|
|
||||||
|
let client = Client::configure()
|
||||||
|
.connector(HttpsConnector::new(num_cpus::get(), &handle)?)
|
||||||
|
.build(&handle);
|
||||||
|
|
||||||
|
let work = s.into_feed(&client, ignore_etags)
|
||||||
|
.and_then(move |feed| feed.index())
|
||||||
|
.map(|_| ());
|
||||||
|
|
||||||
|
core.run(work)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn determine_ep_state(
|
||||||
|
ep: NewEpisodeMinimal,
|
||||||
|
item: &rss::Item,
|
||||||
|
) -> Result<IndexState<NewEpisode>, DataError> {
|
||||||
|
// Check if feed exists
|
||||||
|
let exists = dbqueries::episode_exists(ep.title(), ep.podcast_id())?;
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
Ok(IndexState::Index(ep.into_new_episode(item)))
|
||||||
|
} else {
|
||||||
|
let old = dbqueries::get_episode_minimal_from_pk(ep.title(), ep.podcast_id())?;
|
||||||
|
let rowid = old.rowid();
|
||||||
|
|
||||||
|
if ep != old {
|
||||||
|
Ok(IndexState::Update((ep.into_new_episode(item), rowid)))
|
||||||
|
} else {
|
||||||
|
Ok(IndexState::NotChanged)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn glue_async<'a>(
|
||||||
|
item: &'a rss::Item,
|
||||||
|
id: i32,
|
||||||
|
) -> Box<Future<Item = IndexState<NewEpisode>, Error = DataError> + 'a> {
|
||||||
|
Box::new(
|
||||||
|
result(NewEpisodeMinimal::new(item, id)).and_then(move |ep| determine_ep_state(ep, item)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Weird magic from #rust irc channel
|
||||||
|
// kudos to remexre
|
||||||
|
/// FIXME: Docs
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
|
pub fn collect_futures<F>(
|
||||||
|
futures: Vec<F>,
|
||||||
|
) -> Box<Future<Item = Vec<Result<F::Item, F::Error>>, Error = DataError>>
|
||||||
|
where
|
||||||
|
F: 'static + Future,
|
||||||
|
<F as Future>::Item: 'static,
|
||||||
|
<F as Future>::Error: 'static,
|
||||||
|
{
|
||||||
|
Box::new(loop_fn((futures, vec![]), |(futures, mut done)| {
|
||||||
|
select_all(futures).then(|r| {
|
||||||
|
let (r, rest) = match r {
|
||||||
|
Ok((r, _, rest)) => (Ok(r), rest),
|
||||||
|
Err((r, _, rest)) => (Err(r), rest),
|
||||||
|
};
|
||||||
|
done.push(r);
|
||||||
|
if rest.is_empty() {
|
||||||
|
Ok(Loop::Break(done))
|
||||||
|
} else {
|
||||||
|
Ok(Loop::Continue((rest, done)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use Source;
|
||||||
|
use database::truncate_db;
|
||||||
|
|
||||||
|
// (path, url) tuples.
|
||||||
|
const URLS: &[(&str, &str)] = {
|
||||||
|
&[
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-Intercepted.xml",
|
||||||
|
"https://web.archive.org/web/20180120083840if_/https://feeds.feedburner.\
|
||||||
|
com/InterceptedWithJeremyScahill",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-LinuxUnplugged.xml",
|
||||||
|
"https://web.archive.org/web/20180120110314if_/https://feeds.feedburner.\
|
||||||
|
com/linuxunplugged",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-TheTipOff.xml",
|
||||||
|
"https://web.archive.org/web/20180120110727if_/https://rss.acast.com/thetipoff",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-StealTheStars.xml",
|
||||||
|
"https://web.archive.org/web/20180120104957if_/https://rss.art19.\
|
||||||
|
com/steal-the-stars",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"tests/feeds/2018-01-20-GreaterThanCode.xml",
|
||||||
|
"https://web.archive.org/web/20180120104741if_/https://www.greaterthancode.\
|
||||||
|
com/feed/podcast",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
/// Insert feeds and update/index them.
|
||||||
|
fn test_pipeline() {
|
||||||
|
truncate_db().unwrap();
|
||||||
|
URLS.iter().for_each(|&(_, url)| {
|
||||||
|
// Index the urls into the source table.
|
||||||
|
Source::from_url(url).unwrap();
|
||||||
|
});
|
||||||
|
let sources = dbqueries::get_sources().unwrap();
|
||||||
|
run(sources, true).unwrap();
|
||||||
|
|
||||||
|
let sources = dbqueries::get_sources().unwrap();
|
||||||
|
// Run again to cover Unique constrains erros.
|
||||||
|
run(sources, true).unwrap();
|
||||||
|
|
||||||
|
// Assert the index rows equal the controlled results
|
||||||
|
assert_eq!(dbqueries::get_sources().unwrap().len(), 5);
|
||||||
|
assert_eq!(dbqueries::get_podcasts().unwrap().len(), 5);
|
||||||
|
assert_eq!(dbqueries::get_episodes().unwrap().len(), 354);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#![allow(warnings)]
|
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
episodes (title, show_id) {
|
episode (title, podcast_id) {
|
||||||
rowid -> Integer,
|
rowid -> Integer,
|
||||||
title -> Text,
|
title -> Text,
|
||||||
uri -> Nullable<Text>,
|
uri -> Nullable<Text>,
|
||||||
@@ -12,17 +10,22 @@ table! {
|
|||||||
duration -> Nullable<Integer>,
|
duration -> Nullable<Integer>,
|
||||||
guid -> Nullable<Text>,
|
guid -> Nullable<Text>,
|
||||||
played -> Nullable<Integer>,
|
played -> Nullable<Integer>,
|
||||||
show_id -> Integer,
|
favorite -> Bool,
|
||||||
|
archive -> Bool,
|
||||||
|
podcast_id -> Integer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
shows (id) {
|
podcast (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
title -> Text,
|
title -> Text,
|
||||||
link -> Text,
|
link -> Text,
|
||||||
description -> Text,
|
description -> Text,
|
||||||
image_uri -> Nullable<Text>,
|
image_uri -> Nullable<Text>,
|
||||||
|
favorite -> Bool,
|
||||||
|
archive -> Bool,
|
||||||
|
always_dl -> Bool,
|
||||||
source_id -> Integer,
|
source_id -> Integer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,4 +39,4 @@ table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(episodes, shows, source);
|
allow_tables_to_appear_in_same_query!(episode, podcast, source,);
|
||||||
@@ -7,7 +7,7 @@ use url::{Position, Url};
|
|||||||
|
|
||||||
use dbqueries;
|
use dbqueries;
|
||||||
use errors::DataError;
|
use errors::DataError;
|
||||||
use models::{EpisodeCleanerModel, Save, Show};
|
use models::{EpisodeCleanerQuery, Podcast, Save};
|
||||||
use xdg_dirs::DL_DIR;
|
use xdg_dirs::DL_DIR;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@@ -28,10 +28,10 @@ fn download_checker() -> Result<(), DataError> {
|
|||||||
})
|
})
|
||||||
.for_each(|ep| {
|
.for_each(|ep| {
|
||||||
ep.set_local_uri(None);
|
ep.set_local_uri(None);
|
||||||
ep.save()
|
if let Err(err) = ep.save() {
|
||||||
.map_err(|err| error!("{}", err))
|
error!("Error while trying to update episode: {:#?}", ep);
|
||||||
.map_err(|_| error!("Error while trying to update episode: {:#?}", ep))
|
error!("{}", err);
|
||||||
.ok();
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -48,18 +48,19 @@ fn played_cleaner(cleanup_date: DateTime<Utc>) -> Result<(), DataError> {
|
|||||||
.for_each(|ep| {
|
.for_each(|ep| {
|
||||||
let limit = ep.played().unwrap();
|
let limit = ep.played().unwrap();
|
||||||
if now_utc > limit {
|
if now_utc > limit {
|
||||||
delete_local_content(ep)
|
if let Err(err) = delete_local_content(ep) {
|
||||||
.map(|_| info!("Episode {:?} was deleted succesfully.", ep.local_uri()))
|
error!("Error while trying to delete file: {:?}", ep.local_uri());
|
||||||
.map_err(|err| error!("Error: {}", err))
|
error!("{}", err);
|
||||||
.map_err(|_| error!("Failed to delete file: {:?}", ep.local_uri()))
|
} else {
|
||||||
.ok();
|
info!("Episode {:?} was deleted succesfully.", ep.local_uri());
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check `ep.local_uri` field and delete the file it points to.
|
/// Check `ep.local_uri` field and delete the file it points to.
|
||||||
fn delete_local_content(ep: &mut EpisodeCleanerModel) -> Result<(), DataError> {
|
fn delete_local_content(ep: &mut EpisodeCleanerQuery) -> Result<(), DataError> {
|
||||||
if ep.local_uri().is_some() {
|
if ep.local_uri().is_some() {
|
||||||
let uri = ep.local_uri().unwrap().to_owned();
|
let uri = ep.local_uri().unwrap().to_owned();
|
||||||
if Path::new(&uri).exists() {
|
if Path::new(&uri).exists() {
|
||||||
@@ -108,9 +109,9 @@ pub fn url_cleaner(s: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the URI of a Show Downloads given it's title.
|
/// Returns the URI of a Podcast Downloads given it's title.
|
||||||
pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> {
|
pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> {
|
||||||
// It might be better to make it a hash of the title or the Show rowid
|
// It might be better to make it a hash of the title or the podcast rowid
|
||||||
let download_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), pd_title);
|
let download_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), pd_title);
|
||||||
|
|
||||||
// Create the folder
|
// Create the folder
|
||||||
@@ -123,7 +124,7 @@ pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> {
|
|||||||
/// Removes all the entries associated with the given show from the database,
|
/// Removes all the entries associated with the given show from the database,
|
||||||
/// and deletes all of the downloaded content.
|
/// and deletes all of the downloaded content.
|
||||||
// TODO: Write Tests
|
// TODO: Write Tests
|
||||||
pub fn delete_show(pd: &Show) -> Result<(), DataError> {
|
pub fn delete_show(pd: &Podcast) -> Result<(), DataError> {
|
||||||
dbqueries::remove_feed(pd)?;
|
dbqueries::remove_feed(pd)?;
|
||||||
info!("{} was removed succesfully.", pd.title());
|
info!("{} was removed succesfully.", pd.title());
|
||||||
|
|
||||||
@@ -174,7 +175,7 @@ mod tests {
|
|||||||
// Clean the db
|
// Clean the db
|
||||||
truncate_db().unwrap();
|
truncate_db().unwrap();
|
||||||
// Setup tmp file stuff
|
// Setup tmp file stuff
|
||||||
let tmp_dir = TempDir::new("podcasts_test").unwrap();
|
let tmp_dir = TempDir::new("hammond_test").unwrap();
|
||||||
let valid_path = tmp_dir.path().join("virtual_dl.mp3");
|
let valid_path = tmp_dir.path().join("virtual_dl.mp3");
|
||||||
let bad_path = tmp_dir.path().join("invalid_thing.mp3");
|
let bad_path = tmp_dir.path().join("invalid_thing.mp3");
|
||||||
let mut tmp_file = File::create(&valid_path).unwrap();
|
let mut tmp_file = File::create(&valid_path).unwrap();
|
||||||
@@ -183,7 +184,7 @@ mod tests {
|
|||||||
// Setup episodes
|
// Setup episodes
|
||||||
let n1 = NewEpisodeBuilder::default()
|
let n1 = NewEpisodeBuilder::default()
|
||||||
.title("foo_bar".to_string())
|
.title("foo_bar".to_string())
|
||||||
.show_id(0)
|
.podcast_id(0)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_episode()
|
.to_episode()
|
||||||
@@ -191,14 +192,14 @@ mod tests {
|
|||||||
|
|
||||||
let n2 = NewEpisodeBuilder::default()
|
let n2 = NewEpisodeBuilder::default()
|
||||||
.title("bar_baz".to_string())
|
.title("bar_baz".to_string())
|
||||||
.show_id(1)
|
.podcast_id(1)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_episode()
|
.to_episode()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut ep1 = dbqueries::get_episode_from_pk(n1.title(), n1.show_id()).unwrap();
|
let mut ep1 = dbqueries::get_episode_from_pk(n1.title(), n1.podcast_id()).unwrap();
|
||||||
let mut ep2 = dbqueries::get_episode_from_pk(n2.title(), n2.show_id()).unwrap();
|
let mut ep2 = dbqueries::get_episode_from_pk(n2.title(), n2.podcast_id()).unwrap();
|
||||||
ep1.set_local_uri(Some(valid_path.to_str().unwrap()));
|
ep1.set_local_uri(Some(valid_path.to_str().unwrap()));
|
||||||
ep2.set_local_uri(Some(bad_path.to_str().unwrap()));
|
ep2.set_local_uri(Some(bad_path.to_str().unwrap()));
|
||||||
|
|
||||||
@@ -230,7 +231,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_download_cleaner() {
|
fn test_download_cleaner() {
|
||||||
let _tmp_dir = helper_db();
|
let _tmp_dir = helper_db();
|
||||||
let mut episode: EpisodeCleanerModel =
|
let mut episode: EpisodeCleanerQuery =
|
||||||
dbqueries::get_episode_from_pk("foo_bar", 0).unwrap().into();
|
dbqueries::get_episode_from_pk("foo_bar", 0).unwrap().into();
|
||||||
|
|
||||||
let valid_path = episode.local_uri().unwrap().to_owned();
|
let valid_path = episode.local_uri().unwrap().to_owned();
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||||
name = "podcasts-downloader"
|
name = "hammond-downloader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
workspace = "../"
|
workspace = "../"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
error-chain = "0.12.0"
|
error-chain = "0.11.0"
|
||||||
hyper = "0.11.27"
|
hyper = "0.11.24"
|
||||||
log = "0.4.3"
|
log = "0.4.1"
|
||||||
mime_guess = "1.8.6"
|
mime_guess = "1.8.4"
|
||||||
reqwest = "0.8.6"
|
reqwest = "0.8.5"
|
||||||
tempdir = "0.3.7"
|
tempdir = "0.3.7"
|
||||||
glob = "0.2.11"
|
glob = "0.2.11"
|
||||||
failure = "0.1.1"
|
failure = "0.1.1"
|
||||||
failure_derive = "0.1.1"
|
failure_derive = "0.1.1"
|
||||||
|
|
||||||
[dependencies.podcasts-data]
|
[dependencies.hammond-data]
|
||||||
path = "../podcasts-data"
|
path = "../hammond-data"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = "0.5.1"
|
pretty_assertions = "0.5.1"
|
||||||
@@ -11,8 +11,8 @@ use std::io::{BufWriter, Read, Write};
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use podcasts_data::xdg_dirs::PODCASTS_CACHE;
|
use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery, Save};
|
||||||
use podcasts_data::{EpisodeWidgetModel, Save, ShowCoverModel};
|
use hammond_data::xdg_dirs::HAMMOND_CACHE;
|
||||||
|
|
||||||
// use failure::Error;
|
// use failure::Error;
|
||||||
use errors::DownloadError;
|
use errors::DownloadError;
|
||||||
@@ -78,7 +78,7 @@ fn download_into(
|
|||||||
// Construct a temp file to save desired content.
|
// Construct a temp file to save desired content.
|
||||||
// It has to be a `new_in` instead of new cause rename can't move cross
|
// It has to be a `new_in` instead of new cause rename can't move cross
|
||||||
// filesystems.
|
// filesystems.
|
||||||
let tempdir = TempDir::new_in(PODCASTS_CACHE.to_str().unwrap(), "temp_download")?;
|
let tempdir = TempDir::new_in(HAMMOND_CACHE.to_str().unwrap(), "temp_download")?;
|
||||||
let out_file = format!("{}/temp.part", tempdir.path().to_str().unwrap(),);
|
let out_file = format!("{}/temp.part", tempdir.path().to_str().unwrap(),);
|
||||||
|
|
||||||
ct_len.map(|x| {
|
ct_len.map(|x| {
|
||||||
@@ -127,7 +127,7 @@ fn save_io(
|
|||||||
info!("Downloading into: {}", file);
|
info!("Downloading into: {}", file);
|
||||||
let chunk_size = match content_lenght {
|
let chunk_size = match content_lenght {
|
||||||
Some(x) => x as usize / 99,
|
Some(x) => x as usize / 99,
|
||||||
None => 1024, // default chunk size
|
None => 1024 as usize, // default chunk size
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = BufWriter::new(File::create(&file)?);
|
let mut writer = BufWriter::new(File::create(&file)?);
|
||||||
@@ -161,7 +161,7 @@ fn save_io(
|
|||||||
|
|
||||||
// TODO: Refactor
|
// TODO: Refactor
|
||||||
pub fn get_episode(
|
pub fn get_episode(
|
||||||
ep: &mut EpisodeWidgetModel,
|
ep: &mut EpisodeWidgetQuery,
|
||||||
download_folder: &str,
|
download_folder: &str,
|
||||||
progress: Option<Arc<Mutex<DownloadProgress>>>,
|
progress: Option<Arc<Mutex<DownloadProgress>>>,
|
||||||
) -> Result<(), DownloadError> {
|
) -> Result<(), DownloadError> {
|
||||||
@@ -196,9 +196,8 @@ pub fn get_episode(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cache_image(pd: &ShowCoverModel) -> Result<String, DownloadError> {
|
pub fn cache_image(pd: &PodcastCoverQuery) -> Result<String, DownloadError> {
|
||||||
let url = pd
|
let url = pd.image_uri()
|
||||||
.image_uri()
|
|
||||||
.ok_or_else(|| DownloadError::NoImageLocation)?
|
.ok_or_else(|| DownloadError::NoImageLocation)?
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
@@ -206,7 +205,7 @@ pub fn cache_image(pd: &ShowCoverModel) -> Result<String, DownloadError> {
|
|||||||
return Err(DownloadError::NoImageLocation);
|
return Err(DownloadError::NoImageLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
let cache_path = PODCASTS_CACHE
|
let cache_path = HAMMOND_CACHE
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or_else(|| DownloadError::InvalidCacheLocation)?;
|
.ok_or_else(|| DownloadError::InvalidCacheLocation)?;
|
||||||
let cache_download_fold = format!("{}{}", cache_path, pd.title().to_owned());
|
let cache_download_fold = format!("{}{}", cache_path, pd.title().to_owned());
|
||||||
@@ -216,8 +215,7 @@ pub fn cache_image(pd: &ShowCoverModel) -> Result<String, DownloadError> {
|
|||||||
// For some reason there is no .first() method so nth(0) is used
|
// For some reason there is no .first() method so nth(0) is used
|
||||||
let path = foo.nth(0).and_then(|x| x.ok());
|
let path = foo.nth(0).and_then(|x| x.ok());
|
||||||
if let Some(p) = path {
|
if let Some(p) = path {
|
||||||
return Ok(p
|
return Ok(p.to_str()
|
||||||
.to_str()
|
|
||||||
.ok_or_else(|| DownloadError::InvalidCachedImageLocation)?
|
.ok_or_else(|| DownloadError::InvalidCachedImageLocation)?
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
@@ -236,14 +234,14 @@ pub fn cache_image(pd: &ShowCoverModel) -> Result<String, DownloadError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use podcasts_data::dbqueries;
|
use hammond_data::Source;
|
||||||
use podcasts_data::pipeline;
|
use hammond_data::dbqueries;
|
||||||
use podcasts_data::Source;
|
use hammond_data::pipeline;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
// This test inserts an rss feed to your `XDG_DATA/podcasts/podcasts.db` so we make it explicit
|
// This test inserts an rss feed to your `XDG_DATA/hammond/hammond.db` so we make it explicit
|
||||||
// to run it.
|
// to run it.
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn test_cache_image() {
|
fn test_cache_image() {
|
||||||
@@ -261,7 +259,7 @@ mod tests {
|
|||||||
let img_path = cache_image(&pd);
|
let img_path = cache_image(&pd);
|
||||||
let foo_ = format!(
|
let foo_ = format!(
|
||||||
"{}{}/cover.jpeg",
|
"{}{}/cover.jpeg",
|
||||||
PODCASTS_CACHE.to_str().unwrap(),
|
HAMMOND_CACHE.to_str().unwrap(),
|
||||||
pd.title()
|
pd.title()
|
||||||
);
|
);
|
||||||
assert_eq!(img_path.unwrap(), foo_);
|
assert_eq!(img_path.unwrap(), foo_);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use podcasts_data::errors::DataError;
|
use hammond_data::errors::DataError;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#![recursion_limit = "1024"]
|
||||||
|
#![deny(unused_extern_crates, unused)]
|
||||||
|
#![allow(unknown_lints)]
|
||||||
|
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name))]
|
||||||
|
|
||||||
|
extern crate failure;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate failure_derive;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate pretty_assertions;
|
||||||
|
|
||||||
|
extern crate glob;
|
||||||
|
extern crate hammond_data;
|
||||||
|
extern crate hyper;
|
||||||
|
extern crate mime_guess;
|
||||||
|
extern crate reqwest;
|
||||||
|
extern crate tempdir;
|
||||||
|
|
||||||
|
pub mod downloader;
|
||||||
|
pub mod errors;
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
[package]
|
||||||
|
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||||
|
build = "build.rs"
|
||||||
|
name = "hammond-gtk"
|
||||||
|
version = "0.1.0"
|
||||||
|
workspace = "../"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
chrono = "0.4.1"
|
||||||
|
crossbeam-channel = "0.1.2"
|
||||||
|
gdk = "0.8.0"
|
||||||
|
gdk-pixbuf = "0.4.0"
|
||||||
|
glib = "0.5.0"
|
||||||
|
humansize = "1.1.0"
|
||||||
|
lazy_static = "1.0.0"
|
||||||
|
log = "0.4.1"
|
||||||
|
loggerv = "0.7.1"
|
||||||
|
open = "1.2.1"
|
||||||
|
rayon = "1.0.1"
|
||||||
|
send-cell = "0.1.2"
|
||||||
|
url = "1.7.0"
|
||||||
|
failure = "0.1.1"
|
||||||
|
failure_derive = "0.1.1"
|
||||||
|
take_mut = "0.2.2"
|
||||||
|
regex = "0.2.10"
|
||||||
|
reqwest = "0.8.5"
|
||||||
|
serde_json = "1.0.13"
|
||||||
|
html2pango = { git = "https://gitlab.gnome.org/World/html2pango" }
|
||||||
|
|
||||||
|
[dependencies.gtk]
|
||||||
|
features = ["v3_22"]
|
||||||
|
version = "0.4.0"
|
||||||
|
|
||||||
|
[dependencies.gio]
|
||||||
|
features = ["v2_50"]
|
||||||
|
version = "0.4.0"
|
||||||
|
|
||||||
|
[dependencies.hammond-data]
|
||||||
|
path = "../hammond-data"
|
||||||
|
|
||||||
|
[dependencies.hammond-downloader]
|
||||||
|
path = "../hammond-downloader"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
pretty_assertions = "0.5.1"
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Rerun the build script when files in the resources folder are changed.
|
|
||||||
println!("cargo:rerun-if-changed=resources");
|
|
||||||
println!("cargo:rerun-if-changed=resources/*");
|
|
||||||
|
|
||||||
Command::new("glib-compile-resources")
|
Command::new("glib-compile-resources")
|
||||||
.args(&["--generate", "resources.xml"])
|
.args(&["--generate", "resources.xml"])
|
||||||
.current_dir("resources")
|
.current_dir("resources")
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.21.0
|
||||||
|
|
||||||
|
Copyright (C) 2017 - 2018
|
||||||
|
|
||||||
|
This file is part of Hammond.
|
||||||
|
|
||||||
|
Hammond is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Hammond is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Hammond. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Authors:
|
||||||
|
Jordan Petridis
|
||||||
|
Tobias Bernard
|
||||||
|
|
||||||
|
-->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<!-- interface-license-type gplv3 -->
|
||||||
|
<!-- interface-name Hammond -->
|
||||||
|
<!-- interface-description A podcast client for the GNOME Desktop -->
|
||||||
|
<!-- interface-copyright 2017 - 2018 -->
|
||||||
|
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
||||||
|
<object class="GtkBox" id="empty_view">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">center</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="vexpand">True</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">12</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="pixel_size">128</property>
|
||||||
|
<property name="icon_name">application-rss+xml-symbolic</property>
|
||||||
|
<property name="use_fallback">True</property>
|
||||||
|
<style>
|
||||||
|
<class name="dim-label"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">No Feed Subscription Found</property>
|
||||||
|
<attributes>
|
||||||
|
<attribute name="weight" value="bold"/>
|
||||||
|
<attribute name="scale" value="1.4399999999999999"/>
|
||||||
|
</attributes>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">You can subscribe to feeds using the "+" button</property>
|
||||||
|
<style>
|
||||||
|
<class name="dim-label"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
||||||
+24
-15
@@ -35,34 +35,43 @@ Tobias Bernard
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="margin_left">6</property>
|
|
||||||
<property name="margin_right">6</property>
|
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="info_container">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="spacing">6</property>
|
<property name="spacing">6</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="title_label">
|
<object class="GtkLabel" id="title_label">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="label" translatable="yes">Episode Title</property>
|
<property name="label" translatable="yes">Episode Title</property>
|
||||||
<property name="ellipsize">end</property>
|
<property name="ellipsize">end</property>
|
||||||
<property name="width_chars">55</property>
|
|
||||||
<property name="single_line_mode">True</property>
|
<property name="single_line_mode">True</property>
|
||||||
<property name="track_visited_links">False</property>
|
<property name="track_visited_links">False</property>
|
||||||
<property name="lines">1</property>
|
<property name="lines">1</property>
|
||||||
<property name="xalign">0</property>
|
<property name="xalign">0</property>
|
||||||
|
<property name="yalign">0</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">False</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
@@ -175,7 +184,7 @@ Tobias Bernard
|
|||||||
<object class="GtkLabel" id="total_size">
|
<object class="GtkLabel" id="total_size">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="label" translatable="yes">Calculating episode size...</property>
|
<property name="label" translatable="yes">XX MB</property>
|
||||||
<property name="single_line_mode">True</property>
|
<property name="single_line_mode">True</property>
|
||||||
<property name="track_visited_links">False</property>
|
<property name="track_visited_links">False</property>
|
||||||
<style>
|
<style>
|
||||||
@@ -204,16 +213,16 @@ Tobias Bernard
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButtonBox" id="button_box">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="layout_style">center</property>
|
<property name="spacing">6</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="cancel_button">
|
<object class="GtkButton" id="cancel_button">
|
||||||
<property name="label" translatable="yes">Cancel</property>
|
<property name="label" translatable="yes">Cancel</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">False</property>
|
<property name="receives_default">False</property>
|
||||||
<property name="halign">center</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
@@ -228,8 +237,8 @@ Tobias Bernard
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
|
<property name="no_show_all">True</property>
|
||||||
<property name="tooltip_text" translatable="yes">Download this episode</property>
|
<property name="tooltip_text" translatable="yes">Download this episode</property>
|
||||||
<property name="halign">center</property>
|
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="always_show_image">True</property>
|
<property name="always_show_image">True</property>
|
||||||
<child>
|
<child>
|
||||||
@@ -243,8 +252,8 @@ Tobias Bernard
|
|||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">False</property>
|
||||||
<property name="position">1</property>
|
<property name="pack_type">end</property>
|
||||||
<property name="non_homogeneous">True</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@@ -253,7 +262,6 @@ Tobias Bernard
|
|||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="tooltip_text" translatable="yes">Play this episode</property>
|
<property name="tooltip_text" translatable="yes">Play this episode</property>
|
||||||
<property name="halign">center</property>
|
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage">
|
<object class="GtkImage">
|
||||||
@@ -266,14 +274,15 @@ Tobias Bernard
|
|||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">False</property>
|
||||||
<property name="position">2</property>
|
<property name="pack_type">end</property>
|
||||||
<property name="non_homogeneous">True</property>
|
<property name="position">3</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">False</property>
|
||||||
|
<property name="padding">6</property>
|
||||||
<property name="pack_type">end</property>
|
<property name="pack_type">end</property>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
+9
-3
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.0
|
<!-- Generated with glade 3.21.0
|
||||||
|
|
||||||
Copyright (C) 2017 - 2018
|
Copyright (C) 2017 - 2018
|
||||||
|
|
||||||
@@ -32,14 +32,13 @@ Tobias Bernard
|
|||||||
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
||||||
<object class="GtkBox" id="container">
|
<object class="GtkBox" id="container">
|
||||||
<property name="name">container</property>
|
<property name="name">container</property>
|
||||||
<property name="width_request">290</property>
|
|
||||||
<property name="height_request">420</property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow" id="scrolled_window">
|
<object class="GtkScrolledWindow" id="scrolled_window">
|
||||||
<property name="name">scrolled_window</property>
|
<property name="name">scrolled_window</property>
|
||||||
|
<property name="height_request">400</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="hscrollbar_policy">never</property>
|
<property name="hscrollbar_policy">never</property>
|
||||||
@@ -69,6 +68,8 @@ Tobias Bernard
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="frame_parent">
|
<object class="GtkBox" id="frame_parent">
|
||||||
|
<property name="width_request">600</property>
|
||||||
|
<property name="height_request">-1</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="margin_left">32</property>
|
<property name="margin_left">32</property>
|
||||||
@@ -80,6 +81,7 @@ Tobias Bernard
|
|||||||
<property name="spacing">24</property>
|
<property name="spacing">24</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="today_box">
|
<object class="GtkBox" id="today_box">
|
||||||
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
@@ -137,6 +139,7 @@ Tobias Bernard
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="yday_box">
|
<object class="GtkBox" id="yday_box">
|
||||||
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
@@ -193,6 +196,7 @@ Tobias Bernard
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="week_box">
|
<object class="GtkBox" id="week_box">
|
||||||
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
@@ -249,6 +253,7 @@ Tobias Bernard
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="month_box">
|
<object class="GtkBox" id="month_box">
|
||||||
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
@@ -305,6 +310,7 @@ Tobias Bernard
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="rest_box">
|
<object class="GtkBox" id="rest_box">
|
||||||
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
+2
-1
@@ -36,11 +36,12 @@ Tobias Bernard
|
|||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="margin_top">6</property>
|
<property name="margin_top">6</property>
|
||||||
<property name="margin_bottom">6</property>
|
<property name="margin_bottom">6</property>
|
||||||
|
<property name="spacing">6</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="cover">
|
<object class="GtkImage" id="cover">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="margin_left">8</property>
|
<property name="margin_left">6</property>
|
||||||
<property name="pixel_size">64</property>
|
<property name="pixel_size">64</property>
|
||||||
<property name="icon_name">image-x-generic-symbolic</property>
|
<property name="icon_name">image-x-generic-symbolic</property>
|
||||||
</object>
|
</object>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.0
|
<!-- Generated with glade 3.21.0
|
||||||
|
|
||||||
Copyright (C) 2017 - 2018
|
Copyright (C) 2017 - 2018
|
||||||
|
|
||||||
@@ -151,10 +151,9 @@ Tobias Bernard
|
|||||||
<object class="GtkMenuButton" id="add_toggle">
|
<object class="GtkMenuButton" id="add_toggle">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">False</property>
|
||||||
<property name="tooltip_text" translatable="yes">Add a new feed</property>
|
<property name="tooltip_text" translatable="yes">Add a new feed</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="popover">add_popover</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="add-button-image2">
|
<object class="GtkImage" id="add-button-image2">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@@ -169,7 +168,7 @@ Tobias Bernard
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="back">
|
<object class="GtkButton" id="back_button">
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">False</property>
|
<property name="receives_default">False</property>
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
@@ -258,11 +257,12 @@ Tobias Bernard
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkMenuButton" id="hamburger">
|
<object class="GtkMenuButton" id="menu_toggle">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">False</property>
|
<property name="receives_default">False</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
|
<property name="popover">menu_popover</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage">
|
<object class="GtkImage">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@@ -280,28 +280,99 @@ Tobias Bernard
|
|||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
</object>
|
||||||
|
<object class="GtkPopover" id="menu_popover">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="relative_to">menu_toggle</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkMenuButton" id="secondary_menu">
|
<object class="GtkBox">
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">False</property>
|
|
||||||
<property name="no_show_all">True</property>
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkImage">
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="icon_name">view-more-symbolic</property>
|
<property name="margin_left">10</property>
|
||||||
<property name="icon_size">1</property>
|
<property name="margin_right">10</property>
|
||||||
</object>
|
<property name="margin_top">10</property>
|
||||||
</child>
|
<property name="margin_bottom">10</property>
|
||||||
<style>
|
<property name="orientation">vertical</property>
|
||||||
<class name="image-button"/>
|
<child>
|
||||||
</style>
|
<object class="GtkModelButton">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="text" translatable="yes">Preferences</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="pack_type">end</property>
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkModelButton" id="update_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<property name="text" translatable="yes">Check for new episodes</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSeparator">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkModelButton" id="about_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="text" translatable="yes">About</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">6</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkModelButton">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="text" translatable="yes">Help</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">7</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkModelButton">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="text" translatable="yes">Keyboard Shortcuts</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">8</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
+100
-37
@@ -31,17 +31,16 @@ Tobias Bernard
|
|||||||
<!-- interface-copyright 2017 - 2018 -->
|
<!-- interface-copyright 2017 - 2018 -->
|
||||||
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
||||||
<object class="GtkBox" id="container">
|
<object class="GtkBox" id="container">
|
||||||
<property name="width_request">290</property>
|
|
||||||
<property name="height_request">420</property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow" id="scrolled_window">
|
<object class="GtkScrolledWindow" id="scrolled_window">
|
||||||
<property name="name">scrolled_window</property>
|
<property name="name">scrolled_window</property>
|
||||||
|
<property name="width_request">700</property>
|
||||||
|
<property name="height_request">500</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="vexpand">True</property>
|
|
||||||
<property name="hscrollbar_policy">never</property>
|
<property name="hscrollbar_policy">never</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkViewport">
|
<object class="GtkViewport">
|
||||||
@@ -71,26 +70,26 @@ Tobias Bernard
|
|||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
|
<property name="width_request">700</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="margin_left">32</property>
|
<property name="margin_left">32</property>
|
||||||
<property name="margin_right">32</property>
|
<property name="margin_right">32</property>
|
||||||
<property name="margin_top">32</property>
|
<property name="margin_top">32</property>
|
||||||
<property name="margin_bottom">32</property>
|
<property name="margin_bottom">32</property>
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="spacing">6</property>
|
<property name="spacing">24</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="valign">center</property>
|
||||||
<property name="spacing">6</property>
|
<property name="spacing">12</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="cover">
|
<object class="GtkImage" id="cover">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="pixel_size">256</property>
|
<property name="pixel_size">128</property>
|
||||||
<property name="icon_name">image-x-generic-symbolic</property>
|
<property name="icon_name">image-x-generic-symbolic</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
@@ -100,59 +99,123 @@ Tobias Bernard
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="hscrollbar_policy">never</property>
|
|
||||||
<property name="min_content_height">80</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkViewport">
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="shadow_type">none</property>
|
<property name="valign">end</property>
|
||||||
<child>
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">6</property>
|
||||||
|
<child type="center">
|
||||||
<object class="GtkLabel" id="description">
|
<object class="GtkLabel" id="description">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">start</property>
|
||||||
|
<property name="valign">end</property>
|
||||||
|
<property name="label">foo</property>
|
||||||
|
<property name="use_markup">True</property>
|
||||||
|
<property name="wrap">True</property>
|
||||||
|
<property name="wrap_mode">word-char</property>
|
||||||
|
<property name="max_width_chars">90</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="spacing">6</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkMenuButton" id="settings_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="label">This is embarrasing!
|
<property name="icon_name">emblem-system-symbolic</property>
|
||||||
Sorry, we could not find a description for this Show.</property>
|
|
||||||
<property name="use_markup">True</property>
|
|
||||||
<property name="justify">center</property>
|
|
||||||
<property name="wrap">True</property>
|
|
||||||
<property name="max_width_chars">70</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">1</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="link_button">
|
||||||
|
<property name="label" translatable="yes">Website</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<property name="halign">center</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">True</property>
|
||||||
<property name="padding">6</property>
|
<property name="padding">5</property>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkFrame">
|
<object class="GtkButton" id="unsub_button">
|
||||||
|
<property name="label" translatable="yes">Unsubscribe</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<property name="halign">center</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<style>
|
||||||
|
<class name="destructive-action"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="padding">5</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame" id="episodes">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="label_xalign">0</property>
|
<property name="label_xalign">0</property>
|
||||||
<property name="shadow_type">in</property>
|
<property name="shadow_type">in</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkListBox" id="episodes">
|
<placeholder/>
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="selection_mode">none</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
</child>
|
||||||
<child type="label_item">
|
<child type="label_item">
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
@@ -167,7 +230,7 @@ Sorry, we could not find a description for this Show.</property>
|
|||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">False</property>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
@@ -194,7 +257,7 @@ Sorry, we could not find a description for this Show.</property>
|
|||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
+11
-2
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.0
|
<!-- Generated with glade 3.21.0
|
||||||
|
|
||||||
Copyright (C) 2017 - 2018
|
Copyright (C) 2017 - 2018
|
||||||
|
|
||||||
@@ -39,6 +39,13 @@ Tobias Bernard
|
|||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
|
<object class="GtkOverlay">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child type="overlay">
|
||||||
<object class="GtkImage" id="pd_cover">
|
<object class="GtkImage" id="pd_cover">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
@@ -48,8 +55,10 @@ Tobias Bernard
|
|||||||
<property name="icon_name">image-x-generic-symbolic</property>
|
<property name="icon_name">image-x-generic-symbolic</property>
|
||||||
<property name="icon_size">0</property>
|
<property name="icon_size">0</property>
|
||||||
</object>
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.0
|
<!-- Generated with glade 3.21.0
|
||||||
|
|
||||||
Copyright (C) 2017 - 2018
|
Copyright (C) 2017 - 2018
|
||||||
|
|
||||||
@@ -32,8 +32,6 @@ Tobias Bernard
|
|||||||
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
|
||||||
<object class="GtkBox" id="fb_parent">
|
<object class="GtkBox" id="fb_parent">
|
||||||
<property name="name">fb_parent</property>
|
<property name="name">fb_parent</property>
|
||||||
<property name="width_request">290</property>
|
|
||||||
<property name="height_request">420</property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
@@ -9,12 +9,3 @@ row:last-child {
|
|||||||
list, border {
|
list, border {
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.player-episode-label {
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: smaller;
|
|
||||||
}
|
|
||||||
|
|
||||||
.player-show-label {
|
|
||||||
font-size: smaller;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# subdir('icons')
|
||||||
|
|
||||||
|
install_data('org.gnome.Hammond.desktop', install_dir : datadir + '/applications')
|
||||||
|
install_data('org.gnome.Hammond.appdata.xml', install_dir : datadir + '/appdata')
|
||||||
|
install_data('org.gnome.Hammond.gschema.xml', install_dir: join_paths(datadir, 'glib-2.0', 'schemas'))
|
||||||
|
meson.add_install_script('../../scripts/compile-gschema.py')
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<component type="desktop">
|
||||||
|
<id>org.gnome.Hammond</id>
|
||||||
|
<name>Hammond</name>
|
||||||
|
<project_license>GPL-3.0</project_license>
|
||||||
|
<metadata_license>CC0-1.0</metadata_license>
|
||||||
|
<developer_name>Jordan Petridis</developer_name>
|
||||||
|
<summary>Modern Podcast Client for the GNOME desktop</summary>
|
||||||
|
<description xml:lang="en">
|
||||||
|
<p>
|
||||||
|
Hammond is a modern, reliable, and fast Podcast Client for the GNOME
|
||||||
|
desktop written in Rust.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
<url type="homepage">https://gitlab.gnome.org/alatiera/Hammond</url>
|
||||||
|
<screenshots>
|
||||||
|
<screenshot>
|
||||||
|
<image>https://gitlab.gnome.org/alatiera/hammond/raw/master/screenshots/episodes_view.png</image>
|
||||||
|
<caption>Page 1</caption>
|
||||||
|
</screenshot>
|
||||||
|
<screenshot>
|
||||||
|
<image>https://gitlab.gnome.org/alatiera/hammond/raw/master/screenshots/shows_view.png</image>
|
||||||
|
<caption>Page 2</caption>
|
||||||
|
</screenshot>
|
||||||
|
<screenshot>
|
||||||
|
<image>https://gitlab.gnome.org/alatiera/hammond/raw/master/screenshots/show_widget.png</image>
|
||||||
|
<caption>Page 3</caption>
|
||||||
|
</screenshot>
|
||||||
|
</screenshots>
|
||||||
|
<releases>
|
||||||
|
<release version="0.3.1" date="2018-03-28"/>
|
||||||
|
</releases>
|
||||||
|
<url type="homepage">https://gitlab.gnome.org/alatiera/hammond</url>
|
||||||
|
<update_contact>jpetridis@gnome.org</update_contact>
|
||||||
|
<developer_name>Jordan Petridis and others</developer_name>
|
||||||
|
</component>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Name=Hammond
|
||||||
|
GenericName=Podcast Client
|
||||||
|
Comment=Play, Subscribe and Manage Podcast Feeds.
|
||||||
|
Icon=multimedia-player
|
||||||
|
Exec=hammond
|
||||||
|
Terminal=false
|
||||||
|
Type=Application
|
||||||
|
StartupNotify=true
|
||||||
|
Categories=AudioVideo;Audio;Video;
|
||||||
|
Keywords=Podcast
|
||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<schemalist>
|
<schemalist>
|
||||||
<enum id="org.gnome.Podcasts.timePeriods">
|
<enum id="org.gnome.Hammond.timePeriods">
|
||||||
<value nick="seconds" value="1"/>
|
<value nick="seconds" value="1"/>
|
||||||
<value nick="minutes" value="2"/>
|
<value nick="minutes" value="2"/>
|
||||||
<value nick="hours" value="3"/>
|
<value nick="hours" value="3"/>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<value nick="months" value="6"/>
|
<value nick="months" value="6"/>
|
||||||
</enum>
|
</enum>
|
||||||
|
|
||||||
<schema path="/org/gnome/Podcasts/" id="org.gnome.Podcasts">
|
<schema path="/org/gnome/hammond/" id="org.gnome.Hammond">
|
||||||
<key name="persist-window-geometry-top" type="i">
|
<key name="persist-window-geometry-top" type="i">
|
||||||
<default>-1</default>
|
<default>-1</default>
|
||||||
<summary>Top position of the last open main window</summary>
|
<summary>Top position of the last open main window</summary>
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
<default>1</default>
|
<default>1</default>
|
||||||
<summary>How many periods of time to wait between automatic refreshes</summary>
|
<summary>How many periods of time to wait between automatic refreshes</summary>
|
||||||
</key>
|
</key>
|
||||||
<key name="refresh-interval-period" enum="org.gnome.Podcasts.timePeriods">
|
<key name="refresh-interval-period" enum="org.gnome.Hammond.timePeriods">
|
||||||
<default>'hours'</default>
|
<default>'hours'</default>
|
||||||
<summary>What period of time to wait between automatic refreshes</summary>
|
<summary>What period of time to wait between automatic refreshes</summary>
|
||||||
</key>
|
</key>
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<default>2</default>
|
<default>2</default>
|
||||||
<summary>How many periods of time to wait between automatic cleanups</summary>
|
<summary>How many periods of time to wait between automatic cleanups</summary>
|
||||||
</key>
|
</key>
|
||||||
<key name="cleanup-age-period" enum="org.gnome.Podcasts.timePeriods">
|
<key name="cleanup-age-period" enum="org.gnome.Hammond.timePeriods">
|
||||||
<default>'days'</default>
|
<default>'days'</default>
|
||||||
<summary>What period of time to wait between automatic cleanups</summary>
|
<summary>What period of time to wait between automatic cleanups</summary>
|
||||||
</key>
|
</key>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gresources>
|
||||||
|
<gresource prefix="/org/gnome/hammond/">
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/episode_widget.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/show_widget.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/empty_view.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/empty_show.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/episodes_view.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/episodes_view_widget.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/shows_view.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/shows_child.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/headerbar.ui</file>
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks">gtk/inapp_notif.ui</file>
|
||||||
|
<file compressed="true">gtk/style.css</file>
|
||||||
|
</gresource>
|
||||||
|
</gresources>
|
||||||
@@ -0,0 +1,267 @@
|
|||||||
|
#![allow(new_without_default)]
|
||||||
|
|
||||||
|
use gio::{ApplicationExt, ApplicationExtManual, ApplicationFlags, Settings, SettingsExt};
|
||||||
|
use glib;
|
||||||
|
use gtk;
|
||||||
|
use gtk::SettingsExt as GtkSettingsExt;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
|
use rayon;
|
||||||
|
|
||||||
|
use hammond_data::{Podcast, Source};
|
||||||
|
use hammond_data::utils::delete_show;
|
||||||
|
|
||||||
|
use appnotif::*;
|
||||||
|
use headerbar::Header;
|
||||||
|
use settings::WindowGeometry;
|
||||||
|
use stacks::Content;
|
||||||
|
use utils;
|
||||||
|
use widgets::mark_all_watched;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum Action {
|
||||||
|
UpdateSources(Option<Source>),
|
||||||
|
RefreshAllViews,
|
||||||
|
RefreshEpisodesView,
|
||||||
|
RefreshEpisodesViewBGR,
|
||||||
|
RefreshShowsView,
|
||||||
|
RefreshWidget,
|
||||||
|
RefreshWidgetIfVis,
|
||||||
|
ReplaceWidget(Arc<Podcast>),
|
||||||
|
RefreshWidgetIfSame(i32),
|
||||||
|
ShowWidgetAnimated,
|
||||||
|
ShowShowsAnimated,
|
||||||
|
HeaderBarShowTile(String),
|
||||||
|
HeaderBarNormal,
|
||||||
|
HeaderBarShowUpdateIndicator,
|
||||||
|
HeaderBarHideUpdateIndicator,
|
||||||
|
MarkAllPlayerNotification(Arc<Podcast>),
|
||||||
|
RemoveShow(Arc<Podcast>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct App {
|
||||||
|
app_instance: gtk::Application,
|
||||||
|
window: gtk::Window,
|
||||||
|
overlay: gtk::Overlay,
|
||||||
|
header: Arc<Header>,
|
||||||
|
content: Arc<Content>,
|
||||||
|
receiver: Receiver<Action>,
|
||||||
|
sender: Sender<Action>,
|
||||||
|
settings: Settings,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn new() -> App {
|
||||||
|
let settings = Settings::new("org.gnome.Hammond");
|
||||||
|
let application = gtk::Application::new("org.gnome.Hammond", ApplicationFlags::empty())
|
||||||
|
.expect("Application Initialization failed...");
|
||||||
|
|
||||||
|
// Weird magic I copy-pasted that sets the Application Name in the Shell.
|
||||||
|
glib::set_application_name("Hammond");
|
||||||
|
glib::set_prgname(Some("Hammond"));
|
||||||
|
|
||||||
|
// Create the main window
|
||||||
|
let window = gtk::Window::new(gtk::WindowType::Toplevel);
|
||||||
|
|
||||||
|
window.set_title("Hammond");
|
||||||
|
|
||||||
|
let app_clone = application.clone();
|
||||||
|
let window_clone = window.clone();
|
||||||
|
let settings_clone = settings.clone();
|
||||||
|
window.connect_delete_event(move |_, _| {
|
||||||
|
WindowGeometry::from_window(&window_clone).write(&settings_clone);
|
||||||
|
app_clone.quit();
|
||||||
|
Inhibit(false)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (sender, receiver) = channel();
|
||||||
|
|
||||||
|
// Create a content instance
|
||||||
|
let content =
|
||||||
|
Arc::new(Content::new(sender.clone()).expect("Content Initialization failed."));
|
||||||
|
|
||||||
|
// Create the headerbar
|
||||||
|
let header = Arc::new(Header::new(&content, &window, sender.clone()));
|
||||||
|
|
||||||
|
// Add the content main stack to the overlay.
|
||||||
|
let overlay = gtk::Overlay::new();
|
||||||
|
overlay.add(&content.get_stack());
|
||||||
|
|
||||||
|
// Add the overlay to the main window
|
||||||
|
window.add(&overlay);
|
||||||
|
|
||||||
|
App {
|
||||||
|
app_instance: application,
|
||||||
|
window,
|
||||||
|
overlay,
|
||||||
|
header,
|
||||||
|
content,
|
||||||
|
receiver,
|
||||||
|
sender,
|
||||||
|
settings,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_timed_callbacks(&self) {
|
||||||
|
self.setup_dark_theme();
|
||||||
|
self.setup_refresh_on_startup();
|
||||||
|
self.setup_auto_refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_dark_theme(&self) {
|
||||||
|
let settings = gtk::Settings::get_default().unwrap();
|
||||||
|
let enabled = self.settings.get_boolean("dark-theme");
|
||||||
|
|
||||||
|
settings.set_property_gtk_application_prefer_dark_theme(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_refresh_on_startup(&self) {
|
||||||
|
// Update the feeds right after the Application is initialized.
|
||||||
|
if self.settings.get_boolean("refresh-on-startup") {
|
||||||
|
let cleanup_date = utils::get_cleanup_date(&self.settings);
|
||||||
|
let sender = self.sender.clone();
|
||||||
|
|
||||||
|
info!("Refresh on startup.");
|
||||||
|
|
||||||
|
utils::cleanup(cleanup_date);
|
||||||
|
|
||||||
|
gtk::timeout_add_seconds(2, move || {
|
||||||
|
utils::refresh(None, sender.clone());
|
||||||
|
|
||||||
|
glib::Continue(false)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_auto_refresh(&self) {
|
||||||
|
let refresh_interval = utils::get_refresh_interval(&self.settings).num_seconds() as u32;
|
||||||
|
let sender = self.sender.clone();
|
||||||
|
|
||||||
|
info!("Auto-refresh every {:?} seconds.", refresh_interval);
|
||||||
|
|
||||||
|
gtk::timeout_add_seconds(refresh_interval, move || {
|
||||||
|
utils::refresh(None, sender.clone());
|
||||||
|
|
||||||
|
glib::Continue(true)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(self) {
|
||||||
|
WindowGeometry::from_settings(&self.settings).apply(&self.window);
|
||||||
|
|
||||||
|
let window = self.window.clone();
|
||||||
|
|
||||||
|
self.app_instance.connect_startup(move |app| {
|
||||||
|
build_ui(&window, app);
|
||||||
|
});
|
||||||
|
self.setup_timed_callbacks();
|
||||||
|
|
||||||
|
let content = self.content.clone();
|
||||||
|
let headerbar = self.header.clone();
|
||||||
|
let sender = self.sender.clone();
|
||||||
|
let overlay = self.overlay.clone();
|
||||||
|
let receiver = self.receiver;
|
||||||
|
gtk::idle_add(move || {
|
||||||
|
match receiver.recv_timeout(Duration::from_millis(10)) {
|
||||||
|
Ok(Action::UpdateSources(source)) => {
|
||||||
|
if let Some(s) = source {
|
||||||
|
utils::refresh(Some(vec![s]), sender.clone());
|
||||||
|
} else {
|
||||||
|
utils::refresh(None, sender.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Action::RefreshAllViews) => content.update(),
|
||||||
|
Ok(Action::RefreshShowsView) => content.update_shows_view(),
|
||||||
|
Ok(Action::RefreshWidget) => content.update_widget(),
|
||||||
|
Ok(Action::RefreshWidgetIfVis) => content.update_widget_if_visible(),
|
||||||
|
Ok(Action::RefreshWidgetIfSame(id)) => content.update_widget_if_same(id),
|
||||||
|
Ok(Action::RefreshEpisodesView) => content.update_episode_view(),
|
||||||
|
Ok(Action::RefreshEpisodesViewBGR) => content.update_episode_view_if_baground(),
|
||||||
|
Ok(Action::ReplaceWidget(pd)) => {
|
||||||
|
if let Err(err) = content.get_shows().replace_widget(pd) {
|
||||||
|
error!("Something went wrong while trying to update the ShowWidget.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(Action::ShowWidgetAnimated) => content.get_shows().switch_widget_animated(),
|
||||||
|
Ok(Action::ShowShowsAnimated) => content.get_shows().switch_podcasts_animated(),
|
||||||
|
Ok(Action::HeaderBarShowTile(title)) => headerbar.switch_to_back(&title),
|
||||||
|
Ok(Action::HeaderBarNormal) => headerbar.switch_to_normal(),
|
||||||
|
Ok(Action::HeaderBarShowUpdateIndicator) => headerbar.show_update_notification(),
|
||||||
|
Ok(Action::HeaderBarHideUpdateIndicator) => headerbar.hide_update_notification(),
|
||||||
|
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
||||||
|
let callback = clone!(sender => move || {
|
||||||
|
if let Err(err) = mark_all_watched(&pd, sender.clone()) {
|
||||||
|
error!("Something went horribly wrong with the notif callback: {}", err);
|
||||||
|
}
|
||||||
|
glib::Continue(false)
|
||||||
|
});
|
||||||
|
|
||||||
|
let text = "Marked all episodes as listened".into();
|
||||||
|
let notif = InAppNotification::new(text, callback, || {}, sender.clone());
|
||||||
|
notif.show(&overlay);
|
||||||
|
}
|
||||||
|
Ok(Action::RemoveShow(pd)) => {
|
||||||
|
let text = format!("Unsubscribed from {}", pd.title());
|
||||||
|
|
||||||
|
if let Err(err) = utils::ignore_show(pd.id()) {
|
||||||
|
error!("Could not insert {} to the ignore list.", pd.title());
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
let callback = clone!(pd => move || {
|
||||||
|
if let Err(err) = utils::uningore_show(pd.id()) {
|
||||||
|
error!("Could not remove {} from the ignore list.", pd.title());
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spawn a thread so it won't block the ui.
|
||||||
|
rayon::spawn(clone!(pd => move || {
|
||||||
|
if let Err(err) = delete_show(&pd) {
|
||||||
|
error!("Something went wrong trying to remove {}", pd.title());
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
glib::Continue(false)
|
||||||
|
});
|
||||||
|
|
||||||
|
let sender_ = sender.clone();
|
||||||
|
let undo_wrap = move || -> Result<(), Error> {
|
||||||
|
utils::uningore_show(pd.id())?;
|
||||||
|
sender_.send(Action::RefreshShowsView)?;
|
||||||
|
sender_.send(Action::RefreshEpisodesView)?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
|
let undo_callback = move || {
|
||||||
|
if let Err(err) = undo_wrap() {
|
||||||
|
error!("{}", err)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let sender_ = sender.clone();
|
||||||
|
let notif = InAppNotification::new(text, callback, undo_callback, sender_);
|
||||||
|
notif.show(&overlay);
|
||||||
|
}
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
Continue(true)
|
||||||
|
});
|
||||||
|
|
||||||
|
ApplicationExtManual::run(&self.app_instance, &[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_ui(window: >k::Window, app: >k::Application) {
|
||||||
|
window.set_application(app);
|
||||||
|
window.show_all();
|
||||||
|
window.activate();
|
||||||
|
app.connect_activate(move |_| ());
|
||||||
|
}
|
||||||
@@ -2,14 +2,11 @@ use glib;
|
|||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum UndoState {
|
|
||||||
Shown,
|
|
||||||
Hidden,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InAppNotification {
|
pub struct InAppNotification {
|
||||||
@@ -21,7 +18,7 @@ pub struct InAppNotification {
|
|||||||
|
|
||||||
impl Default for InAppNotification {
|
impl Default for InAppNotification {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Podcasts/gtk/inapp_notif.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/inapp_notif.ui");
|
||||||
|
|
||||||
let revealer: gtk::Revealer = builder.get_object("revealer").unwrap();
|
let revealer: gtk::Revealer = builder.get_object("revealer").unwrap();
|
||||||
let text: gtk::Label = builder.get_object("text").unwrap();
|
let text: gtk::Label = builder.get_object("text").unwrap();
|
||||||
@@ -38,7 +35,12 @@ impl Default for InAppNotification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InAppNotification {
|
impl InAppNotification {
|
||||||
pub fn new<F, U>(text: &str, mut callback: F, undo_callback: U, show_undo: UndoState) -> Self
|
pub fn new<F, U>(
|
||||||
|
text: String,
|
||||||
|
mut callback: F,
|
||||||
|
undo_callback: U,
|
||||||
|
sender: Sender<Action>,
|
||||||
|
) -> Self
|
||||||
where
|
where
|
||||||
F: FnMut() -> glib::Continue + 'static,
|
F: FnMut() -> glib::Continue + 'static,
|
||||||
U: Fn() + 'static,
|
U: Fn() + 'static,
|
||||||
@@ -65,6 +67,10 @@ impl InAppNotification {
|
|||||||
|
|
||||||
// Hide the notification
|
// Hide the notification
|
||||||
revealer.set_reveal_child(false);
|
revealer.set_reveal_child(false);
|
||||||
|
// Refresh the widget if visible
|
||||||
|
if let Err(err) = sender.send(Action::RefreshWidgetIfVis) {
|
||||||
|
error!("Action channel blew up: {}", err)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hide the revealer when the close button is clicked
|
// Hide the revealer when the close button is clicked
|
||||||
@@ -73,11 +79,6 @@ impl InAppNotification {
|
|||||||
revealer.set_reveal_child(false);
|
revealer.set_reveal_child(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
match show_undo {
|
|
||||||
UndoState::Shown => (),
|
|
||||||
UndoState::Hidden => notif.undo.hide(),
|
|
||||||
}
|
|
||||||
|
|
||||||
notif
|
notif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
|
use failure::ResultExt;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
use hammond_data::Source;
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
use stacks::Content;
|
||||||
|
use utils::itunes_to_rss;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Header {
|
||||||
|
container: gtk::HeaderBar,
|
||||||
|
add_toggle: gtk::MenuButton,
|
||||||
|
switch: gtk::StackSwitcher,
|
||||||
|
back_button: gtk::Button,
|
||||||
|
show_title: gtk::Label,
|
||||||
|
about_button: gtk::ModelButton,
|
||||||
|
update_button: gtk::ModelButton,
|
||||||
|
update_box: gtk::Box,
|
||||||
|
update_label: gtk::Label,
|
||||||
|
update_spinner: gtk::Spinner,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Header {
|
||||||
|
fn default() -> Header {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
||||||
|
|
||||||
|
let header: gtk::HeaderBar = builder.get_object("headerbar").unwrap();
|
||||||
|
let add_toggle: gtk::MenuButton = builder.get_object("add_toggle").unwrap();
|
||||||
|
let switch: gtk::StackSwitcher = builder.get_object("switch").unwrap();
|
||||||
|
let back_button: gtk::Button = builder.get_object("back_button").unwrap();
|
||||||
|
let show_title: gtk::Label = builder.get_object("show_title").unwrap();
|
||||||
|
let update_button: gtk::ModelButton = builder.get_object("update_button").unwrap();
|
||||||
|
let update_box: gtk::Box = builder.get_object("update_notification").unwrap();
|
||||||
|
let update_label: gtk::Label = builder.get_object("update_label").unwrap();
|
||||||
|
let update_spinner: gtk::Spinner = builder.get_object("update_spinner").unwrap();
|
||||||
|
let about_button: gtk::ModelButton = builder.get_object("about_button").unwrap();
|
||||||
|
|
||||||
|
Header {
|
||||||
|
container: header,
|
||||||
|
add_toggle,
|
||||||
|
switch,
|
||||||
|
back_button,
|
||||||
|
show_title,
|
||||||
|
about_button,
|
||||||
|
update_button,
|
||||||
|
update_box,
|
||||||
|
update_label,
|
||||||
|
update_spinner,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Refactor components into smaller state machines
|
||||||
|
impl Header {
|
||||||
|
pub fn new(content: &Content, window: >k::Window, sender: Sender<Action>) -> Header {
|
||||||
|
let h = Header::default();
|
||||||
|
h.init(content, window, sender);
|
||||||
|
h
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&self, content: &Content, window: >k::Window, sender: Sender<Action>) {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/headerbar.ui");
|
||||||
|
|
||||||
|
let add_popover: gtk::Popover = builder.get_object("add_popover").unwrap();
|
||||||
|
let new_url: gtk::Entry = builder.get_object("new_url").unwrap();
|
||||||
|
let add_button: gtk::Button = builder.get_object("add_button").unwrap();
|
||||||
|
let result_label: gtk::Label = builder.get_object("result_label").unwrap();
|
||||||
|
self.switch.set_stack(&content.get_stack());
|
||||||
|
|
||||||
|
new_url.connect_changed(clone!(add_button => move |url| {
|
||||||
|
if let Err(err) = on_url_change(url, &result_label, &add_button) {
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
add_button.connect_clicked(clone!(add_popover, new_url, sender => move |_| {
|
||||||
|
if let Err(err) = on_add_bttn_clicked(&new_url, sender.clone()) {
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
add_popover.hide();
|
||||||
|
}));
|
||||||
|
|
||||||
|
self.add_toggle.set_popover(&add_popover);
|
||||||
|
|
||||||
|
self.update_button
|
||||||
|
.connect_clicked(clone!(sender => move |_| {
|
||||||
|
sender
|
||||||
|
.send(Action::UpdateSources(None))
|
||||||
|
.expect("Action channel blew up.");
|
||||||
|
}));
|
||||||
|
|
||||||
|
self.about_button
|
||||||
|
.connect_clicked(clone!(window => move |_| {
|
||||||
|
about_dialog(&window);
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Add the Headerbar to the window.
|
||||||
|
window.set_titlebar(&self.container);
|
||||||
|
|
||||||
|
let switch = &self.switch;
|
||||||
|
let add_toggle = &self.add_toggle;
|
||||||
|
let show_title = &self.show_title;
|
||||||
|
self.back_button.connect_clicked(
|
||||||
|
clone!(switch, add_toggle, show_title, sender => move |back| {
|
||||||
|
switch.show();
|
||||||
|
add_toggle.show();
|
||||||
|
back.hide();
|
||||||
|
show_title.hide();
|
||||||
|
if let Err(err) = sender.send(Action::ShowShowsAnimated) {
|
||||||
|
error!("Action channel blew up: {}", err);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn switch_to_back(&self, title: &str) {
|
||||||
|
self.switch.hide();
|
||||||
|
self.add_toggle.hide();
|
||||||
|
self.back_button.show();
|
||||||
|
self.set_show_title(title);
|
||||||
|
self.show_title.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn switch_to_normal(&self) {
|
||||||
|
self.switch.show();
|
||||||
|
self.add_toggle.show();
|
||||||
|
self.back_button.hide();
|
||||||
|
self.show_title.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_show_title(&self, title: &str) {
|
||||||
|
self.show_title.set_text(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_update_notification(&self) {
|
||||||
|
self.update_spinner.start();
|
||||||
|
self.update_box.show();
|
||||||
|
self.update_spinner.show();
|
||||||
|
self.update_label.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hide_update_notification(&self) {
|
||||||
|
self.update_spinner.stop();
|
||||||
|
self.update_box.hide();
|
||||||
|
self.update_spinner.hide();
|
||||||
|
self.update_label.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: THIS ALSO SUCKS!
|
||||||
|
fn on_add_bttn_clicked(entry: >k::Entry, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
|
let url = entry.get_text().unwrap_or_default();
|
||||||
|
let url = if url.contains("itunes.com") || url.contains("apple.com") {
|
||||||
|
info!("Detected itunes url.");
|
||||||
|
let foo = itunes_to_rss(&url)?;
|
||||||
|
info!("Resolved to {}", foo);
|
||||||
|
foo
|
||||||
|
} else {
|
||||||
|
url.to_owned()
|
||||||
|
};
|
||||||
|
|
||||||
|
let source = Source::from_url(&url).context("Failed to convert url to a Source entry.")?;
|
||||||
|
entry.set_text("");
|
||||||
|
|
||||||
|
sender
|
||||||
|
.send(Action::UpdateSources(Some(source)))
|
||||||
|
.context("App channel blew up.")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: THIS SUCKS!
|
||||||
|
fn on_url_change(
|
||||||
|
entry: >k::Entry,
|
||||||
|
result: >k::Label,
|
||||||
|
add_button: >k::Button,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let uri = entry
|
||||||
|
.get_text()
|
||||||
|
.ok_or_else(|| format_err!("GtkEntry blew up somehow."))?;
|
||||||
|
debug!("Url: {}", uri);
|
||||||
|
|
||||||
|
let url = Url::parse(&uri);
|
||||||
|
// TODO: refactor to avoid duplication
|
||||||
|
match url {
|
||||||
|
Ok(u) => {
|
||||||
|
if !dbqueries::source_exists(u.as_str())? {
|
||||||
|
add_button.set_sensitive(true);
|
||||||
|
result.hide();
|
||||||
|
result.set_label("");
|
||||||
|
} else {
|
||||||
|
add_button.set_sensitive(false);
|
||||||
|
result.set_label("Show already exists.");
|
||||||
|
result.show();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
add_button.set_sensitive(false);
|
||||||
|
if !uri.is_empty() {
|
||||||
|
result.set_label("Invalid url.");
|
||||||
|
result.show();
|
||||||
|
error!("Error: {}", err);
|
||||||
|
} else {
|
||||||
|
result.hide();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Totally copied it from fractal.
|
||||||
|
// https://gitlab.gnome.org/danigm/fractal/blob/503e311e22b9d7540089d735b92af8e8f93560c5/fractal-gtk/src/app.rs#L1883-1912
|
||||||
|
fn about_dialog(window: >k::Window) {
|
||||||
|
// Feel free to add yourself if you contribured.
|
||||||
|
let authors = &[
|
||||||
|
"Constantin Nickel",
|
||||||
|
"Gabriele Musco",
|
||||||
|
"James Wykeham-Martin",
|
||||||
|
"Jordan Petridis",
|
||||||
|
"Julian Sparber",
|
||||||
|
"Rowan Lewis",
|
||||||
|
];
|
||||||
|
|
||||||
|
let dialog = gtk::AboutDialog::new();
|
||||||
|
// Waiting for a logo.
|
||||||
|
// dialog.set_logo_icon_name("org.gnome.Hammond");
|
||||||
|
dialog.set_logo_icon_name("multimedia-player");
|
||||||
|
dialog.set_comments("Podcast Client for the GNOME Desktop.");
|
||||||
|
dialog.set_copyright("© 2017, 2018 Jordan Petridis");
|
||||||
|
dialog.set_license_type(gtk::License::Gpl30);
|
||||||
|
dialog.set_modal(true);
|
||||||
|
// TODO: make it show it fetches the commit hash from which it was built
|
||||||
|
// and the version number is kept in sync automaticly
|
||||||
|
dialog.set_version("0.3.1");
|
||||||
|
dialog.set_program_name("Hammond");
|
||||||
|
// TODO: Need a wiki page first.
|
||||||
|
// dialog.set_website("https://wiki.gnome.org/Design/Apps/Potential/Podcasts");
|
||||||
|
// dialog.set_website_label("Learn more about Hammond");
|
||||||
|
dialog.set_transient_for(window);
|
||||||
|
|
||||||
|
dialog.set_artists(&["Tobias Bernard"]);
|
||||||
|
dialog.set_authors(authors);
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
@@ -1,48 +1,13 @@
|
|||||||
#![cfg_attr(
|
#![cfg_attr(feature = "cargo-clippy",
|
||||||
feature = "cargo-clippy",
|
allow(clone_on_ref_ptr, needless_pass_by_value, useless_format, blacklisted_name,
|
||||||
allow(
|
match_same_arms))]
|
||||||
clone_on_ref_ptr,
|
|
||||||
blacklisted_name,
|
|
||||||
match_same_arms,
|
|
||||||
option_map_unit_fn
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
#![allow(unknown_lints)]
|
#![allow(unknown_lints)]
|
||||||
// Enable lint group collections
|
#![deny(unused_extern_crates, unused)]
|
||||||
#![warn(
|
|
||||||
nonstandard_style,
|
|
||||||
edition_2018,
|
|
||||||
rust_2018_idioms,
|
|
||||||
bad_style,
|
|
||||||
unused
|
|
||||||
)]
|
|
||||||
// standalone lints
|
|
||||||
#![warn(
|
|
||||||
const_err,
|
|
||||||
improper_ctypes,
|
|
||||||
non_shorthand_field_patterns,
|
|
||||||
no_mangle_generic_items,
|
|
||||||
overflowing_literals,
|
|
||||||
plugin_as_library,
|
|
||||||
private_no_mangle_fns,
|
|
||||||
private_no_mangle_statics,
|
|
||||||
unconditional_recursion,
|
|
||||||
unions_with_drop_fields,
|
|
||||||
while_true,
|
|
||||||
missing_debug_implementations,
|
|
||||||
trivial_casts,
|
|
||||||
trivial_numeric_casts,
|
|
||||||
elided_lifetime_in_paths,
|
|
||||||
missing_copy_implementations
|
|
||||||
)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
|
|
||||||
extern crate gdk;
|
extern crate gdk;
|
||||||
extern crate gdk_pixbuf;
|
extern crate gdk_pixbuf;
|
||||||
extern crate gio;
|
extern crate gio;
|
||||||
extern crate glib;
|
extern crate glib;
|
||||||
extern crate gstreamer as gst;
|
|
||||||
extern crate gstreamer_player as gst_player;
|
|
||||||
extern crate gtk;
|
extern crate gtk;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@@ -60,17 +25,18 @@ extern crate pretty_assertions;
|
|||||||
|
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate crossbeam_channel;
|
extern crate crossbeam_channel;
|
||||||
extern crate html2text;
|
extern crate hammond_data;
|
||||||
|
extern crate hammond_downloader;
|
||||||
|
extern crate html2pango;
|
||||||
extern crate humansize;
|
extern crate humansize;
|
||||||
extern crate loggerv;
|
extern crate loggerv;
|
||||||
extern crate open;
|
extern crate open;
|
||||||
extern crate podcasts_data;
|
|
||||||
extern crate podcasts_downloader;
|
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
extern crate send_cell;
|
extern crate send_cell;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
extern crate take_mut;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
|
|
||||||
use log::Level;
|
use log::Level;
|
||||||
@@ -96,17 +62,20 @@ macro_rules! clone {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
mod stacks;
|
// They do not need to be public
|
||||||
mod widgets;
|
// But it helps when looking at the generated docs.
|
||||||
|
pub mod views;
|
||||||
|
pub mod widgets;
|
||||||
|
pub mod stacks;
|
||||||
|
|
||||||
mod app;
|
pub mod headerbar;
|
||||||
mod headerbar;
|
pub mod app;
|
||||||
mod prefs;
|
|
||||||
|
|
||||||
mod manager;
|
pub mod settings;
|
||||||
mod settings;
|
pub mod utils;
|
||||||
mod static_resource;
|
pub mod manager;
|
||||||
mod utils;
|
pub mod static_resource;
|
||||||
|
pub mod appnotif;
|
||||||
|
|
||||||
use app::App;
|
use app::App;
|
||||||
|
|
||||||
@@ -114,17 +83,16 @@ fn main() {
|
|||||||
// TODO: make the the logger a cli -vv option
|
// TODO: make the the logger a cli -vv option
|
||||||
loggerv::init_with_level(Level::Info).expect("Error initializing loggerv.");
|
loggerv::init_with_level(Level::Info).expect("Error initializing loggerv.");
|
||||||
gtk::init().expect("Error initializing gtk.");
|
gtk::init().expect("Error initializing gtk.");
|
||||||
gst::init().expect("Error initializing gstreamer");
|
|
||||||
static_resource::init().expect("Something went wrong with the resource file initialization.");
|
static_resource::init().expect("Something went wrong with the resource file initialization.");
|
||||||
|
|
||||||
// Add custom style
|
// Add custom style
|
||||||
let provider = gtk::CssProvider::new();
|
let provider = gtk::CssProvider::new();
|
||||||
gtk::CssProvider::load_from_resource(&provider, "/org/gnome/Podcasts/gtk/style.css");
|
gtk::CssProvider::load_from_resource(&provider, "/org/gnome/hammond/gtk/style.css");
|
||||||
gtk::StyleContext::add_provider_for_screen(
|
gtk::StyleContext::add_provider_for_screen(
|
||||||
&gdk::Screen::get_default().expect("Error initializing gtk css provider."),
|
&gdk::Screen::get_default().expect("Error initializing gtk css provider."),
|
||||||
&provider,
|
&provider,
|
||||||
600,
|
600,
|
||||||
);
|
);
|
||||||
|
|
||||||
App::run();
|
App::new().run();
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
use failure::Error;
|
use failure::Error;
|
||||||
use rayon;
|
use rayon;
|
||||||
|
|
||||||
// use podcasts_data::Episode;
|
// use hammond_data::Episode;
|
||||||
use podcasts_data::dbqueries;
|
use hammond_data::dbqueries;
|
||||||
use podcasts_downloader::downloader::{get_episode, DownloadProgress};
|
use hammond_downloader::downloader::{get_episode, DownloadProgress};
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
// use std::sync::atomic::AtomicUsize;
|
// use std::sync::atomic::AtomicUsize;
|
||||||
// use std::path::PathBuf;
|
// use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -75,7 +78,7 @@ lazy_static! {
|
|||||||
static ref DLPOOL: rayon::ThreadPool = rayon::ThreadPoolBuilder::new().build().unwrap();
|
static ref DLPOOL: rayon::ThreadPool = rayon::ThreadPoolBuilder::new().build().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(id: i32, directory: String) -> Result<(), Error> {
|
pub fn add(id: i32, directory: String, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
// Create a new `Progress` struct to keep track of dl progress.
|
// Create a new `Progress` struct to keep track of dl progress.
|
||||||
let prog = Arc::new(Mutex::new(Progress::default()));
|
let prog = Arc::new(Mutex::new(Progress::default()));
|
||||||
|
|
||||||
@@ -85,12 +88,14 @@ pub fn add(id: i32, directory: String) -> Result<(), Error> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DLPOOL.spawn(move || {
|
DLPOOL.spawn(move || {
|
||||||
if let Ok(mut episode) = dbqueries::get_episode_widget_from_rowid(id) {
|
if let Ok(episode) = dbqueries::get_episode_from_rowid(id) {
|
||||||
|
let pid = episode.podcast_id();
|
||||||
let id = episode.rowid();
|
let id = episode.rowid();
|
||||||
|
|
||||||
get_episode(&mut episode, directory.as_str(), Some(prog))
|
if let Err(err) = get_episode(&mut episode.into(), directory.as_str(), Some(prog)) {
|
||||||
.map_err(|err| error!("Download Failed: {}", err))
|
error!("Error while trying to download an episode");
|
||||||
.ok();
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(mut m) = ACTIVE_DOWNLOADS.write() {
|
if let Ok(mut m) = ACTIVE_DOWNLOADS.write() {
|
||||||
let foo = m.remove(&id);
|
let foo = m.remove(&id);
|
||||||
@@ -100,6 +105,13 @@ pub fn add(id: i32, directory: String) -> Result<(), Error> {
|
|||||||
// if let Ok(m) = ACTIVE_DOWNLOADS.read() {
|
// if let Ok(m) = ACTIVE_DOWNLOADS.read() {
|
||||||
// debug!("ACTIVE DOWNLOADS: {:#?}", m);
|
// debug!("ACTIVE DOWNLOADS: {:#?}", m);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
sender
|
||||||
|
.send(Action::RefreshEpisodesView)
|
||||||
|
.expect("Action channel blew up.");
|
||||||
|
sender
|
||||||
|
.send(Action::RefreshWidgetIfSame(pid))
|
||||||
|
.expect("Action channel blew up.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -110,19 +122,20 @@ pub fn add(id: i32, directory: String) -> Result<(), Error> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use podcasts_data::dbqueries;
|
use hammond_data::{Episode, Source};
|
||||||
use podcasts_data::pipeline;
|
use hammond_data::dbqueries;
|
||||||
use podcasts_data::utils::get_download_folder;
|
use hammond_data::pipeline;
|
||||||
use podcasts_data::{Episode, Source};
|
use hammond_data::utils::get_download_folder;
|
||||||
|
|
||||||
use podcasts_downloader::downloader::get_episode;
|
use hammond_downloader::downloader::get_episode;
|
||||||
|
|
||||||
|
use std::{thread, time};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{thread, time};
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
// This test inserts an rss feed to your `XDG_DATA/podcasts/podcasts.db` so we make it explicit
|
// This test inserts an rss feed to your `XDG_DATA/hammond/hammond.db` so we make it explicit
|
||||||
// to run it.
|
// to run it.
|
||||||
#[ignore]
|
#[ignore]
|
||||||
// THIS IS NOT A RELIABLE TEST
|
// THIS IS NOT A RELIABLE TEST
|
||||||
@@ -141,9 +154,11 @@ mod tests {
|
|||||||
// Get an episode
|
// Get an episode
|
||||||
let episode: Episode = dbqueries::get_episode_from_pk(title, pd.id()).unwrap();
|
let episode: Episode = dbqueries::get_episode_from_pk(title, pd.id()).unwrap();
|
||||||
|
|
||||||
|
let (sender, _rx) = channel();
|
||||||
|
|
||||||
let download_fold = get_download_folder(&pd.title()).unwrap();
|
let download_fold = get_download_folder(&pd.title()).unwrap();
|
||||||
let fold2 = download_fold.clone();
|
let fold2 = download_fold.clone();
|
||||||
add(episode.rowid(), download_fold).unwrap();
|
add(episode.rowid(), download_fold, sender).unwrap();
|
||||||
assert_eq!(ACTIVE_DOWNLOADS.read().unwrap().len(), 1);
|
assert_eq!(ACTIVE_DOWNLOADS.read().unwrap().len(), 1);
|
||||||
|
|
||||||
// Give it soem time to download the file
|
// Give it soem time to download the file
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
use gio;
|
use gio;
|
||||||
use gio::{Settings, SettingsExt};
|
use gio::SettingsExt;
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::GtkWindowExt;
|
use gtk::GtkWindowExt;
|
||||||
|
|
||||||
use chrono::prelude::*;
|
|
||||||
use chrono::Duration;
|
|
||||||
|
|
||||||
pub struct WindowGeometry {
|
pub struct WindowGeometry {
|
||||||
left: i32,
|
left: i32,
|
||||||
top: i32,
|
top: i32,
|
||||||
@@ -15,7 +12,7 @@ pub struct WindowGeometry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WindowGeometry {
|
impl WindowGeometry {
|
||||||
pub fn from_window(window: >k::ApplicationWindow) -> WindowGeometry {
|
pub fn from_window(window: >k::Window) -> WindowGeometry {
|
||||||
let position = window.get_position();
|
let position = window.get_position();
|
||||||
let size = window.get_size();
|
let size = window.get_size();
|
||||||
let left = position.0;
|
let left = position.0;
|
||||||
@@ -49,7 +46,7 @@ impl WindowGeometry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply(&self, window: >k::ApplicationWindow) {
|
pub fn apply(&self, window: >k::Window) {
|
||||||
if self.width > 0 && self.height > 0 {
|
if self.width > 0 && self.height > 0 {
|
||||||
window.resize(self.width, self.height);
|
window.resize(self.width, self.height);
|
||||||
}
|
}
|
||||||
@@ -70,49 +67,6 @@ impl WindowGeometry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_refresh_interval(settings: &Settings) -> Duration {
|
|
||||||
let time = i64::from(settings.get_int("refresh-interval-time"));
|
|
||||||
let period = settings.get_string("refresh-interval-period").unwrap();
|
|
||||||
|
|
||||||
time_period_to_duration(time, period.as_str())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_cleanup_date(settings: &Settings) -> DateTime<Utc> {
|
|
||||||
let time = i64::from(settings.get_int("cleanup-age-time"));
|
|
||||||
let period = settings.get_string("cleanup-age-period").unwrap();
|
|
||||||
let duration = time_period_to_duration(time, period.as_str());
|
|
||||||
|
|
||||||
Utc::now() - duration
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn time_period_to_duration(time: i64, period: &str) -> Duration {
|
|
||||||
match period {
|
|
||||||
"weeks" => Duration::weeks(time),
|
|
||||||
"days" => Duration::days(time),
|
|
||||||
"hours" => Duration::hours(time),
|
|
||||||
"minutes" => Duration::minutes(time),
|
|
||||||
_ => Duration::seconds(time),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_time_period_to_duration() {
|
|
||||||
let time = 2;
|
|
||||||
let week = 604800 * time;
|
|
||||||
let day = 86400 * time;
|
|
||||||
let hour = 3600 * time;
|
|
||||||
let minute = 60 * time;
|
|
||||||
|
|
||||||
assert_eq!(week, time_period_to_duration(time, "weeks").num_seconds());
|
|
||||||
assert_eq!(day, time_period_to_duration(time, "days").num_seconds());
|
|
||||||
assert_eq!(hour, time_period_to_duration(time, "hours").num_seconds());
|
|
||||||
assert_eq!(
|
|
||||||
minute,
|
|
||||||
time_period_to_duration(time, "minutes").num_seconds()
|
|
||||||
);
|
|
||||||
assert_eq!(time, time_period_to_duration(time, "seconds").num_seconds());
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn test_apply_window_geometry() {
|
// fn test_apply_window_geometry() {
|
||||||
// gtk::init().expect("Error initializing gtk.");
|
// gtk::init().expect("Error initializing gtk.");
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
use stacks::EpisodeStack;
|
||||||
|
use stacks::ShowStack;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Content {
|
||||||
|
stack: gtk::Stack,
|
||||||
|
shows: Arc<ShowStack>,
|
||||||
|
episodes: Arc<EpisodeStack>,
|
||||||
|
sender: Sender<Action>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Content {
|
||||||
|
pub fn new(sender: Sender<Action>) -> Result<Content, Error> {
|
||||||
|
let stack = gtk::Stack::new();
|
||||||
|
let episodes = Arc::new(EpisodeStack::new(sender.clone())?);
|
||||||
|
let shows = Arc::new(ShowStack::new(sender.clone())?);
|
||||||
|
|
||||||
|
stack.add_titled(&episodes.get_stack(), "episodes", "Episodes");
|
||||||
|
stack.add_titled(&shows.get_stack(), "shows", "Shows");
|
||||||
|
|
||||||
|
Ok(Content {
|
||||||
|
stack,
|
||||||
|
shows,
|
||||||
|
episodes,
|
||||||
|
sender,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(&self) {
|
||||||
|
self.update_episode_view();
|
||||||
|
self.update_shows_view();
|
||||||
|
self.update_widget()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Maybe propagate the error?
|
||||||
|
pub fn update_episode_view(&self) {
|
||||||
|
if let Err(err) = self.episodes.update() {
|
||||||
|
error!("Something went wrong while trying to update the episode view.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_episode_view_if_baground(&self) {
|
||||||
|
if self.stack.get_visible_child_name() != Some("episodes".into()) {
|
||||||
|
self.update_episode_view();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_shows_view(&self) {
|
||||||
|
if let Err(err) = self.shows.update_podcasts() {
|
||||||
|
error!("Something went wrong while trying to update the ShowsView.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_widget(&self) {
|
||||||
|
if let Err(err) = self.shows.update_widget() {
|
||||||
|
error!("Something went wrong while trying to update the Show Widget.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_widget_if_same(&self, pid: i32) {
|
||||||
|
if let Err(err) = self.shows.update_widget_if_same(pid) {
|
||||||
|
error!("Something went wrong while trying to update the Show Widget.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_widget_if_visible(&self) {
|
||||||
|
if self.stack.get_visible_child_name() == Some("shows".to_string())
|
||||||
|
&& self.shows.get_stack().get_visible_child_name() == Some("widget".to_string())
|
||||||
|
{
|
||||||
|
self.update_widget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_stack(&self) -> gtk::Stack {
|
||||||
|
self.stack.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_shows(&self) -> Arc<ShowStack> {
|
||||||
|
self.shows.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
use gtk;
|
||||||
|
use gtk::Cast;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
|
use views::{EmptyView, EpisodesView};
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct EpisodeStack {
|
||||||
|
stack: gtk::Stack,
|
||||||
|
sender: Sender<Action>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EpisodeStack {
|
||||||
|
pub fn new(sender: Sender<Action>) -> Result<EpisodeStack, Error> {
|
||||||
|
let episodes = EpisodesView::new(sender.clone())?;
|
||||||
|
let empty = EmptyView::new();
|
||||||
|
let stack = gtk::Stack::new();
|
||||||
|
|
||||||
|
stack.add_named(&episodes.container, "episodes");
|
||||||
|
stack.add_named(&empty.container, "empty");
|
||||||
|
|
||||||
|
if episodes.is_empty() {
|
||||||
|
stack.set_visible_child_name("empty");
|
||||||
|
} else {
|
||||||
|
stack.set_visible_child_name("episodes");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(EpisodeStack { stack, sender })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look into refactoring to a state-machine.
|
||||||
|
pub fn update(&self) -> Result<(), Error> {
|
||||||
|
let old = self.stack
|
||||||
|
.get_child_by_name("episodes")
|
||||||
|
.ok_or_else(|| format_err!("Faild to get \"episodes\" child from the stack."))?
|
||||||
|
.downcast::<gtk::Box>()
|
||||||
|
.map_err(|_| format_err!("Failed to downcast stack child to a Box."))?;
|
||||||
|
debug!("Name: {:?}", WidgetExt::get_name(&old));
|
||||||
|
|
||||||
|
let scrolled_window = old.get_children()
|
||||||
|
.first()
|
||||||
|
.ok_or_else(|| format_err!("Box container has no childs."))?
|
||||||
|
.clone()
|
||||||
|
.downcast::<gtk::ScrolledWindow>()
|
||||||
|
.map_err(|_| format_err!("Failed to downcast stack child to a ScrolledWindow."))?;
|
||||||
|
debug!("Name: {:?}", WidgetExt::get_name(&scrolled_window));
|
||||||
|
|
||||||
|
let eps = EpisodesView::new(self.sender.clone())?;
|
||||||
|
// Copy the vertical scrollbar adjustment from the old view into the new one.
|
||||||
|
scrolled_window
|
||||||
|
.get_vadjustment()
|
||||||
|
.map(|x| eps.set_vadjustment(&x));
|
||||||
|
|
||||||
|
self.stack.remove(&old);
|
||||||
|
self.stack.add_named(&eps.container, "episodes");
|
||||||
|
|
||||||
|
if eps.is_empty() {
|
||||||
|
self.stack.set_visible_child_name("empty");
|
||||||
|
} else {
|
||||||
|
self.stack.set_visible_child_name("episodes");
|
||||||
|
}
|
||||||
|
|
||||||
|
old.destroy();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_stack(&self) -> gtk::Stack {
|
||||||
|
self.stack.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
mod content;
|
||||||
|
mod episode;
|
||||||
|
mod show;
|
||||||
|
|
||||||
|
pub use self::content::Content;
|
||||||
|
pub use self::episode::EpisodeStack;
|
||||||
|
pub use self::show::ShowStack;
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
use gtk;
|
||||||
|
use gtk::Cast;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
|
|
||||||
|
use hammond_data::Podcast;
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
|
use views::{EmptyView, ShowsPopulated};
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
use widgets::ShowWidget;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ShowStack {
|
||||||
|
stack: gtk::Stack,
|
||||||
|
sender: Sender<Action>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShowStack {
|
||||||
|
pub fn new(sender: Sender<Action>) -> Result<ShowStack, Error> {
|
||||||
|
let stack = gtk::Stack::new();
|
||||||
|
|
||||||
|
let show = ShowStack {
|
||||||
|
stack,
|
||||||
|
sender: sender.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let pop = ShowsPopulated::new(sender.clone())?;
|
||||||
|
let widget = ShowWidget::default();
|
||||||
|
let empty = EmptyView::new();
|
||||||
|
|
||||||
|
show.stack.add_named(&pop.container, "podcasts");
|
||||||
|
show.stack.add_named(&widget.container, "widget");
|
||||||
|
show.stack.add_named(&empty.container, "empty");
|
||||||
|
|
||||||
|
if pop.is_empty() {
|
||||||
|
show.stack.set_visible_child_name("empty")
|
||||||
|
} else {
|
||||||
|
show.stack.set_visible_child_name("podcasts")
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(show)
|
||||||
|
}
|
||||||
|
|
||||||
|
// pub fn update(&self) {
|
||||||
|
// self.update_widget();
|
||||||
|
// self.update_podcasts();
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub fn update_podcasts(&self) -> Result<(), Error> {
|
||||||
|
let vis = self.stack
|
||||||
|
.get_visible_child_name()
|
||||||
|
.ok_or_else(|| format_err!("Failed to get visible child name."))?;
|
||||||
|
|
||||||
|
let old = self.stack
|
||||||
|
.get_child_by_name("podcasts")
|
||||||
|
.ok_or_else(|| format_err!("Faild to get \"podcasts\" child from the stack."))?
|
||||||
|
.downcast::<gtk::Box>()
|
||||||
|
.map_err(|_| format_err!("Failed to downcast stack child to a Box."))?;
|
||||||
|
debug!("Name: {:?}", WidgetExt::get_name(&old));
|
||||||
|
|
||||||
|
let scrolled_window = old.get_children()
|
||||||
|
.first()
|
||||||
|
.ok_or_else(|| format_err!("Box container has no childs."))?
|
||||||
|
.clone()
|
||||||
|
.downcast::<gtk::ScrolledWindow>()
|
||||||
|
.map_err(|_| format_err!("Failed to downcast stack child to a ScrolledWindow."))?;
|
||||||
|
debug!("Name: {:?}", WidgetExt::get_name(&scrolled_window));
|
||||||
|
|
||||||
|
let pop = ShowsPopulated::new(self.sender.clone())?;
|
||||||
|
// Copy the vertical scrollbar adjustment from the old view into the new one.
|
||||||
|
scrolled_window
|
||||||
|
.get_vadjustment()
|
||||||
|
.map(|x| pop.set_vadjustment(&x));
|
||||||
|
|
||||||
|
self.stack.remove(&old);
|
||||||
|
self.stack.add_named(&pop.container, "podcasts");
|
||||||
|
|
||||||
|
if pop.is_empty() {
|
||||||
|
self.stack.set_visible_child_name("empty");
|
||||||
|
} else if vis != "empty" {
|
||||||
|
self.stack.set_visible_child_name(&vis);
|
||||||
|
} else {
|
||||||
|
self.stack.set_visible_child_name("podcasts");
|
||||||
|
}
|
||||||
|
|
||||||
|
old.destroy();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn replace_widget(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
||||||
|
let old = self.stack
|
||||||
|
.get_child_by_name("widget")
|
||||||
|
.ok_or_else(|| format_err!("Faild to get \"widget\" child from the stack."))?
|
||||||
|
.downcast::<gtk::Box>()
|
||||||
|
.map_err(|_| format_err!("Failed to downcast stack child to a Box."))?;
|
||||||
|
debug!("Name: {:?}", WidgetExt::get_name(&old));
|
||||||
|
|
||||||
|
let new = ShowWidget::new(pd, self.sender.clone());
|
||||||
|
// Each composite ShowWidget is a gtkBox with the Podcast.id encoded in the
|
||||||
|
// gtk::Widget name. It's a hack since we can't yet subclass GObject
|
||||||
|
// easily.
|
||||||
|
let oldid = WidgetExt::get_name(&old);
|
||||||
|
let newid = WidgetExt::get_name(&new.container);
|
||||||
|
debug!("Old widget Name: {:?}\nNew widget Name: {:?}", oldid, newid);
|
||||||
|
|
||||||
|
// Only copy the old scrollbar if both widget's represent the same podcast.
|
||||||
|
if newid == oldid {
|
||||||
|
let scrolled_window = old.get_children()
|
||||||
|
.first()
|
||||||
|
.ok_or_else(|| format_err!("Box container has no childs."))?
|
||||||
|
.clone()
|
||||||
|
.downcast::<gtk::ScrolledWindow>()
|
||||||
|
.map_err(|_| format_err!("Failed to downcast stack child to a ScrolledWindow."))?;
|
||||||
|
debug!("Name: {:?}", WidgetExt::get_name(&scrolled_window));
|
||||||
|
|
||||||
|
// Copy the vertical scrollbar adjustment from the old view into the new one.
|
||||||
|
scrolled_window
|
||||||
|
.get_vadjustment()
|
||||||
|
.map(|x| new.set_vadjustment(&x));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.stack.remove(&old);
|
||||||
|
self.stack.add_named(&new.container, "widget");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_widget(&self) -> Result<(), Error> {
|
||||||
|
let vis = self.stack
|
||||||
|
.get_visible_child_name()
|
||||||
|
.ok_or_else(|| format_err!("Failed to get visible child name."))?;
|
||||||
|
let old = self.stack
|
||||||
|
.get_child_by_name("widget")
|
||||||
|
.ok_or_else(|| format_err!("Faild to get \"widget\" child from the stack."))?;
|
||||||
|
|
||||||
|
let id = WidgetExt::get_name(&old);
|
||||||
|
if id == Some("GtkBox".to_string()) || id.is_none() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let id = id.ok_or_else(|| format_err!("Failed to get widget's name."))?;
|
||||||
|
let pd = dbqueries::get_podcast_from_id(id.parse::<i32>()?)?;
|
||||||
|
self.replace_widget(Arc::new(pd))?;
|
||||||
|
self.stack.set_visible_child_name(&vis);
|
||||||
|
old.destroy();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only update widget if it's podcast_id is equal to pid.
|
||||||
|
pub fn update_widget_if_same(&self, pid: i32) -> Result<(), Error> {
|
||||||
|
let old = self.stack
|
||||||
|
.get_child_by_name("widget")
|
||||||
|
.ok_or_else(|| format_err!("Faild to get \"widget\" child from the stack."))?;
|
||||||
|
|
||||||
|
let id = WidgetExt::get_name(&old);
|
||||||
|
if id != Some(pid.to_string()) || id.is_none() {
|
||||||
|
debug!("Different widget. Early return");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
self.update_widget()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn switch_podcasts_animated(&self) {
|
||||||
|
self.stack
|
||||||
|
.set_visible_child_full("podcasts", gtk::StackTransitionType::SlideRight);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn switch_widget_animated(&self) {
|
||||||
|
self.stack
|
||||||
|
.set_visible_child_full("widget", gtk::StackTransitionType::SlideLeft)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_stack(&self) -> gtk::Stack {
|
||||||
|
self.stack.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,330 @@
|
|||||||
|
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
|
|
||||||
|
use gdk_pixbuf::Pixbuf;
|
||||||
|
use gio::{Settings, SettingsExt};
|
||||||
|
use glib;
|
||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
|
use rayon;
|
||||||
|
use regex::Regex;
|
||||||
|
use reqwest;
|
||||||
|
use send_cell::SendCell;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
// use hammond_data::feed;
|
||||||
|
use hammond_data::{PodcastCoverQuery, Source};
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
use hammond_data::pipeline;
|
||||||
|
use hammond_data::utils::checkup;
|
||||||
|
use hammond_downloader::downloader;
|
||||||
|
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::sync::{Mutex, RwLock};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc::*;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
|
||||||
|
use chrono::Duration;
|
||||||
|
use chrono::prelude::*;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref IGNORESHOWS: Arc<Mutex<HashSet<i32>>> = Arc::new(Mutex::new(HashSet::new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ignore_show(id: i32) -> Result<bool, Error> {
|
||||||
|
IGNORESHOWS
|
||||||
|
.lock()
|
||||||
|
.map(|mut guard| guard.insert(id))
|
||||||
|
.map_err(|err| format_err!("{}", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uningore_show(id: i32) -> Result<bool, Error> {
|
||||||
|
IGNORESHOWS
|
||||||
|
.lock()
|
||||||
|
.map(|mut guard| guard.remove(&id))
|
||||||
|
.map_err(|err| format_err!("{}", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_ignored_shows() -> Result<Vec<i32>, Error> {
|
||||||
|
IGNORESHOWS
|
||||||
|
.lock()
|
||||||
|
.map(|guard| guard.iter().cloned().collect::<Vec<_>>())
|
||||||
|
.map_err(|err| format_err!("{}", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cleanup(cleanup_date: DateTime<Utc>) {
|
||||||
|
if let Err(err) = checkup(cleanup_date) {
|
||||||
|
error!("Check up failed: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn refresh(source: Option<Vec<Source>>, sender: Sender<Action>) {
|
||||||
|
if let Err(err) = refresh_feed(source, sender) {
|
||||||
|
error!("An error occured while trying to update the feeds.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_refresh_interval(settings: &Settings) -> Duration {
|
||||||
|
let time = settings.get_int("refresh-interval-time") as i64;
|
||||||
|
let period = settings.get_string("refresh-interval-period").unwrap();
|
||||||
|
|
||||||
|
time_period_to_duration(time, period.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_cleanup_date(settings: &Settings) -> DateTime<Utc> {
|
||||||
|
let time = settings.get_int("cleanup-age-time") as i64;
|
||||||
|
let period = settings.get_string("cleanup-age-period").unwrap();
|
||||||
|
let duration = time_period_to_duration(time, period.as_str());
|
||||||
|
|
||||||
|
Utc::now() - duration
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the rss feed(s) originating from `source`.
|
||||||
|
/// If `source` is None, Fetches all the `Source` entries in the database and updates them.
|
||||||
|
/// When It's done,it queues up a `RefreshViews` action.
|
||||||
|
fn refresh_feed(source: Option<Vec<Source>>, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
|
sender.send(Action::HeaderBarShowUpdateIndicator)?;
|
||||||
|
|
||||||
|
rayon::spawn(move || {
|
||||||
|
let mut sources = source.unwrap_or_else(|| {
|
||||||
|
dbqueries::get_sources().expect("Failed to retrieve Sources from the database.")
|
||||||
|
});
|
||||||
|
|
||||||
|
// Work around to improve the feed addition experience.
|
||||||
|
// Many times links to rss feeds are just redirects(usually to an https
|
||||||
|
// version). Sadly I haven't figured yet a nice way to follow up links
|
||||||
|
// redirects without getting to lifetime hell with futures and hyper.
|
||||||
|
// So the requested refresh is only of 1 feed, and the feed fails to be indexed,
|
||||||
|
// (as a 301 redict would update the source entry and exit), another refresh is
|
||||||
|
// run. For more see hammond_data/src/models/source.rs `fn
|
||||||
|
// request_constructor`. also ping me on irc if or open an issue if you
|
||||||
|
// want to tackle it.
|
||||||
|
if sources.len() == 1 {
|
||||||
|
let source = sources.remove(0);
|
||||||
|
let id = source.id();
|
||||||
|
if let Err(err) = pipeline::index_single_source(source, false) {
|
||||||
|
error!("Error While trying to update the database.");
|
||||||
|
error!("Error msg: {}", err);
|
||||||
|
if let Ok(source) = dbqueries::get_source_from_id(id) {
|
||||||
|
if let Err(err) = pipeline::index_single_source(source, false) {
|
||||||
|
error!("Error While trying to update the database.");
|
||||||
|
error!("Error msg: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// This is what would normally run
|
||||||
|
} else if let Err(err) = pipeline::run(sources, false) {
|
||||||
|
error!("Error While trying to update the database.");
|
||||||
|
error!("Error msg: {}", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender
|
||||||
|
.send(Action::HeaderBarHideUpdateIndicator)
|
||||||
|
.expect("Action channel blew up.");
|
||||||
|
sender
|
||||||
|
.send(Action::RefreshAllViews)
|
||||||
|
.expect("Action channel blew up.");
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref CACHED_PIXBUFS: RwLock<HashMap<(i32, u32), Mutex<SendCell<Pixbuf>>>> =
|
||||||
|
{ RwLock::new(HashMap::new()) };
|
||||||
|
static ref COVER_DL_REGISTRY: RwLock<HashSet<i32>> = RwLock::new(HashSet::new());
|
||||||
|
static ref THREADPOOL: rayon::ThreadPool = rayon::ThreadPoolBuilder::new().build().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since gdk_pixbuf::Pixbuf is refference counted and every episode,
|
||||||
|
// use the cover of the Podcast Feed/Show, We can only create a Pixbuf
|
||||||
|
// cover per show and pass around the Rc pointer.
|
||||||
|
//
|
||||||
|
// GObjects do not implement Send trait, so SendCell is a way around that.
|
||||||
|
// Also lazy_static requires Sync trait, so that's what the mutexes are.
|
||||||
|
// TODO: maybe use something that would just scale to requested size?
|
||||||
|
pub fn set_image_from_path(
|
||||||
|
image: >k::Image,
|
||||||
|
pd: Arc<PodcastCoverQuery>,
|
||||||
|
size: u32,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
// Check if there's an active download about this show cover.
|
||||||
|
// If there is, a callback will be set so this function will be called again.
|
||||||
|
// If the download succedes, there should be a quick return from the pixbuf cache_image
|
||||||
|
// If it fails another download will be scheduled.
|
||||||
|
if let Ok(guard) = COVER_DL_REGISTRY.read() {
|
||||||
|
if guard.contains(&pd.id()) {
|
||||||
|
let callback = clone!(image, pd => move || {
|
||||||
|
let _ = set_image_from_path(&image, pd.clone(), size);
|
||||||
|
glib::Continue(false)
|
||||||
|
});
|
||||||
|
gtk::timeout_add(250, callback);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(hashmap) = CACHED_PIXBUFS.read() {
|
||||||
|
// Check if the requested (cover + size) is already in the chache
|
||||||
|
// and if so do an early return after that.
|
||||||
|
if let Some(guard) = hashmap.get(&(pd.id(), size)) {
|
||||||
|
guard
|
||||||
|
.lock()
|
||||||
|
.map_err(|err| format_err!("SendCell Mutex: {}", err))
|
||||||
|
.and_then(|sendcell| {
|
||||||
|
sendcell
|
||||||
|
.try_get()
|
||||||
|
.map(|px| image.set_from_pixbuf(px))
|
||||||
|
.ok_or_else(|| format_err!("Pixbuf was accessed from a different thread"))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let (sender, receiver) = channel();
|
||||||
|
let pd_ = pd.clone();
|
||||||
|
THREADPOOL.spawn(move || {
|
||||||
|
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
|
||||||
|
guard.insert(pd_.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = sender.send(downloader::cache_image(&pd_));
|
||||||
|
|
||||||
|
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
|
||||||
|
guard.remove(&pd_.id());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let image = image.clone();
|
||||||
|
let s = size as i32;
|
||||||
|
gtk::timeout_add(25, move || {
|
||||||
|
if let Ok(path) = receiver.try_recv() {
|
||||||
|
if let Ok(path) = path {
|
||||||
|
if let Ok(px) = Pixbuf::new_from_file_at_scale(&path, s, s, true) {
|
||||||
|
if let Ok(mut hashmap) = CACHED_PIXBUFS.write() {
|
||||||
|
hashmap.insert((pd.id(), size), Mutex::new(SendCell::new(px.clone())));
|
||||||
|
image.set_from_pixbuf(&px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glib::Continue(false)
|
||||||
|
} else {
|
||||||
|
glib::Continue(true)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
// FIXME: the signature should be `fn foo(s: Url) -> Result<Url, Error>`
|
||||||
|
pub fn itunes_to_rss(url: &str) -> Result<String, Error> {
|
||||||
|
let id = itunes_id_from_url(url).ok_or_else(|| format_err!("Failed to find an Itunes ID."))?;
|
||||||
|
lookup_id(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn itunes_id_from_url(url: &str) -> Option<u32> {
|
||||||
|
lazy_static! {
|
||||||
|
static ref RE: Regex = Regex::new(r"/id([0-9]+)").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the itunes id from the url
|
||||||
|
let foo = RE.captures_iter(url).nth(0)?.get(1)?.as_str();
|
||||||
|
// Parse it to a u32, this *should* never fail
|
||||||
|
foo.parse::<u32>().ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn lookup_id(id: u32) -> Result<String, Error> {
|
||||||
|
let url = format!("https://itunes.apple.com/lookup?id={}&entity=podcast", id);
|
||||||
|
let req: Value = reqwest::get(&url)?.json()?;
|
||||||
|
let rssurl = || -> Option<&str> { req.get("results")?.get(0)?.get("feedUrl")?.as_str() };
|
||||||
|
rssurl()
|
||||||
|
.map(From::from)
|
||||||
|
.ok_or_else(|| format_err!("Failed to get url from itunes response"))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn time_period_to_duration(time: i64, period: &str) -> Duration {
|
||||||
|
match period {
|
||||||
|
"weeks" => Duration::weeks(time),
|
||||||
|
"days" => Duration::days(time),
|
||||||
|
"hours" => Duration::hours(time),
|
||||||
|
"minutes" => Duration::minutes(time),
|
||||||
|
_ => Duration::seconds(time),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
// use hammond_data::Source;
|
||||||
|
// use hammond_data::dbqueries;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_time_period_to_duration() {
|
||||||
|
let time = 2;
|
||||||
|
let week = 604800 * time;
|
||||||
|
let day = 86400 * time;
|
||||||
|
let hour = 3600 * time;
|
||||||
|
let minute = 60 * time;
|
||||||
|
|
||||||
|
assert_eq!(week, time_period_to_duration(time, "weeks").num_seconds());
|
||||||
|
assert_eq!(day, time_period_to_duration(time, "days").num_seconds());
|
||||||
|
assert_eq!(hour, time_period_to_duration(time, "hours").num_seconds());
|
||||||
|
assert_eq!(
|
||||||
|
minute,
|
||||||
|
time_period_to_duration(time, "minutes").num_seconds()
|
||||||
|
);
|
||||||
|
assert_eq!(time, time_period_to_duration(time, "seconds").num_seconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[test]
|
||||||
|
// This test inserts an rss feed to your `XDG_DATA/hammond/hammond.db` so we make it explicit
|
||||||
|
// to run it.
|
||||||
|
// #[ignore]
|
||||||
|
// Disabled till https://gitlab.gnome.org/alatiera/Hammond/issues/56
|
||||||
|
// fn test_set_image_from_path() {
|
||||||
|
// let url = "https://web.archive.org/web/20180120110727if_/https://rss.acast.com/thetipoff";
|
||||||
|
// Create and index a source
|
||||||
|
// let source = Source::from_url(url).unwrap();
|
||||||
|
// Copy it's id
|
||||||
|
// let sid = source.id();
|
||||||
|
// pipeline::run(vec![source], true).unwrap();
|
||||||
|
|
||||||
|
// Get the Podcast
|
||||||
|
// let img = gtk::Image::new();
|
||||||
|
// let pd = dbqueries::get_podcast_from_source_id(sid).unwrap().into();
|
||||||
|
// let pxbuf = set_image_from_path(&img, Arc::new(pd), 256);
|
||||||
|
// assert!(pxbuf.is_ok());
|
||||||
|
// }
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_itunes_to_rss() {
|
||||||
|
let itunes_url = "https://itunes.apple.com/podcast/id1195206601";
|
||||||
|
let rss_url = String::from("http://feeds.feedburner.com/InterceptedWithJeremyScahill");
|
||||||
|
assert_eq!(rss_url, itunes_to_rss(itunes_url).unwrap());
|
||||||
|
|
||||||
|
let itunes_url = "https://itunes.apple.com/podcast/id000000000000000";
|
||||||
|
assert!(itunes_to_rss(itunes_url).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_itunes_id() {
|
||||||
|
let id = 1195206601;
|
||||||
|
let itunes_url = "https://itunes.apple.com/podcast/id1195206601";
|
||||||
|
assert_eq!(id, itunes_id_from_url(itunes_url).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_itunes_lookup_id() {
|
||||||
|
let id = 1195206601;
|
||||||
|
let rss_url = "http://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
||||||
|
assert_eq!(rss_url, lookup_id(id).unwrap());
|
||||||
|
|
||||||
|
let id = 000000000;
|
||||||
|
assert!(lookup_id(id).is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ pub struct EmptyView {
|
|||||||
|
|
||||||
impl Default for EmptyView {
|
impl Default for EmptyView {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/Podcasts/gtk/empty_view.ui");
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_view.ui");
|
||||||
let view: gtk::Box = builder.get_object("empty_view").unwrap();
|
let view: gtk::Box = builder.get_object("empty_view").unwrap();
|
||||||
|
|
||||||
EmptyView { container: view }
|
EmptyView { container: view }
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
use chrono::prelude::*;
|
||||||
|
use failure::Error;
|
||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use hammond_data::EpisodeWidgetQuery;
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
use utils::{get_ignored_shows, set_image_from_path};
|
||||||
|
use widgets::EpisodeWidget;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
enum ListSplit {
|
||||||
|
Today,
|
||||||
|
Yday,
|
||||||
|
Week,
|
||||||
|
Month,
|
||||||
|
Rest,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct EpisodesView {
|
||||||
|
pub container: gtk::Box,
|
||||||
|
scrolled_window: gtk::ScrolledWindow,
|
||||||
|
frame_parent: gtk::Box,
|
||||||
|
today_box: gtk::Box,
|
||||||
|
yday_box: gtk::Box,
|
||||||
|
week_box: gtk::Box,
|
||||||
|
month_box: gtk::Box,
|
||||||
|
rest_box: gtk::Box,
|
||||||
|
today_list: gtk::ListBox,
|
||||||
|
yday_list: gtk::ListBox,
|
||||||
|
week_list: gtk::ListBox,
|
||||||
|
month_list: gtk::ListBox,
|
||||||
|
rest_list: gtk::ListBox,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for EpisodesView {
|
||||||
|
fn default() -> Self {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view.ui");
|
||||||
|
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||||
|
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
|
||||||
|
let frame_parent: gtk::Box = builder.get_object("frame_parent").unwrap();
|
||||||
|
let today_box: gtk::Box = builder.get_object("today_box").unwrap();
|
||||||
|
let yday_box: gtk::Box = builder.get_object("yday_box").unwrap();
|
||||||
|
let week_box: gtk::Box = builder.get_object("week_box").unwrap();
|
||||||
|
let month_box: gtk::Box = builder.get_object("month_box").unwrap();
|
||||||
|
let rest_box: gtk::Box = builder.get_object("rest_box").unwrap();
|
||||||
|
let today_list: gtk::ListBox = builder.get_object("today_list").unwrap();
|
||||||
|
let yday_list: gtk::ListBox = builder.get_object("yday_list").unwrap();
|
||||||
|
let week_list: gtk::ListBox = builder.get_object("week_list").unwrap();
|
||||||
|
let month_list: gtk::ListBox = builder.get_object("month_list").unwrap();
|
||||||
|
let rest_list: gtk::ListBox = builder.get_object("rest_list").unwrap();
|
||||||
|
|
||||||
|
EpisodesView {
|
||||||
|
container,
|
||||||
|
scrolled_window,
|
||||||
|
frame_parent,
|
||||||
|
today_box,
|
||||||
|
yday_box,
|
||||||
|
week_box,
|
||||||
|
month_box,
|
||||||
|
rest_box,
|
||||||
|
today_list,
|
||||||
|
yday_list,
|
||||||
|
week_list,
|
||||||
|
month_list,
|
||||||
|
rest_list,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: REFACTOR ME
|
||||||
|
impl EpisodesView {
|
||||||
|
pub fn new(sender: Sender<Action>) -> Result<EpisodesView, Error> {
|
||||||
|
let view = EpisodesView::default();
|
||||||
|
let ignore = get_ignored_shows()?;
|
||||||
|
let episodes = dbqueries::get_episodes_widgets_filter_limit(&ignore, 50)?;
|
||||||
|
let now_utc = Utc::now();
|
||||||
|
|
||||||
|
episodes.into_iter().for_each(|ep| {
|
||||||
|
let epoch = ep.epoch();
|
||||||
|
let viewep = EpisodesViewWidget::new(ep, sender.clone());
|
||||||
|
|
||||||
|
let t = split(&now_utc, i64::from(epoch));
|
||||||
|
match t {
|
||||||
|
ListSplit::Today => {
|
||||||
|
view.today_list.add(&viewep.container);
|
||||||
|
}
|
||||||
|
ListSplit::Yday => {
|
||||||
|
view.yday_list.add(&viewep.container);
|
||||||
|
}
|
||||||
|
ListSplit::Week => {
|
||||||
|
view.week_list.add(&viewep.container);
|
||||||
|
}
|
||||||
|
ListSplit::Month => {
|
||||||
|
view.month_list.add(&viewep.container);
|
||||||
|
}
|
||||||
|
ListSplit::Rest => {
|
||||||
|
view.rest_list.add(&viewep.container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if view.today_list.get_children().is_empty() {
|
||||||
|
view.today_box.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if view.yday_list.get_children().is_empty() {
|
||||||
|
view.yday_box.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if view.week_list.get_children().is_empty() {
|
||||||
|
view.week_box.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if view.month_list.get_children().is_empty() {
|
||||||
|
view.month_box.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if view.rest_list.get_children().is_empty() {
|
||||||
|
view.rest_box.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
view.container.show_all();
|
||||||
|
Ok(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
if !self.today_list.get_children().is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.yday_list.get_children().is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.week_list.get_children().is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.month_list.get_children().is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.rest_list.get_children().is_empty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set scrolled window vertical adjustment.
|
||||||
|
pub fn set_vadjustment(&self, vadjustment: >k::Adjustment) {
|
||||||
|
self.scrolled_window.set_vadjustment(vadjustment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn split(now: &DateTime<Utc>, epoch: i64) -> ListSplit {
|
||||||
|
let ep = Utc.timestamp(epoch, 0);
|
||||||
|
|
||||||
|
if now.ordinal() == ep.ordinal() && now.year() == ep.year() {
|
||||||
|
ListSplit::Today
|
||||||
|
} else if now.ordinal() == ep.ordinal() + 1 && now.year() == ep.year() {
|
||||||
|
ListSplit::Yday
|
||||||
|
} else if now.iso_week().week() == ep.iso_week().week() && now.year() == ep.year() {
|
||||||
|
ListSplit::Week
|
||||||
|
} else if now.month() == ep.month() && now.year() == ep.year() {
|
||||||
|
ListSplit::Month
|
||||||
|
} else {
|
||||||
|
ListSplit::Rest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
struct EpisodesViewWidget {
|
||||||
|
container: gtk::Box,
|
||||||
|
image: gtk::Image,
|
||||||
|
episode: gtk::Box,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for EpisodesViewWidget {
|
||||||
|
fn default() -> Self {
|
||||||
|
let builder =
|
||||||
|
gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui");
|
||||||
|
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||||
|
let image: gtk::Image = builder.get_object("cover").unwrap();
|
||||||
|
let ep = EpisodeWidget::default();
|
||||||
|
container.pack_start(&ep.container, true, true, 6);
|
||||||
|
|
||||||
|
EpisodesViewWidget {
|
||||||
|
container,
|
||||||
|
image,
|
||||||
|
episode: ep.container,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EpisodesViewWidget {
|
||||||
|
fn new(episode: EpisodeWidgetQuery, sender: Sender<Action>) -> EpisodesViewWidget {
|
||||||
|
let builder =
|
||||||
|
gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episodes_view_widget.ui");
|
||||||
|
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||||
|
let image: gtk::Image = builder.get_object("cover").unwrap();
|
||||||
|
let pid = episode.podcast_id();
|
||||||
|
let ep = EpisodeWidget::new(episode, sender.clone());
|
||||||
|
|
||||||
|
let view = EpisodesViewWidget {
|
||||||
|
container,
|
||||||
|
image,
|
||||||
|
episode: ep.container,
|
||||||
|
};
|
||||||
|
|
||||||
|
view.init(pid);
|
||||||
|
view
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(&self, podcast_id: i32) {
|
||||||
|
if let Err(err) = self.set_cover(podcast_id) {
|
||||||
|
error!("Failed to set a cover: {}", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.container.pack_start(&self.episode, true, true, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_cover(&self, podcast_id: i32) -> Result<(), Error> {
|
||||||
|
let pd = Arc::new(dbqueries::get_podcast_cover_from_id(podcast_id)?);
|
||||||
|
set_image_from_path(&self.image, pd, 64)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
mod shows;
|
||||||
|
mod episodes;
|
||||||
|
mod empty;
|
||||||
|
|
||||||
|
pub use self::empty::EmptyView;
|
||||||
|
pub use self::episodes::EpisodesView;
|
||||||
|
pub use self::shows::ShowsPopulated;
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
use failure::Error;
|
||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use hammond_data::{Podcast, PodcastCoverQuery};
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
use utils::{get_ignored_shows, set_image_from_path};
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ShowsPopulated {
|
||||||
|
pub container: gtk::Box,
|
||||||
|
scrolled_window: gtk::ScrolledWindow,
|
||||||
|
flowbox: gtk::FlowBox,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ShowsPopulated {
|
||||||
|
fn default() -> Self {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_view.ui");
|
||||||
|
let container: gtk::Box = builder.get_object("fb_parent").unwrap();
|
||||||
|
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
|
||||||
|
let flowbox: gtk::FlowBox = builder.get_object("flowbox").unwrap();
|
||||||
|
|
||||||
|
ShowsPopulated {
|
||||||
|
container,
|
||||||
|
scrolled_window,
|
||||||
|
flowbox,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShowsPopulated {
|
||||||
|
pub fn new(sender: Sender<Action>) -> Result<ShowsPopulated, Error> {
|
||||||
|
let pop = ShowsPopulated::default();
|
||||||
|
pop.init(sender)?;
|
||||||
|
Ok(pop)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&self, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
|
self.flowbox.connect_child_activated(move |_, child| {
|
||||||
|
if let Err(err) = on_child_activate(child, sender.clone()) {
|
||||||
|
error!(
|
||||||
|
"Something went wrong during flowbox child activation: {}.",
|
||||||
|
err
|
||||||
|
)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// Populate the flowbox with the Podcasts.
|
||||||
|
self.populate_flowbox()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn populate_flowbox(&self) -> Result<(), Error> {
|
||||||
|
let ignore = get_ignored_shows()?;
|
||||||
|
let podcasts = dbqueries::get_podcasts_filter(&ignore)?;
|
||||||
|
|
||||||
|
podcasts.into_iter().for_each(|parent| {
|
||||||
|
let flowbox_child = ShowsChild::new(parent);
|
||||||
|
self.flowbox.add(&flowbox_child.child);
|
||||||
|
});
|
||||||
|
self.flowbox.show_all();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.flowbox.get_children().is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set scrolled window vertical adjustment.
|
||||||
|
pub fn set_vadjustment(&self, vadjustment: >k::Adjustment) {
|
||||||
|
self.scrolled_window.set_vadjustment(vadjustment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_child_activate(child: >k::FlowBoxChild, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
|
use gtk::WidgetExt;
|
||||||
|
|
||||||
|
// This is such an ugly hack...
|
||||||
|
let id = WidgetExt::get_name(child)
|
||||||
|
.ok_or_else(|| format_err!("Faild to get \"episodes\" child from the stack."))?
|
||||||
|
.parse::<i32>()?;
|
||||||
|
let pd = Arc::new(dbqueries::get_podcast_from_id(id)?);
|
||||||
|
|
||||||
|
sender.send(Action::HeaderBarShowTile(pd.title().into()))?;
|
||||||
|
sender.send(Action::ReplaceWidget(pd))?;
|
||||||
|
sender.send(Action::ShowWidgetAnimated)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ShowsChild {
|
||||||
|
container: gtk::Box,
|
||||||
|
cover: gtk::Image,
|
||||||
|
child: gtk::FlowBoxChild,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ShowsChild {
|
||||||
|
fn default() -> Self {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/shows_child.ui");
|
||||||
|
|
||||||
|
let container: gtk::Box = builder.get_object("fb_child").unwrap();
|
||||||
|
let cover: gtk::Image = builder.get_object("pd_cover").unwrap();
|
||||||
|
|
||||||
|
let child = gtk::FlowBoxChild::new();
|
||||||
|
child.add(&container);
|
||||||
|
|
||||||
|
ShowsChild {
|
||||||
|
container,
|
||||||
|
cover,
|
||||||
|
child,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShowsChild {
|
||||||
|
pub fn new(pd: Podcast) -> ShowsChild {
|
||||||
|
let child = ShowsChild::default();
|
||||||
|
child.init(pd);
|
||||||
|
child
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(&self, pd: Podcast) {
|
||||||
|
self.container.set_tooltip_text(pd.title());
|
||||||
|
WidgetExt::set_name(&self.child, &pd.id().to_string());
|
||||||
|
|
||||||
|
let pd = Arc::new(pd.into());
|
||||||
|
if let Err(err) = self.set_cover(pd) {
|
||||||
|
error!("Failed to set a cover: {}", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_cover(&self, pd: Arc<PodcastCoverQuery>) -> Result<(), Error> {
|
||||||
|
set_image_from_path(&self.cover, pd, 256)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,413 @@
|
|||||||
|
use glib;
|
||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
use failure::Error;
|
||||||
|
use humansize::FileSize;
|
||||||
|
use open;
|
||||||
|
use rayon;
|
||||||
|
use take_mut;
|
||||||
|
|
||||||
|
use hammond_data::{EpisodeWidgetQuery, Podcast};
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
use hammond_data::utils::get_download_folder;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
use manager;
|
||||||
|
use widgets::episode_states::*;
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::ops::DerefMut;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct EpisodeWidget {
|
||||||
|
pub container: gtk::Box,
|
||||||
|
date: DateMachine,
|
||||||
|
duration: DurationMachine,
|
||||||
|
title: Rc<RefCell<TitleMachine>>,
|
||||||
|
media: Arc<Mutex<MediaMachine>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for EpisodeWidget {
|
||||||
|
fn default() -> Self {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episode_widget.ui");
|
||||||
|
|
||||||
|
let container: gtk::Box = builder.get_object("episode_container").unwrap();
|
||||||
|
let progress: gtk::ProgressBar = builder.get_object("progress_bar").unwrap();
|
||||||
|
|
||||||
|
let download: gtk::Button = builder.get_object("download_button").unwrap();
|
||||||
|
let play: gtk::Button = builder.get_object("play_button").unwrap();
|
||||||
|
let cancel: gtk::Button = builder.get_object("cancel_button").unwrap();
|
||||||
|
|
||||||
|
let title: gtk::Label = builder.get_object("title_label").unwrap();
|
||||||
|
let date: gtk::Label = builder.get_object("date_label").unwrap();
|
||||||
|
let duration: gtk::Label = builder.get_object("duration_label").unwrap();
|
||||||
|
let local_size: gtk::Label = builder.get_object("local_size").unwrap();
|
||||||
|
let total_size: gtk::Label = builder.get_object("total_size").unwrap();
|
||||||
|
|
||||||
|
let separator1: gtk::Label = builder.get_object("separator1").unwrap();
|
||||||
|
let separator2: gtk::Label = builder.get_object("separator2").unwrap();
|
||||||
|
let prog_separator: gtk::Label = builder.get_object("prog_separator").unwrap();
|
||||||
|
|
||||||
|
let date_machine = DateMachine::new(date, 0);
|
||||||
|
let dur_machine = DurationMachine::new(duration, separator1, None);
|
||||||
|
let title_machine = Rc::new(RefCell::new(TitleMachine::new(title, false)));
|
||||||
|
let media = MediaMachine::new(
|
||||||
|
play,
|
||||||
|
download,
|
||||||
|
progress,
|
||||||
|
cancel,
|
||||||
|
total_size,
|
||||||
|
local_size,
|
||||||
|
separator2,
|
||||||
|
prog_separator,
|
||||||
|
);
|
||||||
|
let media_machine = Arc::new(Mutex::new(media));
|
||||||
|
|
||||||
|
EpisodeWidget {
|
||||||
|
container,
|
||||||
|
title: title_machine,
|
||||||
|
duration: dur_machine,
|
||||||
|
date: date_machine,
|
||||||
|
media: media_machine,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EpisodeWidget {
|
||||||
|
pub fn new(episode: EpisodeWidgetQuery, sender: Sender<Action>) -> EpisodeWidget {
|
||||||
|
let mut widget = EpisodeWidget::default();
|
||||||
|
widget.init(episode, sender);
|
||||||
|
widget
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(&mut self, episode: EpisodeWidgetQuery, sender: Sender<Action>) {
|
||||||
|
WidgetExt::set_name(&self.container, &episode.rowid().to_string());
|
||||||
|
|
||||||
|
// Set the date label.
|
||||||
|
self.set_date(episode.epoch());
|
||||||
|
|
||||||
|
// Set the title label state.
|
||||||
|
self.set_title(&episode);
|
||||||
|
|
||||||
|
// Set the duaration label.
|
||||||
|
self.set_duration(episode.duration());
|
||||||
|
|
||||||
|
// Determine what the state of the media widgets should be.
|
||||||
|
if let Err(err) = self.determine_media_state(&episode) {
|
||||||
|
error!("Something went wrong determining the Media State.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
let episode = Arc::new(Mutex::new(episode));
|
||||||
|
self.connect_buttons(episode, sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn connect_buttons(&self, episode: Arc<Mutex<EpisodeWidgetQuery>>, sender: Sender<Action>) {
|
||||||
|
let title = self.title.clone();
|
||||||
|
if let Ok(media) = self.media.lock() {
|
||||||
|
media.play_connect_clicked(clone!(episode, sender => move |_| {
|
||||||
|
if let Ok(mut ep) = episode.lock() {
|
||||||
|
if let Err(err) = on_play_bttn_clicked(&mut ep, title.clone(), sender.clone()){
|
||||||
|
error!("Error: {}", err);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
media.download_connect_clicked(clone!(episode, sender => move |dl| {
|
||||||
|
dl.set_sensitive(false);
|
||||||
|
if let Ok(ep) = episode.lock() {
|
||||||
|
if let Err(err) = on_download_clicked(&ep, sender.clone()) {
|
||||||
|
error!("Download failed to start.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
} else {
|
||||||
|
info!("Donwload started succesfully.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine the title state.
|
||||||
|
fn set_title(&mut self, episode: &EpisodeWidgetQuery) {
|
||||||
|
let mut machine = self.title.borrow_mut();
|
||||||
|
machine.set_title(episode.title());
|
||||||
|
take_mut::take(machine.deref_mut(), |title| {
|
||||||
|
title.determine_state(episode.played().is_some())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the date label depending on the current time.
|
||||||
|
fn set_date(&mut self, epoch: i32) {
|
||||||
|
let machine = &mut self.date;
|
||||||
|
take_mut::take(machine, |date| date.determine_state(i64::from(epoch)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the duration label.
|
||||||
|
fn set_duration(&mut self, seconds: Option<i32>) {
|
||||||
|
let machine = &mut self.duration;
|
||||||
|
take_mut::take(machine, |duration| duration.determine_state(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn determine_media_state(&self, episode: &EpisodeWidgetQuery) -> Result<(), Error> {
|
||||||
|
let id = WidgetExt::get_name(&self.container)
|
||||||
|
.ok_or_else(|| format_err!("Failed to get widget Name"))?
|
||||||
|
.parse::<i32>()?;
|
||||||
|
|
||||||
|
let active_dl = || -> Result<Option<_>, Error> {
|
||||||
|
let m = manager::ACTIVE_DOWNLOADS
|
||||||
|
.read()
|
||||||
|
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||||
|
|
||||||
|
Ok(m.get(&id).cloned())
|
||||||
|
}()?;
|
||||||
|
|
||||||
|
let mut lock = self.media.lock().map_err(|err| format_err!("{}", err))?;
|
||||||
|
take_mut::take(lock.deref_mut(), |media| {
|
||||||
|
media.determine_state(
|
||||||
|
episode.length(),
|
||||||
|
active_dl.is_some(),
|
||||||
|
episode.local_uri().is_some(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Show or hide the play/delete/download buttons upon widget initialization.
|
||||||
|
if let Some(prog) = active_dl {
|
||||||
|
lock.cancel_connect_clicked(prog.clone());
|
||||||
|
drop(lock);
|
||||||
|
|
||||||
|
// Setup a callback that will update the progress bar.
|
||||||
|
update_progressbar_callback(prog.clone(), self.media.clone(), id);
|
||||||
|
|
||||||
|
// Setup a callback that will update the total_size label
|
||||||
|
// with the http ContentLength header number rather than
|
||||||
|
// relying to the RSS feed.
|
||||||
|
update_total_size_callback(prog.clone(), self.media.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
|
let pd = dbqueries::get_podcast_from_id(ep.podcast_id())?;
|
||||||
|
let download_fold = get_download_folder(&pd.title())?;
|
||||||
|
|
||||||
|
// Start a new download.
|
||||||
|
manager::add(ep.rowid(), download_fold, sender.clone())?;
|
||||||
|
|
||||||
|
// Update Views
|
||||||
|
sender.send(Action::RefreshEpisodesView)?;
|
||||||
|
sender.send(Action::RefreshWidgetIfVis)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn on_play_bttn_clicked(
|
||||||
|
episode: &mut EpisodeWidgetQuery,
|
||||||
|
title: Rc<RefCell<TitleMachine>>,
|
||||||
|
sender: Sender<Action>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
open_uri(episode.rowid())?;
|
||||||
|
episode.set_played_now()?;
|
||||||
|
|
||||||
|
let mut machine = title.try_borrow_mut()?;
|
||||||
|
take_mut::take(machine.deref_mut(), |title| {
|
||||||
|
title.determine_state(episode.played().is_some())
|
||||||
|
});
|
||||||
|
|
||||||
|
sender.send(Action::RefreshEpisodesViewBGR)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_uri(rowid: i32) -> Result<(), Error> {
|
||||||
|
let uri = dbqueries::get_episode_local_uri_from_id(rowid)?
|
||||||
|
.ok_or_else(|| format_err!("Expected Some found None."))?;
|
||||||
|
|
||||||
|
if Path::new(&uri).exists() {
|
||||||
|
info!("Opening {}", uri);
|
||||||
|
open::that(&uri)?;
|
||||||
|
} else {
|
||||||
|
bail!("File \"{}\" does not exist.", uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup a callback that will update the progress bar.
|
||||||
|
#[inline]
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
|
||||||
|
fn update_progressbar_callback(
|
||||||
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
|
media: Arc<Mutex<MediaMachine>>,
|
||||||
|
episode_rowid: i32,
|
||||||
|
) {
|
||||||
|
timeout_add(
|
||||||
|
400,
|
||||||
|
clone!(prog, media => move || {
|
||||||
|
progress_bar_helper(prog.clone(), media.clone(), episode_rowid)
|
||||||
|
.unwrap_or(glib::Continue(false))
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[allow(if_same_then_else)]
|
||||||
|
fn progress_bar_helper(
|
||||||
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
|
media: Arc<Mutex<MediaMachine>>,
|
||||||
|
episode_rowid: i32,
|
||||||
|
) -> Result<glib::Continue, Error> {
|
||||||
|
let (fraction, downloaded) = {
|
||||||
|
let m = prog.lock()
|
||||||
|
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||||
|
(m.get_fraction(), m.get_downloaded())
|
||||||
|
};
|
||||||
|
|
||||||
|
// I hate floating points.
|
||||||
|
// Update the progress_bar.
|
||||||
|
if (fraction >= 0.0) && (fraction <= 1.0) && (!fraction.is_nan()) {
|
||||||
|
// Update local_size label
|
||||||
|
let size = downloaded
|
||||||
|
.file_size(SIZE_OPTS.clone())
|
||||||
|
.map_err(|err| format_err!("{}", err))?;
|
||||||
|
|
||||||
|
let mut m = media.lock().unwrap();
|
||||||
|
m.update_progress(&size, fraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
// info!("Fraction: {}", progress_bar.get_fraction());
|
||||||
|
// info!("Fraction: {}", fraction);
|
||||||
|
|
||||||
|
// Check if the download is still active
|
||||||
|
let active = {
|
||||||
|
let m = manager::ACTIVE_DOWNLOADS
|
||||||
|
.read()
|
||||||
|
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||||
|
m.contains_key(&episode_rowid)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (fraction >= 1.0) && (!fraction.is_nan()) {
|
||||||
|
Ok(glib::Continue(false))
|
||||||
|
} else if !active {
|
||||||
|
Ok(glib::Continue(false))
|
||||||
|
} else {
|
||||||
|
Ok(glib::Continue(true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup a callback that will update the total_size label
|
||||||
|
// with the http ContentLength header number rather than
|
||||||
|
// relying to the RSS feed.
|
||||||
|
#[inline]
|
||||||
|
fn update_total_size_callback(
|
||||||
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
|
media: Arc<Mutex<MediaMachine>>,
|
||||||
|
) {
|
||||||
|
timeout_add(
|
||||||
|
500,
|
||||||
|
clone!(prog, media => move || {
|
||||||
|
total_size_helper(prog.clone(), media.clone()).unwrap_or(glib::Continue(true))
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn total_size_helper(
|
||||||
|
prog: Arc<Mutex<manager::Progress>>,
|
||||||
|
media: Arc<Mutex<MediaMachine>>,
|
||||||
|
) -> Result<glib::Continue, Error> {
|
||||||
|
// Get the total_bytes.
|
||||||
|
let total_bytes = {
|
||||||
|
let m = prog.lock()
|
||||||
|
.map_err(|_| format_err!("Failed to get a lock on the mutex."))?;
|
||||||
|
m.get_total_size()
|
||||||
|
};
|
||||||
|
|
||||||
|
debug!("Total Size: {}", total_bytes);
|
||||||
|
if total_bytes != 0 {
|
||||||
|
// Update the total_size label
|
||||||
|
if let Ok(mut m) = media.lock() {
|
||||||
|
take_mut::take(m.deref_mut(), |machine| {
|
||||||
|
machine.set_size(Some(total_bytes as i32))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not call again the callback
|
||||||
|
Ok(glib::Continue(false))
|
||||||
|
} else {
|
||||||
|
Ok(glib::Continue(true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn on_delete_bttn_clicked(episode_id: i32) -> Result<(), Error> {
|
||||||
|
// let mut ep = dbqueries::get_episode_from_rowid(episode_id)?.into();
|
||||||
|
// delete_local_content(&mut ep).map_err(From::from).map(|_| ())
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub fn episodes_listbox(pd: Arc<Podcast>, sender: Sender<Action>) -> Result<gtk::ListBox, Error> {
|
||||||
|
use crossbeam_channel::TryRecvError::*;
|
||||||
|
use crossbeam_channel::bounded;
|
||||||
|
|
||||||
|
let count = dbqueries::get_pd_episodes_count(&pd)?;
|
||||||
|
|
||||||
|
let (sender_, receiver) = bounded(1);
|
||||||
|
rayon::spawn(move || {
|
||||||
|
let episodes = dbqueries::get_pd_episodeswidgets(&pd).unwrap();
|
||||||
|
sender_
|
||||||
|
.send(episodes)
|
||||||
|
.expect("Something terrible happened to the channnel");
|
||||||
|
});
|
||||||
|
|
||||||
|
let list = gtk::ListBox::new();
|
||||||
|
list.set_visible(true);
|
||||||
|
list.set_selection_mode(gtk::SelectionMode::None);
|
||||||
|
|
||||||
|
if count == 0 {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/empty_show.ui");
|
||||||
|
let container: gtk::Box = builder.get_object("empty_show").unwrap();
|
||||||
|
list.add(&container);
|
||||||
|
return Ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk::idle_add(clone!(list => move || {
|
||||||
|
let episodes = match receiver.try_recv() {
|
||||||
|
Ok(e) => e,
|
||||||
|
Err(Empty) => return glib::Continue(true),
|
||||||
|
Err(Disconnected) => return glib::Continue(false),
|
||||||
|
};
|
||||||
|
|
||||||
|
lazy_load(episodes, list.clone(), clone!(sender => move |ep| {
|
||||||
|
EpisodeWidget::new(ep, sender.clone()).container
|
||||||
|
}));
|
||||||
|
|
||||||
|
glib::Continue(false)
|
||||||
|
}));
|
||||||
|
|
||||||
|
Ok(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
use gtk::{IsA, Widget};
|
||||||
|
|
||||||
|
fn lazy_load<T, U, P, Z>(data: T, container: Z, mut predicate: P)
|
||||||
|
where
|
||||||
|
T: IntoIterator + 'static,
|
||||||
|
T::Item: 'static,
|
||||||
|
Z: ContainerExt + 'static,
|
||||||
|
P: FnMut(T::Item) -> U + 'static,
|
||||||
|
U: IsA<Widget>,
|
||||||
|
{
|
||||||
|
let mut data = data.into_iter();
|
||||||
|
gtk::idle_add(move || {
|
||||||
|
data.next()
|
||||||
|
.map(|x| container.add(&predicate(x)))
|
||||||
|
.map(|_| glib::Continue(true))
|
||||||
|
.unwrap_or(glib::Continue(false))
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,917 @@
|
|||||||
|
// TODO: Things that should be done.
|
||||||
|
//
|
||||||
|
// * Wherever there's a function that take 2 or more arguments of the same type,
|
||||||
|
// eg: fn new(total_size: gtk::Label, local_size: gtk::Label ..)
|
||||||
|
// Wrap the types into Struct-tuples and imple deref so it won't be possible to pass
|
||||||
|
// the wrong argument to the wrong position.
|
||||||
|
|
||||||
|
use chrono;
|
||||||
|
use glib;
|
||||||
|
use gtk;
|
||||||
|
|
||||||
|
use chrono::prelude::*;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use humansize::{file_size_opts as size_opts, FileSize};
|
||||||
|
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use manager::Progress as OtherProgress;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref SIZE_OPTS: Arc<size_opts::FileSizeOpts> = {
|
||||||
|
// Declare a custom humansize option struct
|
||||||
|
// See: https://docs.rs/humansize/1.0.2/humansize/file_size_opts/struct.FileSizeOpts.html
|
||||||
|
Arc::new(size_opts::FileSizeOpts {
|
||||||
|
divider: size_opts::Kilo::Binary,
|
||||||
|
units: size_opts::Kilo::Decimal,
|
||||||
|
decimal_places: 0,
|
||||||
|
decimal_zeroes: 0,
|
||||||
|
fixed_at: size_opts::FixedAt::No,
|
||||||
|
long_units: false,
|
||||||
|
space: true,
|
||||||
|
suffix: "",
|
||||||
|
allow_negative: false,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
static ref NOW: DateTime<Utc> = Utc::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct UnInitialized;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Shown;
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Hidden;
|
||||||
|
|
||||||
|
pub trait Visibility {}
|
||||||
|
|
||||||
|
impl Visibility for Shown {}
|
||||||
|
impl Visibility for Hidden {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Normal;
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct GreyedOut;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Title<S> {
|
||||||
|
title: gtk::Label,
|
||||||
|
state: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Title<S> {
|
||||||
|
#[allow(unused_must_use)]
|
||||||
|
// This does not need to be &mut since gtk-rs does not model ownership
|
||||||
|
// But I think it wouldn't hurt if we treat it as a Rust api.
|
||||||
|
fn set_title(&mut self, s: &str) {
|
||||||
|
self.title.set_text(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Title<Normal> {
|
||||||
|
fn new(title: gtk::Label) -> Self {
|
||||||
|
Title {
|
||||||
|
title,
|
||||||
|
state: Normal {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Title<Normal>> for Title<GreyedOut> {
|
||||||
|
fn from(f: Title<Normal>) -> Self {
|
||||||
|
f.title
|
||||||
|
.get_style_context()
|
||||||
|
.map(|c| c.add_class("dim-label"));
|
||||||
|
|
||||||
|
Title {
|
||||||
|
title: f.title,
|
||||||
|
state: GreyedOut {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Title<GreyedOut>> for Title<Normal> {
|
||||||
|
fn from(f: Title<GreyedOut>) -> Self {
|
||||||
|
f.title
|
||||||
|
.get_style_context()
|
||||||
|
.map(|c| c.remove_class("dim-label"));
|
||||||
|
|
||||||
|
Title {
|
||||||
|
title: f.title,
|
||||||
|
state: Normal {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum TitleMachine {
|
||||||
|
Normal(Title<Normal>),
|
||||||
|
GreyedOut(Title<GreyedOut>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TitleMachine {
|
||||||
|
pub fn new(label: gtk::Label, is_played: bool) -> Self {
|
||||||
|
let m = TitleMachine::Normal(Title::<Normal>::new(label));
|
||||||
|
m.determine_state(is_played)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn determine_state(self, is_played: bool) -> Self {
|
||||||
|
use self::TitleMachine::*;
|
||||||
|
|
||||||
|
match (self, is_played) {
|
||||||
|
(title @ Normal(_), false) => title,
|
||||||
|
(title @ GreyedOut(_), true) => title,
|
||||||
|
(Normal(val), true) => GreyedOut(val.into()),
|
||||||
|
(GreyedOut(val), false) => Normal(val.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_title(&mut self, s: &str) {
|
||||||
|
use self::TitleMachine::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
Normal(ref mut val) => val.set_title(s),
|
||||||
|
GreyedOut(ref mut val) => val.set_title(s),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Usual;
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct YearShown;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Date<S> {
|
||||||
|
date: gtk::Label,
|
||||||
|
epoch: i64,
|
||||||
|
state: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Date<S> {
|
||||||
|
fn into_usual(self, epoch: i64) -> Date<Usual> {
|
||||||
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
|
self.date.set_text(ts.format("%e %b").to_string().trim());
|
||||||
|
|
||||||
|
Date {
|
||||||
|
date: self.date,
|
||||||
|
epoch: self.epoch,
|
||||||
|
state: Usual {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_year_shown(self, epoch: i64) -> Date<YearShown> {
|
||||||
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
|
self.date.set_text(ts.format("%e %b %Y").to_string().trim());
|
||||||
|
|
||||||
|
Date {
|
||||||
|
date: self.date,
|
||||||
|
epoch: self.epoch,
|
||||||
|
state: YearShown {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Date<UnInitialized> {
|
||||||
|
fn new(date: gtk::Label, epoch: i64) -> Self {
|
||||||
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
|
date.set_text(ts.format("%e %b %Y").to_string().trim());
|
||||||
|
|
||||||
|
Date {
|
||||||
|
date,
|
||||||
|
epoch,
|
||||||
|
state: UnInitialized {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum DateMachine {
|
||||||
|
UnInitialized(Date<UnInitialized>),
|
||||||
|
Usual(Date<Usual>),
|
||||||
|
WithYear(Date<YearShown>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DateMachine {
|
||||||
|
pub fn new(label: gtk::Label, epoch: i64) -> Self {
|
||||||
|
let m = DateMachine::UnInitialized(Date::<UnInitialized>::new(label, epoch));
|
||||||
|
m.determine_state(epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn determine_state(self, epoch: i64) -> Self {
|
||||||
|
use self::DateMachine::*;
|
||||||
|
|
||||||
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
|
let is_old = !(NOW.year() == ts.year());
|
||||||
|
|
||||||
|
match (self, is_old) {
|
||||||
|
// Into Usual
|
||||||
|
(Usual(val), false) => Usual(val.into_usual(epoch)),
|
||||||
|
(WithYear(val), false) => Usual(val.into_usual(epoch)),
|
||||||
|
(UnInitialized(val), false) => Usual(val.into_usual(epoch)),
|
||||||
|
|
||||||
|
// Into Year Shown
|
||||||
|
(Usual(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||||
|
(WithYear(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||||
|
(UnInitialized(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Duration<S: Visibility> {
|
||||||
|
// TODO: make duration and separator diff types
|
||||||
|
duration: gtk::Label,
|
||||||
|
separator: gtk::Label,
|
||||||
|
state: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: Visibility> Duration<S> {
|
||||||
|
// This needs a better name.
|
||||||
|
// TODO: make me mut
|
||||||
|
fn set_duration(&self, minutes: i64) {
|
||||||
|
self.duration.set_text(&format!("{} min", minutes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Duration<Hidden> {
|
||||||
|
fn new(duration: gtk::Label, separator: gtk::Label) -> Self {
|
||||||
|
duration.hide();
|
||||||
|
separator.hide();
|
||||||
|
|
||||||
|
Duration {
|
||||||
|
duration,
|
||||||
|
separator,
|
||||||
|
state: Hidden {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Duration<Hidden>> for Duration<Shown> {
|
||||||
|
fn from(f: Duration<Hidden>) -> Self {
|
||||||
|
f.duration.show();
|
||||||
|
f.separator.show();
|
||||||
|
|
||||||
|
Duration {
|
||||||
|
duration: f.duration,
|
||||||
|
separator: f.separator,
|
||||||
|
state: Shown {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Duration<Shown>> for Duration<Hidden> {
|
||||||
|
fn from(f: Duration<Shown>) -> Self {
|
||||||
|
f.duration.hide();
|
||||||
|
f.separator.hide();
|
||||||
|
|
||||||
|
Duration {
|
||||||
|
duration: f.duration,
|
||||||
|
separator: f.separator,
|
||||||
|
state: Hidden {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum DurationMachine {
|
||||||
|
Hidden(Duration<Hidden>),
|
||||||
|
Shown(Duration<Shown>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DurationMachine {
|
||||||
|
pub fn new(duration: gtk::Label, separator: gtk::Label, seconds: Option<i32>) -> Self {
|
||||||
|
let m = DurationMachine::Hidden(Duration::<Hidden>::new(duration, separator));
|
||||||
|
m.determine_state(seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn determine_state(self, seconds: Option<i32>) -> Self {
|
||||||
|
match (self, seconds) {
|
||||||
|
(d @ DurationMachine::Hidden(_), None) => d,
|
||||||
|
(DurationMachine::Shown(val), None) => DurationMachine::Hidden(val.into()),
|
||||||
|
(DurationMachine::Hidden(val), Some(s)) => {
|
||||||
|
let minutes = chrono::Duration::seconds(s.into()).num_minutes();
|
||||||
|
if minutes == 0 {
|
||||||
|
DurationMachine::Hidden(val)
|
||||||
|
} else {
|
||||||
|
val.set_duration(minutes);
|
||||||
|
DurationMachine::Shown(val.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(DurationMachine::Shown(val), Some(s)) => {
|
||||||
|
let minutes = chrono::Duration::seconds(s.into()).num_minutes();
|
||||||
|
if minutes == 0 {
|
||||||
|
DurationMachine::Hidden(val.into())
|
||||||
|
} else {
|
||||||
|
val.set_duration(minutes);
|
||||||
|
DurationMachine::Shown(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Size<S> {
|
||||||
|
size: gtk::Label,
|
||||||
|
separator: gtk::Label,
|
||||||
|
state: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Size<S> {
|
||||||
|
fn set_size(self, s: &str) -> Size<Shown> {
|
||||||
|
self.size.set_text(s);
|
||||||
|
self.size.show();
|
||||||
|
self.separator.show();
|
||||||
|
Size {
|
||||||
|
size: self.size,
|
||||||
|
separator: self.separator,
|
||||||
|
state: Shown {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://play.rust-lang.org/?gist=1acffaf62743eeb85be1ae6ecf474784&version=stable
|
||||||
|
// It might be possible to make a generic definition with Specialization.
|
||||||
|
// https://github.com/rust-lang/rust/issues/31844
|
||||||
|
fn into_shown(self) -> Size<Shown> {
|
||||||
|
self.size.show();
|
||||||
|
self.separator.show();
|
||||||
|
|
||||||
|
Size {
|
||||||
|
size: self.size,
|
||||||
|
separator: self.separator,
|
||||||
|
state: Shown {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_hidden(self) -> Size<Hidden> {
|
||||||
|
self.size.hide();
|
||||||
|
self.separator.hide();
|
||||||
|
|
||||||
|
Size {
|
||||||
|
size: self.size,
|
||||||
|
separator: self.separator,
|
||||||
|
state: Hidden {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Size<UnInitialized> {
|
||||||
|
fn new(size: gtk::Label, separator: gtk::Label) -> Self {
|
||||||
|
size.hide();
|
||||||
|
separator.hide();
|
||||||
|
|
||||||
|
Size {
|
||||||
|
size,
|
||||||
|
separator,
|
||||||
|
state: UnInitialized {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pub trait Playable {}
|
||||||
|
|
||||||
|
// impl Playable for Download {}
|
||||||
|
// impl Playable for Play {}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Download;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Play;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
// FIXME: Needs better name.
|
||||||
|
// Should each button also has it's own type and machine?
|
||||||
|
pub struct DownloadPlay<S> {
|
||||||
|
play: gtk::Button,
|
||||||
|
download: gtk::Button,
|
||||||
|
state: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> DownloadPlay<S> {
|
||||||
|
// https://play.rust-lang.org/?gist=1acffaf62743eeb85be1ae6ecf474784&version=stable
|
||||||
|
// It might be possible to make a generic definition with Specialization.
|
||||||
|
// https://github.com/rust-lang/rust/issues/31844
|
||||||
|
fn into_playable(self) -> DownloadPlay<Play> {
|
||||||
|
self.play.show();
|
||||||
|
self.download.hide();
|
||||||
|
|
||||||
|
DownloadPlay {
|
||||||
|
play: self.play,
|
||||||
|
download: self.download,
|
||||||
|
state: Play {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_fetchable(self) -> DownloadPlay<Download> {
|
||||||
|
self.play.hide();
|
||||||
|
self.download.show();
|
||||||
|
|
||||||
|
DownloadPlay {
|
||||||
|
play: self.play,
|
||||||
|
download: self.download,
|
||||||
|
state: Download {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_hidden(self) -> DownloadPlay<Hidden> {
|
||||||
|
self.play.hide();
|
||||||
|
self.download.hide();
|
||||||
|
|
||||||
|
DownloadPlay {
|
||||||
|
play: self.play,
|
||||||
|
download: self.download,
|
||||||
|
state: Hidden {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn download_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
|
) -> glib::SignalHandlerId {
|
||||||
|
self.download.connect_clicked(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn play_connect_clicked<F: Fn(>k::Button) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||||
|
self.play.connect_clicked(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DownloadPlay<UnInitialized> {
|
||||||
|
fn new(play: gtk::Button, download: gtk::Button) -> Self {
|
||||||
|
play.hide();
|
||||||
|
download.hide();
|
||||||
|
|
||||||
|
DownloadPlay {
|
||||||
|
play,
|
||||||
|
download,
|
||||||
|
state: UnInitialized {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Progress<S> {
|
||||||
|
bar: gtk::ProgressBar,
|
||||||
|
cancel: gtk::Button,
|
||||||
|
local_size: gtk::Label,
|
||||||
|
prog_separator: gtk::Label,
|
||||||
|
state: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Progress<S> {
|
||||||
|
fn into_shown(self) -> Progress<Shown> {
|
||||||
|
self.bar.show();
|
||||||
|
self.cancel.show();
|
||||||
|
self.local_size.show();
|
||||||
|
self.prog_separator.show();
|
||||||
|
|
||||||
|
Progress {
|
||||||
|
bar: self.bar,
|
||||||
|
cancel: self.cancel,
|
||||||
|
local_size: self.local_size,
|
||||||
|
prog_separator: self.prog_separator,
|
||||||
|
state: Shown {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_hidden(self) -> Progress<Hidden> {
|
||||||
|
self.bar.hide();
|
||||||
|
self.cancel.hide();
|
||||||
|
self.local_size.hide();
|
||||||
|
self.prog_separator.hide();
|
||||||
|
|
||||||
|
Progress {
|
||||||
|
bar: self.bar,
|
||||||
|
cancel: self.cancel,
|
||||||
|
local_size: self.local_size,
|
||||||
|
prog_separator: self.prog_separator,
|
||||||
|
state: Hidden {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_must_use)]
|
||||||
|
// This does not need to be &mut since gtk-rs does not model ownership
|
||||||
|
// But I think it wouldn't hurt if we treat it as a Rust api.
|
||||||
|
fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
||||||
|
self.local_size.set_text(local_size);
|
||||||
|
self.bar.set_fraction(fraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cancel_connect_clicked(&self, prog: Arc<Mutex<OtherProgress>>) -> glib::SignalHandlerId {
|
||||||
|
self.cancel.connect_clicked(move |cancel| {
|
||||||
|
if let Ok(mut m) = prog.lock() {
|
||||||
|
m.cancel();
|
||||||
|
cancel.set_sensitive(false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Progress<UnInitialized> {
|
||||||
|
fn new(
|
||||||
|
bar: gtk::ProgressBar,
|
||||||
|
cancel: gtk::Button,
|
||||||
|
local_size: gtk::Label,
|
||||||
|
prog_separator: gtk::Label,
|
||||||
|
) -> Self {
|
||||||
|
bar.hide();
|
||||||
|
cancel.hide();
|
||||||
|
local_size.hide();
|
||||||
|
prog_separator.hide();
|
||||||
|
|
||||||
|
Progress {
|
||||||
|
bar,
|
||||||
|
cancel,
|
||||||
|
local_size,
|
||||||
|
prog_separator,
|
||||||
|
state: UnInitialized {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Media<X, Y, Z> {
|
||||||
|
dl: DownloadPlay<X>,
|
||||||
|
size: Size<Y>,
|
||||||
|
progress: Progress<Z>,
|
||||||
|
}
|
||||||
|
|
||||||
|
type New<Y> = Media<Download, Y, Hidden>;
|
||||||
|
type Playable<Y> = Media<Play, Y, Hidden>;
|
||||||
|
type InProgress = Media<Hidden, Shown, Shown>;
|
||||||
|
type MediaUnInitialized = Media<UnInitialized, UnInitialized, UnInitialized>;
|
||||||
|
|
||||||
|
impl From<New<Shown>> for InProgress {
|
||||||
|
fn from(f: New<Shown>) -> Self {
|
||||||
|
f.into_progress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<New<Hidden>> for InProgress {
|
||||||
|
fn from(f: New<Hidden>) -> Self {
|
||||||
|
f.into_progress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Playable<Shown>> for InProgress {
|
||||||
|
fn from(f: Playable<Shown>) -> Self {
|
||||||
|
f.into_progress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Playable<Hidden>> for InProgress {
|
||||||
|
fn from(f: Playable<Hidden>) -> Self {
|
||||||
|
f.into_progress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Y: Visibility> From<Playable<Y>> for New<Y> {
|
||||||
|
fn from(f: Playable<Y>) -> Self {
|
||||||
|
Media {
|
||||||
|
dl: f.dl.into_fetchable(),
|
||||||
|
size: f.size,
|
||||||
|
progress: f.progress,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Y: Visibility> From<New<Y>> for Playable<Y> {
|
||||||
|
fn from(f: New<Y>) -> Self {
|
||||||
|
Media {
|
||||||
|
dl: f.dl.into_playable(),
|
||||||
|
size: f.size,
|
||||||
|
progress: f.progress,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MediaUnInitialized> for New<Hidden> {
|
||||||
|
fn from(f: MediaUnInitialized) -> Self {
|
||||||
|
Media {
|
||||||
|
dl: f.dl.into_fetchable(),
|
||||||
|
size: f.size.into_hidden(),
|
||||||
|
progress: f.progress.into_hidden(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MediaUnInitialized> for Playable<Hidden> {
|
||||||
|
fn from(f: MediaUnInitialized) -> Self {
|
||||||
|
Media {
|
||||||
|
dl: f.dl.into_playable(),
|
||||||
|
size: f.size.into_hidden(),
|
||||||
|
progress: f.progress.into_hidden(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<X, Y, Z> Media<X, Y, Z> {
|
||||||
|
fn set_size(self, s: &str) -> Media<X, Shown, Z> {
|
||||||
|
Media {
|
||||||
|
dl: self.dl,
|
||||||
|
size: self.size.set_size(s),
|
||||||
|
progress: self.progress,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hide_size(self) -> Media<X, Hidden, Z> {
|
||||||
|
Media {
|
||||||
|
dl: self.dl,
|
||||||
|
size: self.size.into_hidden(),
|
||||||
|
progress: self.progress,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_new(self, size: &str) -> New<Shown> {
|
||||||
|
Media {
|
||||||
|
dl: self.dl.into_fetchable(),
|
||||||
|
size: self.size.set_size(size),
|
||||||
|
progress: self.progress.into_hidden(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_playable(self, size: &str) -> Playable<Shown> {
|
||||||
|
Media {
|
||||||
|
dl: self.dl.into_playable(),
|
||||||
|
size: self.size.set_size(size),
|
||||||
|
progress: self.progress.into_hidden(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<X, Z> Media<X, Shown, Z> {
|
||||||
|
fn into_progress(self) -> InProgress {
|
||||||
|
Media {
|
||||||
|
dl: self.dl.into_hidden(),
|
||||||
|
size: self.size.into_shown(),
|
||||||
|
progress: self.progress.into_shown(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<X, Z> Media<X, Hidden, Z> {
|
||||||
|
fn into_progress(self) -> InProgress {
|
||||||
|
Media {
|
||||||
|
dl: self.dl.into_hidden(),
|
||||||
|
size: self.size.set_size("Unkown"),
|
||||||
|
progress: self.progress.into_shown(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<X, Z> Media<X, UnInitialized, Z> {
|
||||||
|
fn into_progress(self, size: Option<String>) -> InProgress {
|
||||||
|
if let Some(s) = size {
|
||||||
|
Media {
|
||||||
|
dl: self.dl.into_hidden(),
|
||||||
|
size: self.size.set_size(&s),
|
||||||
|
progress: self.progress.into_shown(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Media {
|
||||||
|
dl: self.dl.into_hidden(),
|
||||||
|
size: self.size.set_size("Unkown"),
|
||||||
|
progress: self.progress.into_shown(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InProgress {
|
||||||
|
#[allow(unused_must_use)]
|
||||||
|
// This does not need to be &mut since gtk-rs does not model ownership
|
||||||
|
// But I think it wouldn't hurt if we treat it as a Rust api.
|
||||||
|
fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
||||||
|
self.progress.update_progress(local_size, fraction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum ButtonsState {
|
||||||
|
New(Media<Download, Shown, Hidden>),
|
||||||
|
NewWithoutSize(Media<Download, Hidden, Hidden>),
|
||||||
|
Playable(Media<Play, Shown, Hidden>),
|
||||||
|
PlayableWithoutSize(Media<Play, Hidden, Hidden>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ButtonsState {
|
||||||
|
pub fn determine_state(self, size: Option<String>, is_downloaded: bool) -> Self {
|
||||||
|
use self::ButtonsState::*;
|
||||||
|
|
||||||
|
match (self, size, is_downloaded) {
|
||||||
|
// From whatever to New
|
||||||
|
(New(m), Some(s), false) => New(m.into_new(&s)),
|
||||||
|
(Playable(m), Some(s), false) => New(m.into_new(&s)),
|
||||||
|
|
||||||
|
(NewWithoutSize(m), Some(s), false) => New(m.into_new(&s)),
|
||||||
|
(PlayableWithoutSize(m), Some(s), false) => New(m.into_new(&s)),
|
||||||
|
|
||||||
|
// From whatever to Playable
|
||||||
|
(New(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||||
|
(Playable(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||||
|
|
||||||
|
(NewWithoutSize(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||||
|
(PlayableWithoutSize(m), Some(s), true) => Playable(m.into_playable(&s)),
|
||||||
|
|
||||||
|
// From whatever to NewWithoutSize
|
||||||
|
(New(m), None, false) => NewWithoutSize(m.hide_size()),
|
||||||
|
(Playable(m), None, false) => NewWithoutSize(Media::from(m).hide_size()),
|
||||||
|
|
||||||
|
(b @ NewWithoutSize(_), None, false) => b,
|
||||||
|
(PlayableWithoutSize(m), None, false) => NewWithoutSize(m.into()),
|
||||||
|
|
||||||
|
// From whatever to PlayableWithoutSize
|
||||||
|
(New(m), None, true) => PlayableWithoutSize(Media::from(m).hide_size()),
|
||||||
|
(Playable(m), None, true) => PlayableWithoutSize(m.hide_size()),
|
||||||
|
|
||||||
|
(NewWithoutSize(val), None, true) => PlayableWithoutSize(val.into()),
|
||||||
|
(b @ PlayableWithoutSize(_), None, true) => b,
|
||||||
|
// _ => unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_progress(self) -> InProgress {
|
||||||
|
use self::ButtonsState::*;
|
||||||
|
|
||||||
|
match self {
|
||||||
|
New(m) => m.into(),
|
||||||
|
Playable(m) => m.into(),
|
||||||
|
NewWithoutSize(m) => m.into(),
|
||||||
|
PlayableWithoutSize(m) => m.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_size(self, size: Option<String>) -> Self {
|
||||||
|
use self::ButtonsState::*;
|
||||||
|
|
||||||
|
match (self, size) {
|
||||||
|
(New(m), Some(s)) => New(m.set_size(&s)),
|
||||||
|
(New(m), None) => NewWithoutSize(m.hide_size()),
|
||||||
|
(Playable(m), Some(s)) => Playable(m.set_size(&s)),
|
||||||
|
(Playable(m), None) => PlayableWithoutSize(m.hide_size()),
|
||||||
|
(bttn @ NewWithoutSize(_), None) => bttn,
|
||||||
|
(bttn @ PlayableWithoutSize(_), None) => bttn,
|
||||||
|
(NewWithoutSize(m), Some(s)) => New(m.into_new(&s)),
|
||||||
|
(PlayableWithoutSize(m), Some(s)) => Playable(m.into_playable(&s)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn download_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
|
) -> glib::SignalHandlerId {
|
||||||
|
use self::ButtonsState::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
New(ref val) => val.dl.download_connect_clicked(f),
|
||||||
|
NewWithoutSize(ref val) => val.dl.download_connect_clicked(f),
|
||||||
|
Playable(ref val) => val.dl.download_connect_clicked(f),
|
||||||
|
PlayableWithoutSize(ref val) => val.dl.download_connect_clicked(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn play_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
|
) -> glib::SignalHandlerId {
|
||||||
|
use self::ButtonsState::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
New(ref val) => val.dl.play_connect_clicked(f),
|
||||||
|
NewWithoutSize(ref val) => val.dl.play_connect_clicked(f),
|
||||||
|
Playable(ref val) => val.dl.play_connect_clicked(f),
|
||||||
|
PlayableWithoutSize(ref val) => val.dl.play_connect_clicked(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cancel_connect_clicked(&self, prog: Arc<Mutex<OtherProgress>>) -> glib::SignalHandlerId {
|
||||||
|
use self::ButtonsState::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
New(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||||
|
NewWithoutSize(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||||
|
Playable(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||||
|
PlayableWithoutSize(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum MediaMachine {
|
||||||
|
UnInitialized(Media<UnInitialized, UnInitialized, UnInitialized>),
|
||||||
|
Initialized(ButtonsState),
|
||||||
|
InProgress(Media<Hidden, Shown, Shown>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MediaMachine {
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
|
||||||
|
pub fn new(
|
||||||
|
play: gtk::Button,
|
||||||
|
download: gtk::Button,
|
||||||
|
bar: gtk::ProgressBar,
|
||||||
|
cancel: gtk::Button,
|
||||||
|
total_size: gtk::Label,
|
||||||
|
local_size: gtk::Label,
|
||||||
|
separator: gtk::Label,
|
||||||
|
prog_separator: gtk::Label,
|
||||||
|
) -> Self {
|
||||||
|
let dl = DownloadPlay::<UnInitialized>::new(play, download);
|
||||||
|
let progress = Progress::<UnInitialized>::new(bar, cancel, local_size, prog_separator);
|
||||||
|
let size = Size::<UnInitialized>::new(total_size, separator);
|
||||||
|
|
||||||
|
MediaMachine::UnInitialized(Media { dl, progress, size })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn download_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
|
) -> glib::SignalHandlerId {
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
UnInitialized(ref val) => val.dl.download_connect_clicked(f),
|
||||||
|
Initialized(ref val) => val.download_connect_clicked(f),
|
||||||
|
InProgress(ref val) => val.dl.download_connect_clicked(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn play_connect_clicked<F: Fn(>k::Button) + 'static>(
|
||||||
|
&self,
|
||||||
|
f: F,
|
||||||
|
) -> glib::SignalHandlerId {
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
UnInitialized(ref val) => val.dl.play_connect_clicked(f),
|
||||||
|
Initialized(ref val) => val.play_connect_clicked(f),
|
||||||
|
InProgress(ref val) => val.dl.play_connect_clicked(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cancel_connect_clicked(&self, prog: Arc<Mutex<OtherProgress>>) -> glib::SignalHandlerId {
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
UnInitialized(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||||
|
Initialized(ref val) => val.cancel_connect_clicked(prog),
|
||||||
|
InProgress(ref val) => val.progress.cancel_connect_clicked(prog),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn determine_state(self, bytes: Option<i32>, is_active: bool, is_downloaded: bool) -> Self {
|
||||||
|
use self::ButtonsState::*;
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
|
||||||
|
match (self, size_helper(bytes), is_downloaded, is_active) {
|
||||||
|
(UnInitialized(m), s, _, true) => InProgress(m.into_progress(s)),
|
||||||
|
|
||||||
|
// Into New
|
||||||
|
(UnInitialized(m), Some(s), false, false) => Initialized(New(m.into_new(&s))),
|
||||||
|
(UnInitialized(m), None, false, false) => Initialized(NewWithoutSize(m.into())),
|
||||||
|
|
||||||
|
// Into Playable
|
||||||
|
(UnInitialized(m), Some(s), true, false) => Initialized(Playable(m.into_playable(&s))),
|
||||||
|
(UnInitialized(m), None, true, false) => Initialized(PlayableWithoutSize(m.into())),
|
||||||
|
|
||||||
|
(Initialized(bttn), s, dl, false) => Initialized(bttn.determine_state(s, dl)),
|
||||||
|
(Initialized(bttn), _, _, true) => InProgress(bttn.into_progress()),
|
||||||
|
(i @ InProgress(_), _, _, _) => i,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_size(self, bytes: Option<i32>) -> Self {
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
let size = size_helper(bytes);
|
||||||
|
|
||||||
|
match (self, size) {
|
||||||
|
(Initialized(bttn), s) => Initialized(bttn.set_size(s)),
|
||||||
|
(InProgress(val), Some(s)) => InProgress(val.set_size(&s)),
|
||||||
|
(n @ InProgress(_), None) => n,
|
||||||
|
(n @ UnInitialized(_), _) => n,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_progress(&mut self, local_size: &str, fraction: f64) {
|
||||||
|
use self::MediaMachine::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
Initialized(_) => (),
|
||||||
|
UnInitialized(_) => (),
|
||||||
|
InProgress(ref mut val) => val.update_progress(local_size, fraction),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn size_helper(bytes: Option<i32>) -> Option<String> {
|
||||||
|
let s = bytes?;
|
||||||
|
if s == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
s.file_size(SIZE_OPTS.clone()).ok()
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
mod show;
|
||||||
|
mod episode;
|
||||||
|
mod episode_states;
|
||||||
|
|
||||||
|
pub use self::episode::EpisodeWidget;
|
||||||
|
pub use self::show::ShowWidget;
|
||||||
|
pub use self::show::mark_all_watched;
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
use failure::Error;
|
||||||
|
// use glib;
|
||||||
|
use gtk;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use html2pango::markup_from_raw;
|
||||||
|
use open;
|
||||||
|
|
||||||
|
use hammond_data::Podcast;
|
||||||
|
use hammond_data::dbqueries;
|
||||||
|
|
||||||
|
use app::Action;
|
||||||
|
use utils::set_image_from_path;
|
||||||
|
use widgets::episode::episodes_listbox;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ShowWidget {
|
||||||
|
pub container: gtk::Box,
|
||||||
|
scrolled_window: gtk::ScrolledWindow,
|
||||||
|
cover: gtk::Image,
|
||||||
|
description: gtk::Label,
|
||||||
|
link: gtk::Button,
|
||||||
|
settings: gtk::MenuButton,
|
||||||
|
unsub: gtk::Button,
|
||||||
|
episodes: gtk::Frame,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ShowWidget {
|
||||||
|
fn default() -> Self {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
|
||||||
|
let container: gtk::Box = builder.get_object("container").unwrap();
|
||||||
|
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
|
||||||
|
let episodes: gtk::Frame = builder.get_object("episodes").unwrap();
|
||||||
|
|
||||||
|
let cover: gtk::Image = builder.get_object("cover").unwrap();
|
||||||
|
let description: gtk::Label = builder.get_object("description").unwrap();
|
||||||
|
let unsub: gtk::Button = builder.get_object("unsub_button").unwrap();
|
||||||
|
let link: gtk::Button = builder.get_object("link_button").unwrap();
|
||||||
|
let settings: gtk::MenuButton = builder.get_object("settings_button").unwrap();
|
||||||
|
|
||||||
|
ShowWidget {
|
||||||
|
container,
|
||||||
|
scrolled_window,
|
||||||
|
cover,
|
||||||
|
description,
|
||||||
|
unsub,
|
||||||
|
link,
|
||||||
|
settings,
|
||||||
|
episodes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShowWidget {
|
||||||
|
pub fn new(pd: Arc<Podcast>, sender: Sender<Action>) -> ShowWidget {
|
||||||
|
let pdw = ShowWidget::default();
|
||||||
|
pdw.init(pd, sender);
|
||||||
|
pdw
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(&self, pd: Arc<Podcast>, sender: Sender<Action>) {
|
||||||
|
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/show_widget.ui");
|
||||||
|
|
||||||
|
// Hacky workaround so the pd.id() can be retrieved from the `ShowStack`.
|
||||||
|
WidgetExt::set_name(&self.container, &pd.id().to_string());
|
||||||
|
|
||||||
|
self.unsub
|
||||||
|
.connect_clicked(clone!(pd, sender => move |bttn| {
|
||||||
|
if let Err(err) = on_unsub_button_clicked(pd.clone(), bttn, sender.clone()) {
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
self.setup_listbox(pd.clone(), sender.clone());
|
||||||
|
self.set_description(pd.description());
|
||||||
|
|
||||||
|
if let Err(err) = self.set_cover(pd.clone()) {
|
||||||
|
error!("Failed to set a cover: {}", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
let link = pd.link().to_owned();
|
||||||
|
self.link.set_tooltip_text(Some(link.as_str()));
|
||||||
|
self.link.connect_clicked(move |_| {
|
||||||
|
info!("Opening link: {}", &link);
|
||||||
|
if let Err(err) = open::that(&link) {
|
||||||
|
error!("Failed to open link: {}", &link);
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let show_menu: gtk::Popover = builder.get_object("show_menu").unwrap();
|
||||||
|
let mark_all: gtk::ModelButton = builder.get_object("mark_all_watched").unwrap();
|
||||||
|
|
||||||
|
let episodes = self.episodes.clone();
|
||||||
|
mark_all.connect_clicked(clone!(pd, sender => move |_| {
|
||||||
|
on_played_button_clicked(
|
||||||
|
pd.clone(),
|
||||||
|
&episodes,
|
||||||
|
sender.clone()
|
||||||
|
)
|
||||||
|
}));
|
||||||
|
self.settings.set_popover(&show_menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Populate the listbox with the shows episodes.
|
||||||
|
fn setup_listbox(&self, pd: Arc<Podcast>, sender: Sender<Action>) {
|
||||||
|
let listbox = episodes_listbox(pd, sender.clone());
|
||||||
|
listbox.ok().map(|l| self.episodes.add(&l));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the show cover.
|
||||||
|
fn set_cover(&self, pd: Arc<Podcast>) -> Result<(), Error> {
|
||||||
|
set_image_from_path(&self.cover, Arc::new(pd.into()), 128)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the descripton text.
|
||||||
|
fn set_description(&self, text: &str) {
|
||||||
|
self.description.set_markup(&markup_from_raw(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set scrolled window vertical adjustment.
|
||||||
|
pub fn set_vadjustment(&self, vadjustment: >k::Adjustment) {
|
||||||
|
self.scrolled_window.set_vadjustment(vadjustment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_unsub_button_clicked(
|
||||||
|
pd: Arc<Podcast>,
|
||||||
|
unsub_button: >k::Button,
|
||||||
|
sender: Sender<Action>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
// hack to get away without properly checking for none.
|
||||||
|
// if pressed twice would panic.
|
||||||
|
unsub_button.hide();
|
||||||
|
sender.send(Action::RemoveShow(pd))?;
|
||||||
|
|
||||||
|
sender.send(Action::HeaderBarNormal)?;
|
||||||
|
sender.send(Action::ShowShowsAnimated)?;
|
||||||
|
// Queue a refresh after the switch to avoid blocking the db.
|
||||||
|
sender.send(Action::RefreshShowsView)?;
|
||||||
|
sender.send(Action::RefreshEpisodesView)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_played_button_clicked(pd: Arc<Podcast>, episodes: >k::Frame, sender: Sender<Action>) {
|
||||||
|
if dim_titles(episodes).is_none() {
|
||||||
|
error!("Something went horribly wrong when dimming the titles.");
|
||||||
|
warn!("RUN WHILE YOU STILL CAN!");
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.send(Action::MarkAllPlayerNotification(pd)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mark_all_watched(pd: &Podcast, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
|
dbqueries::update_none_to_played_now(pd)?;
|
||||||
|
sender.send(Action::RefreshWidgetIfVis)?;
|
||||||
|
sender.send(Action::RefreshEpisodesView)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ideally if we had a custom widget this would have been as simple as:
|
||||||
|
// `for row in listbox { ep = row.get_episode(); ep.dim_title(); }`
|
||||||
|
// But now I can't think of a better way to do it than hardcoding the title
|
||||||
|
// position relative to the EpisodeWidget container gtk::Box.
|
||||||
|
fn dim_titles(episodes: >k::Frame) -> Option<()> {
|
||||||
|
let listbox = episodes
|
||||||
|
.get_children()
|
||||||
|
.remove(0)
|
||||||
|
.downcast::<gtk::ListBox>()
|
||||||
|
.ok()?;
|
||||||
|
let children = listbox.get_children();
|
||||||
|
|
||||||
|
for row in children {
|
||||||
|
let row = row.downcast::<gtk::ListBoxRow>().ok()?;
|
||||||
|
let container = row.get_children().remove(0).downcast::<gtk::Box>().ok()?;
|
||||||
|
let foo = container
|
||||||
|
.get_children()
|
||||||
|
.remove(0)
|
||||||
|
.downcast::<gtk::Box>()
|
||||||
|
.ok()?;
|
||||||
|
let bar = foo.get_children().remove(0).downcast::<gtk::Box>().ok()?;
|
||||||
|
let baz = bar.get_children().remove(0).downcast::<gtk::Box>().ok()?;
|
||||||
|
let title = baz.get_children().remove(0).downcast::<gtk::Label>().ok()?;
|
||||||
|
|
||||||
|
title.get_style_context().map(|c| c.add_class("dim-label"));
|
||||||
|
}
|
||||||
|
Some(())
|
||||||
|
}
|
||||||
@@ -5,22 +5,25 @@
|
|||||||
xmlns:gnome="http://api.gnome.org/doap-extensions#"
|
xmlns:gnome="http://api.gnome.org/doap-extensions#"
|
||||||
xmlns="http://usefulinc.com/ns/doap#">
|
xmlns="http://usefulinc.com/ns/doap#">
|
||||||
|
|
||||||
<name xml:lang="en">Podcasts</name>
|
<name xml:lang="en">Hammond</name>
|
||||||
<shortdesc xml:lang="en">
|
<shortdesc xml:lang="en">
|
||||||
Podcast app for GNOME
|
Modern Podcast Client for the GNOME desktop
|
||||||
</shortdesc>
|
</shortdesc>
|
||||||
<description xml:lang="en">
|
<description xml:lang="en">
|
||||||
Listen to your favorite podcasts, right from your desktop.
|
<p>
|
||||||
|
Hammond is a modern, reliable, and fast Podcast Client for the GNOME
|
||||||
|
desktop written in Rust.
|
||||||
|
</p>
|
||||||
</description>
|
</description>
|
||||||
<!-- <homepage rdf:resource="https://wiki.gnome.org/Apps/Podcasts" /> -->
|
<!-- <homepage rdf:resource="https://wiki.gnome.org/Apps/Hammond" /> -->
|
||||||
<bug-database rdf:resource="https://gitlab.gnome.org/World/podcasts/issues" />
|
<bug-database rdf:resource="https://gitlab.gnome.org/alatiera/Hammond/issues" />
|
||||||
|
|
||||||
<category rdf:resource="http://api.gnome.org/doap-extensions#apps" />
|
<category rdf:resource="http://api.gnome.org/doap-extensions#apps" />
|
||||||
<programming-language>Rust</programming-language>
|
<programming-language>Rust</programming-language>
|
||||||
|
|
||||||
<maintainer>
|
<maintainer>
|
||||||
<foaf:Person>
|
<foaf:Person>
|
||||||
<foaf:name>Jordan Petridis</foaf:name>
|
<foaf:name>Jordan petridis</foaf:name>
|
||||||
<foaf:mbox rdf:resource="mailto:jpetridis@gnome.org" />
|
<foaf:mbox rdf:resource="mailto:jpetridis@gnome.org" />
|
||||||
<gnome:userid>jpetridis</gnome:userid>
|
<gnome:userid>jpetridis</gnome:userid>
|
||||||
</foaf:Person>
|
</foaf:Person>
|
||||||
+13
-16
@@ -2,26 +2,23 @@
|
|||||||
# https://gitlab.gnome.org/danigm/fractal/blob/6e2911f9d2353c99a18a6c19fab7f903c4bbb431/meson.build
|
# https://gitlab.gnome.org/danigm/fractal/blob/6e2911f9d2353c99a18a6c19fab7f903c4bbb431/meson.build
|
||||||
|
|
||||||
project(
|
project(
|
||||||
'gnome-podcasts', 'rust',
|
'hammond', 'rust',
|
||||||
version: '0.4.3',
|
version: '0.3.1',
|
||||||
license: 'GPLv3',
|
license: 'GPLv3',
|
||||||
)
|
)
|
||||||
|
|
||||||
podcasts_version = meson.project_version()
|
hammond_version = meson.project_version()
|
||||||
version_array = podcasts_version.split('.')
|
version_array = hammond_version.split('.')
|
||||||
podcasts_major_version = version_array[0].to_int()
|
hammond_major_version = version_array[0].to_int()
|
||||||
podcasts_minor_version = version_array[1].to_int()
|
hammond_minor_version = version_array[1].to_int()
|
||||||
podcasts_version_micro = version_array[2].to_int()
|
hammond_version_micro = version_array[2].to_int()
|
||||||
|
|
||||||
podcasts_prefix = get_option('prefix')
|
hammond_prefix = get_option('prefix')
|
||||||
podcasts_bindir = join_paths(podcasts_prefix, get_option('bindir'))
|
hammond_bindir = join_paths(hammond_prefix, get_option('bindir'))
|
||||||
|
|
||||||
podcasts_conf = configuration_data()
|
|
||||||
podcasts_conf.set('BINDIR', podcasts_bindir)
|
|
||||||
|
|
||||||
datadir = get_option('datadir')
|
datadir = get_option('datadir')
|
||||||
icondir = join_paths(datadir, 'icons')
|
icondir = join_paths(datadir, 'icons')
|
||||||
subdir('podcasts-gtk/resources')
|
subdir('hammond-gtk/resources')
|
||||||
|
|
||||||
cargo = find_program('cargo', required: false)
|
cargo = find_program('cargo', required: false)
|
||||||
gresource = find_program('glib-compile-resources', required: false)
|
gresource = find_program('glib-compile-resources', required: false)
|
||||||
@@ -31,11 +28,11 @@ cargo_script = find_program('scripts/cargo.sh')
|
|||||||
cargo_release = custom_target('cargo-build',
|
cargo_release = custom_target('cargo-build',
|
||||||
build_by_default: true,
|
build_by_default: true,
|
||||||
build_always: true,
|
build_always: true,
|
||||||
output: ['gnome-podcasts'],
|
output: ['hammond'],
|
||||||
install: true,
|
install: true,
|
||||||
install_dir: podcasts_bindir,
|
install_dir: hammond_bindir,
|
||||||
command: [cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@'])
|
command: [cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@'])
|
||||||
|
|
||||||
run_target('release', command: ['scripts/release.sh',
|
run_target('release', command: ['scripts/release.sh',
|
||||||
meson.project_name() + '-' + podcasts_version
|
meson.project_name() + '-' + hammond_version
|
||||||
])
|
])
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"app-id" : "org.gnome.Podcasts",
|
"app-id" : "org.gnome.Hammond",
|
||||||
"runtime" : "org.gnome.Platform",
|
"runtime" : "org.gnome.Platform",
|
||||||
"runtime-version" : "3.28",
|
"runtime-version" : "master",
|
||||||
"sdk" : "org.gnome.Sdk",
|
"sdk" : "org.gnome.Sdk",
|
||||||
"sdk-extensions" : [
|
"sdk-extensions" : [
|
||||||
"org.freedesktop.Sdk.Extension.rust-stable"
|
"org.freedesktop.Sdk.Extension.rust-stable"
|
||||||
],
|
],
|
||||||
"command" : "gnome-podcasts",
|
"command" : "hammond",
|
||||||
"tags" : [
|
"tags" : [
|
||||||
"nightly"
|
"nightly"
|
||||||
],
|
],
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
"--share=ipc",
|
"--share=ipc",
|
||||||
"--socket=x11",
|
"--socket=x11",
|
||||||
"--socket=wayland",
|
"--socket=wayland",
|
||||||
"--socket=pulseaudio",
|
|
||||||
"--talk-name=org.freedesktop.Desktop"
|
"--talk-name=org.freedesktop.Desktop"
|
||||||
],
|
],
|
||||||
"build-options" : {
|
"build-options" : {
|
||||||
@@ -29,19 +28,17 @@
|
|||||||
"--share=network"
|
"--share=network"
|
||||||
],
|
],
|
||||||
"env" : {
|
"env" : {
|
||||||
"CARGO_HOME" : "/run/build/Podcasts/cargo",
|
"CARGO_HOME" : "/run/build/Hammond/cargo"
|
||||||
"RUST_BACKTRACE" : "1",
|
|
||||||
"DEBUG" : "true"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"modules" : [
|
"modules" : [
|
||||||
{
|
{
|
||||||
"name" : "gnome-podcasts",
|
"name" : "hammond",
|
||||||
"buildsystem" : "meson",
|
"buildsystem" : "meson",
|
||||||
"sources" : [
|
"sources" : [
|
||||||
{
|
{
|
||||||
"type" : "git",
|
"type" : "git",
|
||||||
"url" : "https://gitlab.gnome.org/World/podcasts.git",
|
"url" : "https://gitlab.gnome.org/alatiera/Hammond.git",
|
||||||
"branch" : "master"
|
"branch" : "master"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# For documentation on how to configure this file,
|
|
||||||
# see diesel.rs/guides/configuring-diesel-cli
|
|
||||||
|
|
||||||
[print_schema]
|
|
||||||
file = "src/schema.rs"
|
|
||||||
patch_file = "src/schema.patch"
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
ALTER TABLE episode RENAME TO old_table;
|
|
||||||
|
|
||||||
CREATE TABLE episode (
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
uri TEXT,
|
|
||||||
local_uri TEXT,
|
|
||||||
description TEXT,
|
|
||||||
epoch INTEGER NOT NULL DEFAULT 0,
|
|
||||||
length INTEGER,
|
|
||||||
duration INTEGER,
|
|
||||||
guid TEXT,
|
|
||||||
played INTEGER,
|
|
||||||
podcast_id INTEGER NOT NULL,
|
|
||||||
favorite INTEGER DEFAULT 0,
|
|
||||||
archive INTEGER DEFAULT 0,
|
|
||||||
PRIMARY KEY (title, podcast_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO episode (title, uri, local_uri, description, epoch, length, duration, guid, played, podcast_id, favorite, archive)
|
|
||||||
SELECT title, uri, local_uri, description, epoch, length, duration, guid, played, podcast_id, 0, 0
|
|
||||||
FROM old_table;
|
|
||||||
|
|
||||||
Drop table old_table;
|
|
||||||
|
|
||||||
ALTER TABLE podcast RENAME TO old_table;
|
|
||||||
CREATE TABLE `podcast` (
|
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
|
||||||
`title` TEXT NOT NULL,
|
|
||||||
`link` TEXT NOT NULL,
|
|
||||||
`description` TEXT NOT NULL,
|
|
||||||
`image_uri` TEXT,
|
|
||||||
`source_id` INTEGER NOT NULL UNIQUE,
|
|
||||||
`favorite` INTEGER NOT NULL DEFAULT 0,
|
|
||||||
`archive` INTEGER NOT NULL DEFAULT 0,
|
|
||||||
`always_dl` INTEGER NOT NULL DEFAULT 0
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO podcast (
|
|
||||||
id,
|
|
||||||
title,
|
|
||||||
link,
|
|
||||||
description,
|
|
||||||
image_uri,
|
|
||||||
source_id
|
|
||||||
) SELECT id,
|
|
||||||
title,
|
|
||||||
link,
|
|
||||||
description,
|
|
||||||
image_uri,
|
|
||||||
source_id
|
|
||||||
FROM old_table;
|
|
||||||
|
|
||||||
Drop table old_table;
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
ALTER TABLE episode RENAME TO old_table;
|
|
||||||
|
|
||||||
CREATE TABLE episode (
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
uri TEXT,
|
|
||||||
local_uri TEXT,
|
|
||||||
description TEXT,
|
|
||||||
epoch INTEGER NOT NULL DEFAULT 0,
|
|
||||||
length INTEGER,
|
|
||||||
duration INTEGER,
|
|
||||||
guid TEXT,
|
|
||||||
played INTEGER,
|
|
||||||
podcast_id INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY (title, podcast_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO episode (
|
|
||||||
title,
|
|
||||||
uri,
|
|
||||||
local_uri,
|
|
||||||
description,
|
|
||||||
epoch,
|
|
||||||
length,
|
|
||||||
duration,
|
|
||||||
guid,
|
|
||||||
played,
|
|
||||||
podcast_id
|
|
||||||
) SELECT title,
|
|
||||||
uri,
|
|
||||||
local_uri,
|
|
||||||
description,
|
|
||||||
epoch, length,
|
|
||||||
duration,
|
|
||||||
guid,
|
|
||||||
played,
|
|
||||||
podcast_id
|
|
||||||
FROM old_table;
|
|
||||||
|
|
||||||
Drop table old_table;
|
|
||||||
|
|
||||||
ALTER TABLE podcast RENAME TO old_table;
|
|
||||||
CREATE TABLE `podcast` (
|
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
|
||||||
`title` TEXT NOT NULL,
|
|
||||||
`link` TEXT NOT NULL,
|
|
||||||
`description` TEXT NOT NULL,
|
|
||||||
`image_uri` TEXT,
|
|
||||||
`source_id` INTEGER NOT NULL UNIQUE
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO podcast (
|
|
||||||
id,
|
|
||||||
title,
|
|
||||||
link,
|
|
||||||
description,
|
|
||||||
image_uri,
|
|
||||||
source_id
|
|
||||||
) SELECT id,
|
|
||||||
title,
|
|
||||||
link,
|
|
||||||
description,
|
|
||||||
image_uri,
|
|
||||||
source_id
|
|
||||||
FROM old_table;
|
|
||||||
|
|
||||||
Drop table old_table;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
ALTER TABLE episodes RENAME TO old_table;
|
|
||||||
ALTER TABLE shows RENAME TO podcast;
|
|
||||||
|
|
||||||
CREATE TABLE episode (
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
uri TEXT,
|
|
||||||
local_uri TEXT,
|
|
||||||
description TEXT,
|
|
||||||
epoch INTEGER NOT NULL DEFAULT 0,
|
|
||||||
length INTEGER,
|
|
||||||
duration INTEGER,
|
|
||||||
guid TEXT,
|
|
||||||
played INTEGER,
|
|
||||||
podcast_id INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY (title, podcast_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO episode (
|
|
||||||
title,
|
|
||||||
uri,
|
|
||||||
local_uri,
|
|
||||||
description,
|
|
||||||
epoch,
|
|
||||||
length,
|
|
||||||
duration,
|
|
||||||
guid,
|
|
||||||
played,
|
|
||||||
podcast_id
|
|
||||||
) SELECT title,
|
|
||||||
uri,
|
|
||||||
local_uri,
|
|
||||||
description,
|
|
||||||
epoch, length,
|
|
||||||
duration,
|
|
||||||
guid,
|
|
||||||
played,
|
|
||||||
show_id
|
|
||||||
FROM old_table;
|
|
||||||
|
|
||||||
Drop table old_table;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
ALTER TABLE episode RENAME TO old_table;
|
|
||||||
ALTER TABLE podcast RENAME TO shows;
|
|
||||||
|
|
||||||
CREATE TABLE episodes (
|
|
||||||
title TEXT NOT NULL,
|
|
||||||
uri TEXT,
|
|
||||||
local_uri TEXT,
|
|
||||||
description TEXT,
|
|
||||||
epoch INTEGER NOT NULL DEFAULT 0,
|
|
||||||
length INTEGER,
|
|
||||||
duration INTEGER,
|
|
||||||
guid TEXT,
|
|
||||||
played INTEGER,
|
|
||||||
show_id INTEGER NOT NULL,
|
|
||||||
PRIMARY KEY (title, show_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO episodes (
|
|
||||||
title,
|
|
||||||
uri,
|
|
||||||
local_uri,
|
|
||||||
description,
|
|
||||||
epoch,
|
|
||||||
length,
|
|
||||||
duration,
|
|
||||||
guid,
|
|
||||||
played,
|
|
||||||
show_id
|
|
||||||
) SELECT title,
|
|
||||||
uri,
|
|
||||||
local_uri,
|
|
||||||
description,
|
|
||||||
epoch, length,
|
|
||||||
duration,
|
|
||||||
guid,
|
|
||||||
played,
|
|
||||||
podcast_id
|
|
||||||
FROM old_table;
|
|
||||||
|
|
||||||
Drop table old_table;
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(unit_arg))]
|
|
||||||
//! Index Feeds.
|
|
||||||
|
|
||||||
use futures::future::*;
|
|
||||||
use futures::prelude::*;
|
|
||||||
use futures::stream;
|
|
||||||
use rss;
|
|
||||||
|
|
||||||
use dbqueries;
|
|
||||||
use errors::DataError;
|
|
||||||
use models::{Index, IndexState, Update};
|
|
||||||
use models::{NewEpisode, NewEpisodeMinimal, NewShow, Show};
|
|
||||||
|
|
||||||
/// Wrapper struct that hold a `Source` id and the `rss::Channel`
|
|
||||||
/// that corresponds to the `Source.uri` field.
|
|
||||||
#[derive(Debug, Clone, Builder, PartialEq)]
|
|
||||||
#[builder(derive(Debug))]
|
|
||||||
#[builder(setter(into))]
|
|
||||||
pub struct Feed {
|
|
||||||
/// The `rss::Channel` parsed from the `Source` uri.
|
|
||||||
channel: rss::Channel,
|
|
||||||
/// The `Source` id where the xml `rss::Channel` came from.
|
|
||||||
source_id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Feed {
|
|
||||||
/// Index the contents of the RSS `Feed` into the database.
|
|
||||||
pub fn index(self) -> impl Future<Item = (), Error = DataError> + Send {
|
|
||||||
self.parse_podcast_async()
|
|
||||||
.and_then(|pd| pd.to_podcast())
|
|
||||||
.and_then(move |pd| self.index_channel_items(pd))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_podcast(&self) -> NewShow {
|
|
||||||
NewShow::new(&self.channel, self.source_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_podcast_async(&self) -> impl Future<Item = NewShow, Error = DataError> + Send {
|
|
||||||
ok(self.parse_podcast())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn index_channel_items(self, pd: Show) -> impl Future<Item = (), Error = DataError> + Send {
|
|
||||||
let stream = stream::iter_ok::<_, DataError>(self.channel.into_items());
|
|
||||||
|
|
||||||
// Parse the episodes
|
|
||||||
let episodes = stream.filter_map(move |item| {
|
|
||||||
glue(&item, pd.id())
|
|
||||||
.map_err(|err| error!("Failed to parse an episode: {}", err))
|
|
||||||
.ok()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Filter errors, Index updatable episodes, return insertables.
|
|
||||||
filter_episodes(episodes)
|
|
||||||
// Batch index insertable episodes.
|
|
||||||
.and_then(|eps| ok(batch_insert_episodes(&eps)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn glue(item: &rss::Item, id: i32) -> Result<IndexState<NewEpisode>, DataError> {
|
|
||||||
NewEpisodeMinimal::new(item, id).and_then(move |ep| determine_ep_state(ep, item))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn determine_ep_state(
|
|
||||||
ep: NewEpisodeMinimal,
|
|
||||||
item: &rss::Item,
|
|
||||||
) -> Result<IndexState<NewEpisode>, DataError> {
|
|
||||||
// Check if feed exists
|
|
||||||
let exists = dbqueries::episode_exists(ep.title(), ep.show_id())?;
|
|
||||||
|
|
||||||
if !exists {
|
|
||||||
Ok(IndexState::Index(ep.into_new_episode(item)))
|
|
||||||
} else {
|
|
||||||
let old = dbqueries::get_episode_minimal_from_pk(ep.title(), ep.show_id())?;
|
|
||||||
let rowid = old.rowid();
|
|
||||||
|
|
||||||
if ep != old {
|
|
||||||
Ok(IndexState::Update((ep.into_new_episode(item), rowid)))
|
|
||||||
} else {
|
|
||||||
Ok(IndexState::NotChanged)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn filter_episodes<'a, S>(
|
|
||||||
stream: S,
|
|
||||||
) -> impl Future<Item = Vec<NewEpisode>, Error = DataError> + Send + 'a
|
|
||||||
where
|
|
||||||
S: Stream<Item = IndexState<NewEpisode>, Error = DataError> + Send + 'a,
|
|
||||||
{
|
|
||||||
stream.filter_map(|state| match state {
|
|
||||||
IndexState::NotChanged => None,
|
|
||||||
// Update individual rows, and filter them
|
|
||||||
IndexState::Update((ref ep, rowid)) => {
|
|
||||||
ep.update(rowid)
|
|
||||||
.map_err(|err| error!("{}", err))
|
|
||||||
.map_err(|_| error!("Failed to index episode: {:?}.", ep.title()))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
None
|
|
||||||
},
|
|
||||||
IndexState::Index(s) => Some(s),
|
|
||||||
})
|
|
||||||
// only Index is left, collect them for batch index
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn batch_insert_episodes(episodes: &[NewEpisode]) {
|
|
||||||
if episodes.is_empty() {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Indexing {} episodes.", episodes.len());
|
|
||||||
dbqueries::index_new_episodes(episodes)
|
|
||||||
.map_err(|err| {
|
|
||||||
error!("Failed batch indexng: {}", err);
|
|
||||||
info!("Fallign back to individual indexing.");
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
episodes.iter().for_each(|ep| {
|
|
||||||
ep.index()
|
|
||||||
.map_err(|err| error!("Error: {}.", err))
|
|
||||||
.map_err(|_| error!("Failed to index episode: {:?}.", ep.title()))
|
|
||||||
.ok();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use rss::Channel;
|
|
||||||
use tokio_core::reactor::Core;
|
|
||||||
|
|
||||||
use database::truncate_db;
|
|
||||||
use dbqueries;
|
|
||||||
use utils::get_feed;
|
|
||||||
use Source;
|
|
||||||
|
|
||||||
use std::fs;
|
|
||||||
use std::io::BufReader;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
// (path, url) tuples.
|
|
||||||
const URLS: &[(&str, &str)] = {
|
|
||||||
&[
|
|
||||||
(
|
|
||||||
"tests/feeds/2018-01-20-Intercepted.xml",
|
|
||||||
"https://web.archive.org/web/20180120083840if_/https://feeds.feedburner.\
|
|
||||||
com/InterceptedWithJeremyScahill",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"tests/feeds/2018-01-20-LinuxUnplugged.xml",
|
|
||||||
"https://web.archive.org/web/20180120110314if_/https://feeds.feedburner.\
|
|
||||||
com/linuxunplugged",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"tests/feeds/2018-01-20-TheTipOff.xml",
|
|
||||||
"https://web.archive.org/web/20180120110727if_/https://rss.acast.com/thetipoff",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"tests/feeds/2018-01-20-StealTheStars.xml",
|
|
||||||
"https://web.archive.org/web/20180120104957if_/https://rss.art19.\
|
|
||||||
com/steal-the-stars",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"tests/feeds/2018-01-20-GreaterThanCode.xml",
|
|
||||||
"https://web.archive.org/web/20180120104741if_/https://www.greaterthancode.\
|
|
||||||
com/feed/podcast",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_complete_index() {
|
|
||||||
truncate_db().unwrap();
|
|
||||||
|
|
||||||
let feeds: Vec<_> = URLS
|
|
||||||
.iter()
|
|
||||||
.map(|&(path, url)| {
|
|
||||||
// Create and insert a Source into db
|
|
||||||
let s = Source::from_url(url).unwrap();
|
|
||||||
get_feed(path, s.id())
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let mut core = Core::new().unwrap();
|
|
||||||
// Index the channels
|
|
||||||
let list: Vec<_> = feeds.into_iter().map(|x| x.index()).collect();
|
|
||||||
let _foo = core.run(join_all(list));
|
|
||||||
|
|
||||||
// Assert the index rows equal the controlled results
|
|
||||||
assert_eq!(dbqueries::get_sources().unwrap().len(), 5);
|
|
||||||
assert_eq!(dbqueries::get_podcasts().unwrap().len(), 5);
|
|
||||||
assert_eq!(dbqueries::get_episodes().unwrap().len(), 354);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_feed_parse_podcast() {
|
|
||||||
truncate_db().unwrap();
|
|
||||||
|
|
||||||
let path = "tests/feeds/2018-01-20-Intercepted.xml";
|
|
||||||
let feed = get_feed(path, 42);
|
|
||||||
|
|
||||||
let file = fs::File::open(path).unwrap();
|
|
||||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
|
||||||
|
|
||||||
let pd = NewShow::new(&channel, 42);
|
|
||||||
assert_eq!(feed.parse_podcast(), pd);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_feed_index_channel_items() {
|
|
||||||
truncate_db().unwrap();
|
|
||||||
|
|
||||||
let path = "tests/feeds/2018-01-20-Intercepted.xml";
|
|
||||||
let feed = get_feed(path, 42);
|
|
||||||
let pd = feed.parse_podcast().to_podcast().unwrap();
|
|
||||||
|
|
||||||
feed.index_channel_items(pd).wait().unwrap();
|
|
||||||
assert_eq!(dbqueries::get_podcasts().unwrap().len(), 1);
|
|
||||||
assert_eq!(dbqueries::get_episodes().unwrap().len(), 43);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
#![recursion_limit = "1024"]
|
|
||||||
#![allow(unknown_lints)]
|
|
||||||
#![cfg_attr(
|
|
||||||
all(test, feature = "clippy"),
|
|
||||||
allow(option_unwrap_used, result_unwrap_used)
|
|
||||||
)]
|
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(option_map_unit_fn))]
|
|
||||||
#![cfg_attr(
|
|
||||||
feature = "clippy",
|
|
||||||
warn(
|
|
||||||
option_unwrap_used,
|
|
||||||
result_unwrap_used,
|
|
||||||
print_stdout,
|
|
||||||
wrong_pub_self_convention,
|
|
||||||
mut_mut,
|
|
||||||
non_ascii_literal,
|
|
||||||
similar_names,
|
|
||||||
unicode_not_nfc,
|
|
||||||
enum_glob_use,
|
|
||||||
if_not_else,
|
|
||||||
items_after_statements,
|
|
||||||
used_underscore_binding
|
|
||||||
)
|
|
||||||
)]
|
|
||||||
// Enable lint group collections
|
|
||||||
#![warn(
|
|
||||||
nonstandard_style,
|
|
||||||
edition_2018,
|
|
||||||
rust_2018_idioms,
|
|
||||||
bad_style,
|
|
||||||
unused
|
|
||||||
)]
|
|
||||||
// standalone lints
|
|
||||||
#![warn(
|
|
||||||
const_err,
|
|
||||||
improper_ctypes,
|
|
||||||
non_shorthand_field_patterns,
|
|
||||||
no_mangle_generic_items,
|
|
||||||
overflowing_literals,
|
|
||||||
plugin_as_library,
|
|
||||||
private_no_mangle_fns,
|
|
||||||
private_no_mangle_statics,
|
|
||||||
unconditional_recursion,
|
|
||||||
unions_with_drop_fields,
|
|
||||||
while_true,
|
|
||||||
missing_debug_implementations,
|
|
||||||
missing_docs,
|
|
||||||
trivial_casts,
|
|
||||||
trivial_numeric_casts,
|
|
||||||
elided_lifetime_in_paths,
|
|
||||||
missing_copy_implementations
|
|
||||||
)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
// warn when code is not using dyn Trait syntax. req rustc 1.27
|
|
||||||
// #![deny(bare_trait_object)]
|
|
||||||
|
|
||||||
//! FIXME: Docs
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate pretty_assertions;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate maplit;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate derive_builder;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate diesel;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate diesel_migrations;
|
|
||||||
// #[macro_use]
|
|
||||||
extern crate failure;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate failure_derive;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
|
|
||||||
extern crate ammonia;
|
|
||||||
extern crate chrono;
|
|
||||||
extern crate futures;
|
|
||||||
extern crate hyper;
|
|
||||||
extern crate hyper_tls;
|
|
||||||
extern crate native_tls;
|
|
||||||
extern crate num_cpus;
|
|
||||||
extern crate rayon;
|
|
||||||
extern crate rayon_futures;
|
|
||||||
extern crate rfc822_sanitizer;
|
|
||||||
extern crate rss;
|
|
||||||
extern crate tokio_core;
|
|
||||||
extern crate url;
|
|
||||||
extern crate xdg;
|
|
||||||
extern crate xml;
|
|
||||||
|
|
||||||
pub mod database;
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub mod dbqueries;
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub mod errors;
|
|
||||||
mod feed;
|
|
||||||
pub(crate) mod models;
|
|
||||||
pub mod opml;
|
|
||||||
mod parser;
|
|
||||||
pub mod pipeline;
|
|
||||||
mod schema;
|
|
||||||
pub mod utils;
|
|
||||||
|
|
||||||
pub use feed::{Feed, FeedBuilder};
|
|
||||||
pub use models::Save;
|
|
||||||
pub use models::{Episode, EpisodeWidgetModel, Show, ShowCoverModel, Source};
|
|
||||||
|
|
||||||
// Set the user agent, See #53 for more
|
|
||||||
// Keep this in sync with Tor-browser releases
|
|
||||||
/// The user-agent to be used for all the requests.
|
|
||||||
/// It originates from the Tor-browser UA.
|
|
||||||
pub const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0";
|
|
||||||
|
|
||||||
/// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths.
|
|
||||||
#[allow(missing_debug_implementations)]
|
|
||||||
pub mod xdg_dirs {
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use xdg;
|
|
||||||
|
|
||||||
lazy_static!{
|
|
||||||
pub(crate) static ref PODCASTS_XDG: xdg::BaseDirectories = {
|
|
||||||
xdg::BaseDirectories::with_prefix("gnome-podcasts").unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
/// XDG_DATA Directory `Pathbuf`.
|
|
||||||
pub static ref PODCASTS_DATA: PathBuf = {
|
|
||||||
PODCASTS_XDG.create_data_directory(PODCASTS_XDG.get_data_home()).unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
/// XDG_CONFIG Directory `Pathbuf`.
|
|
||||||
pub static ref PODCASTS_CONFIG: PathBuf = {
|
|
||||||
PODCASTS_XDG.create_config_directory(PODCASTS_XDG.get_config_home()).unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
/// XDG_CACHE Directory `Pathbuf`.
|
|
||||||
pub static ref PODCASTS_CACHE: PathBuf = {
|
|
||||||
PODCASTS_XDG.create_cache_directory(PODCASTS_XDG.get_cache_home()).unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
/// GNOME Podcasts Download Direcotry `PathBuf`.
|
|
||||||
pub static ref DL_DIR: PathBuf = {
|
|
||||||
PODCASTS_XDG.create_data_directory("Downloads").unwrap()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user