Skip to content

Commit

Permalink
Merge pull request #122 from SamTV12345/113-allow-more-or-all-previou…
Browse files Browse the repository at this point in the history
…s-episodes-to-be-downloaded

Adds configurable podcast download.
  • Loading branch information
SamTV12345 authored May 8, 2023
2 parents c305763 + a28a7d1 commit 9d5dee0
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE settings DROP COLUMN podcast_prefill;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE settings ADD COLUMN podcast_prefill INTEGER DEFAULT 5 NOT NULL;
1 change: 1 addition & 0 deletions src/constants/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const DEFAULT_SETTINGS: Setting = Setting {
auto_update: true,
auto_cleanup: true,
auto_cleanup_days: 30,
podcast_prefill: 5,
};

pub const ERROR_LOGIN_MESSAGE: &str = "User either not found or password is incorrect";
Expand Down
8 changes: 4 additions & 4 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,15 @@ impl DB {
return inserted_podcast;
}

pub fn get_last_5_podcast_episodes(
pub fn get_last_n_podcast_episodes(
conn: &mut SqliteConnection,
podcast_episode_id: i32,
number_to_download: i32
) -> Result<Vec<PodcastEpisode>, String> {
use crate::schema::podcast_episodes::dsl::*;
let podcasts = podcast_episodes
.filter(podcast_id.eq(podcast_episode_id))
.limit(5)
.limit(number_to_download as i64)
.order(date_of_recording.desc())
.load::<PodcastEpisode>(conn)
.expect("Error loading podcasts");
Expand Down Expand Up @@ -345,8 +346,7 @@ impl DB {
match result {
Some(found_podcast) => {
let history_item = podcast_history_items
.filter(episode_id.eq(podcast_id_tos_search).and(username.eq(username_to_find
.clone())))
.filter(episode_id.eq(podcast_id_tos_search).and(username.eq(username_to_find.clone())))
.order(date.desc())
.first::<PodcastHistoryItem>(conn)
.optional()
Expand Down
2 changes: 2 additions & 0 deletions src/models/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::schema::*;
use diesel::prelude::{AsChangeset, Identifiable, Insertable, Queryable};
use crate::service::environment_service::OidcConfig;
use utoipa::ToSchema;

#[derive(
Serialize, Deserialize, Queryable, Insertable, Debug, Clone, Identifiable, AsChangeset,ToSchema
)]
Expand All @@ -12,6 +13,7 @@ pub struct Setting {
pub auto_update: bool,
pub auto_cleanup: bool,
pub auto_cleanup_days: i32,
pub podcast_prefill: i32
}

#[derive(Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ diesel::table! {
auto_update -> Bool,
auto_cleanup -> Bool,
auto_cleanup_days -> Integer,
podcast_prefill -> Integer,
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/service/podcast_episode_service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::constants::constants::{PodcastType, TELEGRAM_API_ENABLED};
use crate::constants::constants::{DEFAULT_SETTINGS, PodcastType, TELEGRAM_API_ENABLED};
use crate::db::DB;
use crate::models::itunes_models::{Podcast, PodcastEpisode};
use crate::models::messages::BroadcastMessage;
Expand All @@ -16,6 +16,7 @@ use dotenv::var;
use regex::Regex;
use reqwest::blocking::ClientBuilder;
use rss::Channel;
use crate::service::settings_service::SettingsService;
use crate::service::telegram_api::send_new_episode_notification;

#[derive(Clone)]
Expand Down Expand Up @@ -122,9 +123,13 @@ impl PodcastEpisodeService {
return podcast;
}

pub fn get_last_5_podcast_episodes(conn: &mut SqliteConnection, podcast: Podcast) ->
pub fn get_last_n_podcast_episodes(conn: &mut SqliteConnection, podcast: Podcast) ->
Vec<PodcastEpisode> {
DB::get_last_5_podcast_episodes(conn, podcast.id).unwrap()

let mut settings_service = SettingsService::new();
let settings = settings_service.get_settings().unwrap_or(DEFAULT_SETTINGS);
DB::get_last_n_podcast_episodes(conn, podcast.id,
settings.podcast_prefill).unwrap()
}

// Used for creating/updating podcasts
Expand Down Expand Up @@ -210,7 +215,7 @@ impl PodcastEpisodeService {
continue;
}
let result = DB::get_podcast_episode_by_url(
conn, &opt_enclosure.clone().unwrap().url, Option::None);
conn, &opt_enclosure.clone().unwrap().url, None);
// We can't retrieve the duration of the podcast episode, so we set it to 0

if result.unwrap().is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/service/rust_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl PodcastService {
Some(settings) => {
if settings.auto_download {
let result = PodcastEpisodeService::
get_last_5_podcast_episodes(conn, podcast.clone());
get_last_n_podcast_episodes(conn, podcast.clone());
for podcast_episode in result {
self.podcast_episode_service
.download_podcast_episode_if_not_locally_available(
Expand Down
12 changes: 6 additions & 6 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@fontsource/roboto": "^4.5.8",
"@fortawesome/fontawesome-free": "^6.4.0",
"@reduxjs/toolkit": "^1.9.5",
"axios": "^1.3.6",
"chart.js": "^4.2.1",
"axios": "^1.4.0",
"chart.js": "^4.3.0",
"i18next": "^22.4.15",
"i18next-browser-languagedetector": "^7.0.1",
"javascript-time-ago": "^2.5.9",
Expand All @@ -27,22 +27,22 @@
"react-oidc-context": "^2.2.2",
"react-i18next": "^12.2.2",
"react-redux": "^8.0.5",
"react-router-dom": "^6.10.0",
"react-router-dom": "^6.11.1",
"react-waypoint": "^10.3.0",
"redux": "^4.2.1",
"sanitize-html": "^2.10.0",
"notistack": "^3.0.1",
"csstype": "^3.1.2"
},
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.1",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"@types/sanitize-html": "^2.9.0",
"@vitejs/plugin-react-swc": "^3.3.0",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.23",
"tailwindcss": "^3.3.2",
"typescript": "^5.0.4",
"vite": "^4.3.3"
"vite": "^4.3.5"
}
}
3 changes: 2 additions & 1 deletion ui/src/language/json/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@
"no-data-found": "Keine Daten gefunden",
"descendant": "Absteigend",
"sort-by-published-date": "Nach Veröffentlichungsdatum sortieren",
"sort-by-title": "Nach Titel sortieren"
"sort-by-title": "Nach Titel sortieren",
"number-of-podcasts-to-download": "Anzahl an initialen Podcastdownloads"
}
3 changes: 2 additions & 1 deletion ui/src/language/json/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@
"no-data-found": "No data found",
"descendant": "Descendant",
"sort-by-published-date": "Sort by published date",
"sort-by-title": "Sort by title"
"sort-by-title": "Sort by title",
"number-of-podcasts-to-download": "Number of initial podcasts to download"
}
3 changes: 2 additions & 1 deletion ui/src/language/json/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@
"no-data-found": "Aucune donnée trouvée",
"descendant": "Descendant",
"sort-by-published-date": "Trier par date de publication",
"sort-by-title": "Trier par titre"
"sort-by-title": "Trier par titre",
"number-of-podcasts-to-download": "Nombre de podcasts à télécharger"
}
1 change: 1 addition & 0 deletions ui/src/models/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type Setting = {
autoUpdate: boolean,
autoCleanup: boolean,
autoCleanupDays: number,
podcastPrefill: number
}
7 changes: 7 additions & 0 deletions ui/src/pages/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ export const SettingsPage = () => {
<div className="">
{t('auto-update')}
</div>

<div>
<Switcher checked={settings.autoUpdate} setChecked={()=>{
setSettings({...settings, autoUpdate: !settings?.autoUpdate})
}}/>
</div>
<div className="">
{t('number-of-podcasts-to-download')}
</div>
<div><input type="number" className="bg-gray-600 p-2 rounded" value={settings.podcastPrefill} onChange={(e)=>{
setSettings({...settings, podcastPrefill: parseInt(e.target.value)})
}}/></div>
<div>
{t('auto-download')}
</div>
Expand Down

0 comments on commit 9d5dee0

Please sign in to comment.