Skip to content

Commit

Permalink
Update UI to show where to download external tools
Browse files Browse the repository at this point in the history
MakeMKV is now Make H265 MKV
  • Loading branch information
towel42-com committed Mar 6, 2023
1 parent 8485470 commit 97fe8d2
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 0 deletions.
140 changes: 140 additions & 0 deletions Models/MakeH265MKVModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// The MIT License( MIT )
//
// Copyright( c ) 2020-2021 Scott Aron Bloom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files( the "Software" ), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "MakeH265MKVModel.h"
#include "Preferences/Core/Preferences.h"
#include "SABUtils/FileUtils.h"
#include "SABUtils/DoubleProgressDlg.h"
#include "SABUtils/MKVUtils.h"

#include <QDir>
#include <QTimer>

namespace NMediaManager
{
namespace NModels
{
CMakeH265MKVModel::CMakeH265MKVModel( NUi::CBasePage *page, QObject *parent /*= 0*/ ) :
CDirModel( page, parent )
{
}

CMakeH265MKVModel::~CMakeH265MKVModel()
{
}

QStringList CMakeH265MKVModel::dirModelFilter() const
{
return NPreferences::NCore::CPreferences::instance()->getNonMKVMediaExtensions();
}

std::pair< bool, QStandardItem * > CMakeH265MKVModel::processItem( const QStandardItem *item, bool displayOnly )
{
if ( item->data( ECustomRoles::eIsDir ).toBool() )
return std::make_pair( true, nullptr );

SProcessInfo processInfo;
processInfo.fSetMKVTagsOnSuccess = true;
processInfo.fOldName = item->data( ECustomRoles::eAbsFilePath ).toString();
auto fi = QFileInfo( processInfo.fOldName );
processInfo.fNewNames << fi.absoluteDir().absoluteFilePath( fi.completeBaseName() + ".mkv" );
processInfo.fItem = new QStandardItem( QString( "Convert '%1' => '%2'" ).arg( getDispName( processInfo.fOldName ) ).arg( getDispName( processInfo.fNewNames.front() ) ) );
processInfo.fItem->setData( processInfo.fOldName, ECustomRoles::eOldName );
processInfo.fItem->setData( processInfo.fNewNames, ECustomRoles::eNewName );

bool aOK = true;
QStandardItem *myItem = nullptr;
fFirstProcess = true;
if ( !displayOnly )
{
processInfo.fMaximum = NSABUtils::getNumberOfSeconds( processInfo.fOldName );
processInfo.fCmd = NPreferences::NCore::CPreferences::instance()->getFFMpegEXE();
if ( processInfo.fCmd.isEmpty() || !QFileInfo( processInfo.fCmd ).isExecutable() )
{
QStandardItem *errorItem = nullptr;
if ( processInfo.fCmd.isEmpty() )
appendError( processInfo.fItem, tr( "ffmpeg is not set properly" ) );
else
appendError( processInfo.fItem, tr( "ffmpeg '%1' is not an executable" ).arg( processInfo.fCmd ) );
aOK = false;
}

aOK = aOK && checkProcessItemExists( processInfo.fOldName, processInfo.fItem );
processInfo.fTimeStamps = NSABUtils::NFileUtils::timeStamps( processInfo.fOldName );

processInfo.fArgs = QStringList() << "-y"
<< "-fflags"
<< "+genpts"
<< "-i" << processInfo.fOldName << "-c:v"
<< "copy"
<< "-c:a"
<< "copy" << processInfo.fNewNames;
fProcessQueue.push_back( processInfo );
QTimer::singleShot( 0, this, &CDirModel::slotRunNextProcessInQueue );
}
myItem = processInfo.fItem;
return std::make_pair( aOK, myItem );
}

QString CMakeH265MKVModel::getProgressLabel( const SProcessInfo &processInfo ) const
{
auto retVal = QString( "Converting to H.265 MKV<ul><li>%1</li>to<li>%2</li></ul>" ).arg( getDispName( processInfo.fOldName ) ).arg( getDispName( processInfo.fNewNames.front() ) );
return retVal;
}

QStringList CMakeH265MKVModel::headers() const
{
return CDirModel::headers() << getMediaHeaders();
;
}

void CMakeH265MKVModel::postLoad( QTreeView *treeView )
{
CDirModel::postLoad( treeView );
}

void CMakeH265MKVModel::preLoad( QTreeView *treeView )
{
CDirModel::preLoad( treeView );
}

void CMakeH265MKVModel::postProcess( bool /*displayOnly*/ )
{
if ( progressDlg() )
progressDlg()->setValue( 0 );
}

void CMakeH265MKVModel::postFileFunction( bool /*aOK*/, const QFileInfo & /*fileInfo*/, TParentTree & /*tree*/, bool /*countOnly*/ )
{
}

bool CMakeH265MKVModel::preFileFunction( const QFileInfo & /*fileInfo*/, std::unordered_set< QString > & /*alreadyAdded*/, TParentTree & /*tree*/, bool /*countOnly*/ )
{
return true;
}

void CMakeH265MKVModel::attachTreeNodes( QStandardItem * /*nextParent*/, QStandardItem *& /*prevParent*/, const STreeNode & /*treeNode*/ )
{
}

}
}
65 changes: 65 additions & 0 deletions Models/MakeH265MKVModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// The MIT License( MIT )
//
// Copyright( c ) 2020-2021 Scott Aron Bloom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files( the "Software" ), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#ifndef _MAKEH265MKVMODEL_H
#define _MAKEH265MKVMODEL_H

