├── .gitignore ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── circle.yml ├── main.go ├── plex.go ├── tvheadenv.go └── versionist.conf.js /.gitignore: -------------------------------------------------------------------------------- 1 | ## Go 2 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 3 | *.o 4 | *.a 5 | *.so 6 | # Folders 7 | _obj 8 | _test 9 | # Architecture specific extensions/prefixes 10 | *.[568vq] 11 | [568vq].out 12 | *.cgo1.go 13 | *.cgo2.c 14 | _cgo_defun.c 15 | _cgo_gotypes.go 16 | _cgo_export.* 17 | _testmain.go 18 | *.exe 19 | *.test 20 | *.prof 21 | # Output of the go coverage tool 22 | *.out 23 | # external packages folder 24 | vendor/ 25 | 26 | ## Builds 27 | bin/* 28 | build/* 29 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v1.0.1 - 2017-11-29 4 | 5 | * Update golang to 1.9.3 [Will Boyce] 6 | 7 | ## v1.0.0 - 2017-06-11 8 | 9 | * Initial release [Will Boyce] 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.9.2 2 | 3 | ADD *.go /go/src/github.com/wrboyce/plexheadend/ 4 | RUN go get -v github.com/wrboyce/plexheadend 5 | CMD plexheadend 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | USERNAME ?= wrboyce 2 | PROJECT ?= plexheadend 3 | EXECUTABLE ?= plexheadend 4 | DOCKER_IMAGE ?= $(USERNAME)/$(PROJECT) 5 | BRANCH ?= $(shell git branch --format='%(refname:short)' 2>/dev/null) 6 | COMMIT := $(shell git show -s --format='%h' 2>/dev/null) 7 | VERSION := $(shell git describe --abbrev=0 --tags --dirty 2>/dev/null) 8 | BUILD_PLATFORMS ?= darwin/amd64 linux/arm linux/arm64 linux/amd64 windows/amd64 9 | SHASUM ?= sha256sum 10 | 11 | all: bin/$(EXECUTABLE) 12 | 13 | dep: 14 | go get -v ./... 15 | go get github.com/mitchellh/gox 16 | 17 | lint-dep: dep 18 | go get github.com/golang/lint/golint 19 | go get golang.org/x/tools/cmd/goimports 20 | 21 | lint: lint-dep 22 | gofmt -e -l -s . 23 | goimports -d . 24 | golint -set_exit_status ./... 25 | go tool vet . 26 | 27 | test-dep: dep 28 | go test -i -v ./... 29 | 30 | test: test-dep 31 | go test -v ./... 32 | 33 | release: $(addsuffix .tar.gz,$(addprefix build/$(EXECUTABLE)-$(VERSION)_,$(subst /,_,$(BUILD_PLATFORMS)))) 34 | release: $(addsuffix .tar.gz.sha256,$(addprefix build/$(EXECUTABLE)-$(VERSION)_,$(subst /,_,$(BUILD_PLATFORMS)))) 35 | 36 | container: 37 | docker build --pull --tag $(DOCKER_IMAGE):$(COMMIT) . 38 | 39 | container-upload: 40 | docker push $(DOCKER_IMAGE):$(COMMIT) 41 | docker tag $(DOCKER_IMAGE):$(COMMIT) $(DOCKER_IMAGE):$(BRANCH) 42 | docker push $(DOCKER_IMAGE):$(BRANCH) 43 | ifeq ($(BRANCH),master) 44 | docker tag $(DOCKER_IMAGE):$(COMMIT) $(DOCKER_IMAGE):latest 45 | docker push $(DOCKER_IMAGE):latest 46 | endif 47 | ifeq ($(VERSION),$(shell git describe --exact-match --tags 2>&1)) 48 | docker tag $(DOCKER_IMAGE):$(COMMIT) $(DOCKER_IMAGE):$(VERSION) 49 | docker push $(DOCKER_IMAGE):$(VERSION) 50 | endif 51 | 52 | upload-dep: 53 | go get github.com/aktau/github-release 54 | 55 | release-upload: lint test upload-dep 56 | ifndef GITHUB_TOKEN 57 | $(error GITHUB_TOKEN is undefined) 58 | endif 59 | ifneq ($(VERSION),$(shell git describe --exact-match --tags 2>&1)) 60 | $(error refusing to upload dirty release) 61 | endif 62 | git log --format='* %s' --grep='change-type' --regexp-ignore-case $(shell git describe --tag --abbrev=0 $(VERSION)^)...$(VERSION) | \ 63 | github-release release -u $(USERNAME) -r $(PROJECT) -t $(VERSION) -n $(VERSION) -d - || true 64 | $(foreach FILE, $(addsuffix .tar.gz,$(addprefix build/$(EXECUTABLE)-$(VERSION)_,$(subst /,_,$(BUILD_PLATFORMS)))), \ 65 | github-release upload -u $(USERNAME) -r $(PROJECT) -t $(VERSION) -n $(notdir $(FILE)) -f $(FILE) && \ 66 | github-release upload -u $(USERNAME) -r $(PROJECT) -t $(VERSION) -n $(notdir $(addsuffix .sha256,$(FILE))) -f $(addsuffix .sha256,$(FILE)) ;) 67 | 68 | clean: 69 | rm -vrf bin/* build/* 70 | 71 | # binary 72 | bin/$(EXECUTABLE): dep 73 | go build -ldflags="-X main.version=$(VERSION)" -o "$@" -v ./$(PACKAGE) 74 | # release binaries 75 | build/%/$(EXECUTABLE): dep 76 | gox -parallel=1 -osarch=$(subst _,/,$(subst build/,,$(@:/$(EXECUTABLE)=))) -ldflags="-X main.version=$(VERSION)" -output="build/{{.OS}}_{{.Arch}}/$(EXECUTABLE)" ./$(PACKAGE) 77 | # compressed artifacts 78 | build/$(EXECUTABLE)-$(VERSION)_%.tar.gz: build/%/$(EXECUTABLE) 79 | tar -zcf "$@" -C "$(dir $<)" $(EXECUTABLE) || tar -zcf "$@" -C "$(dir $<)" $(EXECUTABLE).exe 80 | # signed artifacts 81 | %.sha256: % 82 | cd $(dir $<) && $(SHASUM) $(notdir $<) > $(addsuffix .sha256,$(notdir $<)) 83 | 84 | .PHONY: dep lint-dep lint test-dep test release upload-dep upload clean 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # plexheadend 2 | 3 | [![GoDoc](https://godoc.org/github.com/wrboyce/plexheadend?status.svg)](https://godoc.org/github.com/wrboyce/plexheadend) 4 | [![Go Report Card](https://goreportcard.com/badge/github.com/wrboyce/plexheadend)](https://goreportcard.com/report/github.com/wrboyce/plexheadend) 5 | [![CircleCI](https://circleci.com/gh/wrboyce/plexheadend.png?style=shield)](https://circleci.com/gh/wrboyce/plexheadend) 6 | 7 | Proxy requests between PlexDVR and TVHeadend 8 | 9 | ## Installation 10 | 11 | ### Binary Release 12 | 13 | Download the latest release from the [downloads page](https://github.com/wrboyce/plexheadend/releases). 14 | 15 | ### Build from Source 16 | 17 | Download and build the project and its dependencies with the standard Go tooling, `go get github.com/wrboyce/plexheadend`. 18 | 19 | ### Docker Container 20 | 21 | There is also a Docker container made available for use at `wrboyce/plexheadend`. 22 | 23 | ## Usage 24 | 25 | All configuration options can be specified as either a commandline parameter or an environment variable. 26 | 27 | | Name | Commandline | Environment | 28 | |--------------------|-----------------------------|-------------------------------| 29 | | Device ID | `--device-id` `-i` | `PLEXHEADEND_DEVICE_ID` | 30 | | Name | `--name` `-n` | `PLEXHEADEND_NAME` | 31 | | Proxy Bind | `--proxy-bind` `-b` | `PLEXHEADEND_PROXY_BIND` | 32 | | Proxy Hostname | `--proxy-hostname` `-H` | `PLEXHEADEND_PROXY_HOSTNAME` | 33 | | Proxy Listen | `--proxy-listen` `-l` | `PLEXHEADEND_PROXY_LISTEN` | 34 | | Filter Tag | `--tag` `-f` | `PLEXHEADEND_TAG` | 35 | | Tuners | `--tuners` `-t` | `PLEXHEADEND_TUNERS` | 36 | | TVHeadend Host | `--tvh-host` `-h` | `PLEXHEADEND_TVH_HOST` | 37 | | TVHeadend Pass | `--tvh-pass` `-P` | `PLEXHEADEND_TVH_PASS` | 38 | | TVHeadend Port | `--tvh-port` `-p` | `PLEXHEADEND_TVH_PORT` | 39 | | TVHeadend User | `--tvh-user` `-u` | `PLEXHEADEND_TVH_USER` | 40 | 41 | ``` 42 | Usage of plexheadend: 43 | -i, --device-id string Device ID reported to Plex (default "1") 44 | -n, --name string Friendly name reported to Plex (default "plexHeadend") 45 | -b, --proxy-bind string Bind address (default all) 46 | -H, --proxy-hostname string Hostname reported to Plex (default "localhost") 47 | -l, --proxy-listen string Listen port (default "80") 48 | -f, --tag string TVHeadend tag to filter reported channels (default none) 49 | -t, --tuners int Number of Tuners reported to Plex (default 1) 50 | -h, --tvh-host string TVHeadend Host (default "localhost") 51 | -P, --tvh-pass string TVHeadend Password (default "plex") 52 | -p, --tvh-port string TVHeadend Port (default "9981") 53 | -u, --tvh-user string TVHeadend Username (default "plex") 54 | ``` 55 | 56 | ### Example `docker-compose` Usage 57 | 58 | ```yaml 59 | services: 60 | tvheadend: 61 | image: linuxserver/tvheadend 62 | container_name: tvheadend 63 | environment: 64 | - VERSION=latest 65 | - TZ=UTC 66 | ports: 67 | - 9981:9981 68 | - 9982:9982 69 | restart: unless-stopped 70 | 71 | plexheadend: 72 | image: wrboyce/plexheadend 73 | container_name: plexheadend 74 | environment: 75 | - PLEXHEADEND_TVH_HOST=tvheadend 76 | - PLEXHEADEND_PROXY_HOSTNAME=plexheadend 77 | restart: unless-stopped 78 | 79 | plex: 80 | image: linuxserver/plex 81 | container_name: plex 82 | environment: 83 | - VERSION=latest 84 | - TZ=UTC 85 | ports: 86 | - 32400:32400 87 | - 32400:32400/udp 88 | restart: unless-stopped 89 | ``` -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | jobs: 4 | build: 5 | working_directory: /go/src/github.com/resin-io/sshproxy 6 | docker: 7 | - image: golang:1.9.2 8 | steps: 9 | - checkout 10 | - setup_remote_docker 11 | - run: 12 | name: Install Docker Client 13 | command: curl -SL https://get.docker.com/builds/Linux/x86_64/docker-17.03.0-ce.tgz | tar -xzC /usr/bin --strip-components=1 14 | - run: 15 | name: Install Dependencies 16 | command: make dep 17 | - run: 18 | name: Lint Code 19 | command: make lint 20 | - run: 21 | name: Run Tests 22 | command: make test 23 | - run: 24 | name: Build Releases 25 | command: make -j release 26 | - run: 27 | name: Build Container 28 | command: make container 29 | - deploy: 30 | name: Upload Releases 31 | command: if git describe --exact-match --tags 2>/dev/null; then make release-upload; fi 32 | - deploy: 33 | name: Upload Container 34 | command: docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}" && make BRANCH=${CIRCLE_BRANCH} container-upload 35 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 Will Boyce 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | "log" 22 | "net/http" 23 | 24 | "github.com/spf13/pflag" 25 | "github.com/spf13/viper" 26 | ) 27 | 28 | var version string 29 | 30 | type plexHeadend struct { 31 | tvhBaseURL string 32 | pxyBaseURL string 33 | listenAddr string 34 | name string 35 | deviceID string 36 | tuners int 37 | tag string 38 | } 39 | 40 | func (p *plexHeadend) listen() { 41 | http.HandleFunc("/discover.json", p.discoverHandler) 42 | http.HandleFunc("/lineup.json", p.lineupHandler) 43 | http.HandleFunc("/lineup_status.json", p.lineupStatusHandler) 44 | http.HandleFunc("/lineup.post", p.lineupPostHandler) 45 | 46 | http.ListenAndServe(p.listenAddr, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 47 | log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL) 48 | http.DefaultServeMux.ServeHTTP(w, r) 49 | })) 50 | } 51 | 52 | func init() { 53 | pflag.CommandLine.BoolP("version", "", false, "Display version and exit") 54 | pflag.CommandLine.StringP("tvh-user", "u", "plex", "TVHeadend Username") 55 | pflag.CommandLine.StringP("tvh-pass", "P", "plex", "TVHeadend Password") 56 | pflag.CommandLine.StringP("tvh-host", "h", "localhost", "TVHeadend Host") 57 | pflag.CommandLine.StringP("tvh-port", "p", "9981", "TVHeadend Port") 58 | pflag.CommandLine.StringP("proxy-bind", "b", "", "Bind address (default all)") 59 | pflag.CommandLine.StringP("proxy-listen", "l", "80", "Listen port") 60 | pflag.CommandLine.StringP("proxy-hostname", "H", "localhost", "Hostname reported to Plex") 61 | pflag.CommandLine.StringP("name", "n", "plexHeadend", "Friendly name reported to Plex") 62 | pflag.CommandLine.StringP("device-id", "i", "1", "Device ID reported to Plex") 63 | pflag.CommandLine.IntP("tuners", "t", 1, "Number of Tuners reported to Plex") 64 | pflag.CommandLine.StringP("tag", "f", "", "TVHeadend tag to filter reported channels (default none)") 65 | 66 | viper.BindPFlags(pflag.CommandLine) 67 | viper.SetEnvPrefix("PLEXHEADEND") 68 | viper.BindEnv("tvh-user", "PLEXHEADEND_TVH_USER") 69 | viper.BindEnv("tvh-pass", "PLEXHEADEND_TVH_PASS") 70 | viper.BindEnv("tvh-host", "PLEXHEADEND_TVH_HOST") 71 | viper.BindEnv("tvh-port", "PLEXHEADEND_TVH_PORT") 72 | viper.BindEnv("proxy-bind", "PLEXHEADEND_PROXY_BIND") 73 | viper.BindEnv("proxy-listen", "PLEXHEADEND_PROXY_LISTEN") 74 | viper.BindEnv("proxy-hostname", "PLEXHEADEND_PROXY_HOSTNAME") 75 | viper.BindEnv("name") // PLEXHEADEND_NAME 76 | viper.BindEnv("device-id", "PLEXHEADEND_DEVICE_ID") 77 | viper.BindEnv("tag") // PLEXHEADEND_TAG 78 | viper.BindEnv("tuners") // PLEXHEADEND_TUNERS 79 | } 80 | 81 | func main() { 82 | pflag.Parse() 83 | 84 | if viper.GetBool("version") { 85 | fmt.Printf("plexheadend v%s\n", version) 86 | return 87 | } 88 | 89 | p := plexHeadend{ 90 | fmt.Sprintf("http://%s:%s@%s:%s", 91 | viper.GetString("tvh-user"), viper.GetString("tvh-pass"), 92 | viper.GetString("tvh-host"), viper.GetString("tvh-port")), 93 | fmt.Sprintf("http://%s:%s", 94 | viper.GetString("proxy-bind"), viper.GetString("proxy-listen")), 95 | fmt.Sprintf("%s:%s", 96 | viper.GetString("proxy-bind"), viper.GetString("proxy-listen")), 97 | viper.GetString("name"), 98 | viper.GetString("device-id"), 99 | viper.GetInt("tuners"), 100 | viper.GetString("tag"), 101 | } 102 | if hostname := viper.GetString("proxy-hostname"); len(hostname) > 0 { 103 | p.pxyBaseURL = fmt.Sprintf("http://%s:%s", hostname, viper.GetString("proxy-listen")) 104 | } 105 | 106 | safeBaseURL := fmt.Sprintf("http://%s:****@%s:%s", 107 | viper.GetString("tvh-user"), viper.GetString("tvh-host"), viper.GetString("tvh-port")) 108 | log.Printf("TvhURL:\t%s", safeBaseURL) 109 | log.Printf("ProxyURL:\t%s", p.pxyBaseURL) 110 | log.Printf("ListenAddr:\t%s", p.listenAddr) 111 | log.Printf("DeviceName:\t%s", p.name) 112 | log.Printf("DeviceID:\t%s", p.deviceID) 113 | log.Printf("TunerCount:\t%d", p.tuners) 114 | if p.tag != "" { 115 | log.Printf("ChannelTag:\t%s", p.tag) 116 | } 117 | 118 | p.listen() 119 | } 120 | -------------------------------------------------------------------------------- /plex.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 Will Boyce 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "net/http" 23 | ) 24 | 25 | type discoverResponse struct { 26 | FriendlyName string 27 | ModelNumber string 28 | FirmwareName string 29 | TunerCount uint 30 | FirmwareVersion string 31 | DeviceID string 32 | DeviceAuth string 33 | BaseURL string 34 | LineupURL string 35 | } 36 | 37 | type lineupResponse struct { 38 | GuideNumber string 39 | GuideName string 40 | URL string 41 | } 42 | 43 | type lineupStatusResponse struct { 44 | ScanInProgress uint 45 | ScanPossible uint 46 | Source string 47 | SourceList []string 48 | } 49 | 50 | func (p *plexHeadend) discoverHandler(w http.ResponseWriter, r *http.Request) { 51 | data := discoverResponse{ 52 | p.name, 53 | "HDHR4-2DT", 54 | "hdhomerun4_dvbt", 55 | uint(p.tuners), 56 | "20160629", 57 | p.deviceID, 58 | "", 59 | p.pxyBaseURL, 60 | fmt.Sprintf("%s/lineup.json", p.pxyBaseURL), 61 | } 62 | json.NewEncoder(w).Encode(data) 63 | } 64 | 65 | func (p *plexHeadend) lineupHandler(w http.ResponseWriter, r *http.Request) { 66 | sliceContains := func(a []string, b string) bool { 67 | for _, s := range a { 68 | if b == s { 69 | return true 70 | } 71 | } 72 | return false 73 | } 74 | 75 | data := make([]lineupResponse, 0) 76 | for _, channel := range p.tvhGetChannels() { 77 | if p.tag == "" || sliceContains(channel.Tags, p.tag) { 78 | data = append(data, 79 | lineupResponse{fmt.Sprintf("%d", channel.Number), channel.Name, channel.URL}) 80 | } 81 | } 82 | json.NewEncoder(w).Encode(data) 83 | } 84 | 85 | func (p *plexHeadend) lineupStatusHandler(w http.ResponseWriter, r *http.Request) { 86 | json.NewEncoder(w).Encode(lineupStatusResponse{ 87 | 0, 1, "Cable", []string{"Cable"}}) 88 | } 89 | 90 | func (p *plexHeadend) lineupPostHandler(w http.ResponseWriter, r *http.Request) {} 91 | -------------------------------------------------------------------------------- /tvheadenv.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 Will Boyce 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "log" 23 | "net/http" 24 | ) 25 | 26 | type apiTagsResponse struct { 27 | Entries []apiTag `json:"entries"` 28 | } 29 | 30 | type apiTag struct { 31 | Key string `json:"key"` 32 | Val string `json:"val"` 33 | } 34 | 35 | type apiChannelsResponse struct { 36 | Entries []apiChannel `json:"entries"` 37 | } 38 | 39 | type apiChannel struct { 40 | UUID string `json:"uuid"` 41 | Name string `json:"name"` 42 | Number int `json:"number"` 43 | Tags []string `json:"tags"` 44 | URL string `json:"url"` 45 | } 46 | 47 | func (p *plexHeadend) tvhGetTags() map[string]string { 48 | resp, err := http.Get(fmt.Sprintf("%s/api/channeltag/list", p.tvhBaseURL)) 49 | if err != nil { 50 | return nil 51 | } 52 | 53 | apiResp := apiTagsResponse{} 54 | json.NewDecoder(resp.Body).Decode(&apiResp) 55 | tags := make(map[string]string) 56 | for _, tag := range apiResp.Entries { 57 | tags[tag.Key] = tag.Val 58 | } 59 | 60 | return tags 61 | } 62 | 63 | func (p *plexHeadend) tvhGetChannels() []apiChannel { 64 | resp, err := http.Get(fmt.Sprintf("%s/api/channel/grid?start=0&limit=100000", p.tvhBaseURL)) 65 | if err != nil { 66 | return nil 67 | } 68 | 69 | apiResp := apiChannelsResponse{} 70 | json.NewDecoder(resp.Body).Decode(&apiResp) 71 | channels := make([]apiChannel, 0) 72 | tags := p.tvhGetTags() 73 | log.Printf("Got %d channels from tvheadend", len(apiResp.Entries)) 74 | for _, channel := range apiResp.Entries { 75 | channelTags := make([]string, 0) 76 | for _, tag := range channel.Tags { 77 | tagName := tags[tag] 78 | if len(tagName) > 0 { 79 | channelTags = append(channelTags, tags[tag]) 80 | } 81 | } 82 | channelURL := fmt.Sprintf("%s/stream/channel/%s", p.tvhBaseURL, channel.UUID) 83 | channels = append(channels, 84 | apiChannel{channel.UUID, 85 | channel.Name, 86 | channel.Number, 87 | channelTags, 88 | channelURL, 89 | }) 90 | } 91 | 92 | return channels 93 | } 94 | -------------------------------------------------------------------------------- /versionist.conf.js: -------------------------------------------------------------------------------- 1 | var execSync = require('child_process').execSync; 2 | 3 | var getAuthor = (commitHash) => { 4 | return execSync(`git show --quiet --format="%an" ${commitHash}`, { encoding: 'utf8' }).replace('\n', ''); 5 | } 6 | 7 | module.exports = { 8 | incrementVersion: 'semver', 9 | updateVersion: (cwd, ver, cb) => cb(), 10 | editChangelog: true, 11 | 12 | // Always add the entry to the top of the Changelog, below the header. 13 | addEntryToChangelog: { 14 | preset: 'prepend', 15 | fromLine: 3 16 | }, 17 | 18 | // Only include a commit when there is a footer tag of 'change-type'. 19 | // Ensures commits which do not up versions are not included. 20 | includeCommitWhen: (commit) => { 21 | return !!commit.footer['change-type']; 22 | }, 23 | 24 | // Determine the type from 'change-type:' tag. 25 | // Should no explicit change type be made, then no changes are assumed. 26 | getIncrementLevelFromCommit: (commit) => { 27 | if (commit.footer['change-type']) { 28 | return commit.footer['change-type'].trim(); 29 | } 30 | }, 31 | 32 | // If a 'changelog-entry' tag is found, use this as the subject rather than the 33 | // first line of the commit. 34 | transformTemplateData: (data) => { 35 | data.commits.forEach((commit) => { 36 | commit.subject = commit.footer['changelog-entry'] || commit.subject; 37 | commit.author = getAuthor(commit.hash); 38 | }); 39 | 40 | return data; 41 | }, 42 | 43 | template: [ 44 | '## v{{version}} - {{moment date "Y-MM-DD"}}', 45 | '', 46 | '{{#each commits}}', 47 | '{{#if this.author}}', 48 | '* {{capitalize this.subject}} [{{this.author}}]', 49 | '{{else}}', 50 | '* {{capitalize this.subject}}', 51 | '{{/if}}', 52 | '{{/each}}' 53 | ].join('\n') 54 | }; 55 | --------------------------------------------------------------------------------