-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschemep3-scrobble.scm
100 lines (93 loc) · 3.89 KB
/
schemep3-scrobble.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#lang scheme/gui
(require srfi/2)
(require framework)
(require "cwb-scrobble.scm")
(require "schemep3-database.scm")
(require "schemep3-playback.scm")
(require "schemep3-helpers.scm")
(require "schemep3-mixins-gui.scm")
(require "schemep3-frame-console.scm")
(define audioscrobbler-username (preferences-backed-variable 'scrobble-username ""))
(define audioscrobbler-password (preferences-backed-variable 'scrobble-password ""))
(define (scrobble?)
(and (> (string-length (audioscrobbler-username)) 0)
(> (string-length (audioscrobbler-password)) 0)))
(add-pre-play-hook
(lambda (index file-index)
(and-let* (((scrobble?))
(filename (schemep3-database-index->filename file-index))
(artist (schemep3-database-retrieve-field file-index 'artist))
(album (schemep3-database-retrieve-field file-index 'album))
(title (schemep3-database-retrieve-field file-index 'title))
(duration (schemep3-database-retrieve-field file-index 'duration)))
(thread
(lambda ()
(if
(scrobble:now-playing
#:artist artist
#:album album
#:title title
#:duration (inexact->exact duration)
#:username (audioscrobbler-username)
#:password (audioscrobbler-password))
(console:printf "[scrobble] Now Playing Win - ~A~%" filename)
(console:printf "[scrobble] Now Playing Fail - ~A~%" filename)))))))
(add-post-play-hook
(lambda (index file-index elapsed percent)
(and-let* (((scrobble?))
(filename (schemep3-database-index->filename file-index))
(artist (schemep3-database-retrieve-field file-index 'artist))
(album (schemep3-database-retrieve-field file-index 'album))
(title (schemep3-database-retrieve-field file-index 'title))
(duration (schemep3-database-retrieve-field file-index 'duration))
(rating (schemep3-database-retrieve-field file-index 'rating))
((>= percent 50))
((>= elapsed 30)))
(thread
(lambda ()
(if
(scrobble:submit
#:artist artist
#:album album
#:title title
#:love (and rating (> rating 4))
#:duration (inexact->exact duration)
#:username (audioscrobbler-username)
#:password (audioscrobbler-password))
(console:printf "[scrobble] Scrobble Win - ~A~%" filename)
(console:printf "[scrobble] Scrobble Fail - ~A~%" filename)))))))
(preferences:add-panel
"AudioScrobbler"
(lambda (parent)
(let* ((v-panel (new vertical-panel%
(parent parent)))
(username-field
(new (stored-value-mixin text-field%)
(parent v-panel)
(settor-gettor audioscrobbler-username)
(label "Username:")))
(password-field
(new (stored-value-mixin text-field%)
(parent v-panel)
(style '(password single))
(settor-gettor audioscrobbler-password)
(label "Password:")))
(password-2-field
(new text-field%
(parent v-panel)
(init-value (or (audioscrobbler-password) ""))
(style '(password single))
(label "Reenter Password:"))))
(preferences:add-can-close-dialog-callback
(lambda ()
(if (string=?
(send password-field get-value)
(send password-2-field get-value))
#t
(begin
(message-box "Schemep3 Preferences"
"Password fields do not match"
(send v-panel get-top-level-window)
'(ok))
#f))))
v-panel)))