diff --git a/hammond-data/migrations/2017-12-09-125835_change_episode_pk/down.sql b/hammond-data/migrations/2017-12-09-125835_change_episode_pk/down.sql
new file mode 100644
index 0000000..01f66ff
--- /dev/null
+++ b/hammond-data/migrations/2017-12-09-125835_change_episode_pk/down.sql
@@ -0,0 +1,19 @@
+ALTER TABLE episode RENAME TO old_table;
+
+CREATE TABLE episode (
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
+ title TEXT,
+ uri TEXT NOT NULL UNIQUE,
+ local_uri TEXT,
+ description TEXT,
+ published_date TEXT,
+ epoch INTEGER NOT NULL DEFAULT 0,
+ length INTEGER,
+ guid TEXT,
+ played INTEGER,
+ favorite INTEGER NOT NULL DEFAULT 0,
+ archive INTEGER NOT NULL DEFAULT 0,
+ podcast_id INTEGER NOT NULL
+);
+
+INSERT INTO episode SELECT * FROM old_table;
\ No newline at end of file
diff --git a/hammond-data/migrations/2017-12-09-125835_change_episode_pk/up.sql b/hammond-data/migrations/2017-12-09-125835_change_episode_pk/up.sql
new file mode 100644
index 0000000..cbe40dd
--- /dev/null
+++ b/hammond-data/migrations/2017-12-09-125835_change_episode_pk/up.sql
@@ -0,0 +1,22 @@
+ALTER TABLE episode RENAME TO old_table;
+
+CREATE TABLE episode (
+ title TEXT NOT NULL,
+ uri TEXT UNIQUE,
+ local_uri TEXT,
+ description TEXT,
+ published_date TEXT,
+ epoch INTEGER NOT NULL DEFAULT 0,
+ length 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, published_date, epoch, length, guid, played, favorite, archive, podcast_id)
+SELECT title, uri, local_uri, description, published_date, epoch, length, guid, played, favorite, archive, podcast_id
+FROM old_table;
+Drop table old_table;
\ No newline at end of file
diff --git a/hammond-data/src/dbqueries.rs b/hammond-data/src/dbqueries.rs
index 1604547..f83bc0b 100644
--- a/hammond-data/src/dbqueries.rs
+++ b/hammond-data/src/dbqueries.rs
@@ -55,7 +55,9 @@ pub fn get_episode_from_id(ep_id: i32) -> Result {
let db = connection();
let con = db.get()?;
- Ok(episode.filter(id.eq(ep_id)).get_result::(&*con)?)
+ Ok(episode
+ .filter(rowid.eq(ep_id))
+ .get_result::(&*con)?)
}
pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result
\n
Plus we chat with Wimpy about the Ubuntu Rally in NYC, \
Microsoft’s sneaky move to turn Windows 10 into the “ULTIMATE LINUX \
RUNTIME”, community news & more!
";
- assert_eq!(i2.title(), Some("Gnome Does it Again | LUP 213"));
+ assert_eq!(i2.title(), "Gnome Does it Again | LUP 213");
assert_eq!(
i2.uri(),
- "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3"
+ Some("http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3")
);
assert_eq!(i2.description(), Some(descr2));
assert_eq!(i2.length(), Some(36544272));
@@ -327,11 +334,13 @@ mod tests {
rel=\"noopener noreferrer\">RFC 2094 \"Non-lexical lifetimes\"";
let i = new_episode(&firstitem, 0).unwrap();
- assert_eq!(i.title(), Some("Episode #9 - A Once in a Lifetime RFC"));
+ assert_eq!(i.title(), "Episode #9 - A Once in a Lifetime RFC");
assert_eq!(
i.uri(),
- "http://request-for-explanation.github.\
- io/podcast/ep9-a-once-in-a-lifetime-rfc/episode.mp3"
+ Some(
+ "http://request-for-explanation.github.\
+ io/podcast/ep9-a-once-in-a-lifetime-rfc/episode.mp3"
+ )
);
assert_eq!(i.description(), Some(descr));
assert_eq!(i.length(), Some(15077388));
@@ -349,11 +358,13 @@ mod tests {
href=\"https://github.com/rust-lang/rfcs/pull/2071\" rel=\"noopener \
noreferrer\">RFC 2071 \"Add impl Trait type alias and variable \
declarations\"";
- assert_eq!(i2.title(), Some("Episode #8 - An Existential Crisis"));
+ assert_eq!(i2.title(), "Episode #8 - An Existential Crisis");
assert_eq!(
i2.uri(),
- "http://request-for-explanation.github.io/podcast/ep8-an-existential-crisis/episode.\
- mp3"
+ Some(
+ "http://request-for-explanation.github.\
+ io/podcast/ep8-an-existential-crisis/episode.mp3"
+ )
);
assert_eq!(i2.description(), Some(descr2));
assert_eq!(i2.length(), Some(13713219));
diff --git a/hammond-data/src/schema.rs b/hammond-data/src/schema.rs
index 00aff92..7b43171 100644
--- a/hammond-data/src/schema.rs
+++ b/hammond-data/src/schema.rs
@@ -1,8 +1,8 @@
table! {
- episode (id) {
- id -> Integer,
- title -> Nullable,
- uri -> Text,
+ episode (title, podcast_id) {
+ rowid -> Integer,
+ title -> Text,
+ uri -> Nullable,
local_uri -> Nullable,
description -> Nullable,
published_date -> Nullable,
diff --git a/hammond-data/src/utils.rs b/hammond-data/src/utils.rs
index 72ef146..42a6af7 100644
--- a/hammond-data/src/utils.rs
+++ b/hammond-data/src/utils.rs
@@ -146,22 +146,26 @@ mod tests {
// Setup episodes
let db = connection();
let con = db.get().unwrap();
- NewEpisodeBuilder::default()
- .uri("foo_bar".to_string())
+ let n1 = NewEpisodeBuilder::default()
+ .title("foo_bar".to_string())
+ .podcast_id(0)
.build()
.unwrap()
.into_episode(&con)
.unwrap();
- NewEpisodeBuilder::default()
- .uri("bar_baz".to_string())
+ let n2 = NewEpisodeBuilder::default()
+ .title("bar_baz".to_string())
+ .podcast_id(1)
.build()
.unwrap()
.into_episode(&con)
.unwrap();
- let mut ep1 = dbqueries::get_episode_from_uri(&con, "foo_bar").unwrap();
- let mut ep2 = dbqueries::get_episode_from_uri(&con, "bar_baz").unwrap();
+ let mut ep1 =
+ dbqueries::get_episode_from_new_episode(&con, n1.title(), n1.podcast_id()).unwrap();
+ let mut ep2 =
+ dbqueries::get_episode_from_new_episode(&con, n2.title(), n2.podcast_id()).unwrap();
ep1.set_local_uri(Some(valid_path.to_str().unwrap()));
ep2.set_local_uri(Some(bad_path.to_str().unwrap()));
@@ -179,7 +183,7 @@ mod tests {
let episodes = dbqueries::get_downloaded_episodes().unwrap();
assert_eq!(episodes.len(), 1);
- assert_eq!("foo_bar", episodes.first().unwrap().uri());
+ assert_eq!("foo_bar", episodes.first().unwrap().title());
}
#[test]
@@ -188,7 +192,7 @@ mod tests {
let mut episode = {
let db = connection();
let con = db.get().unwrap();
- dbqueries::get_episode_from_uri(&con, "bar_baz").unwrap()
+ dbqueries::get_episode_from_new_episode(&con, "bar_baz", 1).unwrap()
};
checker_helper(&mut episode);
@@ -201,7 +205,7 @@ mod tests {
let mut episode = {
let db = connection();
let con = db.get().unwrap();
- dbqueries::get_episode_from_uri(&con, "foo_bar").unwrap()
+ dbqueries::get_episode_from_new_episode(&con, "foo_bar", 0).unwrap()
};
let valid_path = episode.local_uri().unwrap().to_owned();
@@ -215,7 +219,7 @@ mod tests {
let mut episode = {
let db = connection();
let con = db.get().unwrap();
- dbqueries::get_episode_from_uri(&con, "foo_bar").unwrap()
+ dbqueries::get_episode_from_new_episode(&con, "foo_bar", 0).unwrap()
};
let now_utc = Utc::now().timestamp() as i32;
// let limit = now_utc - 172_800;
@@ -235,7 +239,7 @@ mod tests {
let mut episode = {
let db = connection();
let con = db.get().unwrap();
- dbqueries::get_episode_from_uri(&con, "foo_bar").unwrap()
+ dbqueries::get_episode_from_new_episode(&con, "foo_bar", 0).unwrap()
};
let now_utc = Utc::now().timestamp() as i32;
// limit = 172_800;
diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs
index f3b695a..fafd726 100644
--- a/hammond-downloader/src/downloader.rs
+++ b/hammond-downloader/src/downloader.rs
@@ -118,7 +118,7 @@ pub fn get_episode(ep: &mut Episode, download_folder: &str) -> Result<()> {
ep.save()?;
};
- let res = download_into(download_folder, ep.title().unwrap(), ep.uri());
+ let res = download_into(download_folder, ep.title(), ep.uri().unwrap());
if let Ok(path) = res {
// If download succedes set episode local_uri to dlpath.
diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs
index c113b51..7166d0c 100644
--- a/hammond-gtk/src/widgets/episode.rs
+++ b/hammond-gtk/src/widgets/episode.rs
@@ -5,7 +5,6 @@ use gtk::{ContainerExt, TextBufferExt};
use open;
use dissolve::strip_html_tags;
-use diesel::associations::Identifiable;
use hammond_data::dbqueries;
use hammond_data::{Episode, Podcast};
@@ -77,10 +76,7 @@ impl EpisodeWidget {
fn init(&self, episode: &mut Episode, pd: &Podcast) {
self.title.set_xalign(0.0);
-
- if let Some(t) = episode.title() {
- self.title.set_text(t);
- }
+ self.title.set_text(episode.title());
if episode.description().is_some() {
let text = episode.description().unwrap().to_owned();
@@ -116,7 +112,7 @@ impl EpisodeWidget {
self.play
.connect_clicked(clone!(episode, played, unplayed => move |_| {
let mut episode = episode.clone();
- on_play_bttn_clicked(*episode.id());
+ on_play_bttn_clicked(episode.rowid());
let _ = episode.set_played_now();
played.hide();
unplayed.show();
@@ -126,7 +122,7 @@ impl EpisodeWidget {
let download = &self.download;
self.delete
.connect_clicked(clone!(episode, play, download => move |del| {
- on_delete_bttn_clicked(*episode.id());
+ on_delete_bttn_clicked(episode.rowid());
del.hide();
play.hide();
download.show();
@@ -189,7 +185,7 @@ fn on_download_clicked(
let download_fold = downloader::get_download_folder(&pd_title).unwrap();
let e = downloader::get_episode(&mut ep, download_fold.as_str());
if let Err(err) = e {
- error!("Error while trying to download: {}", ep.uri());
+ error!("Error while trying to download: {:?}", ep.uri());
error!("Error: {}", err);
};
sender.send(true).expect("Couldn't send data to channel");;