Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "deadbeef.h"
- // gcc -std=c99 -shared -O2 -o radqueue.so radqueue.c
- typedef int bool;
- #define false 0;
- #define true 1;
- #define trace(fmt,...)
- static DB_functions_t *deadbeef;
- static const char settings_dlg[] =
- "property \"Enable radqueue\" checkbox radqueue.enable 0;"
- "property DJID entry radqueue.djid 7;"
- "property Count entry radqueue.count 50;"
- "property EXEC entry radqueue.exec \"/usr/bin/curl -s -T /dev/shm/radqueue.tmp -u user:pass ftp://r-a-d.io:21/queue.txt\";"
- ;
- char exec[1024];
- char f_title[1024];
- char f_artist[1024];
- void fuck(const char *from, char *to, int n)
- {
- for (int a = 0; a < n; a++)
- {
- if (from[a] == 0x0A)
- to[a] = 0x20;
- else
- to[a] = from[a];
- if (from[a] == '\0')
- break;
- }
- }
- ddb_playItem_t *current = NULL;
- static int updatequeue()
- {
- if (current == NULL) return 0;
- if (!deadbeef->conf_get_int("radqueue.enable", 0))
- return 0;
- bool unref = false;
- ddb_playItem_t *shin;
- ddb_playItem_t *track = current;
- int tracks = deadbeef->conf_get_int("radqueue.count", 50);
- FILE *shm = fopen("/dev/shm/radqueue.tmp", "w");
- int remain = (int)deadbeef->pl_get_item_duration(track);
- remain -= (int)deadbeef->playback_get_pos();
- fprintf(shm, "%d\n%d\n",
- (int)deadbeef->conf_get_int("radqueue.djid", 7),
- remain);
- for (int a = 0; a < tracks; a++)
- {
- shin = deadbeef->pl_get_next(track, PL_MAIN);
- if (unref)
- deadbeef->pl_item_unref(track);
- track = shin;
- unref = true;
- if (track == NULL)
- {
- unref = false;
- break;
- }
- int duration = (int)deadbeef->pl_get_item_duration(track);
- const char *artist = deadbeef->pl_find_meta(track, "artist");
- const char *title = deadbeef->pl_find_meta(track, "title");
- //strncpy(f_artist, artist, sizeof(f_artist));
- fuck(artist, f_artist, 1024);
- fuck(title, f_title, 1024);
- fprintf(shm, "%d %s - %s\n", duration, f_artist, f_title);
- }
- if (unref)
- deadbeef->pl_item_unref(track);
- fclose(shm);
- deadbeef->conf_get_str("radqueue.exec", "/usr/bin/notify-send what", exec, 1024);
- system(exec);
- return 0;
- }
- static int rad_start(ddb_event_track_t *ev, uintptr_t data)
- {
- current = ev->track;
- trace ("rad start %p\n", ev->track);
- return updatequeue();
- }
- static int rad_msg(uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2)
- {
- if (id == DB_EV_SONGSTARTED)
- {
- rad_start((ddb_event_track_t *)ctx, 0);
- }
- else if (id == DB_EV_PLAYLISTCHANGED)
- {
- // idk lol
- }
- return 0;
- }
- static int guipusher(
- DB_plugin_action_t *action,
- DB_playItem_t *it)
- {
- updatequeue();
- }
- static DB_plugin_action_t guinode =
- {
- .title = "Push dick",
- .name = "push_dick",
- .flags = DB_ACTION_SINGLE_TRACK,
- .callback = guipusher,
- .next = NULL
- };
- static DB_plugin_action_t *
- guipush(DB_playItem_t *it)
- {
- if (!current || current == NULL ||
- !deadbeef->pl_find_meta(it, "artist"))
- guinode.flags |= DB_ACTION_DISABLED;
- else
- guinode.flags &= ~DB_ACTION_DISABLED;
- return &guinode;
- }
- static DB_plugin_action_t *
- guipoke(DB_playItem_t *it)
- {
- return &guinode;
- }
- static DB_misc_t plugin =
- {
- DB_PLUGIN_SET_API_VERSION
- .plugin.version_major = 0,
- .plugin.version_minor = 5,
- .plugin.type = DB_PLUGIN_MISC,
- .plugin.name = "radqueue",
- .plugin.descr = "push queue to r/a/dio",
- .plugin.copyright =
- "Copyright (C) 2012 ed <irc.rizon.net>\n"
- "protected by the gpl and stallman's beard",
- .plugin.website = "http://ocv.me/",
- .plugin.configdialog = settings_dlg,
- .plugin.get_actions = guipoke,
- .plugin.message = rad_msg
- };
- // announce our presence
- DB_plugin_t *radqueue_load (DB_functions_t *api)
- {
- deadbeef = api;
- return DB_PLUGIN(&plugin);
- }
Advertisement
Add Comment
Please, Sign In to add comment