Added disc number. Fixed ordering, createdAt in Playlist file.

This commit is contained in:
Jonathan Bernard 2016-03-10 10:41:38 -06:00
parent 107e48a1d0
commit 861717589c
6 changed files with 22 additions and 8 deletions

View File

@ -66,6 +66,7 @@ public class MediaLibrary {
mf.name = fileTag?.getFirst(TITLE)?.trim() ?: f.name mf.name = fileTag?.getFirst(TITLE)?.trim() ?: f.name
mf.filePath = relPath mf.filePath = relPath
mf.comment = fileTag?.getAll(COMMENT)?.collect { it.trim() }.join('\n\n') mf.comment = fileTag?.getAll(COMMENT)?.collect { it.trim() }.join('\n\n')
mf.discNumber = safeToInteger(fileTag?.getFirst(DISC_NO))
mf.trackNumber = safeToInteger(fileTag?.getFirst(TRACK)) mf.trackNumber = safeToInteger(fileTag?.getFirst(TRACK))
def folderParts = mf.filePath.split("[\\\\/]")[1..<-1] as LinkedList def folderParts = mf.filePath.split("[\\\\/]")[1..<-1] as LinkedList
@ -90,6 +91,8 @@ public class MediaLibrary {
associateWithArtistsAndAlbums(mf, artistNames, albumNames, associateWithArtistsAndAlbums(mf, artistNames, albumNames,
safeToInteger(fileTag.getFirst(YEAR))) safeToInteger(fileTag.getFirst(YEAR)))
} }
return mf
} }
public def getByIdOrName(Class modelClass, String input) { public def getByIdOrName(Class modelClass, String input) {
@ -166,7 +169,7 @@ public class MediaLibrary {
if (!album) { if (!album) {
def cur = orm.getAlbumsWhere(name: albumName) def cur = orm.getAlbumsWhere(name: albumName)
album = cur ? cur[0] : 0 } } album = cur ? cur[0] : null } }
// We still can't find the album at all. We'll need to create it // We still can't find the album at all. We'll need to create it
if (!album) if (!album)

View File

@ -371,6 +371,8 @@ public class ORM {
def whereClauses = [] def whereClauses = []
query.append('SELECT mf.* FROM media_files mf ') query.append('SELECT mf.* FROM media_files mf ')
orderClasess << 'mf.disc_number'
orderClauses << 'mf.track_number'
if (params.artistId) { if (params.artistId) {
query.append(' JOIN artists_media_files armf ON ') query.append(' JOIN artists_media_files armf ON ')
@ -385,8 +387,7 @@ public class ORM {
.append(' almf.album_id = ? ') .append(' almf.album_id = ? ')
sqlParams << params.albumId sqlParams << params.albumId
orderClauses << 'almf.album_id ASC' orderClauses << 'almf.album_id ASC' }
orderClauses << 'mf.track_number ASC' }
if (params.playlistId) { if (params.playlistId) {
query.append(' JOIN playlists_media_files pmf ON ') query.append(' JOIN playlists_media_files pmf ON ')
@ -399,6 +400,10 @@ public class ORM {
whereClauses << 'mf.name = ?' whereClauses << 'mf.name = ?'
sqlParams << params.name } sqlParams << params.name }
if (params.discNumber) {
query.append('mf.disc_number = ?')
sqlParams << params.discNumber }
if (params.trackNumber) { if (params.trackNumber) {
query.append('mf.track_number = ?') query.append('mf.track_number = ?')
sqlParams << params.trackNumber } sqlParams << params.trackNumber }

View File

@ -1,5 +1,6 @@
package com.jdbernard.wdiwtlt.db.models; package com.jdbernard.wdiwtlt.db.models;
import java.sql.Timestamp;
import java.util.Date; import java.util.Date;
public class Bookmark extends Model { public class Bookmark extends Model {
@ -8,7 +9,7 @@ public class Bookmark extends Model {
public int mediaFileId; public int mediaFileId;
public int playIndex; public int playIndex;
public boolean user_created; public boolean user_created;
public Date createdAt = new Date(); public Timestamp createdAt = new Timestamp(new Date().getTime());
public String toString() { return name; } public String toString() { return name; }
} }

View File

@ -8,6 +8,7 @@ public class MediaFile extends Model {
public static final String FILE_LOCATION = "file location"; public static final String FILE_LOCATION = "file location";
public String name; public String name;
public Integer discNumber;
public Integer trackNumber; public Integer trackNumber;
public int playCount = 0; public int playCount = 0;
public String filePath; public String filePath;

View File

@ -10,7 +10,7 @@ public class Playlist extends Model {
public int modCount = 0; public int modCount = 0;
public int mediaFileCount = 0; public int mediaFileCount = 0;
public Integer copiedFromId = null; public Integer copiedFromId = null;
public Date createdAt = new Date()t; public Timestamp createdAt = new Timestamp(new Date().getTime());
public String toString() { public String toString() {
if (userCreated) return name; if (userCreated) return name;

View File

@ -17,6 +17,7 @@ CREATE INDEX albums_name_idx ON albums(name);
CREATE TABLE media_files ( CREATE TABLE media_files (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL, name VARCHAR NOT NULL,
disc_number INTEGER NOT NULL DEFAULT 1,
track_number INTEGER, track_number INTEGER,
play_count INTEGER NOT NULL DEFAULT 0, play_count INTEGER NOT NULL DEFAULT 0,
file_path VARCHAR NOT NULL, file_path VARCHAR NOT NULL,
@ -61,7 +62,7 @@ CREATE TABLE playlists_media_files (
playlist_id INTEGER NOT NULL REFERENCES playlists(id) ON DELETE CASCADE, playlist_id INTEGER NOT NULL REFERENCES playlists(id) ON DELETE CASCADE,
media_file_id INTEGER NOT NULL REFERENCES media_files(id) ON DELETE CASCADE, media_file_id INTEGER NOT NULL REFERENCES media_files(id) ON DELETE CASCADE,
position INTEGER NOT NULL DEFAULT 0, position INTEGER NOT NULL DEFAULT 0,
UNIQUE (playlist_id, media_file_id) PRIMARY KEY (playlist_id, media_file_id, position)
); );
CREATE TABLE bookmarks ( CREATE TABLE bookmarks (
@ -74,10 +75,13 @@ CREATE TABLE bookmarks (
created_at TIMESTAMP NOT NULL DEFAULT NOW() created_at TIMESTAMP NOT NULL DEFAULT NOW()
); );
CREATE INDEX bookmarks_playlist_id_idx ON bookmarks (playlist_id);
CREATE INDEX bookmarks_media_file_id_idx ON bookmarks (media_file_id);
CREATE TABLE media_files_tags ( CREATE TABLE media_files_tags (
id SERIAL PRIMARY KEY,
media_file_id INTEGER REFERENCES media_files(id) ON DELETE CASCADE, media_file_id INTEGER REFERENCES media_files(id) ON DELETE CASCADE,
tag_id INTEGER REFERENCES tags(id) ON DELETE CASCADE tag_id INTEGER REFERENCES tags(id) ON DELETE CASCADE,
PRIMARY KEY (media_file_id, tag_id)
); );
CREATE TABLE images ( CREATE TABLE images (