Ticket #12576: lrc_addition.patch

File lrc_addition.patch, 4.3 KB (added by Mike Rice <mikerice1969@…>, 8 years ago)

patch

  • mythtv/libs/libmythmetadata/lyricsdata.cpp

    diff --git a/mythtv/libs/libmythmetadata/lyricsdata.cpp b/mythtv/libs/libmythmetadata/lyricsdata.cpp
    index 8ad688f..7e44390 100644
    a b void LyricsData::loadLyrics(const QString &xmlData) 
    272272        QDomNode lyricNode = itemList.at(x);
    273273        QString lyric = lyricNode.toElement().text();
    274274
    275         lyrics.append(lyric);
     275        if (m_syncronized)
     276        {
     277            QStringList times;
     278            int lastind = 0;
     279            while (lyric.indexOf(QRegExp("\\[\\d\\d:\\d\\d\\]"),
     280                                 lastind) == lastind ||
     281                   lyric.indexOf(QRegExp("\\[\\d\\d:\\d\\d\\.\\d\\d\\]"),
     282                                 lastind) == lastind)
     283            {
     284                if (lyric[lastind+6] == '.')
     285                {
     286                    times.append(lyric.mid(lastind,10));
     287                    lastind += 10;
     288                }
     289                else
     290                {
     291                    // short version
     292                    times.append(lyric.mid(lastind,7));
     293                    lastind += 7;
     294                }
     295            }
     296            if (!times.isEmpty())
     297            {
     298                for (int x = 0; x < times.count(); x++)
     299                {
     300                    lyrics.append(times.at(x) + lyric.mid(lastind));
     301                }
     302            }
     303            else
     304            {
     305                lyrics.append(lyric);
     306            }
     307        }
     308        else
     309        {
     310            lyrics.append(lyric);
     311        }
    276312    }
    277313
    278314    setLyrics(lyrics);
    void LyricsData::setLyrics(const QStringList &lyrics) 
    285321    clearLyrics();
    286322
    287323    int lastTime = -1;
     324    int offset = 0;  // offset in milliseconds
    288325
    289326    for (int x = 0; x < lyrics.count(); x++)
    290327    {
    void LyricsData::setLyrics(const QStringList &lyrics) 
    292329
    293330        LyricsLine *line = new LyricsLine;
    294331
     332        if (lyric.startsWith("[offset:"))
     333        {
     334            offset = lyric.mid(8,lyric.indexOf("]", 8)-8).toInt();
     335        }
     336
    295337        if (m_syncronized)
    296338        {
    297339            if (!lyric.isEmpty())
    298340            {
    299                 // does the line start with a time code like [12:34.56]
    300                 if (lyric.indexOf(QRegExp("\\[\\d\\d:\\d\\d\\.\\d\\d\\]"), 0) == 0)
     341                // does the line start with a time code like [12:34] or [12:34.56]
     342                if (lyric.indexOf(QRegExp("\\[\\d\\d:\\d\\d\\]"), 0) == 0 ||
     343                    lyric.indexOf(QRegExp("\\[\\d\\d:\\d\\d\\.\\d\\d\\]"), 0) == 0)
    301344                {
    302345                    int minutes = lyric.mid(1, 2).toInt();
    303346                    int seconds = lyric.mid(4, 2).toInt();
    304                     int hundredths = lyric.mid(7, 2).toInt();
     347                    int hundredths = 0;
     348                    if (lyric[6] == '.')
     349                    {
     350                        hundredths = lyric.mid(7, 2).toInt();
     351                        line->Lyric = lyric.mid(10);
     352                    }
     353                    else
     354                    {
     355                        line->Lyric = lyric.mid(7);
     356                    }
    305357                    line->Time = (minutes * 60 * 1000) + (seconds * 1000) + (hundredths * 10);
    306                     line->Lyric = lyric.mid(10);
     358                    if (offset > 0)
     359                    {
     360                        if (offset > line->Time) line->Time = 0; 
     361                        else line->Time -= offset;
     362                    }
     363                    else
     364                    {
     365                        line->Time -= offset;
     366                    }
    307367                    lastTime = line->Time;
    308368                }
    309369                else
    void LyricsData::setLyrics(const QStringList &lyrics) 
    332392        // ignore anything that is not a lyric
    333393        if (line->Lyric.startsWith("[ti:") || line->Lyric.startsWith("[al:") ||
    334394            line->Lyric.startsWith("[ar:") || line->Lyric.startsWith("[by:") ||
    335             line->Lyric.startsWith("[url:") || line->Lyric.startsWith("[offset:"))
     395            line->Lyric.startsWith("[url:") || line->Lyric.startsWith("[offset:") ||
     396            line->Lyric.startsWith("[id:") || line->Lyric.startsWith("[length:") ||
     397            line->Lyric.startsWith("[au:") || line->Lyric.startsWith("[la:"))
    336398        {
    337399            delete line;
    338400            continue;