Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Niko Storni
6ac48c929b
changes that will never make it into master
re-added support for UCBerkeley
2018-10-02 20:55:13 -04:00
3 changed files with 37 additions and 23 deletions

View file

@ -1,6 +1,7 @@
package sources package sources
import ( import (
"fmt"
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
@ -22,14 +23,16 @@ import (
) )
type ucbVideo struct { type ucbVideo struct {
id string id string
title string playlistPosition int
channel string title string
description string channel string
publishedAt time.Time description string
dir string publishedAt time.Time
claimNames map[string]bool dir string
syncedVideosMux *sync.RWMutex size *int64
claimNames map[string]bool
syncedVideosMux *sync.RWMutex
} }
func NewUCBVideo(id, title, channel, description, publishedAt, dir string) *ucbVideo { func NewUCBVideo(id, title, channel, description, publishedAt, dir string) *ucbVideo {
@ -48,12 +51,15 @@ func (v *ucbVideo) ID() string {
return v.id return v.id
} }
func (v *ucbVideo) SetPlaylistPosition(p int) {
v.playlistPosition = p
}
func (v *ucbVideo) PlaylistPosition() int { func (v *ucbVideo) PlaylistPosition() int {
return 0 return v.playlistPosition
} }
func (v *ucbVideo) IDAndNum() string { func (v *ucbVideo) IDAndNum() string {
return v.ID() + " (?)" return fmt.Sprintf("%s %d", v.ID(), v.playlistPosition)
} }
func (v *ucbVideo) PublishedAt() time.Time { func (v *ucbVideo) PublishedAt() time.Time {
@ -121,8 +127,9 @@ func (v *ucbVideo) download() error {
log.Debugln(v.id + " already exists at " + videoPath) log.Debugln(v.id + " already exists at " + videoPath)
return nil return nil
} }
awsID := os.Getenv("S3_UCB_ACCESS_ID")
creds := credentials.NewStaticCredentials("ID-GOES-HERE", "SECRET-GOES-HERE", "") awsSecret := os.Getenv("s3_UCB_ACCESS_SECRET")
creds := credentials.NewStaticCredentials(awsID, awsSecret, "")
s, err := session.NewSession(&aws.Config{Region: aws.String("us-east-2"), Credentials: creds}) s, err := session.NewSession(&aws.Config{Region: aws.String("us-east-2"), Credentials: creds})
if err != nil { if err != nil {
return err return err
@ -146,7 +153,7 @@ func (v *ucbVideo) download() error {
} else if bytesWritten == 0 { } else if bytesWritten == 0 {
return errors.Err("zero bytes written") return errors.Err("zero bytes written")
} }
v.size = &bytesWritten
return nil return nil
} }
@ -157,7 +164,9 @@ func (v *ucbVideo) saveThumbnail() error {
} }
defer resp.Body.Close() defer resp.Body.Close()
creds := credentials.NewStaticCredentials("ID-GOES-HERE", "SECRET-GOES-HERE", "") awsID := os.Getenv("S3_UCB_ACCESS_ID")
awsSecret := os.Getenv("s3_UCB_ACCESS_SECRET")
creds := credentials.NewStaticCredentials(awsID, awsSecret, "")
s, err := session.NewSession(&aws.Config{Region: aws.String("us-east-2"), Credentials: creds}) s, err := session.NewSession(&aws.Config{Region: aws.String("us-east-2"), Credentials: creds})
if err != nil { if err != nil {
return err return err
@ -175,6 +184,7 @@ func (v *ucbVideo) saveThumbnail() error {
} }
func (v *ucbVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *namer.Namer) (*SyncSummary, error) { func (v *ucbVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, namer *namer.Namer) (*SyncSummary, error) {
channelID = "de0fcd76d525b1db36f24523e75c28b542e92fa2" //@UCBerkeley#de0fcd76d525b1db36f24523e75c28b542e92fa2
options := jsonrpc.PublishOptions{ options := jsonrpc.PublishOptions{
Title: &v.title, Title: &v.title,
Author: strPtr("UC Berkeley"), Author: strPtr("UC Berkeley"),
@ -191,7 +201,7 @@ func (v *ucbVideo) publish(daemon *jsonrpc.Client, claimAddress string, amount f
} }
func (v *ucbVideo) Size() *int64 { func (v *ucbVideo) Size() *int64 {
return nil return v.size
} }
func (v *ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, maxVideoSize int, namer *namer.Namer) (*SyncSummary, error) { func (v *ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount float64, channelID string, maxVideoSize int, namer *namer.Namer) (*SyncSummary, error) {
@ -209,9 +219,6 @@ func (v *ucbVideo) Sync(daemon *jsonrpc.Client, claimAddress string, amount floa
//log.Debugln("Created thumbnail for " + v.id) //log.Debugln("Created thumbnail for " + v.id)
summary, err := v.publish(daemon, claimAddress, amount, channelID, namer) summary, err := v.publish(daemon, claimAddress, amount, channelID, namer)
if err != nil {
return nil, errors.Prefix("publish error", err)
}
return summary, nil return summary, errors.Prefix("publish error", err)
} }

View file

@ -52,6 +52,8 @@ func (v *YoutubeVideo) ID() string {
return v.id return v.id
} }
func (v *YoutubeVideo) SetPlaylistPosition(p int) {
}
func (v *YoutubeVideo) PlaylistPosition() int { func (v *YoutubeVideo) PlaylistPosition() int {
return int(v.playlistPosition) return int(v.playlistPosition)
} }

View file

@ -46,6 +46,7 @@ const (
type video interface { type video interface {
Size() *int64 Size() *int64
ID() string ID() string
SetPlaylistPosition(p int)
IDAndNum() string IDAndNum() string
PlaylistPosition() int PlaylistPosition() int
PublishedAt() time.Time PublishedAt() time.Time
@ -497,7 +498,7 @@ func (s *Sync) doSync() error {
}(i) }(i)
} }
if s.LbryChannelName == "@UCBerkeley" { if s.YoutubeChannelID == "UCBerkeleyFakeID12345678" {
err = s.enqueueUCBVideos() err = s.enqueueUCBVideos()
} else { } else {
err = s.enqueueYoutubeVideos() err = s.enqueueYoutubeVideos()
@ -689,7 +690,7 @@ func (s *Sync) enqueueUCBVideos() error {
if err != nil { if err != nil {
return err return err
} }
index := 0
reader := csv.NewReader(bufio.NewReader(csvFile)) reader := csv.NewReader(bufio.NewReader(csvFile))
for { for {
line, err := reader.Read() line, err := reader.Read()
@ -705,13 +706,17 @@ func (s *Sync) enqueueUCBVideos() error {
if err != nil { if err != nil {
return err return err
} }
videos = append(videos, sources.NewUCBVideo(line[0], line[2], line[1], line[3], data.PublishedAt, s.videoDirectory)) videos = append(videos, sources.NewUCBVideo(line[0], line[2], line[1], line[3], data.PublishedAt, s.videoDirectory))
index++
} }
log.Printf("Publishing %d videos\n", len(videos)) vCount := len(videos)
log.Printf("Publishing %d videos\n", vCount)
sort.Sort(byPublishedAt(videos)) sort.Sort(byPublishedAt(videos))
for i, v := range videos {
v.SetPlaylistPosition(vCount - i)
}
Enqueue: Enqueue:
for _, v := range videos { for _, v := range videos {