Ticket #6158: PBBMVExport.diff
File PBBMVExport.diff, 14.0 KB (added by , 15 years ago) |
---|
-
mythtv/programs/mythfrontend/playbackbox.cpp
20 20 #include "mythdirs.h" 21 21 #include "mythcontext.h" 22 22 #include "mythdbcon.h" 23 #include "mythdb.h" 23 24 #include "mythverbose.h" 24 25 #include "programinfo.h" 25 26 #include "scheduledrecording.h" … … 1554 1555 stop(pginfo); 1555 1556 } 1556 1557 1558 void PlaybackBox::exportMVSelected() 1559 { 1560 ProgramInfo *pginfo = CurrentItem(); 1561 1562 if (!pginfo) 1563 return; 1564 1565 mvexport(pginfo); 1566 } 1567 1557 1568 void PlaybackBox::deleteSelected(MythUIButtonListItem *item) 1558 1569 { 1559 1570 if (!item) … … 1813 1824 RemoteStopRecording(rec); 1814 1825 } 1815 1826 1827 void 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 1816 1984 bool PlaybackBox::doRemove(ProgramInfo *rec, bool forgetHistory, 1817 1985 bool forceMetadataDelete) 1818 1986 { … … 1867 2035 showActionPopup(pginfo); 1868 2036 } 1869 2037 2038 void 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 1870 2079 void PlaybackBox::showDeletePopup(ProgramInfo *program, deletePopupType types) 1871 2080 { 1872 2081 if (m_popupMenu) … … 2512 2721 true); 2513 2722 m_popupMenu->AddButton(tr("Job Options"), SLOT(showJobPopup()), true); 2514 2723 2724 QString MVlocation = FindPluginName("mythvideo"); 2725 if (QFile(MVlocation).exists()) 2726 m_popupMenu->AddButton(tr("Export to MythVideo"), SLOT(askMVExport())); 2727 2515 2728 if (!(m_player && m_player->IsSameProgram(0, pginfo))) 2516 2729 { 2517 2730 if (pginfo->recgroup == "Deleted") … … 2608 2821 stop(pginfo); 2609 2822 } 2610 2823 2824 void PlaybackBox::doMVExport(void) 2825 { 2826 ProgramInfo *pginfo = CurrentItem(); 2827 mvexport(pginfo); 2828 } 2829 2611 2830 void PlaybackBox::showProgramDetails() 2612 2831 { 2613 2832 ProgramInfo *pginfo = CurrentItem(); … … 2746 2965 } 2747 2966 } 2748 2967 2968 void PlaybackBox::askMVExport(ProgramInfo *pginfo) 2969 { 2970 if (!pginfo) 2971 pginfo = CurrentItem(); 2972 showExportPopup(pginfo); 2973 } 2974 2749 2975 void PlaybackBox::askDelete(ProgramInfo *pginfo) 2750 2976 { 2751 2977 if (!pginfo) -
mythtv/programs/mythfrontend/playbackbox.h
137 137 void upcoming(); 138 138 void details(); 139 139 void stopSelected(); 140 void exportMVSelected(); 140 141 void showMenu(); 141 142 void showActionsSelected(); 142 143 void showRecGroupChanger(); … … 170 171 171 172 void askStop(); 172 173 void doStop(); 174 void askMVExport(ProgramInfo *pginfo = NULL); 175 void doMVExport(); 173 176 174 177 void doEditScheduled(); 175 178 void doAllowRerecord(); … … 260 263 261 264 bool play(ProgramInfo *rec, bool inPlaylist = false); 262 265 void stop(ProgramInfo *); 266 void mvexport(ProgramInfo *); 263 267 void remove(ProgramInfo *); 264 268 void showActions(ProgramInfo *); 265 269 ProgramInfo *CurrentItem(void); … … 279 283 280 284 bool doRemove(ProgramInfo *, bool forgetHistory, bool forceMetadataDelete); 281 285 void showDeletePopup(ProgramInfo *, deletePopupType); 286 void showExportPopup(ProgramInfo *); 282 287 void showActionPopup(ProgramInfo *program); 283 288 void showFileNotFoundActionPopup(ProgramInfo *program); 284 289 void popupString(ProgramInfo *program, QString &message); … … 376 381 // Other state 377 382 /// Program currently selected for deletion 378 383 ProgramInfo *m_delItem; 384 /// Program currently selected for export 385 ProgramInfo *m_expItem; 379 386 /// Program currently selected during an update 380 387 ProgramInfo *m_currentItem; 381 388 /// Group currently selected -
mythplugins/mythvideo/mythvideo/globalsettings.cpp
236 236 return gc; 237 237 } 238 238 239 HostLineEdit *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 250 HostLineEdit *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 239 261 HostLineEdit *VideoArtworkDirectory() 240 262 { 241 263 HostLineEdit *gc = new HostLineEdit("VideoArtworkDir"); … … 683 704 page1->addChild(VideoStartupDirectory()); 684 705 page1->addChild(VideoArtworkDirectory()); 685 706 page1->addChild(VideoDefaultView()); 707 page1->addChild(TVExportDirectoryFormat()); 708 page1->addChild(TVExportFileFormat()); 686 709 687 710 VConfigPage page2(pages, false); 688 711 page2->addChild(VideoListUnknownFiletypes()); -
mythplugins/mythvideo/mythvideo/globals.cpp
28 28 29 29 #ifdef Q_WS_MACX 30 30 const QString DEFAULT_VIDEOSTARTUP_DIR = QDir::homePath() + "/Movies"; 31 const QString DEFAULT_TVEXPORTDIRFORMAT = "Television/%TITLE%"; 32 const QString DEFAULT_TVEXPORTFILEFORMAT = "%TITLE% - %SUBTITLE%"; 31 33 #else 32 34 const QString DEFAULT_VIDEOSTARTUP_DIR = "/share/Movies/dvd"; 35 const QString DEFAULT_TVEXPORTDIRFORMAT = "Television/%TITLE%"; 36 const QString DEFAULT_TVEXPORTFILEFORMAT = "%TITLE% - %SUBTITLE%"; 33 37 #endif -
mythplugins/mythvideo/mythvideo/globals.h
25 25 extern const QString JUMP_VIDEO_DEFAULT; 26 26 27 27 extern const QString DEFAULT_VIDEOSTARTUP_DIR; 28 extern const QString DEFAULT_TVEXPORTDIRFORMAT; 29 extern const QString DEFAULT_TVEXPORTFILEFORMAT; 28 30 29 31 #endif // GLOBALS_H_