diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c4f19fc..74b65c0 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,6 @@ # Release Notes -## 0.16.16 - 2018-12-15 +## 0.16.17 - 2018-12-15 * Update to ASP.NET 2.2 ## 0.15.11 - 2018-11-05 diff --git a/src/Client/ReleaseNotes.fs b/src/Client/ReleaseNotes.fs index ecfa6f2..8862a84 100644 --- a/src/Client/ReleaseNotes.fs +++ b/src/Client/ReleaseNotes.fs @@ -1,13 +1,13 @@ module internal ReleaseNotes -let Version = "0.16.16" +let Version = "0.16.17" let IsPrerelease = false let Notes = """ # Release Notes -## 0.16.16 - 2018-12-15 +## 0.16.17 - 2018-12-15 * Update to ASP.NET 2.2 ## 0.15.11 - 2018-11-05 diff --git a/src/Server/Server.fs b/src/Server/Server.fs index d1f21e2..e8e17ff 100644 --- a/src/Server/Server.fs +++ b/src/Server/Server.fs @@ -57,6 +57,45 @@ let mapBlobMusikTag (tag:Tag) = task { | _ -> return tag } + +let discoverYoutubeLink (youtubeURL:string) = task { + let lines = System.Collections.Generic.List<_>() + let proc = new Process () + let startInfo = new ProcessStartInfo() + startInfo.FileName <- "/usr/local/bin/youtube-dl" + startInfo.Arguments <- sprintf " -g \"%s\"" youtubeURL + startInfo.UseShellExecute <- false + startInfo.RedirectStandardOutput <- true + startInfo.RedirectStandardError <- true + startInfo.CreateNoWindow <- true + proc.StartInfo <- startInfo + + proc.Start() |> ignore + + while not proc.StandardOutput.EndOfStream do + let! line = proc.StandardOutput.ReadLineAsync() + lines.Add line + + while not proc.StandardError.EndOfStream do + let! line = proc.StandardError.ReadLineAsync() + lines.Add line + + let lines = Seq.toArray lines + let links = + lines + |> Array.filter (fun x -> x.Contains "&mime=audio") + + return youtubeURL,links +} + +let mapYoutube (tag:Tag) = task { + match tag.Action with + | TagAction.PlayYoutube url -> + let! _,links = discoverYoutubeLink url + return { tag with Action = TagAction.PlayMusik links.[0] } + | _ -> return tag +} + let uploadEndpoint (token:string) = pipeline { set_header "Content-Type" "application/json" @@ -138,44 +177,7 @@ let firmwareEndpoint = } -let discoverYoutubeLink (youtubeURL:string) = task { - let lines = System.Collections.Generic.List<_>() - let proc = new Process () - let startInfo = new ProcessStartInfo() - startInfo.FileName <- "/usr/local/bin/youtube-dl" - startInfo.Arguments <- sprintf " -g \"%s\"" youtubeURL - startInfo.UseShellExecute <- false - startInfo.RedirectStandardOutput <- true - startInfo.RedirectStandardError <- true - startInfo.CreateNoWindow <- true - proc.StartInfo <- startInfo - - proc.Start() |> ignore - - while not proc.StandardOutput.EndOfStream do - let! line = proc.StandardOutput.ReadLineAsync() - lines.Add line - while not proc.StandardError.EndOfStream do - let! line = proc.StandardError.ReadLineAsync() - lines.Add line - - let lines = Seq.toArray lines - let links = - lines - |> Array.filter (fun x -> x.Contains "&mime=audio") - - return youtubeURL,links -} - -let discoverEndpoint (url) = - pipeline { - set_header "Content-Type" "application/json" - plug (fun next ctx -> task { - let! tag = discoverYoutubeLink url - return! setBodyFromString (sprintf "%A" tag) next ctx - }) - } let tagHistoryBroadcaster = ConnectionManager() @@ -193,7 +195,6 @@ let webApp = postf "/api/upload/%s" uploadEndpoint get "/api/startup" startupEndpoint get "/api/firmware" firmwareEndpoint - get "/api/discover" (discoverEndpoint "https://www.youtube.com/watch?v=kfSlg3HtaSw") get "/api/latestfirmware" getLatestFirmware getf "/api/taghistorysocket/%s" (TagHistorySocket.openSocket tagHistoryBroadcaster) }