diff --git a/handlers.go b/handlers.go
index 642533d..c5e2e5f 100644
--- a/handlers.go
+++ b/handlers.go
@@ -132,6 +132,8 @@ func handleSelect(w http.ResponseWriter, r *http.Request) {
continue
}
+ sortItems(items)
+
groupedItems := groupItemsBySeason(items)
allItems[filename] = groupedItems
}
@@ -184,6 +186,7 @@ func handleProcess(w http.ResponseWriter, r *http.Request) {
}
selectedItems := filterSelectedItems(allItems, items)
+ sortItems(selectedItems)
go processItems(filename, selectedItems)
}
diff --git a/templates/select b/templates/select
index 4d9fb3b..9568500 100644
--- a/templates/select
+++ b/templates/select
@@ -50,6 +50,18 @@
button:hover, input[type="submit"]:hover {
background-color: #45a049;
}
+ #fix-order-button {
+ background-color: #2196F3;
+ color: white;
+ border: none;
+ padding: 10px 15px;
+ margin: 5px;
+ border-radius: 4px;
+ cursor: pointer;
+ }
+ #fix-order-button:hover {
+ background-color: #1976D2;
+ }
@@ -59,11 +71,12 @@
{{range $filename, $fileItems := .AllItems}}
{{$filename}}
{{range $season, $items := $fileItems}}
-
+
{{end}}
{{end}}
@@ -94,7 +108,7 @@
}
function toggleSeason(season) {
- var seasonCheckbox = document.getElementById('season-' + season);
+ var seasonCheckbox = document.getElementById('season-checkbox-' + season);
var episodeCheckboxes = document.getElementsByClassName('episode-' + season);
for (var i = 0; i < episodeCheckboxes.length; i++) {
episodeCheckboxes[i].checked = seasonCheckbox.checked;
diff --git a/utils.go b/utils.go
index 42d8733..0282c06 100644
--- a/utils.go
+++ b/utils.go
@@ -9,6 +9,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
+ "sort"
"strconv"
"strings"
"sync"
@@ -196,6 +197,43 @@ func filterSelectedItems(items []Item, selectedItems []string) []Item {
return filtered
}
+func sortItems(items []Item) {
+ sort.Slice(items, func(i, j int) bool {
+ iMeta := parseMetadata(items[i].Metadata)
+ jMeta := parseMetadata(items[j].Metadata)
+
+ if iMeta.Title != jMeta.Title {
+ return iMeta.Title < jMeta.Title
+ }
+
+ iSeason := extractNumber(iMeta.Season)
+ jSeason := extractNumber(jMeta.Season)
+
+ if iSeason != jSeason {
+ return iSeason < jSeason
+ }
+
+ iEpisode := extractEpisodeNumber(items[i].Filename)
+ jEpisode := extractEpisodeNumber(items[j].Filename)
+
+ return iEpisode < jEpisode
+ })
+}
+
+func extractNumber(s string) int {
+ num, _ := strconv.Atoi(strings.TrimLeft(s, "S"))
+ return num
+}
+
+func extractEpisodeNumber(filename string) int {
+ parts := strings.Split(filename, "E")
+ if len(parts) > 1 {
+ num, _ := strconv.Atoi(parts[1])
+ return num
+ }
+ return 0
+}
+
func processItems(filename string, items []Item) error {
jobsMutex.Lock()
jobInfo := &JobInfo{
@@ -215,6 +253,8 @@ func processItems(filename string, items []Item) error {
}
}()
+ sortItems(items)
+
for i := 0; i < len(items); i++ {
select {
case <-jobInfo.AbortChan: