Skip to content

Commit

Permalink
Merge pull request #56 from alexballas/devel
Browse files Browse the repository at this point in the history
v1.13.0
  • Loading branch information
alexballas authored Sep 30, 2022
2 parents bae562e + 071e1ca commit 578da13
Show file tree
Hide file tree
Showing 32 changed files with 1,164 additions and 399 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ jobs:
- uses: WillAbides/[email protected]
id: setup-go-faster
with:
go-version: "1.17.9"
go-version: "*"

- name: Install fyne
run: go get fyne.io/fyne/v2/cmd/fyne
run: go install fyne.io/fyne/v2/cmd/fyne@latest

- name: Download Android SDK
run: wget https://dl.google.com/android/repository/android-ndk-r23b-linux.zip && unzip android-ndk-r23b-linux.zip

- name: Package (Android)
run: cd cmd/go2tv && GO386='softfloat' ANDROID_NDK_HOME=../../android-ndk-r22b fyne package -os android -name Go2TV -appID com.alexballas.go2tv -icon ../../assets/go2tv-icon.png && mv Go2TV.apk ../../
run: APATH=$(readlink -e android-ndk-r23b) && cd cmd/go2tv && GO386='softfloat' ANDROID_NDK_HOME=$APATH fyne package -os android -name Go2TV -appID com.alexballas.go2tv -icon ../../assets/go2tv-icon.png && mv Go2TV.apk ../../

- uses: actions/upload-artifact@v2
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
with:
copy_repository_path: /go2tv_dir
copy_artifact_path: go2tv
image_additional_mb: 500
image_additional_mb: 800
commands: |
cd /
sudo apt update
sudo apt install -y xorg-dev
sudo apt clean
wget -nv https://go.dev/dl/go1.17.9.linux-armv6l.tar.gz
tar -xzf go1.17.9.linux-armv6l.tar.gz
rm go1.17.9.linux-armv6l.tar.gz
wget -nv https://go.dev/dl/go1.19.linux-armv6l.tar.gz
tar -xzf go1.19.linux-armv6l.tar.gz
rm go1.19.linux-armv6l.tar.gz
export GOROOT=/go
cd /go2tv_dir
/go/bin/go build -ldflags "-s -w" -o go2tv cmd/go2tv/go2tv.go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: WillAbides/[email protected]
id: setup-go-faster
with:
go-version: "1.17.9"
go-version: "*"

- name: Get dependencies
run: sudo apt update && sudo apt install xorg-dev
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- uses: WillAbides/[email protected]
id: setup-go-faster
with:
go-version: "1.17.9"
go-version: "*"

- name: Install fyne
run: go get fyne.io/fyne/v2/cmd/fyne
run: go install fyne.io/fyne/v2/cmd/fyne@latest

- name: Package (macOS)
run: cd cmd/go2tv && fyne package --release -os darwin -icon ../../assets/go2tv-icon.png && mv go2tv.app ../../
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: WillAbides/[email protected]
id: setup-go-faster
with:
go-version: "1.17.9"
go-version: "*"

- name: Get dependencies
run: sudo apt update && sudo apt install gcc xorg-dev gcc-mingw-w64
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ Download the app here https://github.com/alexballas/Go2TV/releases/latest. A sin

Go2TV supports live video transcoding, if ffmpeg is installed. When transcoding, SEEK operations are not available. Transcoding offers the maximum compatibility with the various file formats and devices. Only works with video files.

**MacOS potential issue**
**MacOS potential issues**

If you get the "cannot be opened because the developer cannot be verified" error, you can apply the following workaround.
- Control-click the app icon, then choose Open from the shortcut menu.
- Click Open.

If you get the "go2tv is damaged and can't be opened. You should move it to the Bin." error you can apply the following workaround.
- Launch Terminal and then issue the following command: `xattr -cr /path/to/go2tv.app`.

Tested on
-----
- Samsung UE50JU6400
Expand Down
172 changes: 108 additions & 64 deletions cmd/go2tv-lite/go2tv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ package main
import (
"context"
_ "embed"
"errors"
"flag"
"fmt"
"io"
"net/url"
"os"
"os/exec"
"os/signal"
"path/filepath"
"runtime"
"sort"
"strings"
"sync"
"time"
"syscall"

"github.com/alexballas/go2tv/devices"
"github.com/alexballas/go2tv/httphandlers"
"github.com/alexballas/go2tv/internal/interactive"
"github.com/alexballas/go2tv/soapcalls"
"github.com/alexballas/go2tv/utils"
"github.com/pkg/errors"
)

var (
Expand All @@ -35,26 +34,53 @@ var (
transcodePtr = flag.Bool("tc", false, "Use ffmpeg to transcode input video file.")
listPtr = flag.Bool("l", false, "List all available UPnP/DLNA Media Renderer models and URLs.")
versionPtr = flag.Bool("version", false, "Print version.")

ErrNoCombi = errors.New("can't combine -l with other flags")
ErrFailtoList = errors.New("failed to list devices")
)

type dummyScreen struct {
ctxCancel context.CancelFunc
}

type flagResults struct {
dmrURL string
exit bool
}

func main() {
if err := run(); err != nil {
if errors.Is(err, errNoflag) {
flag.Usage()
os.Exit(0)
}

if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Encountered error(s): %s\n", err)
os.Exit(1)
}
}
}

