Fixed epoch implementation for episode.
This commit is contained in:
parent
cc353c120e
commit
dad74dc706
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
/target/
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
.vscode
|
||||
|
||||
@ -12,7 +12,7 @@ CREATE TABLE `episode` (
|
||||
`local_uri` TEXT,
|
||||
`description` TEXT,
|
||||
`published_date` TEXT ,
|
||||
`epoch` INTEGER,
|
||||
`epoch` INTEGER NOT NULL DEFAULT 0,
|
||||
`length` INTEGER,
|
||||
`guid` TEXT,
|
||||
`podcast_id` INTEGER NOT NULL
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use rss::{Channel, Item};
|
||||
use chrono::DateTime;
|
||||
use models;
|
||||
use errors::*;
|
||||
|
||||
@ -46,12 +47,13 @@ pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result<models::NewEp
|
||||
let local_uri = None;
|
||||
|
||||
let pub_date = item.pub_date();
|
||||
let date = DateTime::parse_from_rfc2822(&pub_date.unwrap())?;
|
||||
// info!("{}", date);
|
||||
|
||||
// FIXME: parse pub_date to epoch later
|
||||
let epoch = 0;
|
||||
let epoch = date.timestamp() as i32;
|
||||
// info!("{}", epoch);
|
||||
|
||||
// let length = Some(item.enclosure().unwrap().length().parse().unwrap());
|
||||
let length = item.enclosure().map(|x| x.length().parse().unwrap());
|
||||
let length = item.enclosure().map(|x| x.length().parse().unwrap_or_default());
|
||||
|
||||
let foo = models::NewEpisode {
|
||||
title,
|
||||
|
||||
@ -87,7 +87,7 @@ fn index_episode(con: &SqliteConnection, item: &rss::Item, parent: &Podcast) ->
|
||||
foo.set_published_date(ep.published_date);
|
||||
foo.set_guid(ep.guid);
|
||||
foo.set_length(ep.length);
|
||||
foo.set_epoch(ep.length);
|
||||
foo.set_epoch(ep.epoch);
|
||||
foo.save_changes::<Episode>(con)?;
|
||||
}
|
||||
Err(_) => {
|
||||
|
||||
@ -22,6 +22,7 @@ extern crate diesel_codegen;
|
||||
extern crate xdg;
|
||||
extern crate reqwest;
|
||||
extern crate rss;
|
||||
extern crate chrono;
|
||||
|
||||
pub mod cli;
|
||||
pub mod schema;
|
||||
@ -35,6 +36,7 @@ pub mod errors {
|
||||
use reqwest;
|
||||
use std::io;
|
||||
use rss;
|
||||
use chrono;
|
||||
use diesel::migrations::RunMigrationsError;
|
||||
use diesel::result;
|
||||
|
||||
@ -46,6 +48,7 @@ pub mod errors {
|
||||
MigrationError(RunMigrationsError);
|
||||
RSSError(rss::Error);
|
||||
DieselResultError(result::Error);
|
||||
ChronoError(chrono::ParseError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ pub struct Episode {
|
||||
local_uri: Option<String>,
|
||||
description: Option<String>,
|
||||
published_date: Option<String>,
|
||||
epoch: Option<i32>,
|
||||
epoch: i32,
|
||||
length: Option<i32>,
|
||||
guid: Option<String>,
|
||||
podcast_id: i32,
|
||||
@ -78,11 +78,11 @@ impl Episode {
|
||||
self.guid = value.map(|x| x.to_string());
|
||||
}
|
||||
|
||||
pub fn epoch(&self) -> Option<i32> {
|
||||
pub fn epoch(&self) -> i32 {
|
||||
self.epoch
|
||||
}
|
||||
|
||||
pub fn set_epoch(&mut self, value: Option<i32>) {
|
||||
pub fn set_epoch(&mut self, value: i32) {
|
||||
self.epoch = value;
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ table! {
|
||||
local_uri -> Nullable<Text>,
|
||||
description -> Nullable<Text>,
|
||||
published_date -> Nullable<Text>,
|
||||
epoch -> Nullable<Integer>,
|
||||
epoch -> Integer,
|
||||
length -> Nullable<Integer>,
|
||||
guid -> Nullable<Text>,
|
||||
podcast_id -> Integer,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user