savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.4k stars 129 forks source link

Playing mp3 files from cloud server #1458

Closed hjkaddict closed 3 years ago

hjkaddict commented 3 years ago

Hi, I hope this question is not so stupid question, I am very new to programming and linux. Thanks for your time to read this.

Okay, I successfully setup icecast2 server on my digitalocean droplet(streaming server) and use liquidsoap to play files which I saved in the same streaming server. All works super well.

For expading the streaming services, I would like to build up cloud server and play music files which we upload to the cloud. My strategy is setting up another server(cloud server) where me and my friend both can upload music files there by using Nextcloud. So that liquidsoap could watch files and update the playlist automatically.

So far, as your tutorial mentioned, I put music files in certain directory in streaming server locally and point the folder in main.liq file. For example: archives = playlist(mode="randomize", reload_mode="watch", "/opt/liquidsoap/archives") My question is, how to point directory(as bold text above) which is not locally but remotely such as directories from other server?

Probably it is not a simple question to be answered, but it would be really appreciated if you could point me something that I can manage this.

Thanks a lot!

gilou commented 3 years ago

Hi,

This is not really a liquidsoap issue, basically you need to give your streaming server access to the filesystem on the other server. There are many ways to do this, the simplest would probably be using sshfs on the "liq" server, assuming a debian-like system: sudo apt install sshfs then inside a directory where you want the files to appear: mkdir cloud_archives and sshfs login@cloudserver:/opt/liquidsoap/archives cloud_archives

You can use various things to make that available on boot, like a mount target or fstab entry… You could also use a NFS or a cloud mounted directory… Or a simple sync client for your cloud instance…

Good luck ;)

hjkaddict commented 3 years ago

That sshfs is the keyword I have been looking for. I actually tried to set up cloud and stream in the same server, seems like it works. However, integrating files between servers by using sshfs is something that I want to try out for further radio project.

Thanks a lot again.

bugoverfl0w commented 3 years ago

The link with http/https in playlist, so It can be played

jonahzheng commented 3 years ago

@quydox i hava the same problem, how to write playlist with http/https url. and how to use it. thanks a lot!

bugoverfl0w commented 3 years ago

@quydox i hava the same problem, how to write playlist with http/https url. and how to use it. thanks a lot!

Here is my playlist content

phan-xet-verse-3.mp3
youtube-dl:https://www.youtube.com/watch?v=41s01TRv0Q0
https://this-is-valid-domain.com/s3/bray.m4a
nvdcnd.m4a
hong-lau-mong.m4a

and it works well

and here is test.liq

#!/usr/bin/liquidsoap
# Log dir
#set("log.file.path","/tmp/basic-radio.log")
set("server.telnet",true)
set("server.telnet.port",  2424)

#

# source 1: live
# source 2: main playlist for user
#   -source 2.once(reload_mode="watch")
# source 3: free
#   - loop: playlist("/path/to/free/playlist.m3u")

channel = "thisischannel"

def apply_metadata(m) =
  print("Now playing: #{m}")
  url = url.encode(m["initial_url"])
  uri = url.encode(m["initial_uri"])
  ignore(http.get("http://localhost/dis.php?f=url=#{url}&uri=#{uri}&channel=#{channel}")) 
  system("echo 111 >/tmp/disnhau")
end

# Music
security = single("~/tmp/Nguoc_Doi_-_Rhymastic.mp3")

myplaylist = playlist.once("~/tmp/music.m3u", reload_mode = "watch")
radio = myplaylist

#live = input.harbor("live",port=8080,password="khanhpro")
radio = fallback(track_sensitive = false, [radio, security])
radio = on_metadata(apply_metadata, radio)

# Start building the feed with music
# Now add some jingles
# Stream it out
output.icecast(%vorbis,
  host = "localhost", port = 8000,
  password = "hackme", mount = "basic-radio.mp3",
  radio
  )
jonahzheng commented 3 years ago

my code,but

[aac @ 0x557107a21480] Qavg: -nan At line 75, char 14-64: (myplaylist1 = playlist.once("./test.m3u", reload_mode = "watch")) Error 7: Invalid value: That source is fallible

#!/usr/bin/liquidsoap

# General settings
# Log dir
set("log.file",true)
set("log.file.append",false)
set("log.file.path","/tmp/basic-radio.log")
set("log.level",3)
set("log.stdout", false)

set("init.daemon",true)
set("init.daemon.pidfile.path", "test.pid")

# Audio settings

set("frame.audio.size",2048)
set("frame.audio.samplerate",44100)
set("frame.audio.channels",2)
set("audio.converter.samplerate.libsamplerate.quality","fast")

# Clocks settings
set("root.max_latency",5.)
set("clock.allow_streaming_errors",false)

set("init.allow_root",true)

# Retrieve configuration from environment

# Define outputs formats

aac_lofi = %ffmpeg(format="mpegts",
                   codec="aac",
                   channels=2,
                   ar=44100,
                   b="32k")

aac_midfi = %ffmpeg(format="mpegts",
                   codec="aac",
                   channels=2,
                   ar=44100,
                   b="96k")

aac_hifi = %ffmpeg(format="mpegts",
                   codec="aac",
                   channels=2,
                   ar=44100,
                   b="192k")

streams_info = [("aac_lofi",(40000,"mp4a.40.29","ts")),
                ("aac_midfi",(110000,"mp4a.40.2","ts")),
                ("aac_hifi",(220000,"mp4a.40.2","ts"))]

streams = [("aac_lofi",aac_lofi), 
           ("aac_midfi", aac_midfi), 
           ("aac_hifi", aac_hifi)]

# Output to HLS

def segment_name(~position,~extname,stream_name) =
  timestamp = int_of_float(time())
  duration = 2
  "#{stream_name}_#{duration}_#{timestamp}_#{position}.ts"
end

def on_file_change(~state,fname) =
  if state == "closed" and file.extension(fname) != '.m3u8' then
    log(label="hls", "Segment #{fname} created")
  end
end

### input

myplaylist1 = playlist.once("./test.m3u", reload_mode = "watch")
input = myplaylist1

### End input

output.file.hls(playlist="live.m3u8",
                segment_duration=2.0,
                segments=5,
                segments_overhead=5,
                segment_name=segment_name,
                on_file_change=on_file_change,
                streams_info=streams_info,
                persist=true,
                persist_at="state.config",
                '/opt/liquidsoap/hls/test',
                streams,
                input)
bugoverfl0w commented 3 years ago

It seems error on test.m3u bro?

bugoverfl0w commented 3 years ago

which user you run this script bro?

jonahzheng commented 3 years ago

test.m3u content https://api.zanmeishi.com/song/p/36481.mp3

jonahzheng commented 3 years ago

which user you run this script bro?

root

gilou commented 3 years ago

Er, guys… What's the relationship with the issue? Maybe you can open another one for your problem/question? ;)

jonahzheng commented 3 years ago

@gilou ok, https://github.com/savonet/liquidsoap/issues/1482

gilou commented 3 years ago

@hjkaddict you may want to close that issue, to avoid further hijacking of the issue ;)

hjkaddict commented 3 years ago

@gilou alright man thanks again.