Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

add stream #3

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ MIRAKURUN_PORT=40772
MIRAKURUN_HTTPS=false
CHINACHU_IP=localhost
CHINACHU_PORT=10772
LAPIS_HOSTNAME=localhost
FFMPEG_BIN=ffmpeg
LAPIS_PORT=8080
GIN_MODE=release
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

.env
lapis
lapis-v2
main
vendor
vendor/*
subs/*
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# lapis builder image
FROM golang:latest as builder
FROM golang:1.13.4 as builder
LABEL maintainer "plainbanana <kazukidegozaimasuruzo@gmail.com>"
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
WORKDIR /go/src/github.com/plainbanana/lapis
WORKDIR /plainbanana/lapis
COPY . .
RUN make

Expand All @@ -14,5 +14,5 @@ FROM alpine
LABEL maintainer "plainbanana <kazukidegozaimasuruzo@gmail.com>"
ENV DOTENV=false
RUN apk add --no-cache ca-certificates
COPY --from=builder /go/src/github.com/plainbanana/lapis/lapis /lapis
COPY --from=builder /plainbanana/lapis/lapis /lapis
CMD ["/lapis"]
21 changes: 14 additions & 7 deletions app/chinachu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ import (
"github.com/plainbanana/lapis/entities"
)

// Xmldateformat is xmltv
const Xmldateformat = "20060102150400 -0700"

// Originalairdateformat chinachu format
const Originalairdateformat = "2006-01-02 15:04:05"

// Episodedateformat episodedate
const Episodedateformat = "0102"

func hashMod(value string) int {
str := fmt.Sprintf("%x", sha256.Sum256([]byte(value)))
numHash, err := strconv.ParseInt(str[:10], 16, 64)
Expand All @@ -32,9 +41,6 @@ func hashMod(value string) int {

// ConvertEpgToXML : GET /api/schedule/programs.json -> epg.xml
func ConvertEpgToXML() *entities.Guide {
const xmldateformat = "20060102150400 -0700"
const originalairdateformat = "2006-01-02 15:04:05"
const episodedateformat = "0102"

base := "http://" + os.Getenv("CHINACHU_IP") + ":" + os.Getenv("CHINACHU_PORT") + "/api/schedule/programs.json"
if os.Getenv("MIRAKURUN_HTTPS") == "true" {
Expand All @@ -61,15 +67,16 @@ func ConvertEpgToXML() *entities.Guide {
c.ID = v.GuideNumber
c.DisplayName.DisplayName = v.GuideName
c.DisplayName.Lang = "ja_JP"
c.Icon.Src = setChannelIconURL(c.ID)
xml.Channel = append(xml.Channel, c)
}
for _, v := range s {
var p entities.ProgrammeGuide
p.Start = time.Unix(0, v.Start*1000000).Format(xmldateformat)
p.Stop = time.Unix(0, v.End*1000000).Format(xmldateformat)
p.Start = time.Unix(0, v.Start*1000000).Format(Xmldateformat)
p.Stop = time.Unix(0, v.End*1000000).Format(Xmldateformat)
p.Channel = strconv.Itoa(v.Channel.SID)
p.Category.Category = v.Category
p.Desc.Desc = v.Detail
p.Desc.Desc = v.Detail + " lapisID:" + v.ID
titleSlice := strings.Split(v.Title, "▽")
p.Title.Title = titleSlice[0]
if len(titleSlice) >= 2 {
Expand All @@ -83,7 +90,7 @@ func ConvertEpgToXML() *entities.Guide {
p.EpisodeNum.System = "dd_progid"
var tail string
if v.Episode == 0 {
tail = time.Unix(0, v.Start*1000000).Format(episodedateformat)
tail = time.Unix(0, v.Start*1000000).Format(Episodedateformat)
} else {
tail = fmt.Sprintf("%04d", v.Episode)
}
Expand Down
47 changes: 41 additions & 6 deletions app/mirakurun.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package app

import (
"encoding/base64"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
Expand All @@ -10,13 +12,12 @@ import (
"github.com/plainbanana/lapis/entities"
)

// MirakurunBase is baseurl
var MirakurunBase string

// SetLineup : get ALL channel
func SetLineup() []entities.Lineup {
base := "http://" + os.Getenv("MIRAKURUN_IP") + ":" + os.Getenv("MIRAKURUN_PORT") + "/api/channels/"
if os.Getenv("MIRAKURUN_HTTPS") == "true" {
base = "https://" + os.Getenv("MIRAKURUN_IP") + ":" + os.Getenv("MIRAKURUN_PORT") + "/api/channels/"
}

base := MirakurunBase + "/api/channels/"
res, err := http.Get(base) // get channel lists as json
if err != nil {
log.Println(err)
Expand All @@ -30,16 +31,50 @@ func SetLineup() []entities.Lineup {
log.Println(err)
}

lapisuri := os.Getenv("LAPIS_HOSTNAME")
if lapisuri == "" {
lapisuri = "localhost"
}

var lineups []entities.Lineup
for _, v := range s {
for _, vv := range v.Services {
var items entities.Lineup
items.GuideName = vv.Name
items.GuideNumber = strconv.Itoa(vv.ServiceID)
items.URL = base + v.Type + "/" + v.Channel + "/services/" + strconv.Itoa(vv.ServiceID) + "/stream/"
origURL := base + v.Type + "/" + v.Channel + "/services/" + strconv.Itoa(vv.ServiceID) + "/stream/"
b64url := base64.StdEncoding.EncodeToString([]byte(origURL))
items.URL = "http://" + lapisuri + ":" + entities.LapisPort + "/stream/" + b64url
lineups = append(lineups, items)
}
}

return lineups
}

// setChannelIconURL set channnel png logo url
func setChannelIconURL(serviceid string) string {
id := ""

base := MirakurunBase + "/api/services/"
res, err := http.Get(base)
if err != nil {
log.Println(err)
}
defer res.Body.Close()

var s entities.Service
decoder := json.NewDecoder(res.Body)
err = decoder.Decode(&s)
if err != nil {
log.Println(err)
}

for _, v := range s {
if fmt.Sprint(v.ServiceID) == serviceid {
id = fmt.Sprint(v.ID)
}
}

return MirakurunBase + "/api/services/" + id + "/logo"
}
1 change: 1 addition & 0 deletions entities/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ func NewDevice() Device {
dev := Device{}
dev.FriendlyName = "lapis"
dev.Manufacturer = "Silicondust"
// Built in Transcoder
dev.ModelNumber = "HDTC-2US"
dev.FirmwareName = "hdhomeruntc_atsc"
dev.DeviceID = "12345678"
Expand Down
94 changes: 77 additions & 17 deletions entities/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package entities

import "encoding/xml"

// LapisVersion is version
var LapisVersion = "1.1.0"

// LapisPort is port of lapis
var LapisPort string

// Device : device info
type Device struct {
FriendlyName string `json:"FriendlyName"`
Expand Down Expand Up @@ -48,19 +54,32 @@ type DeviceChild struct {
}

// Service : json
type Service struct {
ID int `json:"id"`
ServiceID int `json:"serviceId"`
NetworkID int `json:"networkId"`
Name string `json:"name"`
type Service []struct {
ID int64 `json:"id"`
ServiceID int `json:"serviceId"`
NetworkID int `json:"networkId"`
Name string `json:"name"`
Type int `json:"type"`
LogoID int `json:"logoId"`
RemoteControlKeyID int `json:"remoteControlKeyId"`
Channel struct {
Type string `json:"type"`
Channel string `json:"channel"`
} `json:"channel"`
HasLogoData bool `json:"hasLogoData"`
}

// Channel : json
type Channel struct {
Type string `json:"type"`
Channel string `json:"channel"`
Name string `json:"name"`
Services []Service `json:"services"`
Type string `json:"type"`
Channel string `json:"channel"`
Name string `json:"name"`
Services []struct {
ID int `json:"id"`
ServiceID int `json:"serviceId"`
NetworkID int `json:"networkId"`
Name string `json:"name"`
} `json:"services"`
}

// Channels : json
Expand All @@ -76,14 +95,14 @@ type Guide struct {

// ChannelGuide : xml
type ChannelGuide struct {
ID string `xml:"id,attr"`
DisplayName DisplayNameGuide `xml:"display-name"`
}

// DisplayNameGuide : xml
type DisplayNameGuide struct {
Lang string `xml:"lang,attr"`
DisplayName string `xml:",chardata"`
ID string `xml:"id,attr"`
DisplayName struct {
Lang string `xml:"lang,attr"`
DisplayName string `xml:",chardata"`
} `xml:"display-name"`
Icon struct {
Src string `xml:"src,attr"`
} `xml:"icon"`
}

// ProgrammeGuide : xml
Expand Down Expand Up @@ -154,3 +173,44 @@ type ChannelSchedule struct {
SID int `json:"sid"`
Name string `json:"name"`
}

// MirakurunPrograms : json
type MirakurunPrograms []struct {
ID int64 `json:"id"`
EventID int `json:"eventId"`
ServiceID int `json:"serviceId"`
NetworkID int `json:"networkId"`
StartAt int64 `json:"startAt"`
Duration int `json:"duration"`
IsFree bool `json:"isFree"`
Name string `json:"name"`
Description string `json:"description"`
Video struct {
Type string `json:"type"`
Resolution string `json:"resolution"`
StreamContent int `json:"streamContent"`
ComponentType int `json:"componentType"`
} `json:"video"`
Audio struct {
SamplingRate int `json:"samplingRate"`
ComponentType int `json:"componentType"`
} `json:"audio"`
Genres []struct {
Lv1 int `json:"lv1"`
Lv2 int `json:"lv2"`
Un1 int `json:"un1"`
Un2 int `json:"un2"`
} `json:"genres,omitempty"`
RelatedItems []struct {
ServiceID int `json:"serviceId"`
EventID int `json:"eventId"`
} `json:"relatedItems,omitempty"`
Extended struct {
ProgrammeContent string `json:"番組内容"`
Performer string `json:"出演者"`
OriginalScreenplay string `json:"原作・脚本"`
Director string `json:"監督・演出"`
Production string `json:"制作"`
Music string `json:"音楽"`
} `json:"extended,omitempty"`
}
21 changes: 11 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ module github.com/plainbanana/lapis
go 1.13.4

require (
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
github.com/gin-gonic/gin v0.0.0-20170702092826-d459835d2b07
github.com/golang/protobuf v1.1.0 // indirect
github.com/djherbis/stream v1.2.0
github.com/gin-gonic/gin v1.5.0
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/joho/godotenv v1.2.0
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/stretchr/testify v1.4.0 // indirect
github.com/ugorji/go v1.1.1 // indirect
golang.org/x/net v0.0.0-20191207000613-e7e4b65ae663 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
github.com/json-iterator/go v1.1.8 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
golang.org/x/sys v0.0.0-20191206220618-eeba5f6aabab // indirect
gopkg.in/go-playground/validator.v9 v9.30.2 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)
Loading