Ticket #6819: MetaSGs.diff

File MetaSGs.diff, 17.3 KB (added by robert.mcnamara@…, 15 years ago)

Download images to their storage groups when possible.

  • mythplugins/mythvideo/mythvideo/videodlg.cpp

     
    2727#include <mythtv/libmythui/mythdialogbox.h>
    2828#include <mythtv/libmythui/mythgenerictree.h>
    2929#include <mythtv/libmythui/mythsystem.h>
     30#include <mythtv/libmyth/remotefile.h>
    3031
    3132#include "videoscan.h"
    3233#include "globals.h"
     
    143144
    144145                if (!error)
    145146                {
    146                     QFile dest_file(m_dest_file);
    147                     if (dest_file.exists())
    148                         dest_file.remove();
    149 
    150                     if (dest_file.open(QIODevice::WriteOnly))
     147                    if (m_dest_file.startsWith("myth://"))
    151148                    {
    152                         const QByteArray &data = m_data_buffer.data();
    153                         qint64 size = dest_file.write(data);
    154                         if (size != data.size())
     149                        RemoteFile *outFile = new RemoteFile(m_dest_file, true);
     150                        if (!outFile->isOpen())
    155151                        {
    156                             errorMsg = tr("Error writing data to file %1.")
    157                                     .arg(m_dest_file);
     152                            VERBOSE(VB_IMPORTANT,
     153                                QString("RingBuffer::RingBuffer(): Failed to open "
     154                                        "remote file (%1) for write.  Does Coverart "
     155                                        "Storage Group Exist?").arg(m_dest_file));
     156                            delete outFile;
     157                            outFile = NULL;
    158158                            m_error_state = esError;
    159159                        }
     160                        else
     161                        {
     162                            off_t written = outFile->Write(m_data_buffer.data(), m_data_buffer.size());
     163                            if (written != m_data_buffer.size())
     164                            {
     165                                errorMsg = tr("Error writing data to file %1.")
     166                                        .arg(m_dest_file);
     167                                m_error_state = esError;
     168                            }
     169                        }
    160170                    }
    161171                    else
    162172                    {
    163                         errorMsg = tr("Error: file error '%1' for file %2").
    164                                 arg(dest_file.errorString()).arg(m_dest_file);
    165                         m_error_state = esError;
     173                        QFile dest_file(m_dest_file);
     174                        if (dest_file.exists())
     175                            dest_file.remove();
     176
     177                        if (dest_file.open(QIODevice::WriteOnly))
     178                        {
     179                            const QByteArray &data = m_data_buffer.data();
     180                            qint64 size = dest_file.write(data);
     181                            if (size != data.size())
     182                            {
     183                                errorMsg = tr("Error writing data to file %1.")
     184                                        .arg(m_dest_file);
     185                                m_error_state = esError;
     186                            }
     187                        }
     188                        else
     189                        {
     190                            errorMsg = tr("Error: file error '%1' for file %2").
     191                                    arg(dest_file.errorString()).arg(m_dest_file);
     192                            m_error_state = esError;
     193                        }
    166194                    }
    167195                }
    168196
     
    250278
    251279                if (!error)
    252280                {
    253                     QFile dest_file(m_dest_file);
    254                     if (dest_file.exists())
    255                         dest_file.remove();
    256 
    257                     if (dest_file.open(QIODevice::WriteOnly))
     281                    if (m_dest_file.startsWith("myth://"))
    258282                    {
    259                         const QByteArray &data = m_data_buffer.data();
    260                         qint64 size = dest_file.write(data);
    261                         if (size != data.size())
     283                        RemoteFile *outFile = new RemoteFile(m_dest_file, true);
     284                        if (!outFile->isOpen())
    262285                        {
    263                             errorMsg = tr("Error writing data to file %1.")
    264                                     .arg(m_dest_file);
     286                            VERBOSE(VB_IMPORTANT,
     287                                QString("RingBuffer::RingBuffer(): Failed to open "
     288                                        "remote file (%1) for write.  Does Fanart "
     289                                        "Storage Group Exist?").arg(m_dest_file));
     290                            delete outFile;
     291                            outFile = NULL;
    265292                            m_error_state = fesError;
    266293                        }
     294                        else
     295                        {
     296                            off_t written = outFile->Write(m_data_buffer.data(), m_data_buffer.size());
     297                            if (written != m_data_buffer.size())
     298                            {
     299                                errorMsg = tr("Error writing data to file %1.")
     300                                        .arg(m_dest_file);
     301                                m_error_state = fesError;
     302                            }
     303                        }
    267304                    }
    268305                    else
    269306                    {
    270                         errorMsg = tr("Error: file error '%1' for file %2").
    271                                 arg(dest_file.errorString()).arg(m_dest_file);
    272                         m_error_state = fesError;
     307                        QFile dest_file(m_dest_file);
     308                        if (dest_file.exists())
     309                            dest_file.remove();
     310
     311                        if (dest_file.open(QIODevice::WriteOnly))
     312                        {
     313                            const QByteArray &data = m_data_buffer.data();
     314                            qint64 size = dest_file.write(data);
     315                            if (size != data.size())
     316                            {
     317                                errorMsg = tr("Error writing data to file %1.")
     318                                        .arg(m_dest_file);
     319                                m_error_state = fesError;
     320                            }
     321                        }
     322                        else
     323                        {
     324                            errorMsg = tr("Error: file error '%1' for file %2").
     325                                    arg(dest_file.errorString()).arg(m_dest_file);
     326                            m_error_state = fesError;
     327                        }
    273328                    }
    274329                }
    275330
     
    357412
    358413                if (!error)
    359414                {
    360                     QFile dest_file(m_dest_file);
    361                     if (dest_file.exists())
    362                         dest_file.remove();
    363 
    364                     if (dest_file.open(QIODevice::WriteOnly))
     415                    if (m_dest_file.startsWith("myth://"))
    365416                    {
    366                         const QByteArray &data = m_data_buffer.data();
    367                         qint64 size = dest_file.write(data);
    368                         if (size != data.size())
     417                        RemoteFile *outFile = new RemoteFile(m_dest_file, true);
     418                        if (!outFile->isOpen())
     419                        {
     420                            VERBOSE(VB_IMPORTANT,
     421                                QString("RingBuffer::RingBuffer(): Failed to open "
     422                                        "remote file (%1) for write.  Does Banner "
     423                                        "Storage Group Exist?").arg(m_dest_file));
     424                            delete outFile;
     425                            outFile = NULL;
     426                            m_error_state = besError;
     427                        }
     428                        else
    369429                        {
    370                             errorMsg = tr("Error writing data to file %1.")
    371                                     .arg(m_dest_file);
    372                             m_error_state = besError;
     430                            off_t written = outFile->Write(m_data_buffer.data(), m_data_buffer.size());
     431                            if (written != m_data_buffer.size())
     432                            {
     433                                errorMsg = tr("Error writing data to file %1.")
     434                                        .arg(m_dest_file);
     435                                m_error_state = besError;
     436                            }
    373437                        }
    374438                    }
    375439                    else
    376440                    {
    377                         errorMsg = tr("Error: file error '%1' for file %2").
    378                                 arg(dest_file.errorString()).arg(m_dest_file);
    379                         m_error_state = besError;
     441                        QFile dest_file(m_dest_file);
     442                        if (dest_file.exists())
     443                            dest_file.remove();
     444
     445                        if (dest_file.open(QIODevice::WriteOnly))
     446                        {
     447                            const QByteArray &data = m_data_buffer.data();
     448                            qint64 size = dest_file.write(data);
     449                            if (size != data.size())
     450                            {
     451                                errorMsg = tr("Error writing data to file %1.")
     452                                        .arg(m_dest_file);
     453                                m_error_state = besError;
     454                            }
     455                        }
     456                        else
     457                        {
     458                            errorMsg = tr("Error: file error '%1' for file %2").
     459                                    arg(dest_file.errorString()).arg(m_dest_file);
     460                            m_error_state = besError;
     461                        }
    380462                    }
    381463                }
    382464
     
    33423424
    33433425            QString ext = QFileInfo(url.path()).suffix();
    33443426            QString dest_file;
     3427            QString db_value;
    33453428
    33463429            if (metadata->GetSeason() > 0 ||
    33473430                metadata->GetEpisode() > 0)
     
    33493432                // Name TV downloads so that they already work with the PBB
    33503433                QString title = QString("%1 Season %2").arg(metadata->GetTitle())
    33513434                        .arg(metadata->GetSeason());
    3352                 dest_file = QString("%1/%2.%3").arg(fileprefix)
    3353                         .arg(title).arg(ext);
     3435                if (!metadata->GetHost().isEmpty())
     3436                {
     3437                    QString combFileName = QString("%1.%2").arg(title).arg(ext);
     3438                    dest_file = GenRemoteFileURL("Coverart", metadata->GetHost(),
     3439                        combFileName);
     3440                    db_value = combFileName;
     3441                }
     3442                else
     3443                {
     3444                    dest_file = QString("%1/%2.%3").arg(fileprefix)
     3445                            .arg(title).arg(ext);
     3446                    db_value = dest_file;
     3447                }
    33543448            }
    33553449            else
    3356                 dest_file = QString("%1/%2.%3").arg(fileprefix)
    3357                         .arg(metadata->GetInetRef()).arg(ext);
     3450            {
     3451                if (!metadata->GetHost().isEmpty())
     3452                {
     3453                    QString combFileName = QString("%1.%2")
     3454                                           .arg(metadata->GetInetRef())
     3455                                           .arg(ext);
     3456                    dest_file = GenRemoteFileURL("Coverart", metadata->GetHost(),
     3457                        combFileName);
     3458                    db_value = combFileName;
     3459                }
     3460                else
     3461                {
     3462                    dest_file = QString("%1/%2.%3").arg(fileprefix)
     3463                            .arg(metadata->GetInetRef()).arg(ext);
     3464                    db_value = dest_file;
     3465                }
     3466            }
    33583467
    33593468            VERBOSE(VB_IMPORTANT, QString("Copying '%1' -> '%2'...")
    33603469                    .arg(url.toString()).arg(dest_file));
    33613470
    33623471            CoverDownloadProxy *d =
    33633472                    CoverDownloadProxy::Create(url, dest_file, metadata);
    3364             metadata->SetCoverFile(dest_file);
     3473            metadata->SetCoverFile(db_value);
    33653474
    33663475            connect(d, SIGNAL(SigFinished(CoverDownloadErrorState,
    33673476                                          QString, Metadata *)),
     
    34493558
    34503559            QString ext = QFileInfo(url.path()).suffix();
    34513560            QString dest_file;
     3561            QString db_value;
    34523562
    34533563            if (metadata->GetSeason() > 0 ||
    34543564                metadata->GetEpisode() > 0)
    3455             { 
    3456                 // Name TV downloads so that they already work with the PBB   
     3565            {
     3566                // Name TV downloads so that they already work with the PBB
    34573567                QString title = QString("%1 Season %2").arg(metadata->GetTitle())
    34583568                        .arg(metadata->GetSeason());
    3459                 dest_file = QString("%1/%2.%3").arg(fileprefix)
    3460                         .arg(title).arg(ext);
     3569                if (!metadata->GetHost().isEmpty())
     3570                {
     3571                    QString combFileName = QString("%1.%2").arg(title).arg(ext);
     3572                    dest_file = GenRemoteFileURL("Fanart", metadata->GetHost(),
     3573                        combFileName);
     3574                    db_value = combFileName;
     3575                }
     3576                else
     3577                {
     3578                    dest_file = QString("%1/%2.%3").arg(fileprefix)
     3579                            .arg(title).arg(ext);
     3580                    db_value = dest_file;
     3581                }
    34613582            }
    34623583            else
    3463                 dest_file = QString("%1/%2.%3").arg(fileprefix)
    3464                         .arg(metadata->GetInetRef()).arg(ext);
     3584            {
     3585                if (!metadata->GetHost().isEmpty())
     3586                {
     3587                    QString combFileName = QString("%1.%2")
     3588                                           .arg(metadata->GetInetRef())
     3589                                           .arg(ext);
     3590                    dest_file = GenRemoteFileURL("Fanart", metadata->GetHost(),
     3591                        combFileName);
     3592                    db_value = combFileName;
     3593                }
     3594                else
     3595                {
     3596                    dest_file = QString("%1/%2.%3").arg(fileprefix)
     3597                            .arg(metadata->GetInetRef()).arg(ext);
     3598                    db_value = dest_file;
     3599                }
     3600            }
    34653601
    34663602            VERBOSE(VB_IMPORTANT, QString("Copying '%1' -> '%2'...")
    34673603                    .arg(url.toString()).arg(dest_file));
    34683604
    34693605            FanartDownloadProxy *d =
    34703606                    FanartDownloadProxy::Create(url, dest_file, metadata);
    3471             metadata->SetFanart(dest_file);
     3607            metadata->SetFanart(db_value);
    34723608
    34733609            connect(d, SIGNAL(SigFinished(FanartDownloadErrorState,
    34743610                                          QString, Metadata *)),
     
    35563692
    35573693            QString ext = QFileInfo(url.path()).suffix();
    35583694            QString dest_file;
     3695            QString db_value;
    35593696
    35603697            if (metadata->GetSeason() > 0 ||
    35613698                metadata->GetEpisode() > 0)
     
    35633700                // Name TV downloads so that they already work with the PBB   
    35643701                QString title = QString("%1 Season %2").arg(metadata->GetTitle())
    35653702                        .arg(metadata->GetSeason());
    3566                 dest_file = QString("%1/%2.%3").arg(fileprefix)
    3567                         .arg(title).arg(ext);
     3703                if (!metadata->GetHost().isEmpty())
     3704                {
     3705                    QString combFileName = QString("%1.%2").arg(title).arg(ext);
     3706                    dest_file = GenRemoteFileURL("Banners", metadata->GetHost(),
     3707                        combFileName);
     3708                    db_value = combFileName;
     3709                }
     3710                else
     3711                {
     3712                    dest_file = QString("%1/%2.%3").arg(fileprefix)
     3713                            .arg(title).arg(ext);
     3714                    db_value = dest_file;
     3715                }
    35683716            }
    35693717            else
    3570                 dest_file = QString("%1/%2.%3").arg(fileprefix)
    3571                         .arg(metadata->GetInetRef()).arg(ext);
     3718            {
     3719                if (!metadata->GetHost().isEmpty())
     3720                {
     3721                    QString combFileName = QString("%1.%2")
     3722                                           .arg(metadata->GetInetRef())
     3723                                           .arg(ext);
     3724                    dest_file = GenRemoteFileURL("Banners", metadata->GetHost(),
     3725                        combFileName);
     3726                    db_value = combFileName;
     3727                }
     3728                else
     3729                {
     3730                    dest_file = QString("%1/%2.%3").arg(fileprefix)
     3731                            .arg(metadata->GetInetRef()).arg(ext);
     3732                    db_value = dest_file;
     3733                }
     3734            }
    35723735
    35733736            VERBOSE(VB_IMPORTANT, QString("Copying '%1' -> '%2'...")
    35743737                    .arg(url.toString()).arg(dest_file));
    35753738
    35763739            BannerDownloadProxy *d =
    35773740                    BannerDownloadProxy::Create(url, dest_file, metadata);
    3578             metadata->SetBanner(dest_file);
     3741            metadata->SetBanner(db_value);
    35793742
    35803743            connect(d, SIGNAL(SigFinished(BannerDownloadErrorState,
    35813744                                          QString, Metadata *)),