lastfm.liq 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. %ifdef input.lastfm
  2. # Utility to compose last.fm URIs.
  3. # @category String
  4. # @param ~user Lastfm user
  5. # @param ~password Lastfm password
  6. # @param ~discovery Allow lastfm suggestions
  7. # @param radio URI, e.g. user/toots5446/playlist, globaltags/rocksteady.
  8. def lastfm.uri(~user="",~password="",~discovery=false,
  9. radio="globaltags/creative-commons")
  10. auth = if user == "" then "" else "#{user}:#{password}@" end
  11. discovery = if discovery == true then "1" else "0" end
  12. "lastfm://#{auth}#{radio}?discovery=#{discovery}"
  13. end
  14. # Submit metadata to libre.fm using the audioscrobbler protocol.
  15. # @category Interaction
  16. # @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
  17. # @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
  18. def librefm.submit(~user,~password,~source="broadcast",~length=false,m) =
  19. audioscrobbler.submit(user=user,password=password,
  20. source=source,length=length,
  21. host="turtle.libre.fm",port=80,
  22. m)
  23. end
  24. # Submit metadata to lastfm.fm using the audioscrobbler protocol.
  25. # @category Interaction
  26. # @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
  27. # @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
  28. def lastfm.submit(~user,~password,~source="broadcast",~length=false,m) =
  29. audioscrobbler.submit(user=user,password=password,
  30. source=source,length=length,
  31. host="post.audioscrobbler.com",port=80,
  32. m)
  33. end
  34. # Submit metadata to libre.fm using the audioscrobbler protocol (nowplaying mode).
  35. # @category Interaction
  36. # @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
  37. def librefm.nowplaying(~user,~password,~length=false,m) =
  38. audioscrobbler.nowplaying(user=user,password=password,length=length,
  39. host="turtle.libre.fm",port=80,
  40. m)
  41. end
  42. # Submit metadata to lastfm.fm using the audioscrobbler protocol (nowplaying mode).
  43. # @category Interaction
  44. # @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
  45. def lastfm.nowplaying(~user,~password,~length=false,m) =
  46. audioscrobbler.nowplaying(user=user,password=password,length=length,
  47. host="post.audioscrobbler.com",port=80,
  48. m)
  49. end
  50. # Submit songs using audioscrobbler, respecting the full protocol:
  51. # First signal song as now playing when starting, and
  52. # then submit song when it ends.
  53. # @category Interaction
  54. # @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
  55. # @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
  56. # @param ~delay Submit song when there is only this delay left, in seconds.
  57. # @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
  58. def audioscrobbler.submit.full(
  59. ~user,~password,
  60. ~host="post.audioscrobbler.com",~port=80,
  61. ~source="broadcast",~length=false,
  62. ~delay=10.,~force=false,s) =
  63. f = audioscrobbler.nowplaying(
  64. user=user,password=password,
  65. host=host,port=port,length=length)
  66. s = on_metadata(f,s)
  67. f = fun (rem,m) ->
  68. # Avoid skipped songs
  69. if rem > 0. or force then
  70. audioscrobbler.submit(
  71. user=user,password=password,
  72. host=host,port=port,length=length,
  73. source=source,m)
  74. else
  75. log(label="audioscrobbler.submit.full",
  76. level=4,"Remaining time null: \
  77. will not submit song (song skipped ?)")
  78. end
  79. on_end(delay=delay,f,s)
  80. end
  81. # Submit songs to librefm using audioscrobbler, respecting the full protocol:
  82. # First signal song as now playing when starting, and
  83. # then submit song when it ends.
  84. # @category Interaction
  85. # @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
  86. # @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
  87. # @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
  88. # @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
  89. def librefm.submit.full(
  90. ~user,~password,
  91. ~source="broadcast",~length=false,
  92. ~delay=10.,~force=false,s) =
  93. audioscrobbler.submit.full(
  94. user=user,password=password,
  95. source=source,length=length,
  96. host="turtle.libre.fm",port=80,
  97. delay=delay,force=force,s)
  98. end
  99. # Submit songs to lastfm using audioscrobbler, respecting the full protocol:
  100. # First signal song as now playing when starting, and
  101. # then submit song when it ends.
  102. # @category Interaction
  103. # @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
  104. # @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
  105. # @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
  106. # @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
  107. def lastfm.submit.full(
  108. ~user,~password,
  109. ~source="broadcast",~length=false,
  110. ~delay=10.,~force=false,s) =
  111. audioscrobbler.submit.full(
  112. user=user,password=password,
  113. source=source,length=length,
  114. host="post.audioscrobbler.com",port=80,
  115. delay=delay,force=force,s)
  116. end
  117. %endif