Ticket #6158: PBBMVExport.diff

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

Adds Export to MythVideo? to PBB

  • mythtv/programs/mythfrontend/playbackbox.cpp

     
    2020#include "mythdirs.h"
    2121#include "mythcontext.h"
    2222#include "mythdbcon.h"
     23#include "mythdb.h"
    2324#include "mythverbose.h"
    2425#include "programinfo.h"
    2526#include "scheduledrecording.h"
     
    15541555    stop(pginfo);
    15551556}
    15561557
     1558void PlaybackBox::exportMVSelected()
     1559{
     1560    ProgramInfo *pginfo = CurrentItem();
     1561               
     1562    if (!pginfo)
     1563        return; 
     1564                   
     1565    mvexport(pginfo);
     1566}
     1567
    15571568void PlaybackBox::deleteSelected(MythUIButtonListItem *item)
    15581569{
    15591570    if (!item)
     
    18131824    RemoteStopRecording(rec);
    18141825}
    18151826
     1827void PlaybackBox::mvexport(ProgramInfo *rec)
     1828{
     1829    // User Rating Adjustment
     1830    QString exportRating = QString::number((int)((rec->stars * 10.0) + 0.5));
     1831
     1832    // Stuff necessary to perform the copy command
     1833
     1834    QString copyFrom = rec->GetPlaybackURL(false, true);
     1835    QString extension;
     1836
     1837    QRegExp rx(".*\\.(\\w+)$");
     1838    int pos = rx.indexIn(copyFrom);
     1839    if (pos > -1)
     1840    {
     1841        extension = rx.cap(1);
     1842    }
     1843    else
     1844    {
     1845        extension = "";
     1846    }
     1847
     1848    QString baseMVDir = gContext->GetSetting("VideoStartupDir");
     1849    QString MVDirFormat = gContext->GetSetting("TVExportDirFormat",
     1850                              "Television/%TITLE%/");
     1851    if (!MVDirFormat.isEmpty())
     1852    {
     1853         MVDirFormat.replace(QRegExp("%FILE%"), rec->GetRecordBasename(true));
     1854         MVDirFormat.replace(QRegExp("%TITLE%"), rec->title);
     1855         MVDirFormat.replace(QRegExp("%SUBTITLE%"), rec->subtitle);
     1856         MVDirFormat.replace(QRegExp("%DESCRIPTION%"), rec->description);
     1857         MVDirFormat.replace(QRegExp("%HOSTNAME%"), rec->hostname);
     1858         MVDirFormat.replace(QRegExp("%CATEGORY%"), rec->category);
     1859         MVDirFormat.replace(QRegExp("%RECGROUP%"), rec->recgroup);
     1860         MVDirFormat.replace(QRegExp("%PLAYGROUP%"), rec->playgroup);
     1861         MVDirFormat.replace(QRegExp("%CHANID%"), rec->chanid);
     1862         MVDirFormat.replace(QRegExp("%STARTTIME%"),
     1863                         rec->recstartts.toString("yyyyMMddhhmmss"));
     1864         MVDirFormat.replace(QRegExp("%ENDTIME%"),
     1865                         rec->recendts.toString("yyyyMMddhhmmss"));
     1866         MVDirFormat.replace(QRegExp("%STARTTIMEISO%"),
     1867                         rec->recstartts.toString(Qt::ISODate));
     1868         MVDirFormat.replace(QRegExp("%ENDTIMEISO%"),
     1869                         rec->recendts.toString(Qt::ISODate));
     1870         MVDirFormat.replace(QRegExp("%PROGSTART%"),
     1871                         rec->startts.toString("yyyyMMddhhmmss"));
     1872         MVDirFormat.replace(QRegExp("%PROGEND%"),
     1873                         rec->endts.toString("yyyyMMddhhmmss"));
     1874         MVDirFormat.replace(QRegExp("%PROGSTARTISO%"),
     1875                         rec->startts.toString(Qt::ISODate));
     1876         MVDirFormat.replace(QRegExp("%PROGENDISO%"),
     1877                         rec->endts.toString(Qt::ISODate));
     1878
     1879    }
     1880
     1881    QString MVFileFormat = gContext->GetSetting("TVExportFileFormat",
     1882                              "%TITLE% - %SUBTITLE%");
     1883    if (!MVFileFormat.isEmpty())
     1884    {
     1885         MVFileFormat.replace(QRegExp("%FILE%"), rec->GetRecordBasename(true));
     1886         MVFileFormat.replace(QRegExp("%TITLE%"), rec->title);
     1887         MVFileFormat.replace(QRegExp("%SUBTITLE%"), rec->subtitle);
     1888         MVFileFormat.replace(QRegExp("%DESCRIPTION%"), rec->description);
     1889         MVFileFormat.replace(QRegExp("%HOSTNAME%"), rec->hostname);
     1890         MVFileFormat.replace(QRegExp("%CATEGORY%"), rec->category);
     1891         MVFileFormat.replace(QRegExp("%RECGROUP%"), rec->recgroup);
     1892         MVFileFormat.replace(QRegExp("%PLAYGROUP%"), rec->playgroup);
     1893         MVFileFormat.replace(QRegExp("%CHANID%"), rec->chanid);
     1894         MVFileFormat.replace(QRegExp("%STARTTIME%"),
     1895                         rec->recstartts.toString("yyyyMMddhhmmss"));
     1896         MVFileFormat.replace(QRegExp("%ENDTIME%"),
     1897                         rec->recendts.toString("yyyyMMddhhmmss"));
     1898         MVFileFormat.replace(QRegExp("%STARTTIMEISO%"),
     1899                         rec->recstartts.toString(Qt::ISODate));
     1900         MVFileFormat.replace(QRegExp("%ENDTIMEISO%"),
     1901                         rec->recendts.toString(Qt::ISODate));
     1902         MVFileFormat.replace(QRegExp("%PROGSTART%"),
     1903                         rec->startts.toString("yyyyMMddhhmmss"));
     1904         MVFileFormat.replace(QRegExp("%PROGEND%"),
     1905                         rec->endts.toString("yyyyMMddhhmmss"));
     1906         MVFileFormat.replace(QRegExp("%PROGSTARTISO%"),
     1907                         rec->startts.toString(Qt::ISODate));
     1908         MVFileFormat.replace(QRegExp("%PROGENDISO%"),
     1909                         rec->endts.toString(Qt::ISODate));
     1910
     1911    }
     1912
     1913    QString copyToDir = QString("%1/%2/").arg(baseMVDir).arg(MVDirFormat);
     1914    QString copyToFile = QString("%1/%2.%3").arg(copyToDir)
     1915                             .arg(MVFileFormat).arg(extension);
     1916
     1917    // File and Directory Definitions
     1918
     1919    QFile fromFile(copyFrom);
     1920    QDir toDir(copyToDir);
     1921    QFile toFile(copyToFile);
     1922
     1923    if (!toDir.exists())
     1924    {
     1925        // Attempt to create path to export point.
     1926        toDir.mkpath(copyToDir);
     1927        toDir.mkdir(copyToDir);
     1928        if (!toDir.exists())
     1929        {
     1930            VERBOSE(VB_IMPORTANT, QString("Unable to create directory %1! "
     1931                                          "Please ensure the preceding path "
     1932                                          "exists and is writeable.").arg(copyToDir));   
     1933            return;
     1934        }
     1935    }
     1936
     1937    VERBOSE(VB_IMPORTANT, QString("Exporting to MythVideo:\n "
     1938                                   "Title: %1\n "
     1939                                   "Subtitle: %2\n "
     1940                                   "Description: %3\n "
     1941                                   "User Rating: %4\n "
     1942                                   "Year: %5\n "
     1943                                   "Length: %6 Minutes\n "
     1944                                   "Copying From File: %7\n "
     1945                                   "Copying to File: %8 ").arg(rec->title).arg(rec->subtitle).arg(rec->description).arg(exportRating).arg(rec->year).arg(rec->lenMins).arg(copyFrom).arg(copyToFile));
     1946
     1947    long long int bytesCopied = copy(toFile,fromFile);
     1948
     1949    if (bytesCopied != -1)
     1950    {
     1951        // Prepare the DB Query
     1952
     1953        MSqlQuery query(MSqlQuery::InitCon());
     1954
     1955        query.prepare("INSERT INTO videometadata (title,plot,year,"
     1956                          "userrating,length,filename,showlevel,inetref, "
     1957                          "browse) VALUES (:TITLE, :PLOT, :YEAR, :USERRATING, "
     1958                          ":LENGTH, :FILENAME, :SHOWLEVEL, :INETREF, :BROWSE)");
     1959
     1960        query.bindValue(":TITLE", MVFileFormat);
     1961        query.bindValue(":PLOT", rec->description);
     1962        query.bindValue(":YEAR", rec->year);
     1963        query.bindValue(":USERRATING", exportRating);
     1964        query.bindValue(":LENGTH", rec->lenMins);
     1965        query.bindValue(":FILENAME", copyToFile);
     1966        query.bindValue(":SHOWLEVEL", 1);
     1967        query.bindValue(":INETREF", 0);
     1968        query.bindValue(":BROWSE", 1);
     1969
     1970        if (!query.exec() || !query.isActive())
     1971        {
     1972            MythDB::DBError("video metadata update", query);
     1973            return;
     1974        }
     1975
     1976        VERBOSE(VB_IMPORTANT, QString("Copy succeeded, %1 bytes copied.").arg(bytesCopied));
     1977    }
     1978    else
     1979    {
     1980        VERBOSE(VB_IMPORTANT, QString("Copy unsuccessful, check all permissions."));
     1981    }
     1982}
     1983
    18161984bool PlaybackBox::doRemove(ProgramInfo *rec, bool forgetHistory,
    18171985                           bool forceMetadataDelete)
    18181986{
     
    18672035        showActionPopup(pginfo);
    18682036}
    18692037
     2038void PlaybackBox::showExportPopup(ProgramInfo *program)
     2039{
     2040    if (m_popupMenu)
     2041        return;
     2042
     2043    QString label = tr("Are you sure you want to export:");
     2044
     2045    m_expItem = CurrentItem();
     2046    popupString(m_expItem, label);
     2047
     2048    m_popupMenu = new MythDialogBox(label, m_popupStack, "pbbmainmenupopup");
     2049
     2050    connect(m_popupMenu, SIGNAL(Exiting()), SLOT(popupClosed()));
     2051
     2052    if (m_popupMenu->Create())
     2053        m_popupStack->AddScreen(m_popupMenu);
     2054    else
     2055    {
     2056        delete m_popupMenu;
     2057        m_popupMenu = NULL;
     2058    }
     2059
     2060    m_popupMenu->SetReturnEvent(this, "slotmenu");
     2061
     2062    m_freeSpaceNeedsUpdate = true;
     2063    QString tmpmessage;
     2064    const char *tmpslot = NULL;
     2065
     2066    if (program->IsSameProgram(*program))
     2067        {
     2068        tmpmessage = tr("Yes, Export to MythVideo");
     2069        tmpslot = SLOT(doMVExport());
     2070        m_popupMenu->AddButton(tmpmessage, tmpslot);
     2071
     2072        tmpmessage = tr("No, I don't want to Export");
     2073        tmpslot = SLOT(noExport());
     2074        m_popupMenu->AddButton(tmpmessage, tmpslot);
     2075        }
     2076}
     2077
     2078
    18702079void PlaybackBox::showDeletePopup(ProgramInfo *program, deletePopupType types)
    18712080{
    18722081    if (m_popupMenu)
     
    25122721                           true);
    25132722    m_popupMenu->AddButton(tr("Job Options"), SLOT(showJobPopup()), true);
    25142723
     2724    QString MVlocation = FindPluginName("mythvideo");
     2725    if (QFile(MVlocation).exists())
     2726        m_popupMenu->AddButton(tr("Export to MythVideo"), SLOT(askMVExport()));
     2727
    25152728    if (!(m_player && m_player->IsSameProgram(0, pginfo)))
    25162729    {
    25172730        if (pginfo->recgroup == "Deleted")
     
    26082821    stop(pginfo);
    26092822}
    26102823
     2824void PlaybackBox::doMVExport(void)
     2825{
     2826    ProgramInfo *pginfo = CurrentItem();
     2827    mvexport(pginfo);
     2828}
     2829
    26112830void PlaybackBox::showProgramDetails()
    26122831{
    26132832   ProgramInfo *pginfo = CurrentItem();
     
    27462965    }
    27472966}
    27482967
     2968void PlaybackBox::askMVExport(ProgramInfo *pginfo)
     2969{
     2970    if (!pginfo)
     2971        pginfo = CurrentItem();
     2972    showExportPopup(pginfo);
     2973}
     2974
    27492975void PlaybackBox::askDelete(ProgramInfo *pginfo)
    27502976{
    27512977    if (!pginfo)
  • mythtv/programs/mythfrontend/playbackbox.h

     
    137137    void upcoming();
    138138    void details();
    139139    void stopSelected();
     140    void exportMVSelected();
    140141    void showMenu();
    141142    void showActionsSelected();
    142143    void showRecGroupChanger();
     
    170171
    171172    void askStop();
    172173    void doStop();
     174    void askMVExport(ProgramInfo *pginfo = NULL);
     175    void doMVExport();
    173176
    174177    void doEditScheduled();
    175178    void doAllowRerecord();
     
    260263
    261264    bool play(ProgramInfo *rec, bool inPlaylist = false);
    262265    void stop(ProgramInfo *);
     266    void mvexport(ProgramInfo *);
    263267    void remove(ProgramInfo *);
    264268    void showActions(ProgramInfo *);
    265269    ProgramInfo *CurrentItem(void);
     
    279283
    280284    bool doRemove(ProgramInfo *, bool forgetHistory, bool forceMetadataDelete);
    281285    void showDeletePopup(ProgramInfo *, deletePopupType);
     286    void showExportPopup(ProgramInfo *);
    282287    void showActionPopup(ProgramInfo *program);
    283288    void showFileNotFoundActionPopup(ProgramInfo *program);
    284289    void popupString(ProgramInfo *program, QString &message);
     
    376381    // Other state
    377382    /// Program currently selected for deletion
    378383    ProgramInfo *m_delItem;
     384    /// Program currently selected for export
     385    ProgramInfo *m_expItem;
    379386    /// Program currently selected during an update
    380387    ProgramInfo *m_currentItem;
    381388    /// Group currently selected
  • mythplugins/mythvideo/mythvideo/globalsettings.cpp

     
    236236    return gc;
    237237}
    238238
     239HostLineEdit *TVExportDirectoryFormat()
     240{
     241    HostLineEdit *gc = new HostLineEdit("TVExportDirFormat");
     242    gc->setLabel(QObject::tr("TV Export Directory Format"));
     243    gc->setValue(DEFAULT_TVEXPORTDIRFORMAT);
     244    gc->setHelpText(QObject::tr("Directory format for Recording export "
     245                    "to MythVideo, using User Job Style Variables. EX: "
     246                    "Television/%CATEGORY%/%TITLE%"));
     247    return gc;
     248}
     249
     250HostLineEdit *TVExportFileFormat()
     251{
     252    HostLineEdit *gc = new HostLineEdit("TVExportFileFormat");
     253    gc->setLabel(QObject::tr("TV Export File Format"));
     254    gc->setValue(DEFAULT_TVEXPORTFILEFORMAT);
     255    gc->setHelpText(QObject::tr("File Format for Recording export "
     256                    "to MythVideo, using User Job Style Variables. EX: "
     257                    "%TITLE% - %SUBTITLE% (%STARTTIMEISO%)"));
     258    return gc;
     259}
     260
    239261HostLineEdit *VideoArtworkDirectory()
    240262{
    241263    HostLineEdit *gc = new HostLineEdit("VideoArtworkDir");
     
    683704    page1->addChild(VideoStartupDirectory());
    684705    page1->addChild(VideoArtworkDirectory());
    685706    page1->addChild(VideoDefaultView());
     707    page1->addChild(TVExportDirectoryFormat());
     708    page1->addChild(TVExportFileFormat());
    686709
    687710    VConfigPage page2(pages, false);
    688711    page2->addChild(VideoListUnknownFiletypes());
  • mythplugins/mythvideo/mythvideo/globals.cpp

     
    2828
    2929#ifdef Q_WS_MACX
    3030const QString DEFAULT_VIDEOSTARTUP_DIR = QDir::homePath() + "/Movies";
     31const QString DEFAULT_TVEXPORTDIRFORMAT = "Television/%TITLE%";
     32const QString DEFAULT_TVEXPORTFILEFORMAT = "%TITLE% - %SUBTITLE%";
    3133#else
    3234const QString DEFAULT_VIDEOSTARTUP_DIR = "/share/Movies/dvd";
     35const QString DEFAULT_TVEXPORTDIRFORMAT = "Television/%TITLE%";
     36const QString DEFAULT_TVEXPORTFILEFORMAT = "%TITLE% - %SUBTITLE%";
    3337#endif
  • mythplugins/mythvideo/mythvideo/globals.h

     
    2525extern const QString JUMP_VIDEO_DEFAULT;
    2626
    2727extern const QString DEFAULT_VIDEOSTARTUP_DIR;
     28extern const QString DEFAULT_TVEXPORTDIRFORMAT;
     29extern const QString DEFAULT_TVEXPORTFILEFORMAT;
    2830
    2931#endif // GLOBALS_H_