#include "DirModel.h"

namespace NMediaManager
{
namespace NModels
{
class CMakeH265MKVModel : public CDirModel
{
Q_OBJECT
public:
enum EColumns
{
eMediaColumnLoc = NModels::EColumns::eFirstCustomColumn,
};

CMakeH265MKVModel( NUi::CBasePage *page, QObject *parent = nullptr );
virtual ~CMakeH265MKVModel() override;

private:
virtual QStringList dirModelFilter() const override;

virtual std::pair< bool, QStandardItem * > processItem( const QStandardItem *item, bool displayOnly ) override;
virtual bool showMediaItems() const override { return true; };
virtual int firstMediaItemColumn() const override { return EColumns::eMediaColumnLoc; }
virtual QStringList headers() const override;
virtual QString getProgressLabel( const SProcessInfo &processInfo ) const override;
virtual void postLoad( QTreeView * /*treeView*/ ) override;
virtual void preLoad( QTreeView * /*treeView*/ ) override;
virtual void postProcess( bool /*displayOnly*/ ) override;

virtual void postFileFunction( bool aOK, const QFileInfo &fileInfo, TParentTree & /*tree*/, bool countOnly ) override;
virtual bool preFileFunction( const QFileInfo &fileInfo, std::unordered_set< QString > &alreadyAdded, TParentTree &tree, bool countOnly ) override;

virtual void attachTreeNodes( QStandardItem * /*nextParent*/, QStandardItem *& /*prevParent*/, const STreeNode & /*treeNode*/ ) override;

virtual bool usesQueuedProcessing() const override { return true; }
};
}
}
#endif
124 changes: 124 additions & 0 deletions UI/MakeH265MKVPage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// The MIT License( MIT )
//
// Copyright( c ) 2020-2021 Scott Aron Bloom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files( the "Software" ), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "MakeH265MKVPage.h"

#include "Preferences/Core/Preferences.h"
#include "Models/MakeH265MKVModel.h"
#include "SABUtils/DoubleProgressDlg.h"

#include <QRegularExpression>

namespace NMediaManager
{
namespace NUi
{
CMakeH265MKVPage::CMakeH265MKVPage( QWidget *parent ) :
CBasePage( "Make H.265 MKV", parent )
{
}

CMakeH265MKVPage::~CMakeH265MKVPage()
{
}

NModels::CDirModel *CMakeH265MKVPage::createDirModel()
{
return new NModels::CMakeH265MKVModel( this );
}

QString CMakeH265MKVPage::secondaryProgressLabel() const
{
return tr( "Current (seconds):" );
}

QString CMakeH265MKVPage::loadTitleName() const
{
return tr( "Finding Files" );
}

QString CMakeH265MKVPage::loadCancelName() const
{
return tr( "Cancel" );
}

QString CMakeH265MKVPage::actionTitleName() const
{
return tr( "Creating H.265 MKV..." );
}

QString CMakeH265MKVPage::actionCancelName() const
{
return tr( "Abort Creating H.265 MKV" );
}

QString CMakeH265MKVPage::actionErrorName() const
{
return tr( "Error while Creating H.265 MKV:" );
}

void CMakeH265MKVPage::postProcessLog( const QString &string )
{
// time=00:00:00.00
auto regEx = QRegularExpression( "[Tt]ime\\=\\s*(?<hours>\\d{2}):(?<mins>\\d{2}):(?<secs>\\d{2})" );

auto pos = string.lastIndexOf( regEx );
if ( pos == -1 )
return;

auto match = regEx.match( string, pos );
if ( !match.hasMatch() )
return;

auto hours = match.captured( "hours" );
auto mins = match.captured( "mins" );
auto secs = match.captured( "secs" );

int numSeconds = 0;
if ( !hours.isEmpty() )
{
bool aOK;
int curr = hours.toInt( &aOK );
if ( aOK )
numSeconds += curr * 60 * 60;
}

if ( !mins.isEmpty() )
{
bool aOK;
int curr = mins.toInt( &aOK );
if ( aOK )
numSeconds += curr * 60;
}

if ( !secs.isEmpty() )
{
bool aOK;
int curr = secs.toInt( &aOK );
if ( aOK )
numSeconds += curr;
}

fProgressDlg->setSecondaryValue( numSeconds );
}
}
}
60 changes: 60 additions & 0 deletions UI/MakeH265MKVPage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// The MIT License( MIT )
//
// Copyright( c ) 2020-2021 Scott Aron Bloom
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files( the "Software" ), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#ifndef _MAKEH265MKVPAGE_H
#define _MAKEH265MKVPAGE_H

#include "BasePage.h"

namespace NMediaManager
{
namespace NUi
{
class CMakeH265MKVPage : public CBasePage
{
Q_OBJECT
public:
CMakeH265MKVPage( QWidget *parent = nullptr );
virtual ~CMakeH265MKVPage() override;

virtual bool useSecondaryProgressBar() const override { return true; }
virtual QString secondaryProgressLabel() const override;

virtual QString loadTitleName() const override;
virtual QString loadCancelName() const override;

virtual QString actionTitleName() const override;
virtual QString actionCancelName() const override;
virtual QString actionErrorName() const override;

virtual NModels::CDirModel *createDirModel() override;

virtual void postProcessLog( const QString &string ) override;

Q_SIGNALS:
public Q_SLOTS:
protected Q_SLOTS:
protected:
};
}
}
#endif
Binary file added UI/resources/h265.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 97fe8d2

Please sign in to comment.