Skip to content

Commit

Permalink
ensure downloads still work
Browse files Browse the repository at this point in the history
  • Loading branch information
benkaiser committed Sep 4, 2019
1 parent 5f3629f commit 0679460
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
26 changes: 18 additions & 8 deletions src/services/DownloadManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PermissionsAndroid, ToastAndroid } from 'react-native';
import RNFetchBlob from 'rn-fetch-blob';
import Utilities from '../utilities';
import OfflineManager from '../dataAccess/OfflineManager';
import UrlService from './UrlService';

const downloadDir = Utilities.downloadDir;
const parallelDownloads = 10;
Expand Down Expand Up @@ -55,15 +56,24 @@ export class DownloadManager {
}

_downloadSong(song) {
return RNFetchBlob
.config({
path: downloadDir + song.id,
let promise;
if (song.id.indexOf('s_') === 0 || song.streamUrl) {
promise = Promise.resolve(Utilities.urlFor(song));
} else {
promise = UrlService.getYoutubeAudioUrl(song).then()
}
return promise.then((url) => {
console.log('downloading with url: ' + url);
return RNFetchBlob
.config({
path: downloadDir + song.id,
})
.fetch('GET', url)
.then((res) => {
OfflineManager.addSong(song, res.path());
console.log('The file saved to ', res.path())
});
})
.fetch('GET', Utilities.urlFor(song))
.then((res) => {
OfflineManager.addSong(song, res.path());
console.log('The file saved to ', res.path())
});
}

_requestPermissionsAndMakeDir() {
Expand Down
5 changes: 1 addition & 4 deletions src/services/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ class Player {
}

_noStreamUrl(track) {
if (!track) {
return false;
}
if (track.id.indexOf('s_') === 0) {
if (!track || track.id.indexOf('s_') === 0 || OfflineManager.getSongLocation(track)) {
return false;
}
const _foundTrack = this._playlistItemForTrack(track);
Expand Down

0 comments on commit 0679460

Please sign in to comment.