git.iko.soy/maciek134/podphoenix
on main help sign in
Fix for download duplication when restarting Podbird (rev 156)
commitc0ed4e5dd667a77d4f7c75edd784235ab8c4cbb7 authorErzan Uzan <etherpulse@gmail.com> dateSat 3 Dec 2016, 22:33 (10 years ago) parentf010469
2 files changed+36−11
app/podbird.qml+31−7 app/podcasts.js+5−4
app/podbird.qml+31−7
@@ -78,12 +78,21 @@ MainView {
7878 settings.lastCheck = today
7979 }
8080
81− if (!NetworkingStatus.online || settings.maxEpisodeDownload === -1) {
82− console.log("[LOG]: Skipped autodownloading of new episodes...")
83− console.log("[LOG]: Online connectivity: " + NetworkingStatus.online)
84− console.log("[LOG]: User settings (maxEpisodeDownload): " + settings.maxEpisodeDownload)
85− } else {
86− Podcasts.autoDownloadEpisodes(settings.maxEpisodeDownload)
81+ delayStartTimer.start();
82+ }
83+
84+ Timer {
85+ id: delayStartTimer
86+ interval: 500
87+ repeat: false
88+ onTriggered: {
89+ if (!NetworkingStatus.online || podbird.settings.maxEpisodeDownload === -1) {
90+ console.log("[LOG]: Skipped autodownloading of new episodes...")
91+ console.log("[LOG]: Online connectivity: " + NetworkingStatus.online)
92+ console.log("[LOG]: User settings (maxEpisodeDownload): " + podbird.settings.maxEpisodeDownload)
93+ } else {
94+ Podcasts.autoDownloadEpisodes(podbird.settings.maxEpisodeDownload)
95+ }
8796 }
8897 }
8998
@@ -173,7 +182,12 @@ MainView {
173182 }
174183
175184 function downloadEpisode(image, title, guid, url, disableMobileDownload) {
176− var singleDownload = singleDownloadComponent.createObject(podbird, {"image": image, "title": title, "guid": guid , allowMobileDownload : !disableMobileDownload })
185+ if(downloader.isDownloadInQueue(guid)) {
186+ console.log("[LOG]: Download with GUID of :"+guid+ " is already in the download queue.")
187+ return false;
188+ }
189+
190+ var singleDownload = singleDownloadComponent.createObject(podbird, {"image": image, "title": title, "guid": guid, allowMobileDownload : !disableMobileDownload })
177191 singleDownload.download(url)
178192 }
179193
@@ -184,6 +198,16 @@ MainView {
184198 property int progress: downloads.length > 0 ? downloads[0].progress : 0
185199
186200 cleanDownloads: true
201+
202+ function isDownloadInQueue ( guid ) {
203+ for( var i=0; i < downloads.length; i++) {
204+ if( downloads[i].metadata.custom.guid && guid === downloads[i].metadata.custom.guid) {
205+ return true ;
206+ }
207+ }
208+ return false;
209+ }
210+
187211 onDownloadFinished: {
188212 var db = Podcasts.init();
189213 var finalLocation = fileManager.saveDownload(path);
app/podcasts.js+5−4
@@ -356,12 +356,13 @@ function autoDownloadEpisodes(maxEpisodeDownload) {
356356 var rs = tx.executeSql("SELECT rowid, * FROM Podcast ORDER BY name ASC");
357357 for (var i=0; i < rs.rows.length; i++) {
358358 var podcast = rs.rows.item(i);
359− var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=? ORDER BY published DESC", [rs.rows.item(i).rowid]);
359+ var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=? ORDER BY published DESC", [podcast.rowid]);
360360 var loopCount = maxEpisodeDownload > rs2.rows.length ? rs2.rows.length : maxEpisodeDownload
361361 for (var j=0; j < loopCount; j++) {
362− if (!rs2.rows.item(j).downloadedfile && !rs2.rows.item(j).listened && rs2.rows.item(j).audiourl) {
363− podbird.downloadEpisode(rs.rows.item(i).image, rs2.rows.item(j).name, rs2.rows.item(j).guid, rs2.rows.item(j).audiourl, podbird.settings.downloadOverWifiOnly)
364− tx.executeSql("UPDATE Episode SET queued=1 WHERE guid = ?", [rs2.rows.item(j).guid]);
362+ var episode = rs2.rows.item(j);
363+ if ( !episode.downloadedfile && !episode.listened && episode.audiourl && !episode.queued ) {
364+ podbird.downloadEpisode(podcast.image, episode.name, episode.guid, episode.audiourl, podbird.settings.downloadOverWifiOnly)
365+ tx.executeSql("UPDATE Episode SET queued=1 WHERE guid = ?", [episode.guid]);
365366 }
366367 }
367368 }