updated on Wed Jan 25 08:34:36 UTC 2012
[aur-mirror.git] / deadbeef-plugins-psipublish / psipublish.c
blob9c01d39c61ef2b1d61fb17e690206213a1069d36
1 #include "deadbeef.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
6 DB_functions_t *deadbeef;
7 DB_misc_t plugin;
8 char tunefilepath[100];
9 int isplayed;
11 void updatetune(const char *title, const char *artist, const char *album, int length)
13 FILE *tunefile;
14 tunefile = fopen(tunefilepath, "w");
15 if (tunefile) {
16 fprintf(tunefile, "%s%s%s\n%s\n%s\n%s\n%d\n", title, deadbeef->conf_get_int("psipublish.showplayer", 0) ? " [DeaDBeeF]" : "", isplayed ? "" : " [PAUSED]", artist, album, title, length);
17 fclose(tunefile);
21 static int psipublish_songstarted(ddb_event_track_t *ev) {
22 if (deadbeef->conf_get_int("psipublish.enable", 0)) {
23 DB_playItem_t *track = ev->track;
24 if (track) {
25 isplayed = 1;
26 updatetune(deadbeef->pl_find_meta(track, "title"), deadbeef->pl_find_meta(track, "artist"), deadbeef->pl_find_meta(track, "album"), deadbeef->pl_get_item_duration(track));
29 return 0;
32 static int psipublish_songfinished(ddb_event_track_t *ev) {
33 remove(tunefilepath);
34 return 0;
38 static int psipublish_paused() {
39 if (deadbeef->conf_get_int("psipublish.enable", 0)) {
40 DB_playItem_t *track = deadbeef->streamer_get_playing_track();
41 if (track) {
42 isplayed = deadbeef->get_output()->state() == OUTPUT_STATE_PLAYING;
43 updatetune(deadbeef->pl_find_meta(track, "title"), deadbeef->pl_find_meta(track, "artist"), deadbeef->pl_find_meta(track, "album"), deadbeef->pl_get_item_duration(track));
44 deadbeef->pl_item_unref(track);
47 return 0;
50 static int psipublish_pluginmessage(uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
51 switch (id) {
52 case DB_EV_SONGSTARTED:
53 psipublish_songstarted((ddb_event_track_t *)ctx);
54 break;
55 case DB_EV_SONGFINISHED:
56 psipublish_songfinished((ddb_event_track_t *)ctx);
57 break;
58 case DB_EV_PAUSED:
59 psipublish_paused();
60 break;
62 return 0;
65 int psipublish_pluginstart(void) {
66 sprintf(tunefilepath, "%s/.cache/Psi+/tune", getenv("HOME"));
67 return 0;
70 int psipublish_pluginstop (void) {
71 remove(tunefilepath);
72 return 0;
75 static const char settings_dlg[] =
76 "property \"Enable publishing\" checkbox psipublish.enable 0;\n"
77 "property \"Show player\" checkbox psipublish.showplayer 0;\n"
80 DB_misc_t plugin = {
81 DB_PLUGIN_SET_API_VERSION
82 .plugin.type = DB_PLUGIN_MISC,
83 .plugin.version_major = 1,
84 .plugin.version_minor = 2,
85 .plugin.id = "psipublish",
86 .plugin.name = "Psi IM Publish Tune",
87 .plugin.descr = "Now playing for Psi IM",
88 .plugin.website = "",
89 .plugin.start = psipublish_pluginstart,
90 .plugin.stop = psipublish_pluginstop,
91 .plugin.message = psipublish_pluginmessage,
92 .plugin.configdialog = settings_dlg
95 DB_plugin_t *
96 psipublish_load(DB_functions_t *ddb) {
97 deadbeef = ddb;
98 return &plugin.plugin;