Skip to content

Commit b275765

Browse files
committed
YouTube URL detection; added support for 'skipIfEmbeddable' URL action;
1 parent a2c2c3f commit b275765

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

www/scripts/sepiaFW.ui.actions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ function sepiaFW_build_ui_actions(){
225225
//OPEN URLs
226226
Actions.openURL = function(action, forceExternal){
227227
if (!action.url) return;
228+
if (action.skipIfEmbeddable){
229+
if (SepiaFW.ui.cards.canEmbedUrl(action.url)){
230+
//Cards will show it (or at least try)
231+
return;
232+
}
233+
}
228234
Actions.openUrlAutoTarget(action.url, forceExternal);
229235
}
230236
var inAppBrowserOptions = 'location=yes,toolbar=yes,mediaPlaybackRequiresUserAction=yes,allowInlineMediaPlayback=yes,hardwareback=yes,disableswipenavigation=no,clearsessioncache=no,clearcache=no';

www/scripts/sepiaFW.ui.cards.embed.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ function sepiaFW_build_ui_cards_embed(){
295295
SepiaFW.debug.info("Embedded MediaPlayer - Last active player switched to: " + playerId);
296296
//Embed.stopAllMediaPlayers(thisPlayer) //this should be handled globally for ALL media
297297
if (ev.data && ev.data.meta){
298+
//TODO: store (e.g.: for URL open action), use (e.g.: for audio player title)
298299
console.error("META", ev.data.meta); //DEBUG
299300
}
300301

@@ -423,10 +424,10 @@ function sepiaFW_build_ui_cards_embed(){
423424
}
424425

425426
//Specials
426-
thisPlayer.openInExternalPage = function(givenUrl){
427-
//TODO: implement
428-
if (givenUrl){
429-
SepiaFW.ui.actions.openUrlAutoTarget(givenUrl, true);
427+
thisPlayer.openInExternalPage = function(initialUrl){
428+
//TODO: implement - use META to update URL
429+
if (initialUrl){
430+
SepiaFW.ui.actions.openUrlAutoTarget(initialUrl, true);
430431
}else{
431432
SepiaFW.ui.showPopup(SepiaFW.local.g("cant_execute") + " (Coming Soon)");
432433
}

www/scripts/sepiaFW.ui.cards.js

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ function sepiaFW_build_ui_cards(){
2727
//some specials
2828
Cards.canEmbedCustomPlayer = true;
2929
Cards.canEmbedYouTube = true;
30-
Cards.canEmbedSoundCloud = false; //TODO: for testing
30+
Cards.canEmbedSoundCloud = false; //TODO: not selectable yet
3131
Cards.canEmbedSpotify = false; //deactivated by default because it only works in desktop and gives no control over start/stop/volume
3232
Cards.canEmbedAppleMusic = false; // "" ""
33+
Cards.getSupportedWebPlayers = function(){
34+
var players = [];
35+
if (Cards.canEmbedCustomPlayer) players.push("embedded");
36+
if (Cards.canEmbedYouTube) players.push("youtube");
37+
if (Cards.canEmbedSpotify) players.push("spotify");
38+
if (Cards.canEmbedAppleMusic) players.push("apple_music");
39+
if (Cards.canEmbedSoundCloud) players.push("soundcloud");
40+
return players;
41+
}
3342
Cards.canEmbedWebPlayer = function(service){
3443
if (!service) return false;
3544
service = service.toLowerCase().replace(/\s+/, "_"); //support brands too
@@ -47,14 +56,18 @@ function sepiaFW_build_ui_cards(){
4756
return false;
4857
}
4958
}
50-
Cards.getSupportedWebPlayers = function(){
51-
var players = [];
52-
if (Cards.canEmbedCustomPlayer) players.push("embedded");
53-
if (Cards.canEmbedYouTube) players.push("youtube");
54-
if (Cards.canEmbedSpotify) players.push("spotify");
55-
if (Cards.canEmbedAppleMusic) players.push("apple_music");
56-
if (Cards.canEmbedSoundCloud) players.push("soundcloud");
57-
return players;
59+
Cards.canEmbedUrl = function(url){
60+
if (!url) return false;
61+
var testUrl = url.toLowerCase().trim();
62+
//YouTube
63+
if (Cards.canEmbedYouTube && testUrl.indexOf("https://www.youtube.com/embed/") == 0){
64+
//TODO: add more variations
65+
return {
66+
type: "videoSearch",
67+
typeData: {service: "youtube", uri: url}
68+
}
69+
}
70+
return false;
5871
}
5972

6073
//get a full card result as DOM element
@@ -1228,6 +1241,29 @@ function sepiaFW_build_ui_cards(){
12281241
var typeInfo = {};
12291242
linkCardEle.className = 'linkCard cardBodyItem';
12301243
linkCardEle.id = 'link-' + currentLinkItemId++; //links have no database event ID (compare: time-events) so we just create one here to connect item and context-menu
1244+
1245+
//check link sanity
1246+
if (linkUrl){
1247+
var hasValidUrlProtocol = SepiaFW.tools.urlHasValidProtocol(linkUrl);
1248+
var isValidLocalHtmlPage = SepiaFW.tools.isRelativeFileUrl(linkUrl, "html");
1249+
var isUrlOk = hasValidUrlProtocol || isValidLocalHtmlPage;
1250+
if (!isUrlOk){
1251+
//is this enough? - For now its ok ^^
1252+
SepiaFW.ui.showInfo("URL has been removed from link card because it looked suspicious", true);
1253+
SepiaFW.debug.error("Link-Card - Tried to create card with suspicious URL: " + linkUrl);
1254+
linkUrl = "";
1255+
}
1256+
}
1257+
//check for popular links, e.g. YouTube ...
1258+
if (linkUrl && (!data.type || !data.typeData)){
1259+
var embedData = Cards.canEmbedUrl(linkUrl);
1260+
if (!!embedData){
1261+
//set or overwrite data:
1262+
data.type = embedData.type;
1263+
data.typeData = embedData.typeData;
1264+
}
1265+
}
1266+
12311267
var leftElement;
12321268
if (data.type){
12331269
linkCardEle.className += (" " + data.type);
@@ -1260,19 +1296,6 @@ function sepiaFW_build_ui_cards(){
12601296
}
12611297
var description = data.desc;
12621298
if (description && description.length > 120) description = description.substring(0, 119) + "...";
1263-
1264-
//check link
1265-
if (linkUrl){
1266-
var hasValidUrlProtocol = SepiaFW.tools.urlHasValidProtocol(linkUrl);
1267-
var isValidLocalHtmlPage = SepiaFW.tools.isRelativeFileUrl(linkUrl, "html");
1268-
var isUrlOk = hasValidUrlProtocol || isValidLocalHtmlPage;
1269-
if (!isUrlOk){
1270-
//TODO: is this enough?
1271-
SepiaFW.ui.showInfo("URL has been removed from link card because it looked suspicious", true);
1272-
SepiaFW.debug.error("Link-Card - Tried to create card with suspicious URL: " + linkUrl);
1273-
linkUrl = "";
1274-
}
1275-
}
12761299

12771300
//build actual card element
12781301
var rightElement = "<div class='itemRight linkCardRight'><a href='' target='_blank' rel='noopener'><i class='material-icons md-mnu'>&#xE895;</i></a></div>";

0 commit comments

Comments
 (0)