Skip to content

Commit 06d02d5

Browse files
committed
Fix Playback for youtube-dl Supported Links
1 parent ebf01ba commit 06d02d5

File tree

3 files changed

+22
-48
lines changed

3 files changed

+22
-48
lines changed

src/components/Player/utils/sources.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ytdl from 'youtube-dl';
22
import ls from 'local-storage';
33

44
module.exports = {
5-
youtubeDL: (link, cb) => {
5+
youtubeDL: (link, cb, errCb) => {
66
var ytdlArgs = ['-g'];
77

88
if (ls('ytdlQuality') < 4) {
@@ -13,6 +13,9 @@ module.exports = {
1313

1414
var video = ytdl(link, ytdlArgs);
1515

16+
if (errCb)
17+
video.on('error', errCb);
18+
1619
video.on('info', cb);
1720
},
1821
}

src/components/Player/utils/supportedLinks.js

+5-17
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import PlayerActions from '../actions';
33
import PlayerStore from '../store';
44
import needle from 'needle';
55
import _ from 'lodash';
6-
import ytdl from 'youtube-dl';
76
import async from 'async';
87
import ytdlSupported from './ytdl-extractor';
8+
import sources from './sources.js';
99
import plugins from '../../../utils/plugins'
1010
import BaseModalActions from '../../Modal/actions';
1111
import MessageActions from '../../Message/actions';
12-
import ls from 'local-storage';
1312

1413
var fullStop = false;
1514

@@ -202,21 +201,7 @@ class supportedLinks {
202201
var shouldPass = plugin ? plugins.perfectMatch(el, plugin) : ytdlSupported(el);
203202
if (shouldPass) {
204203

205-
var ytdlArgs = ['-g'];
206-
207-
if (ls('ytdlQuality') < 4) {
208-
var qualities = [360, 480, 720, 1080];
209-
ytdlArgs.push('-f');
210-
ytdlArgs.push('[height <=? ' + qualities[ls('ytdlQuality')] + ']');
211-
}
212-
213-
var video = ytdl(el, ytdlArgs);
214-
215-
video.on('error', function(err) {
216-
next();
217-
});
218-
219-
video.on('info', function(info) {
204+
sources.youtubeDL(el, function(info) {
220205
if (!(info['display_id'] && uniqueIDs.indexOf(info['display_id']) > -1) && info.url) {
221206
info['display_id'] && uniqueIDs.push(info['display_id']);
222207
console.log(info);
@@ -239,7 +224,10 @@ class supportedLinks {
239224
}
240225
}
241226
next();
227+
}, function(err) {
228+
next();
242229
});
230+
243231
} else next();
244232
} else next();
245233
};

src/utils/linkUtil.js

+13-30
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import ModalActions from './../components/Modal/actions';
66
import torrentActions from './../actions/torrentActions';
77
import Promise from 'bluebird';
88
import _ from 'lodash';
9-
import ytdl from 'youtube-dl';
9+
import sources from './../components/Player/utils/sources.js';
1010
import ytdlSupported from './../components/Player/utils/ytdl-extractor';
1111
import plugins from './plugins';
12-
import ls from 'local-storage';
1312

1413
module.exports = (inputvalue) => {
1514
return new Promise((resolve, reject) => {
@@ -60,36 +59,24 @@ module.exports = (inputvalue) => {
6059
}), 1000);
6160
} else {
6261
// try youtube-dl with it, use media scanner as a fallback
63-
var ytdlArgs = ['-g'];
64-
65-
if (ls('ytdlQuality') < 4) {
66-
var qualities = [360, 480, 720, 1080];
67-
ytdlArgs.push('-f');
68-
ytdlArgs.push('[height <=? ' + qualities[ls('ytdlQuality')] + ']');
69-
}
70-
71-
var video = ytdl(parsed.url, ytdlArgs);
72-
73-
video.on('error', function(err) {
74-
ModalActions.close();
75-
console.log('ytdl ending error');
76-
reject(new Error('Error: Invalid URL'));
77-
});
78-
79-
video.on('info', function(info) {
62+
sources.youtubeDL(parsed.url, function(info) {
8063
if (info.url) {
8164
ModalActions.close();
8265
console.log(info);
8366
PlayerActions.addPlaylist([{
8467
originalURL: inputvalue,
85-
uri: parsed.url,
68+
uri: info.url,
8669
youtubeDL: true,
8770
image: info.thumbnail,
8871
title: info.fulltitle
8972
}]);
9073
resolve(parsed.url);
9174
} else parseLinks(plugin && plugin.checkFor ? plugin : null);
92-
});
75+
}, function(err) {
76+
ModalActions.close();
77+
console.log('ytdl ending error');
78+
reject(new Error('Error: Invalid URL'));
79+
})
9380
}
9481

9582
}
@@ -110,26 +97,22 @@ module.exports = (inputvalue) => {
11097
if (perfectMatch || ytdlSupported(parsed.url)) {
11198
// a perfect match or a youtube-dl regex match should be
11299
// sent directly to youtube-dl for processing
113-
var video = ytdl(parsed.url, ['-g']);
114-
115-
video.on('error', function(err) {
116-
parseLinks(plugin && plugin.checkFor ? plugin : null);
117-
});
118-
119-
video.on('info', function(info) {
100+
sources.youtubeDL(parsed.url, function(info) {
120101
if (info.url) {
121102
ModalActions.close();
122103
console.log(info);
123104
PlayerActions.addPlaylist([{
124105
originalURL: inputvalue,
125-
uri: parsed.url,
106+
uri: info.url,
126107
youtubeDL: true,
127108
image: info.thumbnail,
128109
title: info.fulltitle
129110
}]);
130111
resolve(parsed.url);
131112
} else parseLinks(plugin && plugin.checkFor ? plugin : null);
132-
});
113+
}, function(err) {
114+
parseLinks(plugin && plugin.checkFor ? plugin : null);
115+
})
133116

134117
} else {
135118
parseLinks(plugin && plugin.checkFor ? plugin : null);

0 commit comments

Comments
 (0)