Sort episodes in a holy way
This commit is contained in:
parent
bd87baa40a
commit
72889d3083
@ -132,6 +132,8 @@ func handleSelect(w http.ResponseWriter, r *http.Request) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortItems(items)
|
||||||
|
|
||||||
groupedItems := groupItemsBySeason(items)
|
groupedItems := groupItemsBySeason(items)
|
||||||
allItems[filename] = groupedItems
|
allItems[filename] = groupedItems
|
||||||
}
|
}
|
||||||
@ -184,6 +186,7 @@ func handleProcess(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectedItems := filterSelectedItems(allItems, items)
|
selectedItems := filterSelectedItems(allItems, items)
|
||||||
|
sortItems(selectedItems)
|
||||||
go processItems(filename, selectedItems)
|
go processItems(filename, selectedItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,18 @@
|
|||||||
button:hover, input[type="submit"]:hover {
|
button:hover, input[type="submit"]:hover {
|
||||||
background-color: #45a049;
|
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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -59,11 +71,12 @@
|
|||||||
{{range $filename, $fileItems := .AllItems}}
|
{{range $filename, $fileItems := .AllItems}}
|
||||||
<h2>{{$filename}}</h2>
|
<h2>{{$filename}}</h2>
|
||||||
{{range $season, $items := $fileItems}}
|
{{range $season, $items := $fileItems}}
|
||||||
<div class="season">
|
<div class="season" id="season-{{$filename}}-{{$season}}">
|
||||||
<div class="season-title">
|
<div class="season-title">
|
||||||
<input type="checkbox" class="season-checkbox" id="season-{{$filename}}-{{$season}}" checked onchange="toggleSeason('{{$filename}}-{{$season}}')">
|
<input type="checkbox" class="season-checkbox" id="season-checkbox-{{$filename}}-{{$season}}" checked onchange="toggleSeason('{{$filename}}-{{$season}}')">
|
||||||
<label for="season-{{$filename}}-{{$season}}">{{$season}}</label>
|
<label for="season-checkbox-{{$filename}}-{{$season}}">{{$season}}</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="season-items">
|
||||||
{{range $item := $items}}
|
{{range $item := $items}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<label>
|
<label>
|
||||||
@ -73,6 +86,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
<div>
|
<div>
|
||||||
@ -94,7 +108,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toggleSeason(season) {
|
function toggleSeason(season) {
|
||||||
var seasonCheckbox = document.getElementById('season-' + season);
|
var seasonCheckbox = document.getElementById('season-checkbox-' + season);
|
||||||
var episodeCheckboxes = document.getElementsByClassName('episode-' + season);
|
var episodeCheckboxes = document.getElementsByClassName('episode-' + season);
|
||||||
for (var i = 0; i < episodeCheckboxes.length; i++) {
|
for (var i = 0; i < episodeCheckboxes.length; i++) {
|
||||||
episodeCheckboxes[i].checked = seasonCheckbox.checked;
|
episodeCheckboxes[i].checked = seasonCheckbox.checked;
|
||||||
|
40
utils.go
40
utils.go
@ -9,6 +9,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -196,6 +197,43 @@ func filterSelectedItems(items []Item, selectedItems []string) []Item {
|
|||||||
return filtered
|
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 {
|
func processItems(filename string, items []Item) error {
|
||||||
jobsMutex.Lock()
|
jobsMutex.Lock()
|
||||||
jobInfo := &JobInfo{
|
jobInfo := &JobInfo{
|
||||||
@ -215,6 +253,8 @@ func processItems(filename string, items []Item) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
sortItems(items)
|
||||||
|
|
||||||
for i := 0; i < len(items); i++ {
|
for i := 0; i < len(items); i++ {
|
||||||
select {
|
select {
|
||||||
case <-jobInfo.AbortChan:
|
case <-jobInfo.AbortChan:
|
||||||
|
Loading…
Reference in New Issue
Block a user