-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from m1k1o/hls-vod
(WIP) Hls vod
- Loading branch information
Showing
10 changed files
with
1,486 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package hlsvod | ||
|
||
import ( | ||
"crypto/sha1" | ||
"fmt" | ||
"os" | ||
"path" | ||
) | ||
|
||
const cacheFileSuffix = ".go-transcode-cache" | ||
|
||
func (m *ManagerCtx) getCacheData() ([]byte, error) { | ||
// check for local cache | ||
localCachePath := m.config.MediaPath + cacheFileSuffix | ||
if _, err := os.Stat(localCachePath); err == nil { | ||
m.logger.Warn().Str("path", localCachePath).Msg("media local cache hit") | ||
return os.ReadFile(localCachePath) | ||
} | ||
|
||
// check for global cache | ||
h := sha1.New() | ||
h.Write([]byte(m.config.MediaPath)) | ||
hash := h.Sum(nil) | ||
|
||
fileName := fmt.Sprintf("%x%s", hash, cacheFileSuffix) | ||
globalCachePath := path.Join(m.config.CacheDir, fileName) | ||
if _, err := os.Stat(globalCachePath); err == nil { | ||
m.logger.Warn().Str("path", globalCachePath).Msg("media global cache hit") | ||
return os.ReadFile(globalCachePath) | ||
} | ||
|
||
return nil, os.ErrNotExist | ||
} | ||
|
||
func (m *ManagerCtx) saveLocalCacheData(data []byte) error { | ||
localCachePath := m.config.MediaPath + cacheFileSuffix | ||
return os.WriteFile(localCachePath, data, 0755) | ||
} | ||
|
||
func (m *ManagerCtx) saveGlobalCacheData(data []byte) error { | ||
h := sha1.New() | ||
h.Write([]byte(m.config.MediaPath)) | ||
hash := h.Sum(nil) | ||
|
||
fileName := fmt.Sprintf("%x%s", hash, cacheFileSuffix) | ||
globalCachePath := path.Join(m.config.CacheDir, fileName) | ||
return os.WriteFile(globalCachePath, data, 0755) | ||
} |
Oops, something went wrong.