Skip to content

Commit

Permalink
chg: refactor: improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
felipemarinho97 authored and zoriya committed Jan 4, 2025
1 parent eb80ca9 commit 487b7d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
17 changes: 8 additions & 9 deletions transcoder/src/subtitles.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ outer:
Path: &match,
Link: &link,
}
flags := separator.Split(match[len(base_path):], -1)
flags_str := strings.ToLower(match[len(base_path):])
flags := separator.Split(flags_str, -1)

// remove extension from flags
flags = flags[:len(flags)-1]

for _, flag := range flags {
switch strings.ToLower(flag) {
switch flag {
case "default":
sub.IsDefault = true
case "forced":
Expand All @@ -70,13 +72,10 @@ outer:
// "hi" by itself means a language code, but when combined with other lang flags it means Hearing Impaired.
// In case Hindi was not detected before, but "hi" is present, assume it is Hindi.
if sub.Language == nil {
hiCount := 0
for _, flag := range flags {
if strings.EqualFold(flag, "hi") {
hiCount++
langStr := language.Hindi.String()
sub.Language = &langStr
}
hiCount := Count(flags, "hi")
if hiCount > 0 {
languageStr := language.Hindi.String()
sub.Language = &languageStr
}
if hiCount == 1 {
sub.IsHearingImpaired = false
Expand Down
11 changes: 11 additions & 0 deletions transcoder/src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ func Filter[E any](s []E, f func(E) bool) []E {
}
return s2
}

// Count returns the number of elements in s that are equal to e.
func Count[S []E, E comparable](s S, e E) int {
var n int
for _, v := range s {
if v == e {
n++
}
}
return n
}

0 comments on commit 487b7d7

Please sign in to comment.