2
* Copyright 2015 Michael Sheldon <mike@mikeasoft.com>
4
* This file is part of Podbird.
6
* Podbird is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* Podbird is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
var db = LocalStorage.openDatabaseSync("Podbird", "1.0", "Database of subscribed podcasts and their episodes", 1000000);
21
db.transaction(function(tx) {
22
tx.executeSql('CREATE TABLE IF NOT EXISTS Podcast(artist TEXT, name TEXT, description TEXT, feed TEXT, image TEXT, lastupdate TIMESTAMP)');
23
tx.executeSql('CREATE TABLE IF NOT EXISTS Episode(guid TEXT, podcast INTEGER, name TEXT, subtitle TEXT, description TEXT, duration INTEGER, audiourl TEXT, downloadedfile TEXT, published TIMESTAMP, listened BOOLEAN, position INTEGER, FOREIGN KEY(podcast) REFERENCES Podcast(rowid))');
28
function subscribe(artist, name, feed, img) {
30
db.transaction(function(tx) {
31
var rs = tx.executeSql("SELECT rowid FROM Podcast WHERE feed = ?", feed);
32
if (rs.rows.length === 0) {
33
tx.executeSql("INSERT INTO Podcast(artist, name, feed, image) VALUES(?, ?, ?, ?)", [artist, name, feed, img]);
38
function formatTime(seconds) {
39
var rem = seconds % 3600;
40
return Math.floor(seconds / 3600) + ":" + zeroFill(Math.floor(rem / 60), 2);
43
function zeroFill(n, width) {
44
width -= n.toString().length;
46
return new Array(width + (/\./.test(n) ? 2 : 1)).join('0') + n;