Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
628 lines (578 loc) · 19.7 KB
/
Copy pathmain.go
File metadata and controls
628 lines (578 loc) · 19.7 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"strings"
"syscall"
"time"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/x/term"
"github.com/bjarneo/cliamp/applog"
"github.com/bjarneo/cliamp/config"
"github.com/bjarneo/cliamp/external/radio"
"github.com/bjarneo/cliamp/internal/appdir"
"github.com/bjarneo/cliamp/internal/appmeta"
"github.com/bjarneo/cliamp/internal/embyapi"
"github.com/bjarneo/cliamp/internal/playback"
"github.com/bjarneo/cliamp/internal/resume"
"github.com/bjarneo/cliamp/ipc"
"github.com/bjarneo/cliamp/luaplugin"
"github.com/bjarneo/cliamp/mediactl"
"github.com/bjarneo/cliamp/player"
"github.com/bjarneo/cliamp/playlist"
"github.com/bjarneo/cliamp/resolve"
"github.com/bjarneo/cliamp/theme"
"github.com/bjarneo/cliamp/ui"
"github.com/bjarneo/cliamp/ui/model"
)
// version is set at build time via -ldflags "-X main.version=vX.Y.Z".
var version string
// buildVersion returns version when -ldflags set it. go install and go
// build set none, so it falls back to the module version that go records,
// and then to "dev". The result is never empty, so --version always works.
func buildVersion() string {
if version != "" {
return version
}
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" {
return info.Main.Version
}
return "dev"
}
const (
defaultUIFPS = 20
lowPowerUIFPS = 5
)
// checkTerminalOutput rejects a TUI that would render escape sequences to a
// non-terminal stdout. Headless mode intentionally has no terminal output.
func checkTerminalOutput(headless bool, stdout *os.File) error {
if !headless && !term.IsTerminal(stdout.Fd()) {
return errors.New("cliamp: stdout is not a terminal")
}
return nil
}
func run(overrides config.Overrides, positional []string, headless, visualizer60FPS bool) error {
if err := checkTerminalOutput(headless, os.Stdout); err != nil {
return err
}
cfg, err := config.Load()
if err != nil {
return fmt.Errorf("config: %w", err)
}
overrides.Apply(&cfg)
closeLog, appliedLevel, logErr := initLogging(cfg.LogLevel)
defer closeLog()
if logErr != nil {
fmt.Fprintf(os.Stderr, "logging: %v (continuing without file log)\n", logErr)
applog.Status("logging: %v", logErr)
} else {
applog.Info("cliamp starting (version=%s level=%s)", appmeta.Version(), appliedLevel)
}
if headless {
if err := checkNotRunning(); err != nil {
return err
}
}
providers := buildProviders(cfg, !headless && isCharDevice(os.Stdin))
defer providers.Close()
positional, err = searchArgs(positional)
if err != nil {
return err
}
if cfg.YouTubeMusic.ExpandPlaylist != nil {
resolve.ExpandYTPlaylist = *cfg.YouTubeMusic.ExpandPlaylist
}
resolved, err := resolve.Args(positional)
if err != nil {
return err
}
defaultProvider := cfg.Provider
if defaultProvider == "" {
defaultProvider = "cliamp"
}
defaultRadio := len(positional) == 0 && defaultProvider == "radio"
// The cliamp radio view waits for the listener to pick a channel. Headless
// mode has no view, and auto-play expects sound without a keypress, so
// both start with the live channel streams instead.
liveChannels := defaultRadio ||
(len(positional) == 0 && defaultProvider == "cliamp" && (headless || cfg.AutoPlay))
resumeState := resume.Load()
pl := playlist.New()
if cfg.Playlist != "" && providers.local != nil {
tracks, err := providers.local.Tracks(cfg.Playlist)
if err != nil {
return fmt.Errorf("playlist %q: %w", cfg.Playlist, err)
}
pl.Add(tracks...)
} else if liveChannels {
// The channel list lives in the M3U the radio provider already serves,
// so resolve that instead of restating it here: the startup playlist
// then matches what browsing "cliamp radio" shows -- same channels,
// same order, same titles -- and a new channel needs no code change.
// It goes through the normal pending path, so the fetch happens in the
// background rather than delaying launch.
resolved.Pending = append(resolved.Pending, radio.BuiltinURL)
}
pl.Add(resolved.Tracks...)
resumeServer := providers.resumeServer(defaultProvider)
restoredContext := false
restoredIndex := 0
restoredResumePath := ""
if !headless && resumeServer != nil && cfg.Playlist == "" && len(positional) == 0 && len(resolved.Pending) == 0 && pl.Len() == 0 {
if tracks, index, activePath, ok := restoreServerContext(resumeState, resumeServer); ok {
pl.Add(tracks...)
restoredContext = true
restoredIndex = index
restoredResumePath = activePath
}
}
p, closePlayer, err := newPlayer(cfg)
if err != nil {
return err
}
defer closePlayer()
providers.registerPlayerHooks(p)
cfg.ApplyPlayer(p)
cfg.ApplyPlaylist(pl)
pluginBroker := ipc.NewBroker()
defer pluginBroker.Close()
luaMgr, luaErr := luaplugin.New(cfg.Plugins, pluginBroker, model.ReservedKeys())
if luaErr != nil {
fmt.Fprintf(os.Stderr, "lua plugins: %v\n", luaErr)
}
if luaMgr != nil {
defer luaMgr.Close()
}
m := model.New(p, pl, providers.entries, defaultProvider, providers.localPlaylists(), providers.favorites, providers.history, theme.LoadAll(), luaMgr, config.SaveFunc{})
panes := ui.NewPaneSet()
m.SetPaneSet(panes)
if luaMgr != nil {
luaMgr.SetLayoutProvider(panes)
}
m.SetRadioFavorites(providers.radioFavorites)
if resumeServer != nil {
m.SetResumeSaver(serverResumeSaver(resumeServer))
}
if restoredContext {
m.SetInitialTrack(restoredIndex)
}
m.SetIPCBroker(pluginBroker)
if luaMgr != nil {
luaMgr.SetStateProvider(luaStateProvider(p, m.PluginStateLoader()))
if names := luaMgr.Visualizers(); len(names) > 0 {
m.RegisterLuaVisualizers(names, luaMgr)
}
}
m.SetPendingURLs(resolved.Pending)
if cfg.Playlist != "" && len(resolved.Tracks) == 0 && len(resolved.Pending) == 0 {
m.SetLoadedPlaylist(cfg.Playlist)
}
if !headless && len(resolved.Tracks) == 0 && len(resolved.Pending) == 0 && pl.Len() == 0 {
m.StartInProvider()
}
if cfg.AutoPlay && !restoredContext {
m.SetAutoPlay(true)
}
configureModel(&m, cfg, headless, visualizer60FPS)
if resumeState.Path != "" && resumeState.PositionSec > 0 {
// Jellyfin and Emby resume the restored context above. Mixcloud is also commonly
// opened from its provider browser rather than a positional URL; preserve
// cliamp's existing positional-file behavior for other providers.
switch {
case restoredResumePath != "":
m.SetResume(restoredResumePath, resumeState.PositionSec)
case playlist.IsMixcloudURL(resumeState.Path) || (!defaultRadio && len(positional) > 0):
m.SetResume(resumeState.Path, resumeState.PositionSec)
}
}
prog := tea.NewProgram(m, programOptions(headless, cfg.LowPower)...)
stopSignals := quitOnSignals(prog.Send)
defer stopSignals()
defer providers.observeAuthURLs(prog.Send)()
svc, svcErr := wireMediaCtl(prog)
if svcErr != nil {
applog.Warn("media control (MPRIS/NowPlaying) unavailable: %v", svcErr)
} else if svc != nil {
defer svc.Close()
}
if luaMgr != nil {
luaSend, stopLuaSend := newOrderedSender(prog.Send)
defer stopLuaSend()
luaMgr.SetControlProvider(luaControlProvider(luaSend))
luaMgr.SetUIProvider(luaUIProvider(luaSend, headless))
}
stopIPC, err := startIPC(prog.Send, pluginBroker, luaMgr, headless)
if err != nil {
return err
}
defer stopIPC()
if headless {
fmt.Fprintf(os.Stderr, "cliamp: running headless (socket: %s)\n", ipc.DefaultSocketPath())
applog.Info("running headless")
}
finalModel, err := mediactl.Run(prog, svc)
if err != nil {
return err
}
saveOnExit(finalModel, headless, resumeServer)
if fm, ok := finalModel.(model.Model); ok {
fm.WaitReports(reportsExitWait)
}
return nil
}
// reportsExitWait bounds the wait at exit for the playback reports that the
// Model queued, such as the scrobble of the track that played at quit.
const reportsExitWait = 3 * time.Second
// checkNotRunning returns an error when another instance serves the socket.
// Headless mode calls it before it builds the providers, opens the audio
// device or loads the plugins. The app.quit hooks of the plugins could
// otherwise change the files of the running instance. startIPC still
// catches an instance that starts after the check.
func checkNotRunning() error {
socket := ipc.DefaultSocketPath()
running, err := ipc.Listening(socket)
if err != nil {
return err
}
if running {
return fmt.Errorf("cliamp is already running (socket %s)", socket)
}
return nil
}
// searchArgs turns cliamp search and cliamp search-sc into one argument that
// plays the first match on YouTube or SoundCloud. It returns other arguments
// as they are.
func searchArgs(positional []string) ([]string, error) {
if len(positional) == 0 || (positional[0] != "search" && positional[0] != "search-sc") {
return positional, nil
}
if len(positional) == 1 {
return nil, fmt.Errorf("search requires a query string (e.g. cliamp search \"never gonna give you up\")")
}
prefix := "ytsearch1:"
if positional[0] == "search-sc" {
prefix = "scsearch1:"
}
return []string{prefix + strings.Join(positional[1:], " ")}, nil
}
// newPlayer opens the audio output that cfg selects. closePlayer releases
// the player and then the audio device.
func newPlayer(cfg config.Config) (p *player.Player, closePlayer func(), err error) {
releaseDevice := func() {}
if cfg.AudioDevice != "" {
releaseDevice = player.PrepareAudioDevice(cfg.AudioDevice)
}
sampleRate := cfg.SampleRate
if sampleRate == 0 {
if detected := player.DeviceSampleRate(); detected > 0 {
sampleRate = detected
} else {
sampleRate = 44100
}
}
p, err = player.New(player.Quality{
SampleRate: sampleRate,
BufferMs: cfg.BufferMs,
ResampleQuality: cfg.ResampleQuality,
BitDepth: cfg.BitDepth,
})
if err != nil {
releaseDevice()
return nil, nil, fmt.Errorf("player: %w", err)
}
return p, func() {
p.Close()
releaseDevice()
}, nil
}
// configureModel applies the settings of cfg to m. Headless mode has no
// screen, so the view settings do not apply there.
func configureModel(m *model.Model, cfg config.Config, headless, visualizer60FPS bool) {
m.SetCustomEQBands(cfg.EQ)
m.SetPadding(cfg.PaddingH, cfg.PaddingV)
m.SetVisVolumeLinked(cfg.VisVolumeLinked)
m.SetSeekStepLarge(cfg.SeekStepLargeDuration())
m.SetLyricsOffset(cfg.LyricsOffsetMs)
m.SetInitialDirectory(cfg.InitialDirectory)
m.SetDownloadsDirectory(cfg.Downloads.Directory)
if cfg.EQPreset != "" && cfg.EQPreset != "Custom" {
m.SetEQPreset(cfg.EQPreset, nil)
}
if cfg.Theme != "" {
m.SetTheme(cfg.Theme)
}
if headless {
// The default visualizer stays, because it serves spectrum.get.
m.SetHeadless(true)
return
}
m.SetVisRows(cfg.VisRows)
m.SetVisualizer60FPS(visualizer60FPS)
if cfg.Visualizer != "" {
m.SetVisualizer(cfg.Visualizer)
}
if cfg.LowPower {
m.SetLowPower(true)
}
if cfg.Simplified {
m.SetSimplified(true)
}
if cfg.HideHelpBar {
m.SetHideHelpBar(true)
}
if cfg.HideSettingsPane {
m.SetHideSettingsPane(true)
}
if cfg.ShowMetadata {
m.SetShowMetadata(true)
}
if cfg.Expanded {
m.SetExpanded(true)
}
}
// startIPC serves the socket and sends its requests to the program through
// send. Headless mode is controlled only through the socket, so there a
// failure is an error. The TUI reports the failure and runs without the
// socket.
func startIPC(send func(tea.Msg), broker *ipc.Broker, plugins *luaplugin.Manager, headless bool) (stop func(), err error) {
srv, err := ipc.NewServerWithBroker(ipc.DefaultSocketPath(), broker)
if err != nil {
// The errors of the ipc package already start with "ipc: ".
if headless {
return nil, err
}
fmt.Fprintln(os.Stderr, err)
return func() {}, nil
}
// Program.Send may wait for the update loop, so the requests go through
// an ordered queue and the socket can acknowledge a job at once.
queue, stopQueue := newOrderedSender(send)
srv.SetV2Dispatcher(newV2Dispatcher(queue, srv.JobStore(), plugins))
srv.SetOperationRegistry(v2Operations(headless, plugins != nil))
go publishV2JobEvents(srv.Done(), srv.JobStore(), broker)
return func() {
_ = srv.Close()
stopQueue()
}, nil
}
// saveOnExit keeps the theme and the resume position of the final Model.
// When a Jellyfin or Emby server is the default provider, it also keeps the
// list that the track played from.
func saveOnExit(final tea.Model, headless bool, resumeServer *embyapi.Provider) {
fm, ok := final.(model.Model)
if !ok {
return
}
// Headless mode has no theme keys, so it keeps the saved theme.
if !headless {
themeName := fm.ThemeName()
if theme.IsDefaultName(themeName) {
themeName = ""
}
_ = config.SaveString("theme", themeName)
}
path, secs, playlistName := fm.ResumeState()
saveExitResume(path, secs, playlistName, fm.ResumeContext, resumeServer)
}
// saveExitResume saves the track and the position of the exit. When
// resumeServer is set and path is a Jellyfin or Emby stream, it also saves
// the list that resumeContext returns. A track with no position saves
// nothing.
func saveExitResume(path string, secs int, playlistName string, resumeContext func() ([]playlist.Track, int), resumeServer *embyapi.Provider) {
if path == "" || secs <= 0 {
return
}
if resumeServer != nil && embyapi.IsStreamURL(path) {
tracks, index := resumeContext()
resume.SaveState(resume.State{
Path: path, PositionSec: secs, Playlist: playlistName,
Context: tracks, ContextIndex: index,
})
return
}
resume.Save(path, secs, playlistName)
}
// programOptions returns the Bubbletea options of the TUI, or of headless
// mode. run handles the signals itself in both modes, see quitOnSignals.
func programOptions(headless, lowPower bool) []tea.ProgramOption {
switch {
case headless:
return headlessProgramOptions()
case lowPower:
return []tea.ProgramOption{tea.WithFPS(lowPowerUIFPS), tea.WithoutSignalHandler()}
}
return []tea.ProgramOption{tea.WithFPS(defaultUIFPS), tea.WithoutSignalHandler()}
}
// headlessProgramOptions build a program with no terminal: no renderer, no
// input and no output. The frame ticker runs at its lowest rate.
func headlessProgramOptions() []tea.ProgramOption {
return []tea.ProgramOption{
tea.WithoutRenderer(),
tea.WithInput(nil),
tea.WithOutput(io.Discard),
tea.WithFPS(1),
tea.WithoutSignalHandler(),
}
}
// quitOnSignals sends SIGINT, SIGTERM and SIGHUP to quitOnSignal until stop
// is called.
func quitOnSignals(send func(tea.Msg)) (stop func()) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
go quitOnSignal(signals, send)
return func() {
signal.Stop(signals)
close(signals)
}
}
// quitOnSignal asks the Model to quit on the first SIGINT, SIGTERM or
// SIGHUP, so it saves the resume position as the q key does. A closed
// terminal sends SIGHUP. The signal handler of Bubbletea ends the program
// with no Update, and on SIGINT it also returns an error. After the first
// signal the default action is back, so a second signal ends a program that
// does not quit.
func quitOnSignal(signals chan os.Signal, send func(tea.Msg)) {
if _, ok := <-signals; ok {
signal.Stop(signals)
send(playback.QuitMsg{})
}
}
// v2Operations returns the V2 operations that this runtime serves. Headless
// mode has no theme or visualizer to change. The plugin operations need the
// plugin manager.
func v2Operations(headless, plugins bool) *ipc.OperationRegistry {
operations := ipc.DefaultOperationRegistry()
if headless {
operations.Unregister("theme", "vis")
}
if !plugins {
operations.Unregister("plugin.call", "plugin.commands")
}
return operations
}
// v2ReplyTimeout bounds the wait for the Model to answer state.get and
// spectrum.get.
var v2ReplyTimeout = 3 * time.Second
// newV2Dispatcher answers the V2 requests of the TUI and of headless mode.
// send delivers a request to the Model. It must return at once and keep the
// order of the requests, as the queue of newOrderedSender does, so a job is
// acknowledged before the Model reads it and jobs run in the order they came
// in. The plugin jobs run against plugins.
func newV2Dispatcher(send func(tea.Msg), jobs *ipc.JobStore, plugins *luaplugin.Manager) ipc.V2Dispatcher {
return ipc.V2DispatcherFunc(func(ctx context.Context, request ipc.V2Request) (ipc.V2Result, *ipc.V2Error) {
switch request.Method {
case "state.get", "spectrum.get":
reply := make(chan model.V2RequestResult, 1)
send(model.V2RequestMsg{Request: request, Reply: reply})
select {
case result := <-reply:
return result.Result, result.Error
case <-ctx.Done():
return ipc.V2Result{}, &ipc.V2Error{Code: ipc.V2ErrorCodeCanceled, Message: ipc.V2MessageCanceled}
case <-time.After(v2ReplyTimeout):
return ipc.V2Result{}, &ipc.V2Error{Code: ipc.V2ErrorCodeUnavailable, Message: ipc.V2MessageUnavailable}
}
}
job, err := jobs.CreateWithContext(ctx, request.Operation)
if err != nil {
return ipc.V2Result{}, &ipc.V2Error{Code: ipc.V2ErrorCodeConflict, Message: ipc.V2MessageConflict}
}
if request.Operation == "plugin.call" || request.Operation == "plugin.commands" {
go runV2PluginJob(jobs, job.ID, request, plugins)
return ipc.V2Result{Job: &job}, nil
}
send(model.V2RequestMsg{Request: request, Jobs: jobs, JobID: job.ID})
return ipc.V2Result{Job: &job}, nil
})
}
func runV2PluginJob(jobs *ipc.JobStore, jobID string, request ipc.V2Request, plugins *luaplugin.Manager) {
ctx, err := jobs.Start(jobID)
if err != nil || ctx.Err() != nil {
return
}
if plugins == nil {
_ = jobs.Fail(jobID, ipc.V2Error{Code: ipc.V2ErrorCodeUnavailable, Message: ipc.V2MessageUnavailable})
return
}
if request.Operation == "plugin.commands" {
data, err := json.Marshal(ipc.Response{OK: true, Items: plugins.CommandList()})
if err != nil {
_ = jobs.Fail(jobID, ipc.V2Error{Code: ipc.V2ErrorCodeInternal, Message: ipc.V2MessageInternal})
return
}
_ = jobs.Succeed(jobID, data)
return
}
var params ipc.Request
if err := json.Unmarshal(request.Params, ¶ms); err != nil || params.Name == "" || params.Sub == "" {
_ = jobs.Fail(jobID, ipc.V2Error{Code: ipc.V2ErrorCodeInvalidParams, Message: ipc.V2MessageInvalidParams})
return
}
output, err := plugins.EmitCommand(ctx, params.Name, params.Sub, params.Args)
if err != nil {
_ = jobs.Fail(jobID, ipc.V2Error{Code: ipc.V2ErrorCodeInternal, Message: ipc.V2MessageInternal, Detail: err.Error()})
return
}
data, err := json.Marshal(ipc.Response{OK: true, Output: output})
if err != nil {
_ = jobs.Fail(jobID, ipc.V2Error{Code: ipc.V2ErrorCodeInternal, Message: ipc.V2MessageInternal})
return
}
_ = jobs.Succeed(jobID, data)
}
func publishV2JobEvents(done <-chan struct{}, jobs *ipc.JobStore, broker *ipc.Broker) {
for {
select {
case <-done:
return
case event := <-jobs.Events():
data, err := json.Marshal(event)
if err == nil {
_ = broker.Publish("runtime.job", data, false)
}
}
}
}
// initLogging always returns a non-nil close func so the caller can defer
// it unconditionally, plus the applied level as a string for diagnostics.
// Errors come back as the third return value; the close func is a no-op
// and the level string is empty in that case.
func initLogging(levelStr string) (func() error, string, error) {
noop := func() error { return nil }
level, err := applog.ParseLevel(levelStr)
if err != nil {
return noop, "", err
}
dir, err := appdir.Dir()
if err != nil {
return noop, "", fmt.Errorf("resolve config dir: %w", err)
}
closeFn, err := applog.Init(filepath.Join(dir, "cliamp.log"), level)
if err != nil {
return noop, "", err
}
return closeFn, level.String(), nil
}
func wireMediaCtl(prog *tea.Program) (*mediactl.Service, error) {
svc, err := mediactl.New(prog.Send)
if err != nil || svc == nil {
return svc, err
}
go prog.Send(model.AttachNotifier(svc))
return svc, nil
}
func main() {
appmeta.SetVersion(buildVersion())
app := buildApp()
if err := app.Run(context.Background(), os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}