Compare commits

...

2 Commits

Author SHA1 Message Date
72889d3083
Sort episodes in a holy way 2024-09-15 04:29:48 +02:00
bd87baa40a
Makefile 2024-09-15 00:34:25 +02:00
4 changed files with 100 additions and 4 deletions

39
Makefile Normal file
View File

@ -0,0 +1,39 @@
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=drmdtool
all: test build
build:
$(GOBUILD) -o $(BINARY_NAME) -v
test:
$(GOTEST) -v ./...
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
run:
$(GOBUILD) -o $(BINARY_NAME) -v
./$(BINARY_NAME)
deps:
$(GOGET) github.com/BurntSushi/toml
$(GOGET) github.com/beevik/etree
$(GOGET) github.com/asticode/go-astisub
# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)_linux -v
build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME).exe -v
build-mac:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)_mac -v
.PHONY: all build test clean run deps build-linux build-windows build-mac

View File

@ -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)
}

View File

@ -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;
}
</style>
</head>
<body>
@ -59,11 +71,12 @@
{{range $filename, $fileItems := .AllItems}}
<h2>{{$filename}}</h2>
{{range $season, $items := $fileItems}}
<div class="season">
<div class="season" id="season-{{$filename}}-{{$season}}">
<div class="season-title">
<input type="checkbox" class="season-checkbox" id="season-{{$filename}}-{{$season}}" checked onchange="toggleSeason('{{$filename}}-{{$season}}')">
<label for="season-{{$filename}}-{{$season}}">{{$season}}</label>
<input type="checkbox" class="season-checkbox" id="season-checkbox-{{$filename}}-{{$season}}" checked onchange="toggleSeason('{{$filename}}-{{$season}}')">
<label for="season-checkbox-{{$filename}}-{{$season}}">{{$season}}</label>
</div>
<div class="season-items">
{{range $item := $items}}
<div class="item">
<label>
@ -72,6 +85,7 @@
</label>
</div>
{{end}}
</div>
</div>
{{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;

View File

@ -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: