mkv

deadbeef queue pusher

mkv
Sep 6th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #include "deadbeef.h"
  2. // gcc -std=c99 -shared -O2 -o radqueue.so radqueue.c
  3.  
  4. typedef int bool;
  5. #define false 0;
  6. #define true 1;
  7. #define trace(fmt,...)
  8. static DB_functions_t *deadbeef;
  9. static const char settings_dlg[] =
  10.     "property \"Enable radqueue\" checkbox radqueue.enable 0;"
  11.     "property DJID entry radqueue.djid 7;"
  12.     "property Count entry radqueue.count 50;"
  13.     "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\";"
  14. ;
  15. char exec[1024];
  16. char f_title[1024];
  17. char f_artist[1024];
  18. void fuck(const char *from, char *to, int n)
  19. {
  20.     for (int a = 0; a < n; a++)
  21.     {
  22.         if (from[a] == 0x0A)
  23.             to[a] = 0x20;
  24.  
  25.         else
  26.             to[a] = from[a];
  27.  
  28.         if (from[a] == '\0')
  29.             break;
  30.     }
  31. }
  32. ddb_playItem_t *current = NULL;
  33. static int updatequeue()
  34. {
  35.     if (current == NULL) return 0;
  36.     if (!deadbeef->conf_get_int("radqueue.enable", 0))
  37.         return 0;
  38.  
  39.     bool unref = false;
  40.     ddb_playItem_t *shin;
  41.     ddb_playItem_t *track = current;
  42.     int tracks = deadbeef->conf_get_int("radqueue.count", 50);
  43.     FILE *shm = fopen("/dev/shm/radqueue.tmp", "w");
  44.     int remain = (int)deadbeef->pl_get_item_duration(track);
  45.     remain -= (int)deadbeef->playback_get_pos();
  46.     fprintf(shm, "%d\n%d\n",
  47.         (int)deadbeef->conf_get_int("radqueue.djid", 7),
  48.         remain);
  49.  
  50.     for (int a = 0; a < tracks; a++)
  51.     {
  52.         shin = deadbeef->pl_get_next(track, PL_MAIN);
  53.         if (unref)
  54.             deadbeef->pl_item_unref(track);
  55.  
  56.         track = shin;
  57.         unref = true;
  58.         if (track == NULL)
  59.         {
  60.             unref = false;
  61.             break;
  62.         }
  63.         int duration = (int)deadbeef->pl_get_item_duration(track);
  64.         const char *artist = deadbeef->pl_find_meta(track, "artist");
  65.         const char *title = deadbeef->pl_find_meta(track, "title");
  66.         //strncpy(f_artist, artist, sizeof(f_artist));
  67.         fuck(artist, f_artist, 1024);
  68.         fuck(title, f_title, 1024);
  69.         fprintf(shm, "%d %s - %s\n", duration, f_artist, f_title);
  70.     }
  71.     if (unref)
  72.         deadbeef->pl_item_unref(track);
  73.  
  74.     fclose(shm);
  75.     deadbeef->conf_get_str("radqueue.exec", "/usr/bin/notify-send what", exec, 1024);
  76.     system(exec);
  77.     return 0;
  78. }
  79. static int rad_start(ddb_event_track_t *ev, uintptr_t data)
  80. {
  81.     current = ev->track;
  82.     trace ("rad start %p\n", ev->track);
  83.     return updatequeue();
  84. }
  85.  
  86. static int rad_msg(uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2)
  87. {
  88.     if (id == DB_EV_SONGSTARTED)
  89.     {
  90.         rad_start((ddb_event_track_t *)ctx, 0);
  91.     }
  92.     else if (id == DB_EV_PLAYLISTCHANGED)
  93.     {
  94.         // idk lol
  95.     }
  96.     return 0;
  97. }
  98.  
  99. static int guipusher(
  100.     DB_plugin_action_t *action,
  101.     DB_playItem_t *it)
  102. {
  103.     updatequeue();
  104. }
  105. static DB_plugin_action_t guinode =
  106. {
  107.     .title = "Push dick",
  108.     .name = "push_dick",
  109.     .flags = DB_ACTION_SINGLE_TRACK,
  110.     .callback = guipusher,
  111.     .next = NULL
  112. };
  113. static DB_plugin_action_t *
  114. guipush(DB_playItem_t *it)
  115. {
  116.     if (!current || current == NULL ||
  117.         !deadbeef->pl_find_meta(it, "artist"))
  118.         guinode.flags |= DB_ACTION_DISABLED;
  119.  
  120.     else
  121.         guinode.flags &= ~DB_ACTION_DISABLED;
  122.  
  123.     return &guinode;
  124. }
  125. static DB_plugin_action_t *
  126. guipoke(DB_playItem_t *it)
  127. {
  128.     return &guinode;
  129. }
  130.  
  131. static DB_misc_t plugin =
  132. {
  133.     DB_PLUGIN_SET_API_VERSION
  134.     .plugin.version_major = 0,
  135.     .plugin.version_minor = 5,
  136.     .plugin.type = DB_PLUGIN_MISC,
  137.     .plugin.name = "radqueue",
  138.     .plugin.descr = "push queue to r/a/dio",
  139.     .plugin.copyright =
  140.         "Copyright (C) 2012 ed <irc.rizon.net>\n"
  141.         "protected by the gpl and stallman's beard",
  142.     .plugin.website = "http://ocv.me/",
  143.     .plugin.configdialog = settings_dlg,
  144.     .plugin.get_actions = guipoke,
  145.     .plugin.message = rad_msg
  146. };
  147.  
  148. // announce our presence
  149. DB_plugin_t *radqueue_load (DB_functions_t *api)
  150. {
  151.     deadbeef = api;
  152.     return DB_PLUGIN(&plugin);
  153. }
Advertisement
Add Comment
Please, Sign In to add comment