Skip to content

Commit

Permalink
Revert "IPTV channel scan with existing channels"
Browse files Browse the repository at this point in the history
This reverts commit ec9b5ae.

Reason: this commit does break test code.
  • Loading branch information
kmdewaal committed Dec 1, 2024
1 parent ec9b5ae commit d98d51a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 81 deletions.
113 changes: 33 additions & 80 deletions mythtv/libs/libmythtv/channelscan/iptvchannelfetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
static bool parse_chan_info(const QString &rawdata,
IPTVChannelInfo &info,
QString &channum,
int &nextChanNum,
uint &lineNum);

static bool parse_extinf(const QString &line,
QString &channum,
QString &name);
QString &name,
int &nextChanNum);

IPTVChannelFetcher::IPTVChannelFetcher(
uint cardid, QString inputname, uint sourceid,
Expand Down Expand Up @@ -99,7 +101,7 @@ void IPTVChannelFetcher::run(void)

if (m_stopNow || url.isEmpty())
{
LOG(VB_CHANNEL, LOG_INFO, LOC + "Playlist URL is empty");
LOG(VB_CHANNEL, LOG_INFO, LOC + "Playlist URL was empty");
QMutexLocker locker(&m_lock);
m_threadRunning = false;
m_stopNow = true;
Expand All @@ -111,8 +113,8 @@ void IPTVChannelFetcher::run(void)
// Step 2/4 : Download
if (m_scanMonitor)
{
m_scanMonitor->ScanAppendTextToLog(tr("Downloading Playlist"));
m_scanMonitor->ScanPercentComplete(5);
m_scanMonitor->ScanAppendTextToLog(tr("Downloading Playlist"));
}

QString playlist = DownloadPlaylist(url);
Expand All @@ -132,13 +134,11 @@ void IPTVChannelFetcher::run(void)
return;
}

LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("Playlist file size: %1").arg(playlist.length()));

// Step 3/4 : Process
if (m_scanMonitor)
{
m_scanMonitor->ScanAppendTextToLog(tr("Processing Playlist"));
m_scanMonitor->ScanPercentComplete(35);
m_scanMonitor->ScanAppendTextToLog(tr("Processing Playlist"));
}

m_channels.clear();
Expand Down Expand Up @@ -265,7 +265,7 @@ QString IPTVChannelFetcher::DownloadPlaylist(const QString &url)

if (!GetMythDownloadManager()->download(url, &data))
{
LOG(VB_GENERAL, LOG_ERR, LOC +
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("DownloadPlaylist failed to "
"download from %1").arg(url));
}
Expand Down Expand Up @@ -318,7 +318,7 @@ fbox_chan_map_t IPTVChannelFetcher::ParsePlaylist(
return chanmap;
}

// Estimate number of channels
// estimate number of channels
if (fetcher)
{
uint num_channels = estimate_number_of_channels(rawdata);
Expand All @@ -329,7 +329,7 @@ fbox_chan_map_t IPTVChannelFetcher::ParsePlaylist(
.arg(num_channels));
}

