- commit
- 23c10d9f4c476a2b1d380096a2e4858274e8309c
- parent
- 189823c3efa08791159c5061d0c08adf0bb595b2
- author
- FelineStateMachine <226808055+FelineStateMachine@users.noreply.github.com>
- kind
- feat risk score 1.8 of 3, Jev's estimate
| M | internal/ | 12 | ++++++++++-- |
| M | internal/ | 21 | ++++++++++++++++++--- |
@@ -70,7 +70,7 @@ func fakeYtDlp(args []string) int {
7070 {"id": "pb2", "title": "B 2", "duration": 3600, "timestamp": now - day},7171 }}7272 case strings.Contains(u, "playlist?list=PLtest00000002"):73- out = map[string]any{"_type": "playlist", "id": "PLtest00000002", "title": "Every Episode", "channel": "Show C", "channel_id": "UCc",73+ out = map[string]any{"_type": "playlist", "id": "PLtest00000002", "title": "Every Episode", "channel": "TheShowC", "channel_id": "UCc",7474 "entries": []map[string]any{7575 {"id": "pc0"},7676 {"id": "pc1", "title": "C 1", "duration": 3600, "timestamp": now - day},@@ -196,7 +196,7 @@ func TestAddStreamsAndPlaylist(t *testing.T) {
196196 if err != nil {197197 t.Fatal(err)198198 }199- if got := ids(c.Episodes); c.Title != "Show C" || !slices.Equal(got, []string{"pc1"}) {199+ if got := ids(c.Episodes); c.Title != "The Show C" || !slices.Equal(got, []string{"pc1"}) {200200 t.Errorf("generic playlist: %q %v", c.Title, got)201201 }202202 }@@ -321,3 +321,11 @@ func TestSearchAndRemove(t *testing.T) {
321321 t.Errorf("remove again: %v", err)322322 }323323 }324+325+func TestSpaced(t *testing.T) {326+ for in, want := range map[string]string{"TheStandupPod": "The Standup Pod", "Sad Boyz": "Sad Boyz", "mkbhd": "mkbhd", "nerd-snipe": "nerd-snipe", "SMN": "SMN"} {327+ if got := spaced(in); got != want {328+ t.Errorf("spaced(%q) = %q, want %q", in, got, want)329+ }330+ }331+}@@ -251,14 +251,29 @@ func (s *show) fits(seconds int, live string, sr src) bool {
251251 252252 // showTitle is what a listing calls the show: a playlist's title, unless253253 // it names no show ("Every Episode", "Full Episodes", "Podcast"), then its254-// channel's name; a channel's name.254+// channel's name; a channel's name. A channel named as a handle is255+// ("TheStandupPod") reads as words ("The Standup Pod").255256 func showTitle(lst youtube.Listing, sr src) string {256257 if sr.playlist && lst.Owner != "" && strings.TrimSpace(generic.ReplaceAllString(lst.Name, "")) == "" {257- return lst.Owner258+ return spaced(lst.Owner)258259 }259- return cmp.Or(lst.Name, lst.Owner)260+ if !sr.playlist {261+ return spaced(lst.Name)262+ }263+ return cmp.Or(lst.Name, spaced(lst.Owner))264+}265+266+// spaced puts spaces between the words of a name written as one267+// ("TheStandupPod"), leaving any other name as it is.268+func spaced(name string) string {269+ if strings.ContainsAny(name, " _-.") || !camel.MatchString(name) {270+ return name271+ }272+ return camel.ReplaceAllString(name, "$1 $2")260273 }261274 275+var camel = regexp.MustCompile(`(\p{Ll})(\p{Lu})`)276+262277 // generic are the words of a playlist's title that say what it holds, not263278 // which show.264279 var generic = regexp.MustCompile(`(?i)\b(the|every|all|full|latest|new|episodes?|podcasts?|shows?|uploads?|videos?)\b|[^\pL\pN]+`)