MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    txt file for MMM embedyoutube

    Scheduled Pinned Locked Moved Unsolved Requests
    8 Posts 3 Posters 1.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cowboysdudeC Offline
      cowboysdude Module Developer
      last edited by

      Why would you create a txt file when you can create a json file and parse it? Much easier.

      C 1 Reply Last reply Reply Quote 0
      • C Offline
        chassain 0 @cowboysdude
        last edited by

        @cowboysdude
        you’re right but it’s not for me but for a friend who want a magicmirror. He doesn’t have knowlegde about javascript and to minimalize some error i wanted to work with a text file on his computer, shared with his raspberry…more easy for him, his wife and children :)

        S 1 Reply Last reply Reply Quote 0
        • S Do not disturb
          sdetweil @chassain 0
          last edited by

          @chassain-0 just read a file, line by line? any comment markers? (#, //, ;);

          something like this?

          list_of_images: [],
          
          read_video_ids: function(){
            let self=this
            var reader = new FileReader();
            reader.onload = function(progressEvent){
              // Entire file
              console.log(this.result);
              self.list_of_images=this.result.split(/\r\n|\n/); // windows or linux line ends
            };
            reader.readAsText( self.config.filename);
          }
          
          

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          C 1 Reply Last reply Reply Quote 0
          • C Offline
            chassain 0 @sdetweil
            last edited by

            @sdetweil
            line by line exactly…
            line 1 is for video_id without “”
            line 2 without “” to have second video for params video list

            i can read line to line but i need to integrate line 1in config/js to :
            video_id:“line 1”,
            and line2, line 3,… to ;
            video_list :[“line2”, “line3”,…]

            S 1 Reply Last reply Reply Quote 0
            • S Do not disturb
              sdetweil @chassain 0
              last edited by

              @chassain-0 with or without quotes?

              the code above

              will turn this

              "line1"
              "line2"
              "line3"
              

              into this

              self.list_of_images=["line1","line2","line3"]
              

              change the variable names

              u can do that live, not have to put them in config.js, just read the file

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              C 1 Reply Last reply Reply Quote 0
              • C Offline
                chassain 0 @sdetweil
                last edited by

                @sdetweil ok thanks i will try this option.

                here a little example of config embedyoutube

                Module.register("MMM-EmbedYoutube", {
                	defaults: {
                		autoplay: false,
                		mute: true,
                		color: "red",
                		controls : false,
                		disablekb: false,
                		fs: true,
                		height: 315,
                		width: 560,
                		loop: false,
                		modestbranding: false,
                		rel : false,
                		showinfo : false,
                		video_id : "",
                		playlist: "",
                		video_list: []
                	},
                
                	getDom: function () {
                		var wrapper = document.createElement("div");
                
                		// Parameter
                		var params = "";
                
                		var videoList = "";
                		if (this.config.video_list && this.config.video_list.length > 0) {
                			videoList = "&playlist=";
                			for (var i = 0; i < this.config.video_list.length; i++) {
                				videoList += this.config.video_list[i];
                				if (i + 1 < this.config.video_list.length)
                					videoList += ",";
                			}
                		}
                
                
                1 Reply Last reply Reply Quote 0
                • S Do not disturb
                  sdetweil
                  last edited by sdetweil

                  u just want the item so u can cut/paste it into the config?

                  even smaller, doit.js

                  var fs = require("fs");
                  var text = fs.readFileSync("./textfile");
                  console.log("file="+text);
                      var list_of_images=text.toString().split(/\r\n|\n/); // windows or linux line ends
                  
                     console.log("video_list:"+JSON.stringify(list_of_images));
                  
                  node doit.js
                  file=line1
                  line2
                  line3
                  line4
                  line5
                  video_list:["line1","line2","line3","line4","line5"]
                  

                  | changed to use ‘:’ instead of = , easier cut/paste jnto config.js

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy