Mercurial > audlegacy-plugins
comparison src/scrobbler/scrobbler.c @ 2306:dd78327f5747
keep track of how long song is played
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Sun, 13 Jan 2008 17:33:47 +0100 |
parents | f074702a0df3 |
children | 6eef090b5114 |
comparison
equal
deleted
inserted
replaced
2305:738914331374 | 2306:dd78327f5747 |
---|---|
63 char *artist, | 63 char *artist, |
64 *title, | 64 *title, |
65 *mb, | 65 *mb, |
66 *album; | 66 *album; |
67 int utctime, track, len; | 67 int utctime, track, len; |
68 int timeplayed; | |
68 int numtries; | 69 int numtries; |
69 void *next; | 70 void *next; |
70 } item_t; | 71 } item_t; |
71 | 72 |
72 static item_t *q_queue = NULL; | 73 static item_t *q_queue = NULL; |
73 static item_t *q_queue_last = NULL; | 74 static item_t *q_queue_last = NULL; |
74 static int q_nitems; | 75 static int q_nitems; |
76 | |
77 /* isn't there better way for that? --desowin */ | |
78 gboolean sc_timeout(gpointer data) { | |
79 if (q_queue_last && audacious_drct_get_playing()) | |
80 q_queue_last->timeplayed+=1; | |
81 | |
82 return TRUE; | |
83 } | |
75 | 84 |
76 gchar * | 85 gchar * |
77 xmms_urldecode_plain(const gchar * encoded_path) | 86 xmms_urldecode_plain(const gchar * encoded_path) |
78 { | 87 { |
79 const gchar *cur, *ext; | 88 const gchar *cur, *ext; |
129 | 138 |
130 item = malloc(sizeof(item_t)); | 139 item = malloc(sizeof(item_t)); |
131 | 140 |
132 item->artist = fmt_escape(aud_tuple_get_string(tuple, FIELD_ARTIST, NULL)); | 141 item->artist = fmt_escape(aud_tuple_get_string(tuple, FIELD_ARTIST, NULL)); |
133 item->title = fmt_escape(aud_tuple_get_string(tuple, FIELD_TITLE, NULL)); | 142 item->title = fmt_escape(aud_tuple_get_string(tuple, FIELD_TITLE, NULL)); |
134 item->utctime = t; | |
135 item->len = len; | 143 item->len = len; |
136 item->track = aud_tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL); | 144 item->track = aud_tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL); |
145 if (t == -1) { /* now playing song */ | |
146 item->timeplayed = 0; | |
147 item->utctime = time(NULL); | |
148 } else { /* item from queue */ | |
149 item->timeplayed = len; | |
150 item->utctime = t; | |
151 } | |
137 | 152 |
138 #ifdef NOTYET | 153 #ifdef NOTYET |
139 if(tuple->mb == NULL) | 154 if(tuple->mb == NULL) |
140 #endif | 155 #endif |
141 item->mb = fmt_escape(""); | 156 item->mb = fmt_escape(""); |
621 { | 636 { |
622 /* | 637 /* |
623 * don't submit queued tracks which don't yet meet audioscrobbler | 638 * don't submit queued tracks which don't yet meet audioscrobbler |
624 * requirements... | 639 * requirements... |
625 */ | 640 */ |
626 if ((time(NULL) - item->utctime) < (item->len / 2) && | 641 if ((item->timeplayed < (item->len / 2)) && |
627 (time(NULL) - item->utctime) < 240) | 642 (item->timeplayed < 240)) |
628 continue; | 643 continue; |
629 | 644 |
630 if (!item) | 645 if (!item) |
631 return i; | 646 return i; |
632 | 647 |
868 artist = g_strdup(entry[0]); | 883 artist = g_strdup(entry[0]); |
869 album = g_strdup(entry[1]); | 884 album = g_strdup(entry[1]); |
870 title = g_strdup(entry[2]); | 885 title = g_strdup(entry[2]); |
871 track = atoi(entry[3]); | 886 track = atoi(entry[3]); |
872 len = atoi(entry[4]); | 887 len = atoi(entry[4]); |
873 /* entry[5] should always be "P"... */ | |
874 t = atoi(entry[6]); | 888 t = atoi(entry[6]); |
875 | 889 |
876 { | 890 if (!strncmp(entry[5], "L", 1)) { |
877 Tuple *tuple = aud_tuple_new(); | 891 Tuple *tuple = aud_tuple_new(); |
878 gchar* string_value; | 892 gchar* string_value; |
879 string_value = xmms_urldecode_plain(artist); | 893 string_value = xmms_urldecode_plain(artist); |
880 aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, string_value); | 894 aud_tuple_associate_string(tuple, FIELD_ARTIST, NULL, string_value); |
881 g_free(string_value); | 895 g_free(string_value); |
944 I_ARTIST(item), | 958 I_ARTIST(item), |
945 I_ALBUM(item), | 959 I_ALBUM(item), |
946 I_TITLE(item), | 960 I_TITLE(item), |
947 item->track, | 961 item->track, |
948 I_LEN(item), | 962 I_LEN(item), |
949 "P", | 963 ((item->timeplayed > item->len/2) || (item->timeplayed > 240)) ? "L" : "S", |
950 I_TIME(item)); | 964 I_TIME(item)); |
951 } | 965 } |
952 | 966 |
953 fclose(fd); | 967 fclose(fd); |
954 } | 968 } |
1026 void sc_addentry(GMutex *mutex, Tuple *tuple, int len) | 1040 void sc_addentry(GMutex *mutex, Tuple *tuple, int len) |
1027 { | 1041 { |
1028 g_mutex_lock(mutex); | 1042 g_mutex_lock(mutex); |
1029 | 1043 |
1030 sc_submit_np(tuple); | 1044 sc_submit_np(tuple); |
1031 q_put(tuple, time(NULL), len); | 1045 q_put(tuple, -1, len); |
1032 | 1046 |
1033 /* | 1047 /* |
1034 * This will help make sure the queue will be saved on a nasty | 1048 * This will help make sure the queue will be saved on a nasty |
1035 * segfault... | 1049 * segfault... |
1036 */ | 1050 */ |