Index: track_info.c IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- track_info.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d) +++ track_info.c (revision ) @@ -54,6 +54,131 @@ ti->comments = NULL; ti->codec = NULL; ti->codec_profile = NULL; + + // Find SRT + int filename_length = 0; + int position_extension = 0; + char c = filename[filename_length]; + for (; c != '\0'; ++filename_length) { + c = filename[filename_length]; + if (c == '.') + position_extension = filename_length + 1; + } + int filename_str_length; + if (position_extension) { + filename_str_length = filename_length - (filename_length - position_extension - 3); + } else { + filename_str_length = filename_length + 3; + } + + char filename_str[filename_str_length]; + memcpy(filename_str, filename, sizeof(char) * filename_str_length); + + filename_str[position_extension + 0] = 's'; + filename_str[position_extension + 1] = 'r'; + filename_str[position_extension + 2] = 't'; + + // Read SRT + ti->count_total_lyrics = 0; + if (access(filename_str, F_OK) != -1) { + ti->showTextLyric = 0; + ti->lastLyric = 0; + + int tempStrFileSize = 30; + ti->lyric = malloc(sizeof(struct sLyric) * tempStrFileSize); + + FILE *fp; + fp = fopen(filename_str, "r"); + + enum {lCounter, lTime, lText, lBlank} currentTypeLine = lCounter; + + char buffer[256]; + int bufferCount = 0; + while ((buffer[bufferCount] = getc(fp)) != EOF) { + if (buffer[bufferCount] == '\n') { + buffer[bufferCount - 1] = '\0'; + if (currentTypeLine == lCounter) { + if (ti->count_total_lyrics == tempStrFileSize) { + tempStrFileSize += 5; + ti->lyric = realloc(ti->lyric, sizeof(struct sLyric) * tempStrFileSize); + } + } else if (currentTypeLine == lTime) { + int temp1; + char start_hours[2]; + start_hours[0] = buffer[0]; + start_hours[1] = buffer[1]; + sscanf(start_hours, "%d", &temp1); + + int temp2; + char start_minutes[2]; + start_minutes[0] = buffer[3]; + start_minutes[1] = buffer[4]; + sscanf(start_minutes, "%d", &temp2); + + int temp3; + char start_seconds[2]; + start_seconds[0] = buffer[6]; + start_seconds[1] = buffer[7]; + sscanf(start_seconds, "%d", &temp3); + + double tempD1; + char start_cents[5]; + start_cents[0] = '0'; + start_cents[1] = '.'; + start_cents[2] = buffer[9]; + start_cents[3] = buffer[10]; + start_cents[4] = buffer[11]; + sscanf(start_cents, "%lf", &tempD1); + + ti->lyric[ti->count_total_lyrics].timeStart = (double) (temp1 * 3600) + (temp2 * 60) + (temp3) + (tempD1); + + int temp4; + char end_hours[2]; + end_hours[0] = buffer[17]; + end_hours[1] = buffer[18]; + sscanf(end_hours, "%d", &temp4); + + int temp5; + char end_minutes[2]; + end_minutes[0] = buffer[20]; + end_minutes[1] = buffer[21]; + sscanf(end_minutes, "%d", &temp5); + + int temp6; + char end_seconds[2]; + end_seconds[0] = buffer[23]; + end_seconds[1] = buffer[24]; + sscanf(end_seconds, "%d", &temp6); + + double tempD2; + char end_cents[5]; + end_cents[0] = '0'; + end_cents[1] = '.'; + end_cents[2] = buffer[26]; + end_cents[3] = buffer[27]; + end_cents[4] = buffer[28]; + sscanf(end_cents, "%lf", &tempD2); + + ti->lyric[ti->count_total_lyrics].timeEnd = (double) (temp4 * 3600) + (temp5 * 60) + (temp6) + (tempD2); + } else if (currentTypeLine == lText) { + strcpy(ti->lyric[ti->count_total_lyrics].messageText, buffer); + ti->count_total_lyrics++; + } + + if (currentTypeLine == lBlank) { + currentTypeLine = lCounter; + } else { + currentTypeLine++; + } + + bufferCount = 0; + buffer[bufferCount] = '\0'; + } else { + bufferCount++; + } + } + } + return ti; } Index: options.c IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- options.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d) +++ options.c (revision ) @@ -225,6 +225,7 @@ " %{status} %{?show_playback_position?%{position} %{?duration?/ %{duration} }?%{?duration?%{duration} }}" "- %{total} " "%{?volume>=0?vol: %{?lvolume!=rvolume?%{lvolume},%{rvolume} ?%{volume} }}" + " | %{lyrics} | " "%{?stream?buf: %{buffer} }" "%{?show_current_bitrate & bitrate>=0? %{bitrate} kbps }" "%=" Index: track_info.h IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- track_info.h (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d) +++ track_info.h (revision ) @@ -22,6 +22,12 @@ #include #include +struct sLyric { + double timeStart; + double timeEnd; + char messageText[100]; +}; + struct track_info { struct keyval *comments; @@ -64,6 +70,12 @@ unsigned int play_count; int is_va_compilation : 1; + + int count_total_lyrics; + struct sLyric *lyric; + int lastLyric; + int showTextLyric; + char *currentTextLyric; }; typedef size_t sort_key_t; Index: ui_curses.c IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- ui_curses.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d) +++ ui_curses.c (revision ) @@ -289,6 +289,7 @@ TF_VOLUME, TF_LVOLUME, TF_RVOLUME, + TF_LYRICS, TF_BUFFER, TF_REPEAT, TF_CONTINUE, @@ -345,6 +346,7 @@ DEF_FO_INT('\0', "volume", 1), DEF_FO_INT('\0', "lvolume", 1), DEF_FO_INT('\0', "rvolume", 1), + DEF_FO_STR('\0', "lyrics", 0), DEF_FO_INT('\0', "buffer", 1), DEF_FO_STR('\0', "repeat", 0), DEF_FO_STR('\0', "continue", 0), @@ -653,8 +655,15 @@ fopt_set_str(&track_fopts[TF_SHUFFLE], shuffle_strs[shuffle]); fopt_set_str(&track_fopts[TF_PLAYLISTMODE], aaa_mode_names[aaa_mode]); - if (player_info.ti) + if (player_info.ti) { duration = player_info.ti->duration; + + if (player_info.ti->count_total_lyrics && player_info.ti->showTextLyric) { + fopt_set_str(&track_fopts[TF_LYRICS], player_info.ti->currentTextLyric); + } else { + fopt_set_str(&track_fopts[TF_LYRICS], ""); + } + } vol_left = vol_right = vol = -1; if (soft_vol) { Index: player.c IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- player.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d) +++ player.c (revision ) @@ -532,6 +532,18 @@ player_info_lock(); player_info.pos = pos; + double pos2 = (double)consumer_pos / (double)buffer_second_size(); + + if (player_info.ti->count_total_lyrics && player_info.ti->lastLyric <= player_info.ti->count_total_lyrics) { + if (player_info.ti->lastLyric > 0 && player_info.ti->lyric[player_info.ti->lastLyric - 1].timeEnd <= pos2) + player_info.ti->showTextLyric = 0; + + if (player_info.ti->lyric[player_info.ti->lastLyric].timeStart <= pos2) { + player_info.ti->currentTextLyric = player_info.ti->lyric[player_info.ti->lastLyric].messageText; + player_info.ti->lastLyric++; + player_info.ti->showTextLyric = 1; + } + } if (show_current_bitrate) { bitrate = ip_current_bitrate(ip);