|
@@ -2,9 +2,11 @@
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Dynamic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
+using System.Reflection.Emit;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
@@ -122,7 +124,7 @@ namespace FNZCM.ConHost.Ver2
|
|
|
var aacTrackSetPath = aacTrackSetName.ToLower();
|
|
|
var aacTrackSet = alb.SubTracks[aacTrackSetPath] = new TrackSet(aacTrackSetName);
|
|
|
|
|
|
- foreach (var file in Directory.GetFiles(aacTrackDir,"*.m4a"))
|
|
|
+ foreach (var file in Directory.GetFiles(aacTrackDir, "*.m4a"))
|
|
|
{
|
|
|
var aacTrackName = Path.GetFileName(file);
|
|
|
var aacTrackPath = aacTrackName.ToLower();
|
|
@@ -211,8 +213,11 @@ namespace FNZCM.ConHost.Ver2
|
|
|
// GET /list/foo/ show all album and cover with name, provide m3u path
|
|
|
// GET /list/foo/bar/bk/ list all picture as grid
|
|
|
// GET /list/foo/bar/tracks/ list all tracks as text list
|
|
|
- // GET /list/foo/bar/playlist.m3u8 auto gen
|
|
|
|
|
|
+ // GET /lib_list/foo/playlist.m3u8 auto gen
|
|
|
+ // GET /lib_list/foo/aac_q1.00/playlist.m3u8 auto gen
|
|
|
+
|
|
|
+ // GET /list/foo/bar/playlist.m3u8 auto gen
|
|
|
// GET /list/foo/bar/aac_q1.00/playlist.m3u8 auto gen
|
|
|
|
|
|
// media streaming HTTP Partial RANGE SUPPORT
|
|
@@ -243,7 +248,7 @@ namespace FNZCM.ConHost.Ver2
|
|
|
|
|
|
sb.Append($"<h2>{ConfigFile.Instance.Title}</h2>");
|
|
|
sb.Append($"<h3>Libraries</h3>");
|
|
|
- sb.Append($"<h4>(Total number of disc: {Libraries.Sum(p=>p.Value.Discs.Count)})</h4>");
|
|
|
+ sb.Append($"<h4>(Total number of disc: {Libraries.Sum(p => p.Value.Discs.Count)})</h4>");
|
|
|
|
|
|
sb.Append("<ul>");
|
|
|
foreach (var library in Libraries.OrderBy(p => p.Key))
|
|
@@ -264,11 +269,11 @@ namespace FNZCM.ConHost.Ver2
|
|
|
else if (pathParts.Count == 2 && pathParts[0] == "list")
|
|
|
{
|
|
|
var libName = pathParts[1];
|
|
|
- if (Libraries.TryGetValue(libName, out var l))
|
|
|
+ if (Libraries.TryGetValue(libName, out var lib))
|
|
|
{
|
|
|
var sb = new StringBuilder();
|
|
|
sb.Append("<!DOCTYPE html><html lang=\"zh-cn\"><meta charset=\"UTF-8\">");
|
|
|
- sb.Append($"<title> Discs of {l.Name} - {ConfigFile.Instance.Title} </title>");
|
|
|
+ sb.Append($"<title> Discs of {lib.Name} - {ConfigFile.Instance.Title} </title>");
|
|
|
sb.Append(
|
|
|
"<style>" +
|
|
|
"a:link{ text-decoration: none; }" +
|
|
@@ -301,11 +306,43 @@ namespace FNZCM.ConHost.Ver2
|
|
|
|
|
|
if (_isLoading) sb.Append("<h4 style=position:fixed;right:0px;top:0px;margin:0>Still Loading...</h4>");
|
|
|
|
|
|
- sb.Append($"<h1>Discs of {l.Name}</h1>");
|
|
|
+ sb.Append($"<h1>Discs of {lib.Name}</h1>");
|
|
|
sb.Append("<div><a href=/>Back to home</a></div>");
|
|
|
|
|
|
+ if (!_isLoading)
|
|
|
+ {
|
|
|
+ sb.Append("<div style=margin-top:1vh;margin-bottom:1vh;>");
|
|
|
+
|
|
|
+ //big m3u8
|
|
|
+ var trackKeys = lib.Discs.SelectMany(p => p.Value.MainTracks.Keys.Select(q => new { DiscName = p.Key, TrackName = q })).ToArray();
|
|
|
+ var totalDur = trackKeys.Sum(p => GetTag($"/media/{libName}/{p.DiscName}/{p.TrackName}", true)?.Duration ?? 0);
|
|
|
+ var totalLen = trackKeys.Sum(p => GetTag($"/media/{libName}/{p.DiscName}/{p.TrackName}", true)?.Length ?? 0);
|
|
|
+
|
|
|
+ sb.Append($"Number of track: {trackKeys.Length}");
|
|
|
+ sb.Append($"<br/>{totalDur.FormatDuration()} {totalLen.FormatFileSize()} <a href=\"/lib_list/{libName}/playlist.m3u8\">ALL_M3U8_MAIN</a>");
|
|
|
+
|
|
|
+ var subTrackSetNames = lib.Discs.SelectMany(p => p.Value.SubTracks.Keys).Distinct().ToArray();
|
|
|
+ foreach (var setName in subTrackSetNames)
|
|
|
+ {
|
|
|
+ trackKeys = lib.Discs.SelectMany(p =>
|
|
|
+ {
|
|
|
+ if (p.Value.SubTracks.TryGetValue(setName, out var tSet))
|
|
|
+ {
|
|
|
+ return tSet.Tracks.Select(q => new { DiscName = p.Key, TrackName = q.Key });
|
|
|
+ }
|
|
|
+ return new string[0].Select(q => new { DiscName = p.Key, TrackName = q });
|
|
|
+ }).ToArray();
|
|
|
+
|
|
|
+ totalDur = trackKeys.Sum(p => GetTag($"/media/{libName}/{p.DiscName}/{setName}/{p.TrackName}", true)?.Duration ?? 0);
|
|
|
+ totalLen = trackKeys.Sum(p => GetTag($"/media/{libName}/{p.DiscName}/{setName}/{p.TrackName}", true)?.Length ?? 0);
|
|
|
+ sb.Append($"<br/>{totalDur.FormatDuration()} {totalLen.FormatFileSize()} <a href=\"/lib_list/{libName}/{setName}/playlist.m3u8\">ALL_M3U8_{setName.ToUpper()}</a>");
|
|
|
+ }
|
|
|
+
|
|
|
+ sb.Append("</div>");
|
|
|
+ }
|
|
|
+
|
|
|
//Cover list
|
|
|
- foreach (var a in l.Discs.OrderByDescending(p => p.Key))
|
|
|
+ foreach (var a in lib.Discs.OrderByDescending(p => p.Key))
|
|
|
{
|
|
|
sb.Append("<div class=item>");
|
|
|
|
|
@@ -449,6 +486,94 @@ namespace FNZCM.ConHost.Ver2
|
|
|
//context.Response.Redirect("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
|
|
}
|
|
|
}
|
|
|
+ else if (pathParts.Count == 3 && pathParts[0] == "lib_list" && pathParts[2] == "playlist.m3u8")
|
|
|
+ {
|
|
|
+ var libName = pathParts[1];
|
|
|
+
|
|
|
+ if (Libraries.TryGetValue(libName, out var lib))
|
|
|
+ {
|
|
|
+ var sb = new StringBuilder();
|
|
|
+ sb.AppendLine("#EXTM3U");
|
|
|
+
|
|
|
+ var prefix = $"{request.Url.GetLeftPart(UriPartial.Scheme | UriPartial.Authority)}";
|
|
|
+
|
|
|
+ foreach (var albKvp in lib.Discs)
|
|
|
+ {
|
|
|
+ var alb = albKvp.Value;
|
|
|
+ var albPath = albKvp.Key;
|
|
|
+
|
|
|
+ var tracks = alb.MainTracks;
|
|
|
+
|
|
|
+ foreach (var track in tracks.OrderBy(p => p.Key))
|
|
|
+ {
|
|
|
+ var mediaTag = GetTag($"/media/{libName}/{albPath}/{track.Key}");
|
|
|
+ if (mediaTag != null)
|
|
|
+ {
|
|
|
+ var coverPath = $"/cover/{libName.FuckVlcAndEscape()}/{albPath.FuckVlcAndEscape()}/cover.jpg";
|
|
|
+ sb.AppendLine($"#EXTINF:{mediaTag.Duration} tvg-logo=\"{prefix + coverPath}\",{mediaTag.Title}");
|
|
|
+ }
|
|
|
+
|
|
|
+ var mediaPath = $"/media/{libName.FuckVlcAndEscape()}/{albPath.FuckVlcAndEscape()}/{track.Key.FuckVlcAndEscape()}";
|
|
|
+ sb.AppendLine(prefix + mediaPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ context.Response.ContentType = "audio/mpegurl";
|
|
|
+ context.Response.ContentEncoding = Encoding.UTF8;
|
|
|
+ context.Response.WriteText(sb.ToString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ context.Response.StatusCode = 404;
|
|
|
+ //context.Response.Redirect("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (pathParts.Count == 4 && pathParts[0] == "lib_list" && pathParts[3] == "playlist.m3u8")
|
|
|
+ {
|
|
|
+ var libName = pathParts[1];
|
|
|
+ var trackSetName = pathParts[2];
|
|
|
+
|
|
|
+ if (Libraries.TryGetValue(libName, out var lib))
|
|
|
+ {
|
|
|
+ var sb = new StringBuilder();
|
|
|
+ sb.AppendLine("#EXTM3U");
|
|
|
+
|
|
|
+ var prefix = $"{request.Url.GetLeftPart(UriPartial.Scheme | UriPartial.Authority)}";
|
|
|
+
|
|
|
+ foreach (var albKvp in lib.Discs)
|
|
|
+ {
|
|
|
+ var alb = albKvp.Value;
|
|
|
+ var albPath = albKvp.Key;
|
|
|
+
|
|
|
+ if (alb.SubTracks.TryGetValue(trackSetName, out var tracksSet))
|
|
|
+ {
|
|
|
+ var tracks = tracksSet.Tracks;
|
|
|
+
|
|
|
+ foreach (var track in tracks.OrderBy(p => p.Key))
|
|
|
+ {
|
|
|
+ var mediaTag = GetTag($"/media/{libName}/{albPath}/{trackSetName}/{track.Key}");
|
|
|
+ if (mediaTag != null)
|
|
|
+ {
|
|
|
+ var coverPath = $"/cover/{libName.FuckVlcAndEscape()}/{albPath.FuckVlcAndEscape()}/cover.jpg";
|
|
|
+ sb.AppendLine($"#EXTINF:{mediaTag.Duration} tvg-logo=\"{prefix + coverPath}\",{mediaTag.Title}");
|
|
|
+ }
|
|
|
+
|
|
|
+ var mediaPath = $"/media/{libName.FuckVlcAndEscape()}/{albPath.FuckVlcAndEscape()}/{track.Key.FuckVlcAndEscape()}";
|
|
|
+ sb.AppendLine(prefix + mediaPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ context.Response.ContentType = "audio/mpegurl";
|
|
|
+ context.Response.ContentEncoding = Encoding.UTF8;
|
|
|
+ context.Response.WriteText(sb.ToString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ context.Response.StatusCode = 404;
|
|
|
+ //context.Response.Redirect("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
|
|
+ }
|
|
|
+ }
|
|
|
else if (pathParts.Count == 4 && pathParts[0] == "list" && pathParts[3] == "playlist.m3u8")
|
|
|
{
|
|
|
var libName = pathParts[1];
|