func run() error {
var absMediaFile string
var mediaType string
var mediaFile interface{}
var isSeek bool
var s *httphandlers.HTTPserver

exitCTX, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

flag.Parse()

flagRes, err := processflags()
check(err)
if err != nil {
return err
}

if flagRes.exit {
os.Exit(0)
return nil
}

if *mediaArg != "" {
Expand All @@ -63,115 +89,120 @@ func main() {

if *mediaArg == "" && *urlArg != "" {
mediaURL, err := utils.StreamURL(context.Background(), *urlArg)
check(err)
if err != nil {
return err
}

mediaURLinfo, err := utils.StreamURL(context.Background(), *urlArg)
check(err)
if err != nil {
return err
}

mediaType, err = utils.GetMimeDetailsFromStream(mediaURLinfo)
check(err)
if err != nil {
return err
}

mediaFile = mediaURL

if strings.Contains(mediaType, "image") {
readerToBytes, err := io.ReadAll(mediaURL)
mediaURL.Close()
check(err)
if err != nil {
return err
}
mediaFile = readerToBytes
}
}

switch t := mediaFile.(type) {
case string:
absMediaFile, err = filepath.Abs(t)
check(err)
if err != nil {
return err
}

mfile, err := os.Open(absMediaFile)
check(err)
if err != nil {
return err
}

mediaFile = absMediaFile
mediaType, err = utils.GetMimeDetailsFromFile(mfile)
if err != nil {
return err
}

if !*transcodePtr {
isSeek = true
}

check(err)
case io.ReadCloser, []byte:
absMediaFile = *urlArg
}

absSubtitlesFile, err := filepath.Abs(*subsArg)
check(err)

upnpServicesURLs, err := soapcalls.DMRextractor(flagRes.dmrURL)
check(err)

whereToListen, err := utils.URLtoListenIPandPort(flagRes.dmrURL)
check(err)

scr, err := interactive.InitTcellNewScreen()
check(err)
if err != nil {
return err
}

callbackPath, err := utils.RandomString()
check(err)
scr := &dummyScreen{ctxCancel: cancel}

tvdata := &soapcalls.TVPayload{
ControlURL: upnpServicesURLs.AvtransportControlURL,
EventURL: upnpServicesURLs.AvtransportEventSubURL,
RenderingControlURL: upnpServicesURLs.RenderingControlURL,
CallbackURL: "http://" + whereToListen + "/" + callbackPath,
MediaURL: "http://" + whereToListen + "/" + utils.ConvertFilename(absMediaFile),
SubtitlesURL: "http://" + whereToListen + "/" + utils.ConvertFilename(absSubtitlesFile),
MediaType: mediaType,
CurrentTimers: make(map[string]*time.Timer),
MediaRenderersStates: make(map[string]*soapcalls.States),
InitialMediaRenderersStates: make(map[string]bool),
RWMutex: &sync.RWMutex{},
Transcode: *transcodePtr,
Seekable: isSeek,
tvdata, err := soapcalls.NewTVPayload(soapcalls.Options{
DMR: flagRes.dmrURL,
Media: absMediaFile,
Subs: absSubtitlesFile,
Mtype: mediaType,
Transcode: *transcodePtr,
Seek: isSeek,
Logging: os.Stdout,
})
if err != nil {
return err
}

s := httphandlers.NewServer(whereToListen)
serverStarted := make(chan struct{})
s = httphandlers.NewServer(tvdata.ListenAddress())
serverStarted := make(chan error)

// We pass the tvdata here as we need the callback handlers to be able to react
// to the different media renderer states.
go func() {
err := s.StartServer(serverStarted, mediaFile, absSubtitlesFile, tvdata, scr)
check(err)
s.StartServer(serverStarted, mediaFile, absSubtitlesFile, tvdata, scr)
}()
// Wait for HTTP server to properly initialize
<-serverStarted

scr.InterInit(tvdata)
}

func check(err error) {
if errors.Is(err, errNoflag) {
flag.Usage()
os.Exit(0)
if err := <-serverStarted; err != nil {
return err
}

err = tvdata.SendtoTV("Play1")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Encountered error(s): %s\n", err)
os.Exit(1)
return err
}

<-exitCTX.Done()

if tvdata != nil {
_ = tvdata.SendtoTV("Stop")
}
if s != nil {
s.StopServer()
}

return nil
}

func listFlagFunction() error {
flagsEnabled := 0
flag.Visit(func(f *flag.Flag) {
flag.Visit(func(*flag.Flag) {
flagsEnabled++
})

if flagsEnabled > 1 {
return errors.New("cant combine -l with other flags")
return ErrNoCombi
}

deviceList, err := devices.LoadSSDPservices(1)
if err != nil {
return errors.New("failed to list devices")
return ErrFailtoList
}

fmt.Println()
Expand Down Expand Up @@ -204,15 +235,18 @@ func listFlagFunction() error {
}

func processflags() (*flagResults, error) {
checkVerflag()

res := &flagResults{}

if checkVerflag() {
res.exit = true
return res, nil
}

if *mediaArg == "" && !*listPtr && *urlArg == "" {
return nil, fmt.Errorf("checkflags error: %w", errNoflag)
}

if err := checkTCflag(res); err != nil {
if err := checkTCflag(); err != nil {
return nil, fmt.Errorf("checkflags error: %w", err)
}

Expand Down Expand Up @@ -268,7 +302,7 @@ func checkSflag() error {
return nil
}

func checkTCflag(res *flagResults) error {
func checkTCflag() error {
if *transcodePtr {
_, err := exec.LookPath("ffmpeg")
if err != nil {
Expand Down Expand Up @@ -315,9 +349,19 @@ func checkLflag() (bool, error) {
return false, nil
}

func checkVerflag() {
func checkVerflag() bool {
if *versionPtr && os.Args[1] == "-version" {
fmt.Printf("Go2TV Version: %s\n", version)
os.Exit(0)
return true
}
return false
}

func (s *dummyScreen) EmitMsg(msg string) {
fmt.Println(msg)
}

func (s *dummyScreen) Fini() {
fmt.Println("exiting..")
s.ctxCancel()
}
Loading

0 comments on commit 578da13

Please sign in to comment.