romeooscar

PlayFolderFlow2

Apr 18th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.29 KB | None | 0 0
  1. [{"id":"7b87d19d.9b85d8","type":"tab","label":"media player V4A","disabled":false,"info":""},{"id":"9b3259ab.f3f87","type":"random-item","z":"7b87d19d.9b85d8","name":"","input":"payload","inputType":"msg","output":"payload","outputType":"msg","number":"1","x":730,"y":80,"wires":[["c236a0ff.dc7c08","85a8a98a.4e5c08"]]},{"id":"3c24667d.773432","type":"api-call-service","z":"7b87d19d.9b85d8","name":"","server":"2bb108ae.8f9de8","version":1,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.living_room_speaker_2","data":"post_data","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":930,"y":560,"wires":[["14185784.434748"]]},{"id":"c236a0ff.dc7c08","type":"function","z":"7b87d19d.9b85d8","name":"deal with url","func":"file_name = \"\";\nfile_names = msg.payload;\nif (!Array.isArray(file_names))\n file_names = new Array(file_names);\nif (file_names.length < 20 || global.get(\"hohoFavoriteSong\") == undefined){\n file_name = file_names[0];\n msg.played = [];\n}else{\n i = 0;\n data = global.get(\"hohoFavoriteSong\");\n msg.played = data.played;\n for(i = 0; i < file_names.length; i++){\n file_name = file_names[i];\n if (msg.played.includes(file_name))\n continue;\n msg.played.push(file_name);\n break;\n }\n if (i >= file_names.length){\n msg.played = [];\n }\n}\nfile_name = file_name.replace(msg.playlist_path,\"\");\n//msg.local_file_name = file_name;\nmsg.filename = msg.playlist_path + file_name;\nmsg.pure_file_name = msg.filename.split(\"/\").pop();\nsong_title = msg.pure_file_name;\nmsg.file_exts.forEach(ext=>song_title=song_title.replace(ext,\"\"))\nmedia_file_name = \"/media/media/\" + msg.playlist_path.replace(\n msg.media_root_path,\n msg.media_root_name)\n + file_name;\nmsg.file_name = file_name;\nmsg.song_title = song_title;\nmsg.post_data = {\"media_content_id\":media_file_name,\"media_content_type\":\"music\"}\nmsg.post_data[\"extra\"] ={\"metadata\": {\"metadataType\":3,\"title\":song_title}}\nglobal.set(\"hohoFavoriteSong\",msg);\nmsg3 = msg;\nglobal.set(\"current_track\",msg3);\nmsg4 = global.get(\"current_track\");\n//msg3.payload = current_track;\nreturn [msg,msg4];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":890,"y":80,"wires":[["d7e070a.c2c601","65cfea0e.7f5184","f85eb831.f505c8","3c24667d.773432"],["ca457b1f.7e914"]]},{"id":"c47daef3.1f01e8","type":"server-state-changed","z":"7b87d19d.9b85d8","name":"media player device","server":"2bb108ae.8f9de8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"media_player.living_room_speaker_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"idle","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":110,"y":300,"wires":[["827b8130.b577e8","e88fb9f6.d05ec","828eddeb.5c2208"],["827b8130.b577e8","1b4e1d9c.c4aa92"]]},{"id":"7c54190f.a3da7","type":"api-current-state","z":"7b87d19d.9b85d8","name":"Check music time button state","server":"2bb108ae.8f9de8","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.music_time","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":170,"y":180,"wires":[["5507dc3e.e0d054","48e14e80.d4d4f"],[]]},{"id":"3db6734e.729e34","type":"server-state-changed","z":"7b87d19d.9b85d8","name":"music time button state","server":"2bb108ae.8f9de8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.music_time","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":120,"y":360,"wires":[["5507dc3e.e0d054","827b8130.b577e8","fda26d9b.1634d8"],["89c71990.738fa8","827b8130.b577e8"]]},{"id":"3a062d21.f8d842","type":"api-call-service","z":"7b87d19d.9b85d8","name":"","server":"2bb108ae.8f9de8","version":1,"debugenabled":false,"service_domain":"media_player","service":"turn_off","entityId":"media_player.living_room_speaker_2","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":260,"y":520,"wires":[["3c24667d.773432"]]},{"id":"e0fbccdc.f78d88","type":"api-call-service","z":"7b87d19d.9b85d8","name":"off music","server":"2bb108ae.8f9de8","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.music_time","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":560,"y":440,"wires":[[]]},{"id":"5507dc3e.e0d054","type":"api-current-state","z":"7b87d19d.9b85d8","name":"load playlist","server":"2bb108ae.8f9de8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.music_playlist","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":130,"y":100,"wires":[["e72c9024.1e9298"]]},{"id":"e72c9024.1e9298","type":"function","z":"7b87d19d.9b85d8","name":"PLAYLIST mapping","func":"//***********************\n//Made by HOHO``(Nov30th) \n//Github: https://github.com/nov30th/ha-hoho-google-media-center\n//***********************\n\n//You can now fully edit the mapping list,\n//also can remove the \"My Favorite\" if you don't want this feature,\n//otherwise you need to keep \"My Favorite\" with an exist write accessible path with fav button working.\n\n//============THE CONFIG AREA=============\n\n//For Robert and someone who has different mounting point\n//e.g. if you have \"music: /config/media\" in \"media_dirs:\", put it here\n//one media_dirs mapping only\none_media_dirs_in_ha_conf = \"Music: /media/Music\"\n\n//The playlist path mapping, you can edit them to yours.\n//values are relative path under the one_media_dirs_in_ha_conf\n//e.g. I have /config/media/mp3/ and /config/media/favorite_mp3/\n//Make sure the key name exists in input_select.music_playlist\n\nplaylist_mapping = {\n \"Music\":\"/\",\n \"Favourite\":\"favourite_mp3/\",\n \"Classical\":\"Classical Music/\",\n \"Playlist\":\"Playlist/\",\n \"Random Mix\":\"RandomMix/\",\n \"Pop Modern\":\"Pop Modern/\",\n};\n//Temp album cover file location\nmsg.album_cover_temp_file = \"/config/www/album_cover_temp.jpg\";\n//The URL of album cover file\nmsg.album_cover_temp_url = \"https[OR HTTP]://[YOUR HA DOMAIN OR IP]/local/album_cover_temp.jpg?\" + Math.random();\n//The file type you willing to shuffle\nfile_exts_filter = [\"ogg\",\"mp3\"];\n//Whether fixes the issue of HA media_player, need write accessible with mp3 folders\n//Turn off this option will skip these unsupport file names,\n//If files in your folder are all unsupport file names, it may makes this flow script loop.\nmsg.fix_ha_media_player = true;\n//Whether read the metadata in music file push to media_player instead of filenames.\nmsg.rich_info_support = true;\n//============END CONFIG AREA=============\n\n\n\nObject.map = function(o, f, ctx) {\n ctx = ctx || this;\n var result = {};\n Object.keys(o).forEach(function(k) {\n result[k] = f.call(ctx, o[k], k, o); \n });\n return result;\n}\n\none_media_dirs_in_ha_conf = one_media_dirs_in_ha_conf.replace(\" \",\"\").split(':');\nmsg.media_root_name = one_media_dirs_in_ha_conf[0];\nmsg.media_root_path = one_media_dirs_in_ha_conf[1];\nplaylist_mapping = Object.map(playlist_mapping, function(v, k, playlist_mapping) {\n return msg.media_root_path + '/' + v;\n });\n// msg.playlist_mapping = playlist_mapping.map((key,value)=>value=media_root_path+value);\npath = playlist_mapping[msg.payload];\nmsg.playlist_path = path;\nmsg.playlist_name = msg.payload;\nmsg.file_exts = file_exts_filter.map(item=>\".\"+item);\nmsg.payload = {\"start\":path,\"pattern\": file_exts_filter.map(item=>\"*.\"+item).join(\",\")};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":100,"wires":[["785ae8e7.a8e74"]]},{"id":"ae97dbfc.4c8d","type":"fs-ops-access","z":"7b87d19d.9b85d8","name":"is fav file exists","path":"playlist_mapping[\"Favourite\"]","pathType":"msg","filename":"pure_file_name","filenameType":"msg","read":true,"write":false,"throwerror":false,"x":840,"y":440,"wires":[["d20a591a.e509b8"],["2207e57e.efd1ea"]]},{"id":"d20a591a.e509b8","type":"api-call-service","z":"7b87d19d.9b85d8","name":"fav button on","server":"2bb108ae.8f9de8","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.favourite_song","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1030,"y":420,"wires":[["3c24667d.773432"]]},{"id":"2207e57e.efd1ea","type":"api-call-service","z":"7b87d19d.9b85d8","name":"fav button off","server":"2bb108ae.8f9de8","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.favourite_song","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1030,"y":480,"wires":[["3c24667d.773432"]]},{"id":"dcf2a336.21522","type":"get media tags","z":"7b87d19d.9b85d8","name":"","filename":"","x":1000,"y":220,"wires":[["7c627b08.90166c"]]},{"id":"7c627b08.90166c","type":"function","z":"7b87d19d.9b85d8","name":"","func":"if (msg.payload != undefined && msg.payload.error != undefined){\n return msg;\n}\nmetadata = msg.post_data[\"extra\"][\"metadata\"];\nif (msg.payload.tags != undefined){\n tags = msg.payload.tags;\n if (tags.title != undefined)\n metadata['title'] = tags.title;\n \n if (tags.artist != undefined)\n metadata['artist'] = tags.artist;\n \n if (tags.album != undefined)\n metadata['albumName'] = tags.album;\n \n if (tags.track != undefined)\n metadata['trackNumber'] = tags.track;\n \n if (tags.year != undefined)\n metadata['releaseDate'] = tags.year;\n \n if (tags.picture != undefined){\n msg.image = \"yes\";\n msg.payload = new Buffer(tags.picture.data);\n msg.filename = msg.album_cover_temp_file;\n metadata['images'] = [{\"url\":msg.album_cover_temp_url}];\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":300,"wires":[["f920cb20.5ed778"]]},{"id":"f920cb20.5ed778","type":"switch","z":"7b87d19d.9b85d8","name":"album image","property":"image","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":300,"wires":[["6599838.a9bac7c"],["8de3c8a0.4db3b8"]]},{"id":"6599838.a9bac7c","type":"file","z":"7b87d19d.9b85d8","name":"","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":1090,"y":300,"wires":[["8de3c8a0.4db3b8"]]},{"id":"7e2d834a.e4d124","type":"switch","z":"7b87d19d.9b85d8","name":"","property":"file_name","propertyType":"msg","rules":[{"t":"cont","v":"..","vt":"str"},{"t":"cont","v":"~","vt":"str"},{"t":"cont","v":"%","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":4,"x":550,"y":160,"wires":[["5c6fa55c.fbd1fc"],["5c6fa55c.fbd1fc"],["5c6fa55c.fbd1fc"],["a468c5e5.56949"]]},{"id":"5c6fa55c.fbd1fc","type":"function","z":"7b87d19d.9b85d8","name":"remove spec chars","func":"file_name = msg.file_name;\nwhile(file_name.includes(\"..\"))\n file_name = file_name.replace(\"..\",\"__\");\nwhile(file_name.includes(\"%\"))\n file_name = file_name.replace(\"%\",\"\");\nwhile(file_name.includes(\"~\"))\n file_name = file_name.replace(\"~\",\"-\");\nmsg.to_file_name = file_name;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":790,"y":160,"wires":[["6a540d71.c10d54"]]},{"id":"7ffb92f9.97fc94","type":"fs-ops-move","z":"7b87d19d.9b85d8","name":"move file","sourcePath":"playlist_path","sourcePathType":"msg","sourceFilename":"file_name","sourceFilenameType":"msg","destPath":"playlist_path","destPathType":"msg","destFilename":"to_file_name","destFilenameType":"msg","link":false,"x":1160,"y":160,"wires":[["785ae8e7.a8e74"]]},{"id":"785ae8e7.a8e74","type":"fs-file-lister","z":"7b87d19d.9b85d8","name":"","start":"/","pattern":"*.*","folders":"*","hidden":false,"lstype":"files","path":true,"single":true,"depth":"5","stat":false,"showWarnings":true,"x":540,"y":80,"wires":[["9b3259ab.f3f87"]]},{"id":"8de3c8a0.4db3b8","type":"switch","z":"7b87d19d.9b85d8","name":"fav enabled?","property":"playlist_mapping[\"Favourite\"]","propertyType":"msg","rules":[{"t":"nempty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":360,"wires":[["ae97dbfc.4c8d"],["3c24667d.773432"]]},{"id":"89c71990.738fa8","type":"api-current-state","z":"7b87d19d.9b85d8","name":"if media player is playing","server":"2bb108ae.8f9de8","version":1,"outputs":2,"halt_if":"playing","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.living_room_speaker_2","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":170,"y":440,"wires":[["3a062d21.f8d842"],[]]},{"id":"ac86ddcd.c6f49","type":"api-current-state","z":"7b87d19d.9b85d8","name":"button is on?","server":"2bb108ae.8f9de8","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.music_time","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":570,"y":300,"wires":[["e0fbccdc.f78d88"],[]]},{"id":"6a540d71.c10d54","type":"switch","z":"7b87d19d.9b85d8","name":"fix filename","property":"fix_ha_media_player","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":970,"y":160,"wires":[["7ffb92f9.97fc94"],["785ae8e7.a8e74"]]},{"id":"a468c5e5.56949","type":"switch","z":"7b87d19d.9b85d8","name":"rich info?","property":"rich_info_support","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":760,"y":200,"wires":[["dcf2a336.21522"],["8de3c8a0.4db3b8"]]},{"id":"827b8130.b577e8","type":"debug","z":"7b87d19d.9b85d8","d":true,"name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":320,"wires":[]},{"id":"e88fb9f6.d05ec","type":"switch","z":"7b87d19d.9b85d8","name":"if prev status playing","property":"data.old_state.state","propertyType":"msg","rules":[{"t":"eq","v":"playing","vt":"str"},{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":140,"y":240,"wires":[["7c54190f.a3da7"],["7c54190f.a3da7"]]},{"id":"fda26d9b.1634d8","type":"function","z":"7b87d19d.9b85d8","name":"last button on timestamp","func":"flow.set(\"last_on\",Math.floor(Date.now() / 1000));\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":360,"wires":[[]]},{"id":"1b4e1d9c.c4aa92","type":"function","z":"7b87d19d.9b85d8","name":"button on time check","func":"if (msg.payload != \"off\" \n && msg.payload != \"paused\"\n && msg.payload != \"unknown\"\n ){\n msg.inv = msg.payload;\n return [null,msg];\n}\nif (flow.get(\"last_on\") !== undefined){\n inv = Math.floor(Date.now() / 1000) - flow.get(\"last_on\")\n if (inv > 5){\n msg.inv = inv;\n return [msg,null];\n }\n else{\n msg.inv = \"last_on undefined\"\n return [null,msg];\n }\n}\nmsg.inv = \"not exist\";\nreturn [msg,null];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":460,"y":240,"wires":[["ac86ddcd.c6f49"],[]]},{"id":"d7e070a.c2c601","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":500,"wires":[]},{"id":"1a8cc4c.9de17bb","type":"inject","z":"7b87d19d.9b85d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":40,"wires":[["5507dc3e.e0d054"]]},{"id":"14185784.434748","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1150,"y":560,"wires":[]},{"id":"e0cf897d.006568","type":"server-state-changed","z":"7b87d19d.9b85d8","name":"","server":"2bb108ae.8f9de8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"script.service_play","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":340,"y":20,"wires":[["6c82429.3494ebc"],[]]},{"id":"6c82429.3494ebc","type":"api-current-state","z":"7b87d19d.9b85d8","name":"Check music time button state","server":"2bb108ae.8f9de8","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.music_time","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":650,"y":20,"wires":[["5507dc3e.e0d054"],[]]},{"id":"65cfea0e.7f5184","type":"function","z":"7b87d19d.9b85d8","d":true,"name":"","func":"/*\nplayerList_mapping = {\n \"Google Mini\":\"media_player.living_room_speaker_2\",\n \"NAD Amp\":\"media_player.nadc368_4176_4\",\n \"Chromecast on TV\":\"media_player.living_room_tv\",\n \"Samsung TV\":\"media_player.samsung_ua40f6400\",\n};\n//msg.playerList_mapping = playerList_mapping;\nvar newmsg = msg.payload;\nvar media_file_name = \"\";\n*/\nvar msg2 = \"\";\nvar msg3 = \"\";\nvar newmsg = msg.state;\nvar track = msg.post_data;\nif (newmsg == \"Google Mini\") \n msg.topic = \"media_player.living_room_speaker_2\";\nelse if (newmsg == \"NAD Amp\")\n// msg.topic = 'media_player.nadc368_4176';\n msg2 = \"http://192.168.1.47:11000/Play\";\nelse if (newmsg == \"Chromecast on TV\" )\n msg.selected == \"media_player.living_room_tv\";\nelse if (newmsg == \"Samsung TV\")\n msg.selected == \"media_player.samsung_ua40f6400\";\nelse \n msg.track = newmsg;\n \nglobal.get(\"current_track\",track); \nmsg3.payload = track;\n \n//msg.post_data = {\"entity_id\":msg.topic,\"media_content_id\":msg.track,\"media_content_type\":\"music\"}\n msg.payload = track + msg2.payload;\nreturn [msg,msg2,msg3];","outputs":3,"noerr":0,"initialize":"","finalize":"","x":420,"y":780,"wires":[["2ce20c99.ed2eec"],["32a1cf2f.848c6"],["8b8a8900.6566b"]],"info":"\n\nTest function to select the chosen player and pass through the random track previously determined."},{"id":"2ce20c99.ed2eec","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":800,"wires":[]},{"id":"8ad6ea49.39d238","type":"api-current-state","z":"7b87d19d.9b85d8","name":"load player","server":"2bb108ae.8f9de8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.player_list","state_type":"str","state_location":"state","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":310,"y":700,"wires":[["f85eb831.f505c8"]],"info":"\n\nList of available players by player name."},{"id":"7b9b9ba7.74af44","type":"inject","z":"7b87d19d.9b85d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":800,"wires":[["8ad6ea49.39d238"]]},{"id":"32a1cf2f.848c6","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":840,"wires":[]},{"id":"8b8a8900.6566b","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":880,"wires":[]},{"id":"ca457b1f.7e914","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":80,"wires":[]},{"id":"85a8a98a.4e5c08","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":940,"y":40,"wires":[]},{"id":"75bc1bee.449df4","type":"http response","z":"7b87d19d.9b85d8","name":"","statusCode":"","headers":{},"x":850,"y":780,"wires":[]},{"id":"6619f3c0.738f34","type":"http request","z":"7b87d19d.9b85d8","name":"NAD Play","method":"POST","ret":"txt","paytoqs":"ignore","url":"msg.payload","tls":"","persist":false,"proxy":"","authType":"","x":660,"y":760,"wires":[["75bc1bee.449df4"]],"info":"\n\nThis player plays using an http endpoint."},{"id":"74eb1b8e.29bfdc","type":"fs-file-lister","z":"7b87d19d.9b85d8","name":"","start":"/","pattern":"*.*","folders":"*","hidden":false,"lstype":"files","path":true,"single":true,"depth":"5","stat":false,"showWarnings":true,"x":540,"y":600,"wires":[["c9319437.bd499","828eddeb.5c2208"]],"info":"\n\nLists the files (music tracks) in the selected folder starting with the first in the array (i=0)."},{"id":"75298631.f652f8","type":"function","z":"7b87d19d.9b85d8","name":"FolderLIST mapping","func":"//if (msg.payload != \"playing\" \none_media_dirs_in_ha_conf = \"Music: /media/Music\"\n\nfolderlist_mapping = {\n \"Music\":\"/\",\n \"Favourite\":\"favourite_mp3/\",\n \"Classical\":\"Classical Music/\",\n \"Playlist\":\"Playlist/\",\n \"Led Zeppelin III\":\"Pop Modern/Led Zeppelin - III\",\n \"Led Zeppelin IV\":\"Pop Modern/Led Zeppelin - IV\",\n};\n\n//Temp album cover file location\nmsg.album_cover_temp_file = \"/config/www/album_cover_temp.jpg\";\n//The URL of album cover file\n//msg.album_cover_temp_url = \"https[OR HTTP]://[YOUR HA DOMAIN OR IP]/local/album_cover_temp.jpg?\" + Math.random();\nmsg.album_cover_temp_url = \"http://192.168.1.29/local/album_cover_temp.jpg?\" + Math.random();\n//The file type you willing to shuffle\nfile_exts_filter = [\"ogg\",\"mp3\"];\n//Whether fixes the issue of HA media_player, need write accessible with mp3 folders\n//Turn off this option will skip these unsupport file names,\n//If files in your folder are all unsupport file names, it may makes this flow script loop.\nmsg.fix_ha_media_player = true;\n//Whether read the metadata in music file push to media_player instead of filenames.\nmsg.rich_info_support = true;\n//============END CONFIG AREA=============\n\n\n\nObject.map = function(o, f, ctx) {\n ctx = ctx || this;\n var result = {};\n Object.keys(o).forEach(function(k) {\n result[k] = f.call(ctx, o[k], k, o); \n });\n return result;\n}\n\none_media_dirs_in_ha_conf = one_media_dirs_in_ha_conf.replace(\" \",\"\").split(':');\nmsg.media_root_name = one_media_dirs_in_ha_conf[0];\nmsg.media_root_path = one_media_dirs_in_ha_conf[1];\nfolderlist_mapping = Object.map(folderlist_mapping, function(v, k, folderlist_mapping) {\n return msg.media_root_path + '/' + v;\n });\n// msg.folderlist_mapping = folderlist_mapping.map((key,value)=>value=media_root_path+value);\npath = folderlist_mapping[msg.payload];\nmsg.folderlist_path = path;\nmsg.folderlist_name = msg.payload;\nmsg.file_exts = file_exts_filter.map(item=>\".\"+item);\nmsg.payload = {\"start\":path,\"pattern\": file_exts_filter.map(item=>\"*.\"+item).join(\",\")};\n\n//msg. payload = folderlist_mapping[msg.payload];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":600,"wires":[["74eb1b8e.29bfdc"]],"info":"\n\nMaps the text from the folderlist input_select to a folder path below /media/Music. Generates an array of all of the tracks in the selected folder."},{"id":"c9319437.bd499","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":600,"wires":[]},{"id":"b9baf39b.f8e0b","type":"inject","z":"7b87d19d.9b85d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":660,"wires":[["48e14e80.d4d4f"]]},{"id":"48e14e80.d4d4f","type":"api-current-state","z":"7b87d19d.9b85d8","name":"load folderlist","server":"2bb108ae.8f9de8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.music_folderlist","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":130,"y":600,"wires":[["75298631.f652f8"]],"info":"This provides a text list of music folders for user selection in a loveleace card. Currently testing with just 2 folders. I.e provides a friendly name for a folder."},{"id":"5251a3be.f9afe4","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":620,"wires":[]},{"id":"b1fc021b.390a2","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":660,"wires":[]},{"id":"828eddeb.5c2208","type":"function","z":"7b87d19d.9b85d8","name":"","func":"file_name = \"\";\nfile_names = msg.payload;\n\n//if (folderlist_path has changed)\n// do some things\nif (!Array.isArray(file_names))\n file_names = new Array(file_names);\nif (file_names.length < 20 || global.get(\"hohoFavoriteSong\") == undefined){\n file_name = file_names[0];\n msg.played = [];\n} \n\nfor(i = 0; i < file_names.length; i++){\n if (msg.state == \"idle\") { // track has finished\n i = i + 1;\n file_name = file_name[i];\n global.set(\"trackname\",file_name);\n// do some things, set i to i + 1, save file_name[],\n}\n}\n\n\n/* \n}else{\n i = 0;\n data = global.get(\"hohoFavoriteSong\");\n msg.played = data.played;\n for(i = 0; i < file_names.length; i++){\n file_name = file_names[i];\n if (msg.played.includes(file_name))\n continue;\n msg.played.push(file_name);\n break;\n }\n if (i >= file_names.length){\n msg.played = [];\n }\n*/ \n\nfile_name = file_name.replace(msg.folderlist_path,\"\");\n//msg.local_file_name = file_name;\nglobal.set(\"trackname\", file_name);\nglobal.set(\"foldername\", msg.folderlist_path);\nmsg.filename = msg.folderlist_path + file_name;\nmsg.pure_file_name = msg.filename.split(\"/\").pop();\nmedia_file_name = \"/media/media/\" + msg.folderlist_path.replace(\n msg.media_root_path,\n msg.media_root_name)\n + file_name;\nmsg.post_data = {\"media_content_id\":media_file_name,\"media_content_type\":\"music\"}\n\n//msg.post_data[\"extra\"] ={\"metadata\": {\"metadataType\":3,\"title\":song_title}}\nmsg2 = \"\";\nmsg2 = file_name;\nreturn [msg,msg2];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":700,"y":640,"wires":[["5251a3be.f9afe4","3c24667d.773432","f85eb831.f505c8"],["b1fc021b.390a2"]],"info":"Provides the filename for the track including the path and then when the track has finished playing (player goes to 'idle') it selects the next (i+1) track for playing and starts it playing."},{"id":"f85eb831.f505c8","type":"api-call-service","z":"7b87d19d.9b85d8","d":true,"name":"","server":"2bb108ae.8f9de8","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_next_track","entityId":"media_player.nadc368_4176_2","data":"{}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":650,"y":700,"wires":[["3af87889.a22ed"]],"info":"\n\nThis hardware player does not currently support the media_player.play_media call service."},{"id":"3af87889.a22ed","type":"debug","z":"7b87d19d.9b85d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":700,"wires":[]},{"id":"2bb108ae.8f9de8","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]
Advertisement
Add Comment
Please, Sign In to add comment