# Seed TV Development Note
## Overview
Seed TV(previous name: "TVHK") is a TV set-top-box project aim to create a video platform for Hong Konger. It contains several essential components:
- **Kodi**, an open-source media center application with add-on capability, with some addons developed:
- **plugin.video.tvhk** addon, read metadata from API server and display them
- **plugin.video.peertube** player addon(fork from an open-source project)
- **plugin.video.youtube** player addon(temp-ly disabled)
- **script.module.libtorrent** provide python-libtorrent (cpython) binding as an Kodi addon
- **Aura-tvhk** skin, modified version of `Aura`
- **Peertube**, a open-source video platform base on `WebTorrent`
- **CMS**, contains several parts:
- **API server** for Kodi to retrieve video metadata
- **Crawler** to collect video metadata from Peertube&Youtube(and manipulate them a bit)
- **Crawler management console** to config the crawler
- ~~**Device management console** Enroll new hardward ID and integrate with Ad system.~~**(NO progress, need help!)**
- ~~**Youtube Downloader**, a managed youtube to peertube sync tools~~ **(NO progress, need help!)**
- ~~**Ad management system**, to management and provide ad to Kodi~~ **(NO progress, need help!)**
- **CoreELEC**, a just enough Linux for Kodi
- Some depolyment/helper tools:
- **KPM**, standalone Kodi package manager
- **BASH setup script**, to prepare Kodi+addons+CoreELEC. Might add ability to pack Mac/Android/Windows app later.
The customized Kodi app (lightly modified Kodi+addons) is capable to release a standalone version for Mac/Android/Windows. Which might explore a bit later
All sources can be found from here: http://github.com/tvhk-dev
## Kodi
### Kodi it self
Nothing really need to modified on Kodi currently.
### plugin.video.tvhk
What it actually do?
- Display channels/playlists/videos in Kodi
- Trigger playback, by calling `plugin.video.peertube`, or fallback to `plugin.video.youtube` if needed.
- Data from API server, cache in local DB, uni-directional sync periodically
- Pass parameter to `skin.Aura-tvhk` for displaying ad
Bugs:
- Too many
TODO:
- Merge old code to add back live capability from youtube
- Handle Kodi player event(like pause, next etc.)
- Merge old code to implement youtube fallback
- Many more
### plugin.video.peertube
What it actually do?
- Play peertube video in Kodi
- Original from [StCyr/plugin.video.peertube](https://framagit.org/StCyr/plugin.video.peertube)
- Added to play playlist functionality
Bugs:
- This plugin simply download the video to temp folder via `libtorrent`(a standard BitTorrent). It doesn't delete/purge the temp folder. Which may lead the storage getting full.
- The plugin code launch mutliple libtorrent instances simultaneously and start downloading from all of them when playing a playlist. That may slow down the network awfully. And the libtorrent instances **won't** stop even after user completely stop the playlist.
TODO:
- Fix the bug above
### plugin.video.youtube
What it actually do?
- Play youtube video in Kodi
- Original from [jdf76/plugin.video.youtube](https://github.com/jdf76/plugin.video.youtube)
Bugs:
- API key / API cost issue
TODO:
- TBC
### script.module.libtorrent
What it actually do?
- A python-libtorrent binding binary required by `plugin.video.peertube`
- Auto detect and switch binaries on OSes (Linux or Mac) and architecture (x86-64 or ARM)
- Packed in Kodi addon format, capable to be a dependency for any other addon
Bugs:
- Not yet found
TODO:
- Add Windows platfrom and x86-32 architecture
- We did manaually resolved all dependencies in a very hacky way. It's not maintain-able and not upgrade-able. We need some way to sort it out.
### skin.aura-tvhk
What it actually do?
- Fork from skin.aura
- Disabled user-configurable home screen outlook
- Included a home screen outlook we want
- Added a ad display view in video-loading-screen
- Adjusted some minor size parameters
- Display advertisement on video loading screen
Bugs:
- Not yet found
TODO:
- Add device activation dialog on first boot, collect some information(like district, home/shop etc.) and use OAuth(like google account) to login.
- Update loading screen, display advertisement according to hardware ID
-
## Peertube
What it actually do?
- A P2P, `Webtorrent` based video platform, BitTorrent compatible.
- Youtube-like user experience. Easy to adapt/drop-in-replace.
- Self-hosted, not a single cloud platform.
## CMS
The CMS is now made from several dispersed parts. We need to combine them together (with one CMS framework?) someday. Here are the parts below:
### API Server
What it actually do?
- Provide channels/playlists/videos metadata and some display parameter needed by `plugin.video.tvhk`
- Capable to filter data with last update time, for differential sync
- Data from database
Bugs:
- Currently implemented via raw PHP and simple ORM, doesn't do any API limitation and authencation etc.
- Youtube and peertube code implemented separately. You need to `git checkout <branch>`....
- Differential filter is buggy, something it just throw all data
TODO:
- Adapt CMS with rate limit funcationality and hardware ID based authencation
- Merge back youtube code so that youtube fallback will work
- Despite time base filter, the API server should offload some metadata to CDN since they're static. Also implement gzip or any compression if possible.
### Crawler
What it actually do?
- Fetch channels/playlists/videos metadata from Peertube and Youtube, write to DB
- Manipulate the metadata a little bit(like replace/add cover pic, description text etc.)
- All channels/playlists/videos metadata rule store in config JSON file
- Control display parameters via the config JSON file
- The crawler eventually write display parameters into DB, which the API server will read them later
- Currently wrote in NodeJS
Bugs:
- Similar to stuffs above, the youtube code is separate, need to merge into current peertube code
- Poor performance, since we need to initial a lot of API call.
TODO:
- Might change to distributed mode(e.g. run parallelly across different channels)
- Migrate to read config from CMS, instead of JSON
### Crawler management console
What it actually do?
- A HTML UI to manage the Crawler's config JSON file
Bugs:
- TBC
TODO:
- TBC
### Device management console
What it actually do?
- Enroll/management a new hardware
- Authenticate a hardware
- Keep user information
- Idenify a hardware for Ad management system
TODO:
- **No progress!!**
### Youtube Downloader
What it actually do?
- Unidirectional sync video from youtube to peertube
- Make it distributed/parllel if possible
TODO:
- **No progress!!**
- Reference project(python): https://github.com/mister-monster/YouTube2PeerTube
### Ad management system
What it actually do?
- Provide ad to display and management them
- Integrate with `device management console`, simply obtain some device information for stats
- Provide CRM feature, like reach report etc.
Bugs:
- TBC
TODO:
- **No progress!!**
- We prefer to find some open-source software instead of develop ourself
## CoreELEC
What it actually do?
- A just enough Linux tended to use as TVBox/Media Center.
Bugs:
- Can't modify splash screen
TODO:
- Make it clone-able/easy to spread
- Add Bit-torrent seeding software on it
- Write a tools(binary?) for OTA update
## Tools
### KPM
What it actually do?
- Kodi will resolve&install all dependencies while installing an addon, we made the exactly some functionality, but standalone and works even when Kodi is not running. This give us capability to provide OOBX(Open box experience).
- Design for compile & pack procedure
Bugs:
- Some minor bugs, TBC
TODO:
- TBC
### BASH setup script
What it actually do?
- Compile / pack for several platform, either:
- Pack all files needs by CoreElec
- ~~Compile Mac app~~ (**no progress!!**)
- ~~Compile Android app~~ (**no progress!!**)