-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add get videos + start working on sqlite watchdog
- Loading branch information
Showing
4 changed files
with
187 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package watchdog | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"time" | ||
|
||
"enssat.tv/autovodsaver/twitch" | ||
_ "github.com/mattn/go-sqlite3" | ||
) | ||
|
||
const ( | ||
createVideosStatusTableStatement = ` | ||
CREATE TABLE IF NOT EXISTS videos_status ( | ||
id INTEGER NOT NULL PRIMARY KEY, | ||
title VARCHAR(255) NOT NULL, | ||
description TEXT NOT NULL, | ||
published_at DATETIME NOT NULL, | ||
duration INTEGER NOT NULL, | ||
status VARCHAR(50) NOT NULL | ||
); | ||
` | ||
) | ||
|
||
type SQLiteWatchdog struct { | ||
Watchdog | ||
Database *sql.DB | ||
DatabaseFilePath string | ||
} | ||
|
||
func NewSQLiteWatchdog(channelId string) *SQLiteWatchdog { | ||
return &SQLiteWatchdog{ | ||
DatabaseFilePath: "./db.sqlite", | ||
Watchdog: Watchdog{ | ||
Status: WatchdogStatusStop, | ||
ChannelId: channelId, | ||
VideoHashMap: make(map[twitch.Video]VideoStatus), | ||
OnVideoUpdateChannel: nil, | ||
}, | ||
} | ||
} | ||
|
||
func (wd *SQLiteWatchdog) Run() error { | ||
// Open connection to the database | ||
db, openDatabaseError := sql.Open("sqlite3", wd.DatabaseFilePath) | ||
if openDatabaseError != nil { | ||
return openDatabaseError | ||
} | ||
defer db.Close() | ||
|
||
// Create table "videos_status" | ||
_, createVideoTableError := db.Exec(createVideosStatusTableStatement) | ||
if createVideoTableError != nil { | ||
return createVideoTableError | ||
} | ||
|
||
wd.Status = WatchdogStatusRun | ||
wd.Database = db | ||
go wd.watchdog() | ||
return nil | ||
} | ||
|
||
func (wd *SQLiteWatchdog) watchdog() { | ||
for wd.Status == WatchdogStatusRun { | ||
fmt.Println("hey") | ||
time.Sleep(1 * time.Second) | ||
} | ||
} | ||
|
||
func (wd *SQLiteWatchdog) Stop() error { | ||
wd.Status = WatchdogStatusStop | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package watchdog | ||
|
||
import "enssat.tv/autovodsaver/twitch" | ||
|
||
const ( | ||
VideoStatusMissing = "VIDEO_STATUS_MISSING" | ||
VideoStatusArchived = "VIDEO_STATUS_ARCHIVED" | ||
VideoStatusDownloading = "VIDEO_STATUS_DOWNLOADING" | ||
VideoStatusConcatenating = "VIDEO_STATUS_CONCATENATING" | ||
) | ||
|
||
const ( | ||
WatchdogStatusRun = "WATCHDOG_STATUS_RUN" | ||
WatchdogStatusStop = "WATCHDOG_STATUS_STOP" | ||
) | ||
|
||
type VideoStatus string | ||
type WatchdogStatus string | ||
|
||
type Watchdog struct { | ||
Status WatchdogStatus | ||
ChannelId string | ||
VideoHashMap map[twitch.Video]VideoStatus | ||
OnVideoUpdateChannel *chan UpdateMessage | ||
} | ||
|
||
type UpdateMessage struct { | ||
Type VideoStatus | ||
Video twitch.Video | ||
} | ||
|
||
type Watchdoger interface { | ||
Run() error | ||
Stop() error | ||
OnVideoUpdate(ch *chan UpdateMessage) | ||
} |