add duration to song table and default it's value to None for all
formats on song tags
This commit is contained in:
parent
d06263cff7
commit
418c8e52ab
5 changed files with 28 additions and 0 deletions
19
src/db/migrations/20171015224223_add_song_duration/down.sql
Normal file
19
src/db/migrations/20171015224223_add_song_duration/down.sql
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
CREATE TEMPORARY TABLE songs_backup(id, path, parent, track_number, disc_number, title, artist, album_artist, year, album, artwork);
|
||||||
|
INSERT INTO songs_backup SELECT id, path, parent, track_number, disc_number, title, artist, album_artist, year, album, artwork FROM songs;
|
||||||
|
DROP TABLE songs;
|
||||||
|
CREATE TABLE songs (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
path TEXT NOT NULL,
|
||||||
|
parent TEXT NOT NULL,
|
||||||
|
track_number INTEGER,
|
||||||
|
disc_number INTEGER,
|
||||||
|
title TEXT,
|
||||||
|
artist TEXT,
|
||||||
|
album_artist TEXT,
|
||||||
|
year INTEGER,
|
||||||
|
album TEXT,
|
||||||
|
artwork TEXT,
|
||||||
|
UNIQUE(path) ON CONFLICT REPLACE
|
||||||
|
);
|
||||||
|
INSERT INTO songs SELECT * FROM songs_backup;
|
||||||
|
DROP TABLE songs_backup;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE songs ADD COLUMN duration INTEGER;
|
Binary file not shown.
|
@ -49,6 +49,7 @@ pub struct Song {
|
||||||
pub year: Option<i32>,
|
pub year: Option<i32>,
|
||||||
pub album: Option<String>,
|
pub album: Option<String>,
|
||||||
pub artwork: Option<String>,
|
pub artwork: Option<String>,
|
||||||
|
pub duration: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Queryable, Serialize)]
|
#[derive(Debug, Queryable, Serialize)]
|
||||||
|
@ -84,6 +85,7 @@ struct NewSong {
|
||||||
year: Option<i32>,
|
year: Option<i32>,
|
||||||
album: Option<String>,
|
album: Option<String>,
|
||||||
artwork: Option<String>,
|
artwork: Option<String>,
|
||||||
|
duration: Option<i32>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Insertable)]
|
#[derive(Debug, Insertable)]
|
||||||
|
@ -247,6 +249,7 @@ impl<'conn> IndexBuilder<'conn> {
|
||||||
disc_number: tags.disc_number.map(|n| n as i32),
|
disc_number: tags.disc_number.map(|n| n as i32),
|
||||||
track_number: tags.track_number.map(|n| n as i32),
|
track_number: tags.track_number.map(|n| n as i32),
|
||||||
title: tags.title,
|
title: tags.title,
|
||||||
|
duration: tags.duration.map(|n| n as i32),
|
||||||
artist: tags.artist,
|
artist: tags.artist,
|
||||||
album_artist: tags.album_artist,
|
album_artist: tags.album_artist,
|
||||||
album: tags.album,
|
album: tags.album,
|
||||||
|
|
|
@ -15,6 +15,7 @@ pub struct SongTags {
|
||||||
pub disc_number: Option<u32>,
|
pub disc_number: Option<u32>,
|
||||||
pub track_number: Option<u32>,
|
pub track_number: Option<u32>,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
pub duration: Option<u32>,
|
||||||
pub artist: Option<String>,
|
pub artist: Option<String>,
|
||||||
pub album_artist: Option<String>,
|
pub album_artist: Option<String>,
|
||||||
pub album: Option<String>,
|
pub album: Option<String>,
|
||||||
|
@ -50,6 +51,7 @@ fn read_id3(path: &Path) -> Result<SongTags> {
|
||||||
album_artist: album_artist,
|
album_artist: album_artist,
|
||||||
album: album,
|
album: album,
|
||||||
title: title,
|
title: title,
|
||||||
|
duration: None,
|
||||||
disc_number: disc_number,
|
disc_number: disc_number,
|
||||||
track_number: track_number,
|
track_number: track_number,
|
||||||
year: year,
|
year: year,
|
||||||
|
@ -98,6 +100,7 @@ fn read_ape(path: &Path) -> Result<SongTags> {
|
||||||
album_artist: album_artist,
|
album_artist: album_artist,
|
||||||
album: album,
|
album: album,
|
||||||
title: title,
|
title: title,
|
||||||
|
duration: None,
|
||||||
disc_number: disc_number,
|
disc_number: disc_number,
|
||||||
track_number: track_number,
|
track_number: track_number,
|
||||||
year: year,
|
year: year,
|
||||||
|
@ -114,6 +117,7 @@ fn read_vorbis(path: &Path) -> Result<SongTags> {
|
||||||
album_artist: None,
|
album_artist: None,
|
||||||
album: None,
|
album: None,
|
||||||
title: None,
|
title: None,
|
||||||
|
duration:None,
|
||||||
disc_number: None,
|
disc_number: None,
|
||||||
track_number: None,
|
track_number: None,
|
||||||
year: None,
|
year: None,
|
||||||
|
@ -147,6 +151,7 @@ fn read_flac(path: &Path) -> Result<SongTags> {
|
||||||
album_artist: vorbis.album_artist().map(|v| v[0].clone()),
|
album_artist: vorbis.album_artist().map(|v| v[0].clone()),
|
||||||
album: vorbis.album().map(|v| v[0].clone()),
|
album: vorbis.album().map(|v| v[0].clone()),
|
||||||
title: vorbis.title().map(|v| v[0].clone()),
|
title: vorbis.title().map(|v| v[0].clone()),
|
||||||
|
duration: None,
|
||||||
disc_number: disc_number,
|
disc_number: disc_number,
|
||||||
track_number: vorbis.track(),
|
track_number: vorbis.track(),
|
||||||
year: year,
|
year: year,
|
||||||
|
|
Loading…
Add table
Reference in a new issue