// Get the next available channel number for the source (only used if we can't find one in the playlist)
// get the next available channel number for the source (only used if we can't find one in the playlist)
if (fetcher)
{
MSqlQuery query(MSqlQuery::InitCon());
Expand All @@ -348,14 +348,12 @@ fbox_chan_map_t IPTVChannelFetcher::ParsePlaylist(
if (query.first())
{
nextChanNum = query.value(0).toInt() + 1;
LOG(VB_CHANNEL, LOG_INFO, LOC +
QString("Next available channel number from DB is: %1").arg(nextChanNum));
LOG(VB_GENERAL, LOG_INFO, LOC + QString("Next available channel number from DB is: %1").arg(nextChanNum));
}
else
{
nextChanNum = 1;
LOG(VB_CHANNEL, LOG_INFO, LOC +
QString("No channels found for this source, using default channel number: %1").arg(nextChanNum));
LOG(VB_GENERAL, LOG_INFO, LOC + QString("No channels found for this source, using default channel number: %1").arg(nextChanNum));
}
}
}
Expand All @@ -367,68 +365,15 @@ fbox_chan_map_t IPTVChannelFetcher::ParsePlaylist(
IPTVChannelInfo info;
QString channum;

if (!parse_chan_info(rawdata, info, channum, lineNum))
if (!parse_chan_info(rawdata, info, channum, nextChanNum, lineNum))
break;

// Check if parsed channel number is valid
if (!channum.isEmpty())
{
bool ok = false;
int channel_number = channum.toInt(&ok);
if (ok && channel_number > 0)
{
// Positive integer channel number found
}
else
{
// Ignore invalid or negative channel numbers
channum.clear();
}
}

// No channel number found, try to find channel in database and use that channel number
if (channum.isEmpty())
{
QString channum_db = ChannelUtil::GetChannelNumber(m_sourceId, info.m_name);
if (!channum_db.isEmpty())
{
LOG(VB_RECORD, LOG_INFO, LOC +
QString("Found channel in database, channel number: %1 for channel: %2")
.arg(channum_db).arg(info.m_name));

channum = channum_db;
}
}

// Update highest channel number found so far
if (!channum.isEmpty())
{
bool ok = false;
int channel_number = channum.toInt(&ok);
if (ok && channel_number > 0)
{
if (channel_number >= nextChanNum)
{
nextChanNum = channel_number + 1;
}
}
}

// No channel number found, use the default next one
if (channum.isEmpty())
{
LOG(VB_RECORD, LOG_INFO, QString("No channel number found, using next available: %1 for channel: %2")
.arg(nextChanNum).arg(info.m_name));
channum = QString::number(nextChanNum);
nextChanNum++;
}

QString msg = tr("Encountered malformed channel");
if (!channum.isEmpty())
{
chanmap[channum] = info;

msg = QString("Parsing Channel #%1: '%2' %3")
msg = QString("Parsing Channel #%1 : %2 : %3")
.arg(channum, info.m_name,
info.m_tuning.GetDataURL().toString());
LOG(VB_CHANNEL, LOG_INFO, LOC + msg);
Expand All @@ -450,6 +395,7 @@ fbox_chan_map_t IPTVChannelFetcher::ParsePlaylist(
static bool parse_chan_info(const QString &rawdata,
IPTVChannelInfo &info,
QString &channum,
int &nextChanNum,
uint &lineNum)
{
// #EXTINF:0,2 - France 2 <-- duration,channum - channame
Expand All @@ -474,14 +420,12 @@ static bool parse_chan_info(const QString &rawdata,
if (line.isEmpty())
return false;

LOG(VB_CHANNEL, LOG_INFO, LOC + line);

++lineNum;
if (line.startsWith("#"))
{
if (line.startsWith("#EXTINF:"))
{
parse_extinf(line.mid(line.indexOf(':')+1), channum, name);
parse_extinf(line.mid(line.indexOf(':')+1), channum, name, nextChanNum);
}
else if (line.startsWith("#EXTMYTHTV:"))
{
Expand All @@ -507,13 +451,13 @@ static bool parse_chan_info(const QString &rawdata,
if (name.isEmpty())
return false;

LOG(VB_CHANNEL, LOG_DEBUG, LOC +
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("parse_chan_info name='%2'").arg(name));
LOG(VB_CHANNEL, LOG_DEBUG, LOC +
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("parse_chan_info channum='%2'").arg(channum));
for (auto it = values.cbegin(); it != values.cend(); ++it)
{
LOG(VB_CHANNEL, LOG_DEBUG, LOC +
LOG(VB_GENERAL, LOG_INFO, LOC +
QString("parse_chan_info [%1]='%2'")
.arg(it.key(), *it));
}
Expand All @@ -530,7 +474,8 @@ static bool parse_chan_info(const QString &rawdata,

static bool parse_extinf(const QString &line,
QString &channum,
QString &name)
QString &name,
int &nextChanNum)
{
// Parse extension portion, Freebox or SAT>IP format
static const QRegularExpression chanNumName1
Expand Down Expand Up @@ -618,15 +563,23 @@ static bool parse_extinf(const QString &line,
channum = match.captured(1).simplified();
name = match.captured(2).simplified();

if (name.isEmpty())
return false;
bool ok = false;
int channel_number = channum.toInt(&ok);
if (ok && channel_number > 0)
{
if (channel_number >= nextChanNum)
nextChanNum = channel_number + 1;
return true;
}

// no valid channel number found use the default next one
LOG(VB_GENERAL, LOG_ERR, QString("No channel number found, using next available: %1 for channel: %2").arg(nextChanNum).arg(name));
channum = QString::number(nextChanNum);
nextChanNum++;
return true;
}



// Not one of the formats we support
// not one of the formats we support
QString msg = LOC + QString("Invalid header in channel list line \n\t\t\tEXTINF:%1").arg(line);
LOG(VB_GENERAL, LOG_ERR, msg);
return false;
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/channelscan/iptvchannelfetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class IPTVChannelFetcher : public QRunnable
fbox_chan_map_t GetChannels(void);

static QString DownloadPlaylist(const QString &url);
MTV_PUBLIC fbox_chan_map_t ParsePlaylist(
MTV_PUBLIC static fbox_chan_map_t ParsePlaylist(
const QString &rawdata, IPTVChannelFetcher *fetcher = nullptr);

private:
Expand Down

0 comments on commit d98d51a

Please sign in to comment.