Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom
Commits
24ac7c3e
Commit
24ac7c3e
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
record played songs to the playlog
parent
6842a7e9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/mpd/djmpd/djmpd.go
+3
-1
3 additions, 1 deletion
client/mpd/djmpd/djmpd.go
client/mpd/djrandom.go
+56
-0
56 additions, 0 deletions
client/mpd/djrandom.go
with
59 additions
and
1 deletion
client/mpd/djmpd/djmpd.go
+
3
−
1
View file @
24ac7c3e
...
...
@@ -17,7 +17,9 @@ func main() {
flag
.
Parse
()
db
:=
djmpd
.
NewDJRandomDatabase
()
m
:=
mpd
.
NewMPD
(
mpd
.
NewPortAudioPlayer
(),
db
)
player
:=
mpd
.
NewPortAudioPlayer
()
db
.
SetupPlayRecorder
(
player
)
m
:=
mpd
.
NewMPD
(
player
,
db
)
m
.
HandleURL
(
"djrandom"
,
db
)
log
.
Fatal
(
m
.
ListenAndServe
(
fmt
.
Sprintf
(
":%d"
,
*
port
)))
}
This diff is collapsed.
Click to expand it.
client/mpd/djrandom.go
+
56
−
0
View file @
24ac7c3e
...
...
@@ -2,6 +2,7 @@ package djmpd
import
(
"bytes"
"container/list"
"errors"
"flag"
"fmt"
...
...
@@ -251,3 +252,58 @@ func (d *DJRandomDatabase) GetSong(songURL *url.URL) (mpd.Song, error) {
// Convert api.Song to Song.
return
newDJRandomSong
(
&
resp
,
d
.
client
),
nil
}
func
(
d
*
DJRandomDatabase
)
SetupPlayRecorder
(
player
mpd
.
Player
)
{
rec
:=
newPlayRecorder
(
d
.
client
)
player
.
SetSongPlayedCallback
(
rec
.
SongPlayed
)
}
type
PlayRecorder
struct
{
client
*
util
.
HttpClient
played
*
list
.
List
count
int
size
int
lock
sync
.
Mutex
}
func
newPlayRecorder
(
client
*
util
.
HttpClient
)
*
PlayRecorder
{
return
&
PlayRecorder
{
client
:
client
,
played
:
list
.
New
(),
size
:
5
,
}
}
func
(
r
*
PlayRecorder
)
SongPlayed
(
song
mpd
.
Song
)
{
s
,
ok
:=
song
.
(
*
DJRandomSong
)
if
!
ok
{
return
}
r
.
lock
.
Lock
()
defer
r
.
lock
.
Unlock
()
// songID := s.Id
r
.
played
.
PushBack
(
s
.
Id
)
if
r
.
count
<
r
.
size
{
r
.
count
++
}
else
{
r
.
played
.
Remove
(
r
.
played
.
Front
())
}
var
ids
[]
api
.
SongID
for
e
:=
r
.
played
.
Front
();
e
!=
nil
;
e
=
e
.
Next
()
{
ids
=
append
(
ids
,
e
.
Value
.
(
api
.
SongID
))
}
// Make the HTTP request in a separate goroutine so that we
// don't block on network issues (ignores errors).
go
func
()
{
log
.
Printf
(
"add_playlog: %v"
,
ids
)
req
:=
api
.
AddPlayLogRequest
{
Songs
:
ids
}
var
resp
bool
if
err
:=
r
.
client
.
Post
(
"/api/add_playlog"
,
&
req
,
&
resp
);
err
!=
nil
{
log
.
Printf
(
"add_playlog error: %v"
,
err
)
}
}()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment