-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2174 from dennisrijsdijk/media-metadata
Media metadata
- Loading branch information
Showing
10 changed files
with
256 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
|
||
const { OutputDataType, VariableCategory } = require("../../../shared/variable-constants"); | ||
|
||
const frontendCommunicator = require("../../common/frontend-communicator"); | ||
|
||
const model = { | ||
definition: { | ||
handle: "audioDuration", | ||
usage: "audioDuration[filePathOrUrl]", | ||
description: "Attempts to retrieve audio duration.", | ||
categories: [VariableCategory.ADVANCED], | ||
possibleDataOutput: [OutputDataType.NUMBER] | ||
}, | ||
evaluator: async (trigger, url) => { | ||
if (url == null) { | ||
return "[NO URL PROVIDED]"; | ||
} | ||
try { | ||
return await frontendCommunicator.fireEventAsync("getSoundDuration", { | ||
path: url | ||
}); | ||
} catch (err) { | ||
return "[ERROR FETCHING DURATION]"; | ||
} | ||
} | ||
}; | ||
|
||
module.exports = model; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use strict"; | ||
|
||
const { OutputDataType, VariableCategory } = require("../../../shared/variable-constants"); | ||
|
||
const frontendCommunicator = require("../../common/frontend-communicator"); | ||
const logger = require("../../logwrapper"); | ||
|
||
const model = { | ||
definition: { | ||
handle: "videoDuration", | ||
usage: "videoDuration[filePathOrUrl]", | ||
description: "Attempts to retrieve video duration.", | ||
categories: [VariableCategory.ADVANCED], | ||
possibleDataOutput: [OutputDataType.TEXT] | ||
}, | ||
evaluator: async (trigger, url) => { | ||
if (url == null) { | ||
return "[NO URL PROVIDED]"; | ||
} | ||
const result = await frontendCommunicator.fireEventAsync("getVideoDuration", url); | ||
|
||
if (isNaN(result)) { | ||
logger.error("Error while retrieving video duration", result); | ||
return "[ERROR FETCHING DURATION]"; | ||
} | ||
return result; | ||
} | ||
}; | ||
|
||
module.exports = model; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use strict"; | ||
|
||
const { OutputDataType, VariableCategory } = require("../../../shared/variable-constants"); | ||
const logger = require("../../logwrapper"); | ||
const frontendCommunicator = require("../../common/frontend-communicator"); | ||
const { parseYoutubeId } = require("../../../shared/youtube-url-parser"); | ||
|
||
const model = { | ||
definition: { | ||
handle: "youtubeVideoDuration", | ||
usage: "youtubeVideoDuration[urlOrId]", | ||
description: "Attempts to retrieve youtube video duration.", | ||
categories: [VariableCategory.ADVANCED], | ||
possibleDataOutput: [OutputDataType.TEXT] | ||
}, | ||
evaluator: async (trigger, id) => { | ||
if (id == null) { | ||
return "[NO VIDEO ID PROVIDED]"; | ||
} | ||
const result = await frontendCommunicator.fireEventAsync("getYoutubeVideoDuration", parseYoutubeId(id).id); | ||
|
||
if (isNaN(result)) { | ||
logger.error("Error while retrieving youtube video duration", result); | ||
return "[ERROR FETCHING DURATION]"; | ||
} | ||
return result; | ||
} | ||
}; | ||
|
||
module.exports = model; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"use strict"; | ||
|
||
(function() { | ||
|
||
const uuid = require("uuid"); | ||
|
||
// This provides methods for playing sounds | ||
|
||
angular | ||
.module("firebotApp") | ||
.factory("videoService", function(backendCommunicator) { | ||
const service = {}; | ||
|
||
service.getVideoDuration = function (path) { | ||
return new Promise((resolve) => { | ||
const id = "video-" + uuid(); | ||
const videoElement = `<video id="${id}" preload="metadata" style="display: none;"></video>`; | ||
$(document.documentElement).append(videoElement); | ||
const video = document.getElementById(id); | ||
video.onloadedmetadata = () => { | ||
resolve(video.duration); | ||
video.remove(); | ||
}; | ||
|
||
video.onerror = () => { | ||
const result = { | ||
error: video.error.message, | ||
path: video.src | ||
}; | ||
video.remove(); | ||
resolve(result); | ||
}; | ||
|
||
video.src = path; | ||
}); | ||
}; | ||
|
||
service.getYoutubeVideoDuration = function (videoId) { | ||
return new Promise((resolve) => { | ||
const id = "video-" + uuid(); | ||
$(document.documentElement).append(`<div id="${id}" style="display: none;"></div>`); | ||
// eslint-disable-next-line no-undef | ||
const player = new YT.Player(id, { | ||
videoId: videoId, | ||
events: { | ||
onReady: (event) => { | ||
event.target.setVolume(0); | ||
event.target.playVideo(); | ||
resolve(player.getDuration()); | ||
document.getElementById(id).remove(); | ||
}, | ||
onError: (event) => { | ||
const error = { | ||
code: event.data, | ||
youtubeId: videoId | ||
}; | ||
if (event.data === 2) { | ||
error.error = "The request contains an invalid parameter value."; | ||
} | ||
if (event.data === 5) { | ||
error.error = "The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred."; | ||
} | ||
if (event.data === 100) { | ||
error.error = "The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private."; | ||
} | ||
if (event.data === 101 || event.data === 150) { | ||
error.error = "The owner of the requested video does not allow it to be played in embedded players."; | ||
} | ||
resolve(error); | ||
document.getElementById(id).remove(); | ||
} | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
backendCommunicator.onAsync("getVideoDuration", async (path) => { | ||
return service.getVideoDuration(path); | ||
}); | ||
|
||
backendCommunicator.onAsync("getYoutubeVideoDuration", async (youtubeId) => { | ||
return service.getYoutubeVideoDuration(youtubeId); | ||
}); | ||
|
||
return service; | ||
}); | ||
}(window.angular)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.