forked from wickes1/MMM-BackgroundYouTube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMM-BackgroundYouTube.js
More file actions
66 lines (54 loc) · 2.02 KB
/
MMM-BackgroundYouTube.js
File metadata and controls
66 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* MagicMirror Module: MMM-BackgroundYouTube
* Description: A module to display YouTube videos or playlists as background in your MagicMirror.
* Author: wickes1 (modified by adamlove86)
* License: MIT
*
* Configuration Options:
* - videoID: YouTube Video ID to display as background.
* - videoIDs: Array of YouTube Video IDs to play as a playlist.
* - playlistID: YouTube Playlist ID to display as background.
*
* For more information, visit: https://github.com/wickes1/MMM-BackgroundYouTube
*/
Module.register("MMM-BackgroundYouTube", {
defaults: {
videoID: "",
videoIDs: [], // Array of video IDs
playlistID: "" // Playlist ID
},
getStyles: function () {
return ["MMM-BackgroundYouTube.css"];
},
getDom: function () {
let iframe = document.createElement("iframe");
iframe.classList.add("video-background");
let params = "controls=0&showinfo=0&playsinline=1&autoplay=1&mute=1&loop=1&playlist=";
let src = "";
if (this.config.playlistID) {
// If a playlist ID is provided
src = `https://www.youtube.com/embed?listType=playlist&list=${this.config.playlistID}&${params}`;
} else {
// Handle single or multiple video IDs
let videoIDs = [];
if (this.config.videoID) {
videoIDs.push(this.config.videoID);
}
if (Array.isArray(this.config.videoIDs) && this.config.videoIDs.length > 0) {
videoIDs = videoIDs.concat(this.config.videoIDs);
}
if (videoIDs.length > 0) {
let firstVideoID = videoIDs[0];
let remainingVideoIDs = videoIDs.slice(1).join(',');
src = `https://www.youtube.com/embed/${firstVideoID}?${params}${remainingVideoIDs}`;
} else {
// Default video if none provided
src = `https://www.youtube.com/embed/${this.config.videoID}?${params}${this.config.videoID}`;
}
}
iframe.src = src;
iframe.allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
iframe.allowFullscreen = true;
return iframe;
}
});