Skip to content
This repository has been archived by the owner on May 26, 2018. It is now read-only.

Commit

Permalink
Better youtube error messaging (#602)
Browse files Browse the repository at this point in the history
- fixes #523
- fixes #285
- fixes #471
  • Loading branch information
Dave Justice authored and jaredhirsch committed Feb 7, 2017
1 parent 38e7828 commit 5014ab7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
13 changes: 11 additions & 2 deletions client-lib/nsa.js
Expand Up @@ -75,7 +75,15 @@ emitter.on('init', (opts) => {
if (ev.data === PLAYING && !appData.playing) emitter.emit('play')
else if (ev.data === PAUSED && appData.playing) emitter.emit('pause')
},
onError: (err) => emitter.emit('error')
onError: (err) => {
let msg = true;
if (err.data === 150 || err.data === 101) msg = 'errorYTNotAllowed';
else if (err.data === 100) msg = 'errorYTNotFound';

emitter.emit('error', {
msg: msg
});
}
});
} else {
playerMap['video'] = new VideoCtrl(opts);
Expand Down Expand Up @@ -212,7 +220,8 @@ emitter.on('send-to-tab', () => {
});

emitter.on('error', (opts) => {
appData.set({error: true});
const msg = opts.msg ? opts.msg : true;
appData.set({error: msg});
});

function getView() {
Expand Down
18 changes: 10 additions & 8 deletions lib/get-locale-strings.js
Expand Up @@ -6,6 +6,15 @@ module.exports = function(domain, isAudio) {
return JSON.stringify({
errorMsg: _('error_msg'),
errorLink: _('error_link'),
errorYTNotFound: _('error_youtube_not_found'),
errorYTNotAllowed: _('error_youtube_not_allowed'),
errorScLimit: _('error_sc_limit'),
errorScConnection: _('error_sc_connection'),
errorScTrack: _('error_sc_not_track'),
errorScStreamable: _('error_sc_not_streamable'),
errorScRestricted: _('error_sc_restricted'),
errorVimeoConnection: _('error_vimeo_connection'),
errorVineConnection: _('error_vine_connection'),
loadingMsg: _('loading_view_msg', mediaType, domain),
ttMute: _('tooltip_mute'),
ttPlay: _('tooltip_play'),
Expand All @@ -15,13 +24,6 @@ module.exports = function(domain, isAudio) {
ttMinimize: _('tooltip_minimize'),
ttMaximize: _('tooltip_maximize'),
ttSendToTab: _('tooltip_send_to_tab'),
ttSwitchVis: _('tooltip_switch_visual'),
ttScLimit: _('error_sc_limit'),
ttScConnection: _('error_sc_connection'),
ttScTrack: _('error_sc_not_track'),
ttScStreamable: _('error_sc_not_streamable'),
ttScRestricted: _('error_sc_restricted'),
ttVimeoConnection: _('error_vimeo_connection'),
ttVineConnection: _('error_vine_connection')
ttSwitchVis: _('tooltip_switch_visual')
});
}
10 changes: 5 additions & 5 deletions lib/get-soundcloud-url.js
Expand Up @@ -8,19 +8,19 @@ function getSoundcloudUrl(videoUrl, cb) {
url: `https://api.soundcloud.com/resolve.json?client_id=${clientId}&url=${videoUrl}`,
onComplete: function (resp) {
if (resp.status === 429) {
cb('ttScTrackLimit');
cb('errorScTrackLimit');
return;
} else if (resp.status === 403) {
cb('ttScRestricted');
cb('errorScRestricted');
return;
} else if (!resp.json) {
cb('ttScTrackConnection');
cb('errorScTrackConnection');
return;
} else if (resp.json.kind !== 'track') {
cb('ttScTrack');
cb('errorScTrack');
return;
} else if (!resp.json.streamable) {
cb('ttScStreamable');
cb('errorScStreamable');
return;
} else {
cb(null, resp.json.stream_url+'?client_id='+clientId);
Expand Down
2 changes: 1 addition & 1 deletion lib/get-vimeo-url.js
Expand Up @@ -7,7 +7,7 @@ function getVimeoUrl(videoId, cb) {
url: 'https://player.vimeo.com/video/' + videoId + '/config',
onComplete: function (resp) {
if (!resp.json) {
cb('ttVimeoConnection');
cb('errorVimeoConnection');
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/get-vine-url.js
Expand Up @@ -13,7 +13,7 @@ function getVineUrl(id, cb) {
const vineURL = `https://vine.co/v/${id}`;

isReachable(vineURL, (up) => {
if (!up) cb('ttVineConnection');
if (!up) cb('errorVineConnection');
else {
const hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
onReady: function() {
Expand Down
5 changes: 4 additions & 1 deletion locales/en-US/addon.properties
Expand Up @@ -21,4 +21,7 @@ error_sc_not_streamable= The track you have sent from Soundcloud is not streamab
error_sc_restricted= The publisher of this track has restricted access to third parties, try another track.

error_vimeo_connection= Could not connect to Vimeo. Try again later.
error_vine_connection= Could not connect to Vine. Try again later.
error_vine_connection= Could not connect to Vine. Try again later.

error_youtube_not_found= Video not found. The video you've requested has either been removed or marked private.
error_youtube_not_allowed= This video has been marked as unembeddable by the owner. Please try another video or contact the publisher.

0 comments on commit 5014ab7

Please sign in to comment.