Skip to content

Commit

Permalink
Merge pull request #12 from kadrim/5-load-local-app-or-remote-accordi…
Browse files Browse the repository at this point in the history
…ng-to-args

allow caching of plex-app after download
  • Loading branch information
kadrim authored Jan 5, 2022
2 parents 13f6803 + 04b8a10 commit 52dca01
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dll
*.so
*.dylib
*.zip

# Test binary, built with `go test -c`
*.test
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ _Notice: this will only work, if the system you are running on, is on the same n

This process has only to be done once. So after the app has been installed via this method, it stays on the TV!

Proxy4plex will automatically download the the plex-app and modify it for network-sideloading. If, for whatever reason, you want to [predownload the app](https://www.dropbox.com/s/f17hx2w7tvofjqr/Plex_2.014_11112020.zip?dl=1) yourself, and place it in the same folder as the executable for proxy4plex.

##### E/F-Series TV

1. Start the `proxy4plex` binary
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
host = "plex.tv"
officialAppURL = "https://www.dropbox.com/s/f17hx2w7tvofjqr/Plex_2.014_11112020.zip?dl=1"
officialAppChksum = "8c6b2bb25a4c2492fd5dbde885946dcb6b781ba292e5038239559fd7a20e707e"
officialAppFile = "Plex_2.014_11112020.zip"
modifiedAppName = "Plex_2.014_net"
modifiedAppFile = "Plex_2.014_11112020_net.zip"
)
Expand Down
60 changes: 48 additions & 12 deletions zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
)

Expand All @@ -27,36 +28,69 @@ func extractZipFile(zipFile *zip.File) ([]byte, error) {
func retreiveZipFile() ([]byte, error) {
// only retreive data once
if modifiedBuffer != nil {
log.Println("reusing already prepared net-sideloader")
return modifiedBuffer, nil
}

// download the original zip
resp, err := http.Get(officialAppURL)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var zipData []byte
var download bool

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
if _, err := os.Stat(officialAppFile); err == nil { // check if the plex-app has already been downloaded
log.Println("plex-app exists in local directory, not downloading it again")
zipData, err = ioutil.ReadFile(officialAppFile)
if err != nil {
return nil, err
}
} else {
// download the original zip
log.Println("downloading application from " + officialAppURL + " ... ")
resp, err := http.Get(officialAppURL)
if err != nil {
return nil, err
}
defer resp.Body.Close()
log.Println("done!")

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
} else {
zipData = body
}

download = true
}

// checksum
chksum := sha256.Sum256(body)
chksum := sha256.Sum256(zipData)
if hex.EncodeToString(chksum[:]) == officialAppChksum {
log.Println("checksum match. going on ...")
} else {
err := errors.New("checksum did not match, aborting")
var message string
message = "checksum did not match, aborting"
if !download {
message = message + "\nPlease delete existing file " + officialAppFile + " to force redownload"
}
err := errors.New(message)
log.Println(message)

return nil, err
}

if download {
// write zipData to local file for caching
err := ioutil.WriteFile(officialAppFile, zipData, 0664)
if err != nil {
log.Fatal("could not save downloaded file, going on anyway")
}
}

// attach the zipWriter to the buffer
buf := new(bytes.Buffer)
w := zip.NewWriter(buf)

// create zipReader
zipReader, err := zip.NewReader(bytes.NewReader(body), int64(len(body)))
zipReader, err := zip.NewReader(bytes.NewReader(zipData), int64(len(zipData)))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -93,5 +127,7 @@ func retreiveZipFile() ([]byte, error) {
// write data to global var
modifiedBuffer = buf.Bytes()

log.Println("app ready for net-sideloading!")

return modifiedBuffer, nil
}

0 comments on commit 52dca01

Please sign in to comment.