No known key found for this signature in database
GPG Key ID: B9918E382ED08059
4 changed files with
39 additions and
34 deletions
-
DirectoryIndexers/DirectoryIndexer.go
-
DirectoryIndexers/MetadataParser.go
-
PageHandlers/View.go
-
main.go
|
|
@ -66,42 +66,13 @@ func Index(path string, results chan FileList) { |
|
|
|
|
|
|
|
id := filenameToID(video.Name()) |
|
|
|
|
|
|
|
videoObject := VideoFile{ |
|
|
|
Filename: video.Name(), |
|
|
|
Extension: extension, |
|
|
|
Title: filenameToTitle(video.Name(), extension), |
|
|
|
Id: id, |
|
|
|
} |
|
|
|
|
|
|
|
metadataFilename := strings.TrimSuffix(video.Name(), filepath.Ext(video.Name())) + ".info.json" |
|
|
|
jsonMetadataFile, err := os.Open(path + metadataFilename) |
|
|
|
if err != nil { |
|
|
|
FL.Lock() |
|
|
|
FL.Files[id] = videoObject |
|
|
|
FL.Unlock() |
|
|
|
wg.Done() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
metadataBytes, _ := ioutil.ReadAll(jsonMetadataFile) |
|
|
|
_ = jsonMetadataFile.Close() |
|
|
|
|
|
|
|
metadata, err := ParseMetadata(metadataBytes) |
|
|
|
if err != nil { |
|
|
|
FL.Lock() |
|
|
|
FL.Files[id] = videoObject |
|
|
|
FL.Unlock() |
|
|
|
wg.Done() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
FL.Lock() |
|
|
|
FL.Files[id] = VideoFile{ |
|
|
|
Filename: video.Name(), |
|
|
|
Extension: extension, |
|
|
|
Title: filenameToTitle(video.Name(), extension), |
|
|
|
Id: id, |
|
|
|
Metadata: metadata, |
|
|
|
Metadata: Metadata{}, |
|
|
|
} |
|
|
|
FL.Unlock() |
|
|
|
|
|
|
|
|
|
@ -3,6 +3,10 @@ package DirectoryIndexers |
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
|
|
|
|
type Metadata struct { |
|
|
@ -50,3 +54,21 @@ func ParseMetadata(jsonBytes []byte) (Metadata, error) { |
|
|
|
} |
|
|
|
return meta, err |
|
|
|
} |
|
|
|
|
|
|
|
func LoadMetadata(videoobject VideoFile, path string) (Metadata, error) { |
|
|
|
metadataFilename := strings.TrimSuffix(videoobject.Filename, filepath.Ext(videoobject.Filename)) + ".info.json" |
|
|
|
jsonMetadataFile, err := os.Open(path + metadataFilename) |
|
|
|
if err != nil { |
|
|
|
return Metadata{}, err |
|
|
|
} |
|
|
|
|
|
|
|
metadataBytes, _ := ioutil.ReadAll(jsonMetadataFile) |
|
|
|
_ = jsonMetadataFile.Close() |
|
|
|
|
|
|
|
metadata, err := ParseMetadata(metadataBytes) |
|
|
|
if err != nil { |
|
|
|
return Metadata{}, err |
|
|
|
} |
|
|
|
|
|
|
|
return metadata, nil |
|
|
|
} |
|
|
|
|
|
@ -5,6 +5,7 @@ import ( |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"net/http" |
|
|
|
"reflect" |
|
|
|
"ytdlp-viewer/DirectoryIndexers" |
|
|
|
) |
|
|
|
|
|
|
@ -16,9 +17,9 @@ type ViewPageData struct { |
|
|
|
Metadata DirectoryIndexers.Metadata |
|
|
|
} |
|
|
|
|
|
|
|
func View(writer http.ResponseWriter, request *http.Request, FL *DirectoryIndexers.FileList) { |
|
|
|
FL.RLock() |
|
|
|
defer FL.RUnlock() |
|
|
|
func View(writer http.ResponseWriter, request *http.Request, FL *DirectoryIndexers.FileList, path string) { |
|
|
|
FL.Lock() |
|
|
|
defer FL.Unlock() |
|
|
|
|
|
|
|
keys, ok := request.URL.Query()["id"] |
|
|
|
if !ok || len(keys[0]) < 1 { |
|
|
@ -30,6 +31,17 @@ func View(writer http.ResponseWriter, request *http.Request, FL *DirectoryIndexe |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// if no metadata loaded, do so
|
|
|
|
if reflect.ValueOf(FL.Files[keys[0]].Metadata).IsZero() { |
|
|
|
metadata, err := DirectoryIndexers.LoadMetadata(FL.Files[keys[0]], path) |
|
|
|
if err == nil { |
|
|
|
var fileObject DirectoryIndexers.VideoFile |
|
|
|
fileObject = FL.Files[keys[0]] |
|
|
|
fileObject.Metadata = metadata |
|
|
|
FL.Files[keys[0]] = fileObject |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
video := FL.Files[keys[0]] |
|
|
|
data := ViewPageData{ |
|
|
|
Title: video.Title, |
|
|
|
|
|
@ -50,7 +50,7 @@ func main() { |
|
|
|
}) |
|
|
|
http.HandleFunc("/view", func(writer http.ResponseWriter, request *http.Request) { |
|
|
|
fmt.Println(time.Now().String(),request.URL) |
|
|
|
PageHandlers.View(writer, request, &FL) |
|
|
|
PageHandlers.View(writer, request, &FL, path) |
|
|
|
}) |
|
|
|
http.Handle("/videos/", http.StripPrefix("/videos/", http.FileServer(http.Dir(path)))) |
|
|
|
|
|
|
|