Procházet zdrojové kódy

Allow specifying playlists separately

Svilen Markov před 5 měsíci
rodič
revize
c583057d45
2 změnil soubory, kde provedl 25 přidání a 7 odebrání
  1. 13 7
      docs/configuration.md
  2. 12 0
      internal/glance/widget-videos.go

+ 13 - 7
docs/configuration.md

@@ -589,6 +589,7 @@ Preview:
 | Name | Type | Required | Default |
 | ---- | ---- | -------- | ------- |
 | channels | array | yes | |
+| playlists | array | no | |
 | limit | integer | no | 25 |
 | style | string | no | horizontal-cards |
 | collapse-after | integer | no | 7 |
@@ -597,13 +598,7 @@ Preview:
 | video-url-template | string | no | https://www.youtube.com/watch?v={VIDEO-ID} |
 
 ##### `channels`
-A list of channel or playlist IDs. To specify a playlist, use the `playlist:` prefix like such:
-
-```yaml
-channels:
-  - playlist:PL8mG-RkN2uTyZZ00ObwZxxoG_nJbs3qec
-  - playlist:PL8mG-RkN2uTxTK4m_Vl2dYR9yE41kRdBg
-```
+A list of channels IDs.
 
 One way of getting the ID of a channel is going to the channel's page and clicking on its description:
 
@@ -613,6 +608,17 @@ Then scroll down and click on "Share channel", then "Copy channel ID":
 
 ![](images/videos-copy-channel-id-example.png)
 
+##### `playlists`
+
+A list of playlist IDs:
+
+```yaml
+- type: videos
+  playlists:
+    - PL8mG-RkN2uTyZZ00ObwZxxoG_nJbs3qec
+    - PL8mG-RkN2uTxTK4m_Vl2dYR9yE41kRdBg
+```
+
 ##### `limit`
 The maximum number of videos to show.
 

+ 12 - 0
internal/glance/widget-videos.go

@@ -28,6 +28,7 @@ type videosWidget struct {
 	CollapseAfter     int       `yaml:"collapse-after"`
 	CollapseAfterRows int       `yaml:"collapse-after-rows"`
 	Channels          []string  `yaml:"channels"`
+	Playlists         []string  `yaml:"playlists"`
 	Limit             int       `yaml:"limit"`
 	IncludeShorts     bool      `yaml:"include-shorts"`
 }
@@ -47,6 +48,17 @@ func (widget *videosWidget) initialize() error {
 		widget.CollapseAfter = 7
 	}
 
+	// A bit cheeky, but from a user's perspective it makes more sense when channels and
+	// playlists are separate things rather than specifying a list of channels and some of
+	// them awkwardly have a "playlist:" prefix
+	if len(widget.Playlists) > 0 {
+		widget.Channels = append(widget.Channels, make([]string, len(widget.Playlists))...)
+
+		for i := range widget.Playlists {
+			widget.Channels[len(widget.Channels)-1+i] = "playlist:" + widget.Playlists[i]
+		}
+	}
+
 	return nil
 }