Advertisement
KeplerBR

[cmus] View SRT - beta

Jun 29th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.07 KB | None | 0 0
  1. Index: track_info.c
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- track_info.c    (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  7. +++ track_info.c    (revision )
  8. @@ -54,6 +54,92 @@
  9.     ti->comments = NULL;
  10.     ti->codec = NULL;
  11.     ti->codec_profile = NULL;
  12. +
  13. +   // TODO: There must be a better way to locate the SRT
  14. +   char filename_str[strlen(filename)];
  15. +   memcpy(filename_str, filename, sizeof(char) * strlen(filename));
  16. +
  17. +   filename_str[strlen(filename) - 3] = 's';
  18. +   filename_str[strlen(filename) - 2] = 'r';
  19. +   filename_str[strlen(filename) - 1] = 't';
  20. +
  21. +   if (access(filename_str, F_OK) != -1) {
  22. +       ti->have_lyrics = 1;
  23. +       ti->showTextLyric = 0;
  24. +       ti->lastLyric = 0;
  25. +
  26. +       FILE *fp;
  27. +       fp = fopen(filename_str, "r");
  28. +
  29. +       enum {lCounter, lTime, lText, lBlank} currentTypeLine = lCounter;
  30. +
  31. +       int countLyrics = 0;
  32. +       char buffer[256];
  33. +       int bufferCount = 0;
  34. +       while ((buffer[bufferCount] = getc(fp)) != EOF) {
  35. +           if (buffer[bufferCount] == '\n') {
  36. +               buffer[bufferCount - 1] = '\0';
  37. +               if (currentTypeLine == lTime) {
  38. +                   int temp1;
  39. +                   char start_hours[2];
  40. +                   start_hours[0] = buffer[0];
  41. +                   start_hours[1] = buffer[1];
  42. +                   sscanf(start_hours, "%d", &temp1);
  43. +
  44. +                   int temp2;
  45. +                   char start_minutes[2];
  46. +                   start_minutes[0] = buffer[3];
  47. +                   start_minutes[1] = buffer[4];
  48. +                   sscanf(start_minutes, "%d", &temp2);
  49. +
  50. +                   int temp3;
  51. +                   char start_seconds[2];
  52. +                   start_seconds[0] = buffer[6];
  53. +                   start_seconds[1] = buffer[7];
  54. +                   sscanf(start_seconds, "%d", &temp3);
  55. +
  56. +                   ti->lyric[countLyrics].timeStart = (temp1 * 3600) + (temp2 * 60) + (temp3);
  57. +
  58. +                   int temp4;
  59. +                   char end_hours[2];
  60. +                   end_hours[0] = buffer[17];
  61. +                   end_hours[1] = buffer[18];
  62. +                   sscanf(end_hours, "%d", &temp4);
  63. +
  64. +                   int temp5;
  65. +                   char end_minutes[2];
  66. +                   end_minutes[0] = buffer[20];
  67. +                   end_minutes[1] = buffer[21];
  68. +                   sscanf(end_minutes, "%d", &temp5);
  69. +
  70. +                   int temp6;
  71. +                   char end_seconds[2];
  72. +                   end_seconds[0] = buffer[23];
  73. +                   end_seconds[1] = buffer[24];
  74. +                   sscanf(end_seconds, "%d", &temp6);
  75. +
  76. +                   ti->lyric[countLyrics].timeEnd = (temp4 * 3600) + (temp5 * 60) + (temp6);
  77. +               } else if (currentTypeLine == lText) {
  78. +                   strcpy(ti->lyric[countLyrics].messageText, buffer);
  79. +                   countLyrics++;
  80. +               }
  81. +
  82. +               if (currentTypeLine == lBlank) {
  83. +                   currentTypeLine = lCounter;
  84. +               } else {
  85. +                   currentTypeLine++;
  86. +               }
  87. +
  88. +               bufferCount = 0;
  89. +               buffer[bufferCount] = '\0';
  90. +           } else {
  91. +               bufferCount++;
  92. +           }
  93. +       }
  94. +   } else {
  95. +       ti->have_lyrics = 0;
  96. +   }
  97. +
  98.     return ti;
  99.  }
  100.  
  101. Index: options.c
  102. IDEA additional info:
  103. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  104. <+>UTF-8
  105. ===================================================================
  106. --- options.c   (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  107. +++ options.c   (revision )
  108. @@ -225,6 +225,7 @@
  109.         " %{status} %{?show_playback_position?%{position} %{?duration?/ %{duration} }?%{?duration?%{duration} }}"
  110.         "- %{total} "
  111.         "%{?volume>=0?vol: %{?lvolume!=rvolume?%{lvolume},%{rvolume} ?%{volume} }}"
  112. +       " | %{lyrics} | "
  113.         "%{?stream?buf: %{buffer} }"
  114.         "%{?show_current_bitrate & bitrate>=0? %{bitrate} kbps }"
  115.         "%="
  116. Index: track_info.h
  117. IDEA additional info:
  118. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  119. <+>UTF-8
  120. ===================================================================
  121. --- track_info.h    (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  122. +++ track_info.h    (revision )
  123. @@ -22,6 +22,12 @@
  124.  #include <time.h>
  125.  #include <stddef.h>
  126.  
  127. +struct sLyric {
  128. +   int timeStart;
  129. +   int timeEnd;
  130. +   char messageText[256];
  131. +};
  132. +
  133.  struct track_info {
  134.     struct keyval *comments;
  135.  
  136. @@ -64,6 +70,12 @@
  137.     unsigned int play_count;
  138.  
  139.     int is_va_compilation : 1;
  140. +
  141. +   int have_lyrics;
  142. +   struct sLyric lyric[256];
  143. +   int lastLyric;
  144. +   int showTextLyric;
  145. +   char *currentTextLyric;
  146.  };
  147.  
  148.  typedef size_t sort_key_t;
  149. Index: ui_curses.c
  150. IDEA additional info:
  151. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  152. <+>UTF-8
  153. ===================================================================
  154. --- ui_curses.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  155. +++ ui_curses.c (revision )
  156. @@ -289,6 +289,7 @@
  157.     TF_VOLUME,
  158.     TF_LVOLUME,
  159.     TF_RVOLUME,
  160. +   TF_LYRICS,
  161.     TF_BUFFER,
  162.     TF_REPEAT,
  163.     TF_CONTINUE,
  164. @@ -345,6 +346,7 @@
  165.     DEF_FO_INT('\0', "volume", 1),
  166.     DEF_FO_INT('\0', "lvolume", 1),
  167.     DEF_FO_INT('\0', "rvolume", 1),
  168. +   DEF_FO_STR('\0', "lyrics", 0),
  169.     DEF_FO_INT('\0', "buffer", 1),
  170.     DEF_FO_STR('\0', "repeat", 0),
  171.     DEF_FO_STR('\0', "continue", 0),
  172. @@ -653,8 +655,15 @@
  173.     fopt_set_str(&track_fopts[TF_SHUFFLE], shuffle_strs[shuffle]);
  174.     fopt_set_str(&track_fopts[TF_PLAYLISTMODE], aaa_mode_names[aaa_mode]);
  175.  
  176. -   if (player_info.ti)
  177. +   if (player_info.ti) {
  178.         duration = player_info.ti->duration;
  179. +
  180. +       if (player_info.ti->have_lyrics && player_info.ti->showTextLyric) {
  181. +           fopt_set_str(&track_fopts[TF_LYRICS], player_info.ti->currentTextLyric);
  182. +       } else {
  183. +           fopt_set_str(&track_fopts[TF_LYRICS], "");
  184. +       }
  185. +   }
  186.  
  187.     vol_left = vol_right = vol = -1;
  188.     if (soft_vol) {
  189. Index: player.c
  190. IDEA additional info:
  191. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  192. <+>UTF-8
  193. ===================================================================
  194. --- player.c    (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  195. +++ player.c    (revision )
  196. @@ -533,6 +533,17 @@
  197.         player_info_lock();
  198.         player_info.pos = pos;
  199.  
  200. +       if (player_info.ti->have_lyrics) {
  201. +           if (player_info.ti->lastLyric > 0 && player_info.ti->lyric[player_info.ti->lastLyric - 1].timeEnd <= pos)
  202. +               player_info.ti->showTextLyric = 0;
  203. +
  204. +           if (player_info.ti->lyric[player_info.ti->lastLyric].timeStart <= pos) {
  205. +               player_info.ti->currentTextLyric = player_info.ti->lyric[player_info.ti->lastLyric].messageText;
  206. +               player_info.ti->lastLyric++;
  207. +               player_info.ti->showTextLyric = 1;
  208. +           }
  209. +       }
  210. +
  211.         if (show_current_bitrate) {
  212.             bitrate = ip_current_bitrate(ip);
  213.             if (bitrate != -1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement