mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Rename api constants
This commit is contained in:
@@ -70,8 +70,8 @@ func main() {
|
||||
feed := feeds.NewFeedService(
|
||||
feeds.WithIdGen(hashIds),
|
||||
feeds.WithStorage(redis),
|
||||
feeds.WithBuilder(api.Youtube, youtube),
|
||||
feeds.WithBuilder(api.Vimeo, vimeo),
|
||||
feeds.WithBuilder(api.ProviderYoutube, youtube),
|
||||
feeds.WithBuilder(api.ProviderVimeo, vimeo),
|
||||
)
|
||||
|
||||
srv := http.Server{
|
||||
|
@@ -13,37 +13,37 @@ var (
|
||||
type Provider string
|
||||
|
||||
const (
|
||||
Youtube = Provider("youtube")
|
||||
Vimeo = Provider("vimeo")
|
||||
ProviderYoutube = Provider("youtube")
|
||||
ProviderVimeo = Provider("vimeo")
|
||||
)
|
||||
|
||||
type LinkType string
|
||||
|
||||
const (
|
||||
Channel = LinkType("channel")
|
||||
Playlist = LinkType("playlist")
|
||||
User = LinkType("user")
|
||||
Group = LinkType("group")
|
||||
LinkTypeChannel = LinkType("channel")
|
||||
LinkTypePlaylist = LinkType("playlist")
|
||||
LinkTypeUser = LinkType("user")
|
||||
LinkTypeGroup = LinkType("group")
|
||||
)
|
||||
|
||||
type Quality string
|
||||
|
||||
const (
|
||||
HighQuality = Quality("high")
|
||||
LowQuality = Quality("low")
|
||||
QualityHigh = Quality("high")
|
||||
QualityLow = Quality("low")
|
||||
)
|
||||
|
||||
type Format string
|
||||
|
||||
const (
|
||||
AudioFormat = Format("audio")
|
||||
VideoFormat = Format("video")
|
||||
FormatAudio = Format("audio")
|
||||
FormatVideo = Format("video")
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultPageSize = 50
|
||||
DefaultFormat = VideoFormat
|
||||
DefaultQuality = HighQuality
|
||||
DefaultFormat = FormatVideo
|
||||
DefaultQuality = QualityHigh
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
|
@@ -15,7 +15,7 @@ const (
|
||||
func makeEnclosure(feed *api.Feed, id string, lengthInBytes int64) (string, itunes.EnclosureType, int64) {
|
||||
ext := "mp4"
|
||||
contentType := itunes.MP4
|
||||
if feed.Format == api.AudioFormat {
|
||||
if feed.Format == api.FormatAudio {
|
||||
ext = "m4a"
|
||||
contentType = itunes.M4A
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ func (v *VimeoBuilder) selectImage(p *vimeo.Pictures, q api.Quality) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
if q == api.LowQuality {
|
||||
if q == api.QualityLow {
|
||||
return p.Sizes[0].Link
|
||||
} else {
|
||||
return p.Sizes[len(p.Sizes)-1].Link
|
||||
@@ -153,7 +153,7 @@ func (v *VimeoBuilder) queryVideos(getVideos getVideosFunc, podcast *itunes.Podc
|
||||
}
|
||||
|
||||
func (v *VimeoBuilder) Build(feed *api.Feed) (podcast *itunes.Podcast, err error) {
|
||||
if feed.LinkType == api.Channel {
|
||||
if feed.LinkType == api.LinkTypeChannel {
|
||||
if podcast, err = v.queryChannel(feed); err == nil {
|
||||
err = v.queryVideos(v.client.Channels.ListVideo, podcast, feed)
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func (v *VimeoBuilder) Build(feed *api.Feed) (podcast *itunes.Podcast, err error
|
||||
return
|
||||
}
|
||||
|
||||
if feed.LinkType == api.Group {
|
||||
if feed.LinkType == api.LinkTypeGroup {
|
||||
if podcast, err = v.queryGroup(feed); err == nil {
|
||||
err = v.queryVideos(v.client.Groups.ListVideo, podcast, feed)
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func (v *VimeoBuilder) Build(feed *api.Feed) (podcast *itunes.Podcast, err error
|
||||
return
|
||||
}
|
||||
|
||||
if feed.LinkType == api.User {
|
||||
if feed.LinkType == api.LinkTypeUser {
|
||||
if podcast, err = v.queryUser(feed); err == nil {
|
||||
err = v.queryVideos(v.client.Users.ListVideo, podcast, feed)
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ func TestQueryVimeoChannel(t *testing.T) {
|
||||
builder, err := NewVimeoBuilder(context.Background(), vimeoKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
podcast, err := builder.queryChannel(&api.Feed{ItemId: "staffpicks", Quality: api.HighQuality})
|
||||
podcast, err := builder.queryChannel(&api.Feed{ItemId: "staffpicks", Quality: api.QualityHigh})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "https://vimeo.com/channels/staffpicks", podcast.Link)
|
||||
@@ -33,7 +33,7 @@ func TestQueryVimeoGroup(t *testing.T) {
|
||||
builder, err := NewVimeoBuilder(context.Background(), vimeoKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
podcast, err := builder.queryGroup(&api.Feed{ItemId: "motion", Quality: api.HighQuality})
|
||||
podcast, err := builder.queryGroup(&api.Feed{ItemId: "motion", Quality: api.QualityHigh})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "https://vimeo.com/groups/motion", podcast.Link)
|
||||
@@ -48,7 +48,7 @@ func TestQueryVimeoUser(t *testing.T) {
|
||||
builder, err := NewVimeoBuilder(context.Background(), vimeoKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
podcast, err := builder.queryUser(&api.Feed{ItemId: "motionarray", Quality: api.HighQuality})
|
||||
podcast, err := builder.queryUser(&api.Feed{ItemId: "motionarray", Quality: api.QualityHigh})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "https://vimeo.com/motionarray", podcast.Link)
|
||||
|
@@ -37,9 +37,9 @@ type YouTubeBuilder struct {
|
||||
func (yt *YouTubeBuilder) listChannels(linkType api.LinkType, id string) (*youtube.Channel, error) {
|
||||
req := yt.client.Channels.List("id,snippet,contentDetails")
|
||||
|
||||
if linkType == api.Channel {
|
||||
if linkType == api.LinkTypeChannel {
|
||||
req = req.Id(id)
|
||||
} else if linkType == api.User {
|
||||
} else if linkType == api.LinkTypeUser {
|
||||
req = req.ForUsername(id)
|
||||
} else {
|
||||
return nil, errors.New("unsupported link type")
|
||||
@@ -110,7 +110,7 @@ func (yt *YouTubeBuilder) parseDate(s string) (time.Time, error) {
|
||||
func (yt *YouTubeBuilder) selectThumbnail(snippet *youtube.ThumbnailDetails, quality api.Quality) string {
|
||||
// Use high resolution thumbnails for high quality mode
|
||||
// https://github.com/mxpv/Podsync/issues/14
|
||||
if quality == api.HighQuality {
|
||||
if quality == api.QualityHigh {
|
||||
if snippet.Maxres != nil {
|
||||
return snippet.Maxres.Url
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func (yt *YouTubeBuilder) selectThumbnail(snippet *youtube.ThumbnailDetails, qua
|
||||
func (yt *YouTubeBuilder) queryFeed(feed *api.Feed) (*itunes.Podcast, string, error) {
|
||||
now := time.Now()
|
||||
|
||||
if feed.LinkType == api.Channel || feed.LinkType == api.User {
|
||||
if feed.LinkType == api.LinkTypeChannel || feed.LinkType == api.LinkTypeUser {
|
||||
channel, err := yt.listChannels(feed.LinkType, feed.ItemId)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
@@ -142,7 +142,7 @@ func (yt *YouTubeBuilder) queryFeed(feed *api.Feed) (*itunes.Podcast, string, er
|
||||
itemId := channel.ContentDetails.RelatedPlaylists.Uploads
|
||||
|
||||
link := ""
|
||||
if feed.LinkType == api.Channel {
|
||||
if feed.LinkType == api.LinkTypeChannel {
|
||||
link = fmt.Sprintf("https://youtube.com/channel/%s", itemId)
|
||||
} else {
|
||||
link = fmt.Sprintf("https://youtube.com/user/%s", itemId)
|
||||
@@ -165,7 +165,7 @@ func (yt *YouTubeBuilder) queryFeed(feed *api.Feed) (*itunes.Podcast, string, er
|
||||
return &podcast, itemId, nil
|
||||
}
|
||||
|
||||
if feed.LinkType == api.Playlist {
|
||||
if feed.LinkType == api.LinkTypePlaylist {
|
||||
playlist, err := yt.listPlaylists(feed.ItemId, "")
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
@@ -198,14 +198,14 @@ func (yt *YouTubeBuilder) queryFeed(feed *api.Feed) (*itunes.Podcast, string, er
|
||||
// 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
|
||||
func (yt *YouTubeBuilder) getSize(duration int64, feed *api.Feed) int64 {
|
||||
if feed.Format == api.AudioFormat {
|
||||
if feed.Quality == api.HighQuality {
|
||||
if feed.Format == api.FormatAudio {
|
||||
if feed.Quality == api.QualityHigh {
|
||||
return highAudioBytesPerSecond * duration
|
||||
} else {
|
||||
return lowAudioBytesPerSecond * duration
|
||||
}
|
||||
} else {
|
||||
if feed.Quality == api.HighQuality {
|
||||
if feed.Quality == api.QualityHigh {
|
||||
return duration * hdBytesPerSecond
|
||||
} else {
|
||||
return duration * ldBytesPerSecond
|
||||
|
@@ -18,11 +18,11 @@ func TestQueryYTChannel(t *testing.T) {
|
||||
builder, err := NewYouTubeBuilder(ytKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel, err := builder.listChannels(api.Channel, "UC2yTVSttx7lxAOAzx1opjoA")
|
||||
channel, err := builder.listChannels(api.LinkTypeChannel, "UC2yTVSttx7lxAOAzx1opjoA")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "UC2yTVSttx7lxAOAzx1opjoA", channel.Id)
|
||||
|
||||
channel, err = builder.listChannels(api.User, "fxigr1")
|
||||
channel, err = builder.listChannels(api.LinkTypeUser, "fxigr1")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "UCr_fwF-n-2_olTYd-m3n32g", channel.Id)
|
||||
}
|
||||
@@ -36,8 +36,8 @@ func TestBuildYTFeed(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
podcast, err := builder.Build(&api.Feed{
|
||||
Provider: api.Youtube,
|
||||
LinkType: api.Channel,
|
||||
Provider: api.ProviderYoutube,
|
||||
LinkType: api.LinkTypeChannel,
|
||||
ItemId: "UCupvZG-5ko_eiXAupbDfxWw",
|
||||
PageSize: maxYoutubeResults,
|
||||
})
|
||||
|
@@ -46,8 +46,8 @@ func (s *service) CreateFeed(req *api.CreateFeedRequest, identity *api.Identity)
|
||||
|
||||
// Set default fields
|
||||
feed.PageSize = api.DefaultPageSize
|
||||
feed.Format = api.VideoFormat
|
||||
feed.Quality = api.HighQuality
|
||||
feed.Format = api.FormatVideo
|
||||
feed.Quality = api.QualityHigh
|
||||
feed.FeatureLevel = api.DefaultFeatures
|
||||
feed.LastAccess = time.Now().UTC()
|
||||
|
||||
|
@@ -23,14 +23,14 @@ func TestService_CreateFeed(t *testing.T) {
|
||||
s := service{
|
||||
id: id,
|
||||
storage: storage,
|
||||
builders: map[api.Provider]builder{api.Youtube: nil},
|
||||
builders: map[api.Provider]builder{api.ProviderYoutube: nil},
|
||||
}
|
||||
|
||||
req := &api.CreateFeedRequest{
|
||||
URL: "youtube.com/channel/123",
|
||||
PageSize: 50,
|
||||
Quality: api.HighQuality,
|
||||
Format: api.VideoFormat,
|
||||
Quality: api.QualityHigh,
|
||||
Format: api.FormatVideo,
|
||||
}
|
||||
|
||||
hashId, err := s.CreateFeed(req, &api.Identity{})
|
||||
@@ -42,7 +42,7 @@ func TestService_GetFeed(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
feed := &api.Feed{Provider: api.Youtube}
|
||||
feed := &api.Feed{Provider: api.ProviderYoutube}
|
||||
|
||||
storage := NewMockstorageService(ctrl)
|
||||
storage.EXPECT().GetFeed("123").Times(1).Return(feed, nil)
|
||||
@@ -52,7 +52,7 @@ func TestService_GetFeed(t *testing.T) {
|
||||
|
||||
s := service{
|
||||
storage: storage,
|
||||
builders: map[api.Provider]builder{api.Youtube: bld},
|
||||
builders: map[api.Provider]builder{api.ProviderYoutube: bld},
|
||||
}
|
||||
|
||||
_, err := s.GetFeed("123")
|
||||
|
@@ -27,7 +27,7 @@ func parseURL(link string) (*api.Feed, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
feed.Provider = api.Youtube
|
||||
feed.Provider = api.ProviderYoutube
|
||||
feed.LinkType = kind
|
||||
feed.ItemId = id
|
||||
|
||||
@@ -40,7 +40,7 @@ func parseURL(link string) (*api.Feed, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
feed.Provider = api.Vimeo
|
||||
feed.Provider = api.ProviderVimeo
|
||||
feed.LinkType = kind
|
||||
feed.ItemId = id
|
||||
|
||||
@@ -56,7 +56,7 @@ func parseYoutubeURL(parsed *url.URL) (kind api.LinkType, id string, err error)
|
||||
// https://www.youtube.com/playlist?list=PLCB9F975ECF01953C
|
||||
// https://www.youtube.com/watch?v=rbCbho7aLYw&list=PLMpEfaKcGjpWEgNtdnsvLX6LzQL0UC0EM
|
||||
if strings.HasPrefix(path, "/playlist") || strings.HasPrefix(path, "/watch") {
|
||||
kind = api.Playlist
|
||||
kind = api.LinkTypePlaylist
|
||||
|
||||
id = parsed.Query().Get("list")
|
||||
if id != "" {
|
||||
@@ -70,7 +70,7 @@ func parseYoutubeURL(parsed *url.URL) (kind api.LinkType, id string, err error)
|
||||
// - https://www.youtube.com/channel/UC5XPnUk8Vvv_pWslhwom6Og
|
||||
// - https://www.youtube.com/channel/UCrlakW-ewUT8sOod6Wmzyow/videos
|
||||
if strings.HasPrefix(path, "/channel") {
|
||||
kind = api.Channel
|
||||
kind = api.LinkTypeChannel
|
||||
parts := strings.Split(parsed.EscapedPath(), "/")
|
||||
if len(parts) <= 2 {
|
||||
err = errors.New("invalid youtube channel link")
|
||||
@@ -87,7 +87,7 @@ func parseYoutubeURL(parsed *url.URL) (kind api.LinkType, id string, err error)
|
||||
|
||||
// - https://www.youtube.com/user/fxigr1
|
||||
if strings.HasPrefix(path, "/user") {
|
||||
kind = api.User
|
||||
kind = api.LinkTypeUser
|
||||
|
||||
parts := strings.Split(parsed.EscapedPath(), "/")
|
||||
if len(parts) <= 2 {
|
||||
@@ -116,14 +116,14 @@ func parseVimeoURL(parsed *url.URL) (kind api.LinkType, id string, err error) {
|
||||
}
|
||||
|
||||
if parts[1] == "groups" {
|
||||
kind = api.Group
|
||||
kind = api.LinkTypeGroup
|
||||
} else if parts[1] == "channels" {
|
||||
kind = api.Channel
|
||||
kind = api.LinkTypeChannel
|
||||
} else {
|
||||
kind = api.User
|
||||
kind = api.LinkTypeUser
|
||||
}
|
||||
|
||||
if kind == api.Group || kind == api.Channel {
|
||||
if kind == api.LinkTypeGroup || kind == api.LinkTypeChannel {
|
||||
if len(parts) <= 2 {
|
||||
err = errors.New("invalid channel link")
|
||||
return
|
||||
@@ -137,7 +137,7 @@ func parseVimeoURL(parsed *url.URL) (kind api.LinkType, id string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if kind == api.User {
|
||||
if kind == api.LinkTypeUser {
|
||||
id = parts[1]
|
||||
if id == "" {
|
||||
err = errors.New("invalid id")
|
||||
|
@@ -12,13 +12,13 @@ func TestParseYoutubeURL_Playlist(t *testing.T) {
|
||||
link, _ := url.ParseRequestURI("https://www.youtube.com/playlist?list=PLCB9F975ECF01953C")
|
||||
kind, id, err := parseYoutubeURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Playlist, kind)
|
||||
require.Equal(t, api.LinkTypePlaylist, kind)
|
||||
require.Equal(t, "PLCB9F975ECF01953C", id)
|
||||
|
||||
link, _ = url.ParseRequestURI("https://www.youtube.com/watch?v=rbCbho7aLYw&list=PLMpEfaKcGjpWEgNtdnsvLX6LzQL0UC0EM")
|
||||
kind, id, err = parseYoutubeURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Playlist, kind)
|
||||
require.Equal(t, api.LinkTypePlaylist, kind)
|
||||
require.Equal(t, "PLMpEfaKcGjpWEgNtdnsvLX6LzQL0UC0EM", id)
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ func TestParseYoutubeURL_Channel(t *testing.T) {
|
||||
link, _ := url.ParseRequestURI("https://www.youtube.com/channel/UC5XPnUk8Vvv_pWslhwom6Og")
|
||||
kind, id, err := parseYoutubeURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Channel, kind)
|
||||
require.Equal(t, api.LinkTypeChannel, kind)
|
||||
require.Equal(t, "UC5XPnUk8Vvv_pWslhwom6Og", id)
|
||||
|
||||
link, _ = url.ParseRequestURI("https://www.youtube.com/channel/UCrlakW-ewUT8sOod6Wmzyow/videos")
|
||||
kind, id, err = parseYoutubeURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Channel, kind)
|
||||
require.Equal(t, api.LinkTypeChannel, kind)
|
||||
require.Equal(t, "UCrlakW-ewUT8sOod6Wmzyow", id)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestParseYoutubeURL_User(t *testing.T) {
|
||||
link, _ := url.ParseRequestURI("https://youtube.com/user/fxigr1")
|
||||
kind, id, err := parseYoutubeURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.User, kind)
|
||||
require.Equal(t, api.LinkTypeUser, kind)
|
||||
require.Equal(t, "fxigr1", id)
|
||||
}
|
||||
|
||||
@@ -58,25 +58,25 @@ func TestParseVimeoURL_Group(t *testing.T) {
|
||||
link, _ := url.ParseRequestURI("https://vimeo.com/groups/109")
|
||||
kind, id, err := parseVimeoURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Group, kind)
|
||||
require.Equal(t, api.LinkTypeGroup, kind)
|
||||
require.Equal(t, "109", id)
|
||||
|
||||
link, _ = url.ParseRequestURI("http://vimeo.com/groups/109")
|
||||
kind, id, err = parseVimeoURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Group, kind)
|
||||
require.Equal(t, api.LinkTypeGroup, kind)
|
||||
require.Equal(t, "109", id)
|
||||
|
||||
link, _ = url.ParseRequestURI("http://www.vimeo.com/groups/109")
|
||||
kind, id, err = parseVimeoURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Group, kind)
|
||||
require.Equal(t, api.LinkTypeGroup, kind)
|
||||
require.Equal(t, "109", id)
|
||||
|
||||
link, _ = url.ParseRequestURI("https://vimeo.com/groups/109/videos/")
|
||||
kind, id, err = parseVimeoURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Group, kind)
|
||||
require.Equal(t, api.LinkTypeGroup, kind)
|
||||
require.Equal(t, "109", id)
|
||||
}
|
||||
|
||||
@@ -84,13 +84,13 @@ func TestParseVimeoURL_Channel(t *testing.T) {
|
||||
link, _ := url.ParseRequestURI("https://vimeo.com/channels/staffpicks")
|
||||
kind, id, err := parseVimeoURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Channel, kind)
|
||||
require.Equal(t, api.LinkTypeChannel, kind)
|
||||
require.Equal(t, "staffpicks", id)
|
||||
|
||||
link, _ = url.ParseRequestURI("http://vimeo.com/channels/staffpicks/146224925")
|
||||
kind, id, err = parseVimeoURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.Channel, kind)
|
||||
require.Equal(t, api.LinkTypeChannel, kind)
|
||||
require.Equal(t, "staffpicks", id)
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func TestParseVimeoURL_User(t *testing.T) {
|
||||
link, _ := url.ParseRequestURI("https://vimeo.com/awhitelabelproduct")
|
||||
kind, id, err := parseVimeoURL(link)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.User, kind)
|
||||
require.Equal(t, api.LinkTypeUser, kind)
|
||||
require.Equal(t, "awhitelabelproduct", id)
|
||||
}
|
||||
|
||||
|
@@ -25,8 +25,8 @@ func TestCreateFeed(t *testing.T) {
|
||||
req := &api.CreateFeedRequest{
|
||||
URL: "https://youtube.com/channel/123",
|
||||
PageSize: 55,
|
||||
Quality: api.LowQuality,
|
||||
Format: api.AudioFormat,
|
||||
Quality: api.QualityLow,
|
||||
Format: api.FormatAudio,
|
||||
}
|
||||
|
||||
feed := NewMockfeedService(ctrl)
|
||||
|
@@ -10,8 +10,8 @@ import (
|
||||
func TestPgStorage_CreateFeed(t *testing.T) {
|
||||
feed := &api.Feed{
|
||||
HashId: "xyz",
|
||||
Provider: api.Youtube,
|
||||
LinkType: api.Channel,
|
||||
Provider: api.ProviderYoutube,
|
||||
LinkType: api.LinkTypeChannel,
|
||||
ItemId: "123",
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ func TestPgStorage_CreateFeed(t *testing.T) {
|
||||
func TestPgStorage_CreateFeedWithDuplicate(t *testing.T) {
|
||||
feed := &api.Feed{
|
||||
HashId: "123",
|
||||
Provider: api.Youtube,
|
||||
LinkType: api.Channel,
|
||||
Provider: api.ProviderYoutube,
|
||||
LinkType: api.LinkTypeChannel,
|
||||
ItemId: "123",
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ func TestPgStorage_GetFeed(t *testing.T) {
|
||||
feed := &api.Feed{
|
||||
HashId: "xyz",
|
||||
UserId: "123",
|
||||
Provider: api.Youtube,
|
||||
LinkType: api.Channel,
|
||||
Provider: api.ProviderYoutube,
|
||||
LinkType: api.LinkTypeChannel,
|
||||
ItemId: "123",
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ func TestPgStorage_UpdateLastAccess(t *testing.T) {
|
||||
feed := &api.Feed{
|
||||
HashId: "xyz",
|
||||
UserId: "123",
|
||||
Provider: api.Youtube,
|
||||
LinkType: api.Channel,
|
||||
Provider: api.ProviderYoutube,
|
||||
LinkType: api.LinkTypeChannel,
|
||||
ItemId: "123",
|
||||
}
|
||||
|
||||
|
@@ -39,17 +39,17 @@ func (r *RedisStorage) parsePageSize(m map[string]string) (int, error) {
|
||||
func (r *RedisStorage) parseFormat(m map[string]string) (api.Format, api.Quality, error) {
|
||||
quality, ok := m["quality"]
|
||||
if !ok {
|
||||
return api.VideoFormat, api.HighQuality, nil
|
||||
return api.FormatVideo, api.QualityHigh, nil
|
||||
}
|
||||
|
||||
if quality == "VideoHigh" {
|
||||
return api.VideoFormat, api.HighQuality, nil
|
||||
return api.FormatVideo, api.QualityHigh, nil
|
||||
} else if quality == "VideoLow" {
|
||||
return api.VideoFormat, api.LowQuality, nil
|
||||
return api.FormatVideo, api.QualityLow, nil
|
||||
} else if quality == "AudioHigh" {
|
||||
return api.AudioFormat, api.HighQuality, nil
|
||||
return api.FormatAudio, api.QualityHigh, nil
|
||||
} else if quality == "AudioLow" {
|
||||
return api.AudioFormat, api.LowQuality, nil
|
||||
return api.FormatAudio, api.QualityLow, nil
|
||||
}
|
||||
|
||||
return "", "", fmt.Errorf("unsupported formmat %s", quality)
|
||||
@@ -87,27 +87,27 @@ func (r *RedisStorage) GetFeed(hashId string) (*api.Feed, error) {
|
||||
provider := m["provider"]
|
||||
linkType := m["type"]
|
||||
if strings.EqualFold(provider, "youtube") {
|
||||
feed.Provider = api.Youtube
|
||||
feed.Provider = api.ProviderYoutube
|
||||
|
||||
if strings.EqualFold(linkType, "channel") {
|
||||
feed.LinkType = api.Channel
|
||||
feed.LinkType = api.LinkTypeChannel
|
||||
} else if strings.EqualFold(linkType, "playlist") {
|
||||
feed.LinkType = api.Playlist
|
||||
feed.LinkType = api.LinkTypePlaylist
|
||||
} else if strings.EqualFold(linkType, "user") {
|
||||
feed.LinkType = api.User
|
||||
feed.LinkType = api.LinkTypeUser
|
||||
} else {
|
||||
return nil, fmt.Errorf("unsupported yt link type %s", linkType)
|
||||
}
|
||||
|
||||
} else if strings.EqualFold(provider, "vimeo") {
|
||||
feed.Provider = api.Vimeo
|
||||
feed.Provider = api.ProviderVimeo
|
||||
|
||||
if strings.EqualFold(linkType, "channel") {
|
||||
feed.LinkType = api.Channel
|
||||
feed.LinkType = api.LinkTypeChannel
|
||||
} else if strings.EqualFold(linkType, "user") {
|
||||
feed.LinkType = api.User
|
||||
feed.LinkType = api.LinkTypeUser
|
||||
} else if strings.EqualFold(linkType, "group") {
|
||||
feed.LinkType = api.Group
|
||||
feed.LinkType = api.LinkTypeGroup
|
||||
} else {
|
||||
return nil, fmt.Errorf("unsupported vimeo link type %s", linkType)
|
||||
}
|
||||
@@ -162,9 +162,9 @@ func (r *RedisStorage) CreateFeed(feed *api.Feed) error {
|
||||
"pagesize": feed.PageSize,
|
||||
}
|
||||
|
||||
if feed.Format == api.VideoFormat {
|
||||
if feed.Format == api.FormatVideo {
|
||||
|
||||
if feed.Quality == api.HighQuality {
|
||||
if feed.Quality == api.QualityHigh {
|
||||
fields["quality"] = "VideoHigh"
|
||||
} else {
|
||||
fields["quality"] = "VideoLow"
|
||||
@@ -172,7 +172,7 @@ func (r *RedisStorage) CreateFeed(feed *api.Feed) error {
|
||||
|
||||
} else {
|
||||
|
||||
if feed.Quality == api.HighQuality {
|
||||
if feed.Quality == api.QualityHigh {
|
||||
fields["quality"] = "AudioHigh"
|
||||
} else {
|
||||
fields["quality"] = "AudioLow"
|
||||
|
@@ -40,12 +40,12 @@ func TestRedisStorage_CreateFeed(t *testing.T) {
|
||||
err := client.CreateFeed(&api.Feed{
|
||||
HashId: hashId,
|
||||
UserId: "321",
|
||||
Provider: api.Youtube,
|
||||
LinkType: api.Channel,
|
||||
Provider: api.ProviderYoutube,
|
||||
LinkType: api.LinkTypeChannel,
|
||||
ItemId: "123",
|
||||
PageSize: 45,
|
||||
Quality: api.LowQuality,
|
||||
Format: api.AudioFormat,
|
||||
Quality: api.QualityLow,
|
||||
Format: api.FormatAudio,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
@@ -55,12 +55,12 @@ func TestRedisStorage_CreateFeed(t *testing.T) {
|
||||
|
||||
require.Equal(t, hashId, feed.HashId)
|
||||
require.Equal(t, "321", feed.UserId)
|
||||
require.Equal(t, api.Youtube, feed.Provider)
|
||||
require.Equal(t, api.Channel, feed.LinkType)
|
||||
require.Equal(t, api.ProviderYoutube, feed.Provider)
|
||||
require.Equal(t, api.LinkTypeChannel, feed.LinkType)
|
||||
require.Equal(t, "123", feed.ItemId)
|
||||
require.Equal(t, 45, feed.PageSize)
|
||||
require.Equal(t, api.LowQuality, feed.Quality)
|
||||
require.Equal(t, api.AudioFormat, feed.Format)
|
||||
require.Equal(t, api.QualityLow, feed.Quality)
|
||||
require.Equal(t, api.FormatAudio, feed.Format)
|
||||
}
|
||||
|
||||
func createRedisClient(t *testing.T) *RedisStorage {
|
||||
|
Reference in New Issue
Block a user