| 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->originalAirDate.toString("yyyy")).arg(rec->lenMins).arg(copyFrom).arg(copyToFile)); |
| 1946 | |
| 1947 | long long int bytesCopied = copy(toFile,fromFile); |
| 1948 | |
| 1949 | if (bytesCopied != -1) |
| 1950 | { |
| 1951 | // Add File into videometadata |
| 1952 | |
| 1953 | MSqlQuery query(MSqlQuery::InitCon()); |
| 1954 | |
| 1955 | query.prepare("INSERT INTO videometadata (title,plot,year,category," |
| 1956 | "userrating,length,filename,showlevel,inetref, " |
| 1957 | "browse) VALUES (:TITLE, :PLOT, :YEAR, :CATEGORY, " |
| 1958 | ":USERRATING, :LENGTH, :FILENAME, :SHOWLEVEL, " |
| 1959 | ":INETREF, :BROWSE)"); |
| 1960 | |
| 1961 | query.bindValue(":TITLE", MVFileFormat); |
| 1962 | query.bindValue(":PLOT", rec->description); |
| 1963 | query.bindValue(":YEAR", rec->originalAirDate.toString("yyyy")); |
| 1964 | query.bindValue(":CATEGORY", rec->category); |
| 1965 | query.bindValue(":USERRATING", exportRating); |
| 1966 | query.bindValue(":LENGTH", rec->lenMins); |
| 1967 | query.bindValue(":FILENAME", copyToFile); |
| 1968 | query.bindValue(":SHOWLEVEL", 1); |
| 1969 | query.bindValue(":INETREF", 0); |
| 1970 | query.bindValue(":BROWSE", 1); |
| 1971 | |
| 1972 | if (!query.exec() || !query.isActive()) |
| 1973 | { |
| 1974 | MythDB::DBError("video metadata update", query); |
| 1975 | return; |
| 1976 | } |
| 1977 | |
| 1978 | // Move recordedmarkup for file into videometadata |
| 1979 | |
| 1980 | MSqlQuery markup(MSqlQuery::InitCon()); |
| 1981 | |
| 1982 | markup.prepare("INSERT INTO filemarkup (filename,mark,offset,type) " |
| 1983 | "SELECT :FILENAME, mark, data, type from " |
| 1984 | "recordedmarkup where chanid=:CHANID and starttime=:STARTTIME"); |
| 1985 | |
| 1986 | markup.bindValue(":FILENAME", copyToFile); |
| 1987 | markup.bindValue(":CHANID", rec->chanid); |
| 1988 | markup.bindValue(":STARTTIME", rec->recstartts); |
| 1989 | |
| 1990 | if (!markup.exec() || !markup.isActive()) |
| 1991 | { |
| 1992 | MythDB::DBError("video metadata update", markup); |
| 1993 | return; |
| 1994 | } |
| 1995 | |
| 1996 | // Copy and set preview image as coverfile |
| 1997 | |
| 1998 | QString imagefile = NULL; |
| 1999 | imagefile = getPreviewImage(rec); |
| 2000 | QString MVScreenshotDir = gContext->GetSetting("VideoScreenshotDir"); |
| 2001 | QString MVimagefile = QString("%1/%2.png").arg(MVScreenshotDir).arg(MVFileFormat); |
| 2002 | |
| 2003 | VERBOSE(VB_IMPORTANT, QString("Copying %1 to %2").arg(imagefile).arg(MVimagefile)); |
| 2004 | |
| 2005 | QFile fromPoster(imagefile); |
| 2006 | QFile toPoster(MVimagefile); |
| 2007 | |
| 2008 | long long int posterBytesCopied = copy(toPoster,fromPoster); |
| 2009 | |
| 2010 | if (posterBytesCopied != -1) |
| 2011 | { |
| 2012 | MSqlQuery poster(MSqlQuery::InitCon()); |
| 2013 | |
| 2014 | poster.prepare("UPDATE videometadata set screenshot=:COVERFILE " |
| 2015 | "where filename=:FILENAME"); |
| 2016 | |
| 2017 | poster.bindValue(":COVERFILE", MVimagefile); |
| 2018 | poster.bindValue(":FILENAME", copyToFile); |
| 2019 | |
| 2020 | if (!poster.exec() || !poster.isActive()) |
| 2021 | { |
| 2022 | MythDB::DBError("video metadata update", poster); |
| 2023 | return; |
| 2024 | } |
| 2025 | } |
| 2026 | else |
| 2027 | { |
| 2028 | VERBOSE(VB_IMPORTANT, QString("Copy succeeded, but image copy failed.").arg(posterBytesCopied)); |
| 2029 | return; |
| 2030 | } |
| 2031 | VERBOSE(VB_IMPORTANT, QString("Copy succeeded, %1 bytes copied.").arg(bytesCopied)); |
| 2032 | } |
| 2033 | else |
| 2034 | { |
| 2035 | VERBOSE(VB_IMPORTANT, QString("Copy unsuccessful, check all permissions.")); |
| 2036 | } |
| 2037 | } |
| 2038 | |