hammond-data: Add duration column to the episode table.
This commit is contained in:
parent
5541b18a6a
commit
4512790f2d
@ -0,0 +1,22 @@
|
||||
ALTER TABLE episode RENAME TO old_table;
|
||||
|
||||
CREATE TABLE episode (
|
||||
title TEXT NOT NULL,
|
||||
uri TEXT,
|
||||
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;
|
||||
@ -0,0 +1,23 @@
|
||||
ALTER TABLE episode RENAME TO old_table;
|
||||
|
||||
CREATE TABLE episode (
|
||||
title TEXT NOT NULL,
|
||||
uri TEXT,
|
||||
local_uri TEXT,
|
||||
description TEXT,
|
||||
published_date 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, 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;
|
||||
@ -111,6 +111,7 @@ pub fn get_episodes_widgets_with_limit(limit: u32) -> Result<Vec<EpisodeWidgetQu
|
||||
episode::local_uri,
|
||||
episode::epoch,
|
||||
episode::length,
|
||||
episode::duration,
|
||||
episode::played,
|
||||
episode::podcast_id,
|
||||
))
|
||||
@ -156,7 +157,7 @@ pub fn get_pd_episodeswidgets(parent: &Podcast) -> Result<Vec<EpisodeWidgetQuery
|
||||
let con = db.get()?;
|
||||
|
||||
Ok(
|
||||
episode.select((rowid, title, uri, local_uri, epoch, length, played, podcast_id))
|
||||
episode.select((rowid, title, uri, local_uri, epoch, length, duration, played, podcast_id))
|
||||
.filter(podcast_id.eq(parent.id()))
|
||||
// .group_by(epoch)
|
||||
.order(epoch.desc())
|
||||
|
||||
@ -162,6 +162,7 @@ pub(crate) struct NewEpisode {
|
||||
description: Option<String>,
|
||||
published_date: Option<String>,
|
||||
length: Option<i32>,
|
||||
duration: Option<i32>,
|
||||
guid: Option<String>,
|
||||
epoch: i32,
|
||||
podcast_id: i32,
|
||||
@ -207,6 +208,7 @@ impl NewEpisode {
|
||||
|
||||
if foo.title() != self.title.as_str() || foo.epoch() != self.epoch
|
||||
|| foo.uri() != self.uri.as_ref().map(|s| s.as_str())
|
||||
|| foo.duration() != self.duration
|
||||
{
|
||||
self.update(con, foo.rowid())?;
|
||||
}
|
||||
|
||||
@ -33,6 +33,7 @@ pub struct Episode {
|
||||
published_date: Option<String>,
|
||||
epoch: i32,
|
||||
length: Option<i32>,
|
||||
duration: Option<i32>,
|
||||
guid: Option<String>,
|
||||
played: Option<i32>,
|
||||
favorite: bool,
|
||||
@ -125,6 +126,8 @@ impl Episode {
|
||||
}
|
||||
|
||||
/// Get the `length`.
|
||||
///
|
||||
/// The number represents the size of the file in bytes.
|
||||
pub fn length(&self) -> Option<i32> {
|
||||
self.length
|
||||
}
|
||||
@ -134,6 +137,18 @@ impl Episode {
|
||||
self.length = value;
|
||||
}
|
||||
|
||||
/// Get the `duration` value.
|
||||
///
|
||||
/// The number represents the duration of the item/episode in seconds.
|
||||
pub fn duration(&self) -> Option<i32> {
|
||||
self.duration
|
||||
}
|
||||
|
||||
/// Set the `duration`.
|
||||
pub fn set_duration(&mut self, value: Option<i32>) {
|
||||
self.duration = value;
|
||||
}
|
||||
|
||||
/// Epoch representation of the last time the episode was played.
|
||||
///
|
||||
/// None/Null for unplayed.
|
||||
@ -204,6 +219,7 @@ pub struct EpisodeWidgetQuery {
|
||||
local_uri: Option<String>,
|
||||
epoch: i32,
|
||||
length: Option<i32>,
|
||||
duration: Option<i32>,
|
||||
played: Option<i32>,
|
||||
// favorite: bool,
|
||||
// archive: bool,
|
||||
@ -250,6 +266,8 @@ impl EpisodeWidgetQuery {
|
||||
}
|
||||
|
||||
/// Get the `length`.
|
||||
///
|
||||
/// The number represents the size of the file in bytes.
|
||||
pub fn length(&self) -> Option<i32> {
|
||||
self.length
|
||||
}
|
||||
@ -259,6 +277,18 @@ impl EpisodeWidgetQuery {
|
||||
self.length = value;
|
||||
}
|
||||
|
||||
/// Get the `duration` value.
|
||||
///
|
||||
/// The number represents the duration of the item/episode in seconds.
|
||||
pub fn duration(&self) -> Option<i32> {
|
||||
self.duration
|
||||
}
|
||||
|
||||
/// Set the `duration`.
|
||||
pub fn set_duration(&mut self, value: Option<i32>) {
|
||||
self.duration = value;
|
||||
}
|
||||
|
||||
/// Epoch representation of the last time the episode was played.
|
||||
///
|
||||
/// None/Null for unplayed.
|
||||
|
||||
@ -64,13 +64,14 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
|
||||
let epoch = date.map(|x| x.timestamp() as i32).unwrap_or(0);
|
||||
|
||||
let length = item.enclosure().map(|x| x.length().parse().unwrap_or(0));
|
||||
let _duration = parse_itunes_duration(item);
|
||||
let duration = parse_itunes_duration(item);
|
||||
|
||||
Ok(NewEpisodeBuilder::default()
|
||||
.title(title)
|
||||
.uri(uri)
|
||||
.description(description)
|
||||
.length(length)
|
||||
.duration(duration)
|
||||
.published_date(pub_date)
|
||||
.epoch(epoch)
|
||||
.guid(guid)
|
||||
|
||||
@ -8,6 +8,7 @@ table! {
|
||||
published_date -> Nullable<Text>,
|
||||
epoch -> Integer,
|
||||
length -> Nullable<Integer>,
|
||||
duration -> Nullable<Integer>,
|
||||
guid -> Nullable<Text>,
|
||||
played -> Nullable<Integer>,
|
||||
favorite -> Bool,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user