From b646c841be59500c02d90c3a3ae8203b6bbc6234 Mon Sep 17 00:00:00 2001 From: Romain Beauxis Date: Mon, 9 Dec 2024 17:39:43 -0600 Subject: [PATCH] Remove external lastfm. --- dune-project | 2 - liquidsoap-core.opam | 2 - src/config/lastfm_option.disabled.ml | 1 - src/config/lastfm_option.enabled.ml | 1 - src/core/builtins/builtins_lastfm.ml | 110 ----------- src/core/builtins/builtins_optionals.ml | 1 - src/core/dune | 14 -- src/core/tools/liqfm.ml | 244 ------------------------ src/runtime/build_config.ml | 1 - 9 files changed, 376 deletions(-) delete mode 120000 src/config/lastfm_option.disabled.ml delete mode 120000 src/config/lastfm_option.enabled.ml delete mode 100644 src/core/builtins/builtins_lastfm.ml delete mode 100644 src/core/tools/liqfm.ml diff --git a/dune-project b/dune-project index b1f1a11f16..7b1be7b7f6 100644 --- a/dune-project +++ b/dune-project @@ -83,7 +83,6 @@ jemalloc ladspa lame - lastfm lilv lo mad @@ -123,7 +122,6 @@ (inotify (< 1.0)) (ladspa (< 0.2.0)) (lame (< 0.3.7)) - (lastfm (< 0.3.4)) (lo (< 0.2.0)) (mad (< 0.5.0)) (magic (< 0.6)) diff --git a/liquidsoap-core.opam b/liquidsoap-core.opam index 9f33a5b40e..6a75736720 100644 --- a/liquidsoap-core.opam +++ b/liquidsoap-core.opam @@ -48,7 +48,6 @@ depopts: [ "jemalloc" "ladspa" "lame" - "lastfm" "lilv" "lo" "mad" @@ -89,7 +88,6 @@ conflicts: [ "inotify" {< "1.0"} "ladspa" {< "0.2.0"} "lame" {< "0.3.7"} - "lastfm" {< "0.3.4"} "lo" {< "0.2.0"} "mad" {< "0.5.0"} "magic" {< "0.6"} diff --git a/src/config/lastfm_option.disabled.ml b/src/config/lastfm_option.disabled.ml deleted file mode 120000 index 370c3e56d3..0000000000 --- a/src/config/lastfm_option.disabled.ml +++ /dev/null @@ -1 +0,0 @@ -noop.disabled.ml \ No newline at end of file diff --git a/src/config/lastfm_option.enabled.ml b/src/config/lastfm_option.enabled.ml deleted file mode 120000 index 34bd7cbe43..0000000000 --- a/src/config/lastfm_option.enabled.ml +++ /dev/null @@ -1 +0,0 @@ -noop.enabled.ml \ No newline at end of file diff --git a/src/core/builtins/builtins_lastfm.ml b/src/core/builtins/builtins_lastfm.ml deleted file mode 100644 index dd743b3b09..0000000000 --- a/src/core/builtins/builtins_lastfm.ml +++ /dev/null @@ -1,110 +0,0 @@ -(***************************************************************************** - - Liquidsoap, a programmable stream generator. - Copyright 2003-2024 Savonet team - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details, fully stated in the COPYING - file at the root of the liquidsoap distribution. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - *****************************************************************************) - -let audioscrobbler = Lang.add_module "audioscrobbler" -let log = Log.make ["lastfm"; "submit"] - -let () = - let f name stype descr = - let proto = - [ - ("user", Lang.string_t, None, None); - ("password", Lang.string_t, None, None); - ( "host", - Lang.string_t, - Some (Lang.string !Liqfm.Audioscrobbler.base_host), - Some "Host for audioscrobbling submissions." ); - ( "port", - Lang.int_t, - Some (Lang.int !Liqfm.Audioscrobbler.base_port), - Some "Port for audioscrobbling submissions." ); - ( "length", - Lang.bool_t, - Some (Lang.bool false), - Some - "Try to submit length information. This operation can be CPU \ - intensive. Value forced to true when used with the \"user\" \ - source type." ); - ("", Lang.metadata_t, None, None); - ] - in - let proto = - if stype = Liqfm.Played then - ( "source", - Lang.string_t, - Some (Lang.string "broadcast"), - Some - "Source for tracks. Should be one of: \"broadcast\", \"user\", \ - \"recommendation\" or \"unknown\". Since liquidsoap is intended \ - for radio broadcasting, this is the default. Sources other than \ - user don't need duration to be set." ) - :: proto - else proto - in - let tasks = Hashtbl.create 1 in - ignore - (Lang.add_builtin ~base:audioscrobbler name - ~category:`Interaction (* TODO better cat *) ~descr proto Lang.unit_t - (fun p -> - let user = Lang.to_string (List.assoc "user" p) in - let password = Lang.to_string (List.assoc "password" p) in - let metas = Lang.to_metadata (Lang.assoc "" 1 p) in - let host = Lang.to_string (List.assoc "host" p) in - let port = Lang.to_int (List.assoc "port" p) in - let host = (host, port) in - let mode = - if stype = Liqfm.Played then ( - match Lang.to_string (List.assoc "source" p) with - | "broadcast" -> Liqfm.Broadcast - | "user" -> Liqfm.User - | "recommendation" -> Liqfm.Recommendation - | "unknown" -> Liqfm.Unknown - | _ -> - raise - (Error.Invalid_value - ( List.assoc "source" p, - "unknown lastfm submission mode" ))) - else Liqfm.Unknown - in - let length = Lang.to_bool (List.assoc "length" p) in - let length = - if length = false && mode = Liqfm.User then ( - log#severe - "length information is required for \"user\" sources, setting \ - to true."; - true) - else length - in - let task = - try Hashtbl.find tasks host - with Not_found -> - let t = Liqfm.init host in - Hashtbl.replace tasks host t; - t - in - Liqfm.submit (user, password) task length mode stype [metas]; - Lang.unit)) - in - f "submit" Liqfm.Played - "Submit a played song using the audioscrobbler protocol."; - f "nowplaying" Liqfm.NowPlaying - "Submit a now playing song using the audioscrobbler protocol." diff --git a/src/core/builtins/builtins_optionals.ml b/src/core/builtins/builtins_optionals.ml index 8544b6532f..bf0cee5700 100644 --- a/src/core/builtins/builtins_optionals.ml +++ b/src/core/builtins/builtins_optionals.ml @@ -28,7 +28,6 @@ let () = ("irc", Irc_option.enabled); ("ladspa", Ladspa_option.enabled); ("lame", Lame_option.enabled); - ("lastfm", Lastfm_option.enabled); ("lilv", Lilv_option.enabled); ("lo", Lo_option.enabled); ("mad", Mad_option.enabled); diff --git a/src/core/dune b/src/core/dune index 6933405e89..111931789c 100644 --- a/src/core/dune +++ b/src/core/dune @@ -465,14 +465,6 @@ (optional) (modules lame_encoder)) -(library - (name liquidsoap_lastfm) - (libraries lastfm liquidsoap_core) - (library_flags -linkall) - (wrapped false) - (optional) - (modules builtins_lastfm liqfm)) - (library (name liquidsoap_lilv) (libraries lilv liquidsoap_core) @@ -737,7 +729,6 @@ jemalloc_option ladspa_option lame_option - lastfm_option lilv_option lo_option mad_option @@ -858,11 +849,6 @@ from (liquidsoap_lame -> lame_option.enabled.ml) (-> lame_option.disabled.ml)) - (select - lastfm_option.ml - from - (liquidsoap_lastfm -> lastfm_option.enabled.ml) - (-> lastfm_option.disabled.ml)) (select lilv_option.ml from diff --git a/src/core/tools/liqfm.ml b/src/core/tools/liqfm.ml deleted file mode 100644 index d4c0eeddad..0000000000 --- a/src/core/tools/liqfm.ml +++ /dev/null @@ -1,244 +0,0 @@ -(***************************************************************************** - - Liquidsoap, a programmable stream generator. - Copyright 2003-2024 Savonet team - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details, fully stated in the COPYING - file at the root of the liquidsoap distribution. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - *****************************************************************************) - -(* A custom implementation of HTTP - * requests. *) -module Liq_http = struct - type request = Get | Post of string - - exception Http of string - - let exc_of_exc = function - | Http s -> Http s - | e -> Http (Printexc.to_string e) - - (* This in unused for now.. *) - let default_timeout = ref 50. - - let request ?timeout ?headers ?(port = 80) ~host ~url ~request () = - try - let timeout = - match timeout with None -> !default_timeout | Some t -> t - in - let mk_read s = - let buf = Buffer.create 10 in - Buffer.add_string buf s; - fun len -> - let len = min (Buffer.length buf) len in - let ret = Buffer.sub buf 0 len in - Utils.buffer_drop buf len; - ret - in - let request = - match request with - | Get -> `Get - | Post s -> `Post (Some (Int64.of_int (String.length s)), mk_read s) - in - let url = Printf.sprintf "http://%s:%d%s" host port url in - let data = Buffer.create 1024 in - let x, code, y, _ = - Liqcurl.http_request ?headers ~pos:[] ~follow_redirect:true - ~on_body_data:(Buffer.add_string data) - ~timeout:(Some (int_of_float (timeout *. 1000.))) - ~url ~request () - in - if code <> 200 then - raise (Http (Printf.sprintf "Http request failed: %s %i %s" x code y)); - Buffer.contents data - with e -> raise (exc_of_exc e) -end - -module Audioscrobbler = Lastfm_generic.Audioscrobbler_generic (Liq_http) - -let error_translator = function - | Audioscrobbler.Error x -> - Some - (Printf.sprintf "Audioscrobbler error: %s" - (Audioscrobbler.string_of_error x)) - | _ -> None - -let () = Printexc.register_printer error_translator - -open Lastfm_generic -open Audioscrobbler - -type source = User | Lastfm | Broadcast | Recommendation | Unknown -type submission = NowPlaying | Played - -type task = { - task : Duppy.Async.t; - submit_m : Mutex.t; - submissions : - (string * string * source * submission * bool * Frame.metadata) Queue.t; -} - -let log = Log.make ["audioscrobbler"] - -exception Duration - -let client = { client = "lsp"; version = "0.1" } - -let init host = - (* The list of waiting submissions *) - let submissions = Queue.create () in - (* A mutex to manage thread concurrency *) - let submit_m = Mutex.create () in - let reason s = log#important "Lastfm Submission failed: %s" s in - (* Define a new task *) - let do_submit () = - try - (* This function checks that the submission is valid *) - let song songs (user, password, (source : source), stype, length, m) = - let login = { user; password } in - let f x = try Frame.Metadata.find x m with Not_found -> "" in - let artist, track = (f "artist", f "title") in - let s = - match stype with Played -> "submit" | NowPlaying -> "nowplaying" - in - let h, p = host in - log#info "Submitting %s -- %s with mode: %s to %s:%i" artist track s h p; - try - let duration () = - try - match float_of_string_opt (Frame.Metadata.find "duration" m) with - | Some d -> d - | None -> raise Not_found - with Not_found -> ( - let exception Bad_rid in - try - let rid = - match int_of_string_opt (Frame.Metadata.find "rid" m) with - | Some rid -> rid - | None -> raise Bad_rid - in - let request = Request.from_id rid in - match request with - | Some s -> ( - match Request.get_filename s with - | Some file -> ( - match - Request.duration ~metadata:(Request.metadata s) - file - with - | Some f -> f - | None -> raise Not_found) - | None -> raise Not_found) - | None -> raise Not_found - with - | Not_found -> raise Duration - | Bad_rid -> - log#severe "Metadata 'rid' is not associated to an integer!"; - raise Duration) - in - let duration = - if length then ( - try Some (duration ()) - with Duration -> if source = User then raise Duration else None) - else if source <> User then None - else raise Duration - in - let time = Unix.time () in - let trackauth = - (* Only when source is lasftm *) - match source with - | Lastfm -> Some (f "lastfm:trackauth") - | _ -> None - in - let source = - match source with - | User -> Audioscrobbler.User - | Lastfm -> Audioscrobbler.Lastfm - | Broadcast -> Audioscrobbler.Broadcast - | Recommendation -> Audioscrobbler.Recommendation - | Unknown -> Audioscrobbler.Unknown - in - let song = - { - artist; - track; - time = Some time; - source = Some source; - rating = None; - length = duration; - album = Some (f "album"); - tracknumber = None; - musicbrainzid = None; - trackauth; - } - in - check_song song Submit; - (login, stype, song) :: songs - with - | Duration -> - log#info "could not submit track %s -- %s, no duration available" - artist track; - songs - | Error e -> - log#info "could not submit track %s -- %s, %s" artist track - (string_of_error e); - songs - | e -> - log#info "could not submit track %s -- %s: unknown error %s" - artist track (Printexc.to_string e); - songs - in - Mutex.lock submit_m; - let songs = Queue.fold song [] submissions in - Queue.clear submissions; - Mutex.unlock submit_m; - let submit = Hashtbl.create 10 in - let filter (c, t, m) = - try - let v = Hashtbl.find submit (c, t) in - Hashtbl.replace submit (c, t) (m :: v) - with Not_found -> Hashtbl.replace submit (c, t) [m] - in - List.iter filter songs; - let f (login, (stype : submission)) songs = - try - match stype with - | NowPlaying -> - List.iter - (fun song -> Audioscrobbler.do_np ~host client login song) - songs - | Played -> - ignore (Audioscrobbler.do_submit ~host client login songs) - with Audioscrobbler.Error e -> - reason (Audioscrobbler.string_of_error e) - in - Hashtbl.iter f submit; - -1. - with e -> - reason (Printexc.to_string e); - -1. - in - let task = Duppy.Async.add ~priority:`Blocking Tutils.scheduler do_submit in - { task; submit_m; submissions } - -let submit (user, password) task length source stype songs = - let songs = - List.map (fun x -> (user, password, source, stype, length, x)) songs - in - Mutex.lock task.submit_m; - List.iter (fun x -> Queue.add x task.submissions) songs; - Mutex.unlock task.submit_m; - Duppy.Async.wake_up task.task diff --git a/src/runtime/build_config.ml b/src/runtime/build_config.ml index 20495b0da7..206dfbacde 100644 --- a/src/runtime/build_config.ml +++ b/src/runtime/build_config.ml @@ -121,7 +121,6 @@ let build_config = - inotify : %{Inotify_option.detected} - irc : %{Irc_option.detected} - jemalloc : %{Jemalloc_option.detected} - - lastfm : %{Lastfm_option.detected} - lo : %{Lo_option.detected} - memtrace : %{Memtrace_option.detected} - osc : %{Osc_option.detected}