Compare commits
2 Commits
2f738413f3
...
72889d3083
Author | SHA1 | Date | |
---|---|---|---|
72889d3083 | |||
bd87baa40a |
39
Makefile
Normal file
39
Makefile
Normal 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
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
40
utils.go
40
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:
|
||||
|
Loading…
Reference in New Issue
Block a user