1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Rename database package

This commit is contained in:
Maksym Pavlenko
2017-08-05 18:35:52 -07:00
parent 23ea998147
commit 402ac4cde7
11 changed files with 35 additions and 35 deletions

View File

@ -4,7 +4,7 @@ import (
"fmt"
itunes "github.com/mxpv/podcast"
"github.com/mxpv/podsync/web/pkg/database"
"github.com/mxpv/podsync/web/pkg/storage"
)
const (
@ -22,10 +22,10 @@ const (
linkTypeGroup
)
func makeEnclosure(feed *database.Feed, id string, lengthInBytes int64) (string, itunes.EnclosureType, int64) {
func makeEnclosure(feed *storage.Feed, id string, lengthInBytes int64) (string, itunes.EnclosureType, int64) {
ext := "mp4"
contentType := itunes.MP4
if feed.Format == database.AudioFormat {
if feed.Format == storage.AudioFormat {
ext = "mp3"
contentType = itunes.MP3
}

View File

@ -8,7 +8,7 @@ import (
"strings"
itunes "github.com/mxpv/podcast"
"github.com/mxpv/podsync/web/pkg/database"
"github.com/mxpv/podsync/web/pkg/storage"
"github.com/pkg/errors"
"github.com/silentsokolov/go-vimeo"
"golang.org/x/net/context"
@ -77,19 +77,19 @@ func (v *VimeoBuilder) parseUrl(link string) (kind linkType, id string, err erro
return
}
func (v *VimeoBuilder) selectImage(p *vimeo.Pictures, q database.Quality) string {
func (v *VimeoBuilder) selectImage(p *vimeo.Pictures, q storage.Quality) string {
if p == nil || len(p.Sizes) < 1 {
return ""
}
if q == database.LowQuality {
if q == storage.LowQuality {
return p.Sizes[0].Link
} else {
return p.Sizes[len(p.Sizes)-1].Link
}
}
func (v *VimeoBuilder) queryChannel(channelId string, feed *database.Feed) (*itunes.Podcast, error) {
func (v *VimeoBuilder) queryChannel(channelId string, feed *storage.Feed) (*itunes.Podcast, error) {
ch, resp, err := v.client.Channels.Get(channelId)
if err != nil {
return nil, errors.Wrapf(err, "failed to query channel with channelId %s", channelId)
@ -109,7 +109,7 @@ func (v *VimeoBuilder) queryChannel(channelId string, feed *database.Feed) (*itu
return &podcast, nil
}
func (v *VimeoBuilder) queryGroup(groupId string, feed *database.Feed) (*itunes.Podcast, error) {
func (v *VimeoBuilder) queryGroup(groupId string, feed *storage.Feed) (*itunes.Podcast, error) {
gr, resp, err := v.client.Groups.Get(groupId)
if err != nil {
return nil, errors.Wrapf(err, "failed to query group with id %s", groupId)
@ -129,7 +129,7 @@ func (v *VimeoBuilder) queryGroup(groupId string, feed *database.Feed) (*itunes.
return &podcast, nil
}
func (v *VimeoBuilder) queryUser(userId string, feed *database.Feed) (*itunes.Podcast, error) {
func (v *VimeoBuilder) queryUser(userId string, feed *storage.Feed) (*itunes.Podcast, error) {
user, resp, err := v.client.Users.Get(userId)
if err != nil {
return nil, errors.Wrapf(err, "failed to query user with id %s", userId)
@ -156,7 +156,7 @@ func (v *VimeoBuilder) getVideoSize(video *vimeo.Video) int64 {
type queryVideosFunc func(id string, opt *vimeo.ListVideoOptions) ([]*vimeo.Video, *vimeo.Response, error)
func (v *VimeoBuilder) queryVideos(queryVideos queryVideosFunc, id string, podcast *itunes.Podcast, feed *database.Feed) error {
func (v *VimeoBuilder) queryVideos(queryVideos queryVideosFunc, id string, podcast *itunes.Podcast, feed *storage.Feed) error {
opt := vimeo.ListVideoOptions{}
opt.Page = 1
opt.PerPage = vimeoDefaultPageSize
@ -207,7 +207,7 @@ func (v *VimeoBuilder) queryVideos(queryVideos queryVideosFunc, id string, podca
}
}
func (v *VimeoBuilder) Build(feed *database.Feed) (podcast *itunes.Podcast, err error) {
func (v *VimeoBuilder) Build(feed *storage.Feed) (podcast *itunes.Podcast, err error) {
kind, id, err := v.parseUrl(feed.URL)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse link: %s", feed.URL)

View File

@ -7,13 +7,13 @@ import (
"context"
itunes "github.com/mxpv/podcast"
"github.com/mxpv/podsync/web/pkg/database"
"github.com/mxpv/podsync/web/pkg/storage"
"github.com/stretchr/testify/require"
)
var (
vimeoKey = os.Getenv("VIMEO_TEST_API_KEY")
defaultFeed = &database.Feed{Quality: database.HighQuality}
defaultFeed = &storage.Feed{Quality: storage.HighQuality}
)
func TestParseVimeoGroupLink(t *testing.T) {
@ -125,7 +125,7 @@ func TestQueryVimeoVideos(t *testing.T) {
feed := &itunes.Podcast{}
err = builder.queryVideos(builder.client.Channels.ListVideo, "staffpicks", feed, &database.Feed{})
err = builder.queryVideos(builder.client.Channels.ListVideo, "staffpicks", feed, &storage.Feed{})
require.NoError(t, err)
require.Equal(t, vimeoDefaultPageSize, len(feed.Items))

View File

@ -9,7 +9,7 @@ import (
"github.com/BrianHicks/finch/duration"
itunes "github.com/mxpv/podcast"
"github.com/mxpv/podsync/web/pkg/database"
"github.com/mxpv/podsync/web/pkg/storage"
"github.com/pkg/errors"
"google.golang.org/api/youtube/v3"
)
@ -170,10 +170,10 @@ func (yt *YouTubeBuilder) parseDate(s string) (time.Time, error) {
return date, nil
}
func (yt *YouTubeBuilder) selectThumbnail(snippet *youtube.ThumbnailDetails, quality database.Quality) string {
func (yt *YouTubeBuilder) selectThumbnail(snippet *youtube.ThumbnailDetails, quality storage.Quality) string {
// Use high resolution thumbnails for high quality mode
// https://github.com/mxpv/Podsync/issues/14
if quality == database.HighQuality {
if quality == storage.HighQuality {
if snippet.Maxres != nil {
return snippet.Maxres.Url
}
@ -190,7 +190,7 @@ func (yt *YouTubeBuilder) selectThumbnail(snippet *youtube.ThumbnailDetails, qua
return snippet.Default.Url
}
func (yt *YouTubeBuilder) queryFeed(kind linkType, id string, feed *database.Feed) (*itunes.Podcast, string, error) {
func (yt *YouTubeBuilder) queryFeed(kind linkType, id string, feed *storage.Feed) (*itunes.Podcast, string, error) {
now := time.Now()
if kind == linkTypeChannel || kind == linkTypeUser {
@ -255,7 +255,7 @@ func (yt *YouTubeBuilder) queryFeed(kind linkType, id string, feed *database.Fee
return nil, "", errors.New("unsupported link format")
}
func (yt *YouTubeBuilder) getVideoSize(definition string, duration int64, fmt database.Format) int64 {
func (yt *YouTubeBuilder) getVideoSize(definition string, duration int64, fmt storage.Format) int64 {
// Video size information requires 1 additional call for each video (1 feed = 50 videos = 50 calls),
// which is too expensive, so get approximated size depending on duration and definition params
var size int64 = 0
@ -268,14 +268,14 @@ func (yt *YouTubeBuilder) getVideoSize(definition string, duration int64, fmt da
// Some podcasts are coming in with exactly double the actual runtime and with the second half just silence.
// https://github.com/mxpv/Podsync/issues/6
if fmt == database.AudioFormat {
if fmt == storage.AudioFormat {
size /= 2
}
return size
}
func (yt *YouTubeBuilder) queryVideoDescriptions(ids []string, feed *database.Feed, podcast *itunes.Podcast) error {
func (yt *YouTubeBuilder) queryVideoDescriptions(ids []string, feed *storage.Feed, podcast *itunes.Podcast) error {
req, err := yt.client.Videos.List("id,snippet,contentDetails").Id(strings.Join(ids, ",")).Do(yt.key)
if err != nil {
return errors.Wrap(err, "failed to query video descriptions")
@ -329,7 +329,7 @@ func (yt *YouTubeBuilder) queryVideoDescriptions(ids []string, feed *database.Fe
return nil
}
func (yt *YouTubeBuilder) queryItems(itemId string, feed *database.Feed, podcast *itunes.Podcast) error {
func (yt *YouTubeBuilder) queryItems(itemId string, feed *storage.Feed, podcast *itunes.Podcast) error {
pageToken := ""
count := 0
@ -361,7 +361,7 @@ func (yt *YouTubeBuilder) queryItems(itemId string, feed *database.Feed, podcast
}
}
func (yt *YouTubeBuilder) Build(feed *database.Feed) (*itunes.Podcast, error) {
func (yt *YouTubeBuilder) Build(feed *storage.Feed) (*itunes.Podcast, error) {
kind, id, err := yt.parseUrl(feed.URL)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse link: %s", feed.URL)

View File

@ -5,7 +5,7 @@ import (
"os"
"github.com/mxpv/podsync/web/pkg/database"
"github.com/mxpv/podsync/web/pkg/storage"
"github.com/stretchr/testify/require"
)
@ -78,7 +78,7 @@ func TestBuildYTFeed(t *testing.T) {
builder, err := NewYouTubeBuilder(ytKey)
require.NoError(t, err)
podcast, err := builder.Build(&database.Feed{
podcast, err := builder.Build(&storage.Feed{
URL: "https://youtube.com/channel/UCupvZG-5ko_eiXAupbDfxWw",
PageSize: maxYoutubeResults,
})

View File

@ -3,7 +3,7 @@ package id
import (
"hash/fnv"
"github.com/mxpv/podsync/web/pkg/database"
"github.com/mxpv/podsync/web/pkg/storage"
hd "github.com/speps/go-hashids"
)
@ -23,7 +23,7 @@ func hashString(s string) int {
return int(h.Sum32())
}
func (h *hashId) Encode(feed *database.Feed) (string, error) {
func (h *hashId) Encode(feed *storage.Feed) (string, error) {
// Don't create duplicate urls for same playlist/settings
// https://github.com/podsync/issues/issues/6
numbers := []int{

View File

@ -3,7 +3,7 @@ package id
import (
"testing"
"github.com/mxpv/podsync/web/pkg/database"
"github.com/mxpv/podsync/web/pkg/storage"
"github.com/stretchr/testify/require"
)
@ -11,12 +11,12 @@ func TestEncode(t *testing.T) {
hid, err := NewIdGenerator()
require.NoError(t, err)
feed := &database.Feed{
feed := &storage.Feed{
UserId: "1",
URL: "https://www.youtube.com/channel/UC2yTVSttx7lxAOAzx1opjoA",
PageSize: 10,
Quality: database.HighQuality,
Format: database.AudioFormat,
Quality: storage.HighQuality,
Format: storage.AudioFormat,
}
hash1, err := hid.Encode(feed)

View File

@ -1,4 +1,4 @@
package database
package storage
import "time"

View File

@ -1,4 +1,4 @@
package database
package storage
import (
"log"

View File

@ -1,4 +1,4 @@
package database
package storage
const installScript = `
BEGIN;

View File

@ -1,4 +1,4 @@
package database
package storage
import (
"testing"