Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
910dd499
Commit
910dd499
authored
Jan 12, 2008
by
Rafaël Carré
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
audioscrobbler: use exclusively mdate() for time-related purposes
parent
d21bf97e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
26 deletions
+22
-26
modules/misc/audioscrobbler.c
modules/misc/audioscrobbler.c
+22
-26
No files found.
modules/misc/audioscrobbler.c
View file @
910dd499
...
@@ -30,10 +30,6 @@
...
@@ -30,10 +30,6 @@
* Preamble
* Preamble
*****************************************************************************/
*****************************************************************************/
#if defined( WIN32 )
#include <time.h>
#endif
#include <vlc/vlc.h>
#include <vlc/vlc.h>
#include <vlc_interface.h>
#include <vlc_interface.h>
#include <vlc_meta.h>
#include <vlc_meta.h>
...
@@ -58,7 +54,7 @@ typedef struct audioscrobbler_song_t
...
@@ -58,7 +54,7 @@ typedef struct audioscrobbler_song_t
char
*
psz_n
;
/**< track number */
char
*
psz_n
;
/**< track number */
int
i_l
;
/**< track length */
int
i_l
;
/**< track length */
char
*
psz_m
;
/**< musicbrainz id */
char
*
psz_m
;
/**< musicbrainz id */
time_t
date
;
/**< date since epoch */
mtime_t
date
;
/**< date since epoch */
}
audioscrobbler_song_t
;
}
audioscrobbler_song_t
;
struct
intf_sys_t
struct
intf_sys_t
...
@@ -69,7 +65,7 @@ struct intf_sys_t
...
@@ -69,7 +65,7 @@ struct intf_sys_t
vlc_mutex_t
lock
;
/**< p_sys mutex */
vlc_mutex_t
lock
;
/**< p_sys mutex */
/* data about audioscrobbler session */
/* data about audioscrobbler session */
time_t
next_exchange
;
/**< when can we send data */
mtime_t
next_exchange
;
/**< when can we send data */
unsigned
int
i_interval
;
/**< waiting interval (secs)*/
unsigned
int
i_interval
;
/**< waiting interval (secs)*/
/* submission of played songs */
/* submission of played songs */
...
@@ -89,8 +85,8 @@ struct intf_sys_t
...
@@ -89,8 +85,8 @@ struct intf_sys_t
/* data about song currently playing */
/* data about song currently playing */
audioscrobbler_song_t
p_current_song
;
/**< song being played */
audioscrobbler_song_t
p_current_song
;
/**< song being played */
time_t
time_pause
;
/**< time when vlc paused */
mtime_t
time_pause
;
/**< time when vlc paused */
time_t
time_total_pauses
;
/**< total time in pause */
mtime_t
time_total_pauses
;
/**< total time in pause */
vlc_bool_t
b_submit
;
/**< do we have to submit ? */
vlc_bool_t
b_submit
;
/**< do we have to submit ? */
...
@@ -116,7 +112,7 @@ static int Handshake ( intf_thread_t * );
...
@@ -116,7 +112,7 @@ static int Handshake ( intf_thread_t * );
static
int
ReadMetaData
(
intf_thread_t
*
);
static
int
ReadMetaData
(
intf_thread_t
*
);
static
void
DeleteSong
(
audioscrobbler_song_t
*
);
static
void
DeleteSong
(
audioscrobbler_song_t
*
);
static
int
ParseURL
(
char
*
,
char
**
,
char
**
,
int
*
);
static
int
ParseURL
(
char
*
,
char
**
,
char
**
,
int
*
);
static
void
HandleInterval
(
time_t
*
,
unsigned
int
*
);
static
void
HandleInterval
(
m
time_t
*
,
unsigned
int
*
);
/*****************************************************************************
/*****************************************************************************
* Module descriptor
* Module descriptor
...
@@ -266,10 +262,9 @@ static void Run( intf_thread_t *p_intf )
...
@@ -266,10 +262,9 @@ static void Run( intf_thread_t *p_intf )
{
{
/* waiting for data to submit, if waiting interval is elapsed */
/* waiting for data to submit, if waiting interval is elapsed */
vlc_object_lock
(
p_intf
);
vlc_object_lock
(
p_intf
);
if
(
time
(
NULL
)
<
p_sys
->
next_exchange
)
if
(
mdate
(
)
<
p_sys
->
next_exchange
)
{
{
mtime_t
deadline
=
(
mtime_t
)
p_sys
->
next_exchange
*
(
mtime_t
)
1000000
;
b_die
=
(
vlc_object_timedwait
(
p_intf
,
p_sys
->
next_exchange
)
<
0
);
b_die
=
(
vlc_object_timedwait
(
p_intf
,
deadline
)
<
0
);
}
}
else
else
b_die
=
vlc_object_wait
(
p_intf
);
b_die
=
vlc_object_wait
(
p_intf
);
...
@@ -281,7 +276,7 @@ static void Run( intf_thread_t *p_intf )
...
@@ -281,7 +276,7 @@ static void Run( intf_thread_t *p_intf )
return
;
return
;
}
}
/* we are signaled each time there is a song to submit */
/* we are signaled each time there is a song to submit */
else
if
(
time
(
NULL
)
<
p_sys
->
next_exchange
)
else
if
(
mdate
(
)
<
p_sys
->
next_exchange
)
continue
;
continue
;
/* handshake if needed */
/* handshake if needed */
...
@@ -310,7 +305,7 @@ static void Run( intf_thread_t *p_intf )
...
@@ -310,7 +305,7 @@ static void Run( intf_thread_t *p_intf )
msg_Dbg
(
p_intf
,
"Handshake successfull :)"
);
msg_Dbg
(
p_intf
,
"Handshake successfull :)"
);
p_sys
->
b_handshaked
=
VLC_TRUE
;
p_sys
->
b_handshaked
=
VLC_TRUE
;
p_sys
->
i_interval
=
0
;
p_sys
->
i_interval
=
0
;
time
(
&
p_sys
->
next_exchange
);
p_sys
->
next_exchange
=
mdate
(
);
break
;
break
;
case
VLC_AUDIOSCROBBLER_EFATAL
:
case
VLC_AUDIOSCROBBLER_EFATAL
:
...
@@ -349,7 +344,7 @@ static void Run( intf_thread_t *p_intf )
...
@@ -349,7 +344,7 @@ static void Run( intf_thread_t *p_intf )
"&l%%5B%d%%5D=%d&b%%5B%d%%5D=%s"
"&l%%5B%d%%5D=%d&b%%5B%d%%5D=%s"
"&n%%5B%d%%5D=%s&m%%5B%d%%5D=%s"
,
"&n%%5B%d%%5D=%s&m%%5B%d%%5D=%s"
,
i_song
,
p_song
->
psz_a
,
i_song
,
p_song
->
psz_t
,
i_song
,
p_song
->
psz_a
,
i_song
,
p_song
->
psz_t
,
i_song
,
(
uintmax_t
)
p_song
->
date
,
i_song
,
i_song
,
i_song
,
(
uintmax_t
)
(
p_song
->
date
/
1000000
)
,
i_song
,
i_song
,
i_song
,
p_song
->
i_l
,
i_song
,
p_song
->
psz_b
,
i_song
,
p_song
->
i_l
,
i_song
,
p_song
->
psz_b
,
i_song
,
p_song
->
psz_n
,
i_song
,
p_song
->
psz_m
i_song
,
p_song
->
psz_n
,
i_song
,
p_song
->
psz_m
)
)
)
)
...
@@ -438,7 +433,7 @@ static void Run( intf_thread_t *p_intf )
...
@@ -438,7 +433,7 @@ static void Run( intf_thread_t *p_intf )
DeleteSong
(
&
p_sys
->
p_queue
[
i
]
);
DeleteSong
(
&
p_sys
->
p_queue
[
i
]
);
p_sys
->
i_songs
=
0
;
p_sys
->
i_songs
=
0
;
p_sys
->
i_interval
=
0
;
p_sys
->
i_interval
=
0
;
time
(
&
p_sys
->
next_exchange
);
p_sys
->
next_exchange
=
mdate
(
);
msg_Dbg
(
p_intf
,
"Submission successful!"
);
msg_Dbg
(
p_intf
,
"Submission successful!"
);
}
}
else
else
...
@@ -476,9 +471,9 @@ static int PlayingChange( vlc_object_t *p_this, const char *psz_var,
...
@@ -476,9 +471,9 @@ static int PlayingChange( vlc_object_t *p_this, const char *psz_var,
return
VLC_ENOMEM
;
return
VLC_ENOMEM
;
}
}
else
if
(
oldval
.
i_int
==
PLAYING_S
&&
newval
.
i_int
==
PAUSE_S
)
else
if
(
oldval
.
i_int
==
PLAYING_S
&&
newval
.
i_int
==
PAUSE_S
)
time
(
&
p_sys
->
time_pause
);
p_sys
->
time_pause
=
mdate
(
);
else
if
(
oldval
.
i_int
==
PAUSE_S
&&
newval
.
i_int
==
PLAYING_S
)
else
if
(
oldval
.
i_int
==
PAUSE_S
&&
newval
.
i_int
==
PLAYING_S
)
p_sys
->
time_total_pauses
+=
time
(
NULL
)
-
p_sys
->
time_pause
;
p_sys
->
time_total_pauses
+=
(
mdate
()
-
p_sys
->
time_pause
)
;
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
}
}
...
@@ -537,7 +532,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
...
@@ -537,7 +532,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
}
}
p_sys
->
time_total_pauses
=
0
;
p_sys
->
time_total_pauses
=
0
;
time
(
&
p_sys
->
p_current_song
.
date
);
p_sys
->
p_current_song
.
date
=
mdate
(
);
var_AddCallback
(
p_input
,
"state"
,
PlayingChange
,
p_intf
);
var_AddCallback
(
p_input
,
"state"
,
PlayingChange
,
p_intf
);
p_sys
->
b_state_cb
=
VLC_TRUE
;
p_sys
->
b_state_cb
=
VLC_TRUE
;
...
@@ -556,7 +551,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
...
@@ -556,7 +551,7 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
*****************************************************************************/
*****************************************************************************/
static
int
AddToQueue
(
intf_thread_t
*
p_this
)
static
int
AddToQueue
(
intf_thread_t
*
p_this
)
{
{
time_t
played_time
;
mtime_t
played_time
;
intf_sys_t
*
p_sys
=
p_this
->
p_sys
;
intf_sys_t
*
p_sys
=
p_this
->
p_sys
;
vlc_mutex_lock
(
&
p_sys
->
lock
);
vlc_mutex_lock
(
&
p_sys
->
lock
);
...
@@ -568,9 +563,10 @@ static int AddToQueue ( intf_thread_t *p_this )
...
@@ -568,9 +563,10 @@ static int AddToQueue ( intf_thread_t *p_this )
}
}
/* wait for the user to listen enough before submitting */
/* wait for the user to listen enough before submitting */
time
(
&
played_time
);
played_time
=
mdate
(
);
played_time
-=
p_sys
->
p_current_song
.
date
;
played_time
-=
p_sys
->
p_current_song
.
date
;
played_time
-=
p_sys
->
time_total_pauses
;
played_time
-=
p_sys
->
time_total_pauses
;
played_time
/=
1000000
;
/* µs → s */
if
(
(
played_time
<
240
)
&&
if
(
(
played_time
<
240
)
&&
(
played_time
<
(
p_sys
->
p_current_song
.
i_l
/
2
)
)
)
(
played_time
<
(
p_sys
->
p_current_song
.
i_l
/
2
)
)
)
{
{
...
@@ -696,7 +692,7 @@ static int ParseURL( char *psz_url, char **psz_host, char **psz_file,
...
@@ -696,7 +692,7 @@ static int ParseURL( char *psz_url, char **psz_host, char **psz_file,
static
int
Handshake
(
intf_thread_t
*
p_this
)
static
int
Handshake
(
intf_thread_t
*
p_this
)
{
{
char
*
psz_username
,
*
psz_password
;
char
*
psz_username
,
*
psz_password
;
time_t
timestamp
;
mtime_t
timestamp
;
char
psz_timestamp
[
33
];
char
psz_timestamp
[
33
];
struct
md5_s
p_struct_md5
;
struct
md5_s
p_struct_md5
;
...
@@ -731,7 +727,7 @@ static int Handshake( intf_thread_t *p_this )
...
@@ -731,7 +727,7 @@ static int Handshake( intf_thread_t *p_this )
return
VLC_ENOVAR
;
return
VLC_ENOVAR
;
}
}
time
(
&
timestamp
);
time
stamp
=
mdate
(
);
/* generates a md5 hash of the password */
/* generates a md5 hash of the password */
InitMD5
(
&
p_struct_md5
);
InitMD5
(
&
p_struct_md5
);
...
@@ -747,7 +743,7 @@ static int Handshake( intf_thread_t *p_this )
...
@@ -747,7 +743,7 @@ static int Handshake( intf_thread_t *p_this )
return
VLC_ENOMEM
;
return
VLC_ENOMEM
;
}
}
snprintf
(
psz_timestamp
,
33
,
"%llu"
,
(
uintmax_t
)
timestamp
);
snprintf
(
psz_timestamp
,
33
,
"%llu"
,
(
uintmax_t
)
(
timestamp
/
1000000
)
);
/* generates a md5 hash of :
/* generates a md5 hash of :
* - md5 hash of the password, plus
* - md5 hash of the password, plus
...
@@ -1005,7 +1001,7 @@ static int ReadMetaData( intf_thread_t *p_this )
...
@@ -1005,7 +1001,7 @@ static int ReadMetaData( intf_thread_t *p_this )
}
}
static
void
HandleInterval
(
time_t
*
next
,
unsigned
int
*
i_interval
)
static
void
HandleInterval
(
m
time_t
*
next
,
unsigned
int
*
i_interval
)
{
{
if
(
*
i_interval
==
0
)
if
(
*
i_interval
==
0
)
{
{
...
@@ -1019,6 +1015,6 @@ static void HandleInterval( time_t *next, unsigned int *i_interval )
...
@@ -1019,6 +1015,6 @@ static void HandleInterval( time_t *next, unsigned int *i_interval )
if
(
*
i_interval
>
60
*
120
)
if
(
*
i_interval
>
60
*
120
)
*
i_interval
=
60
*
120
;
*
i_interval
=
60
*
120
;
}
}
*
next
=
time
(
NULL
)
+
*
i_interval
;
*
next
=
mdate
()
+
(
*
i_interval
*
1000000
)
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment