Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CUtil Class Reference

#include <Util.h>

Static Public Member Functions

static void CleanString (const std::string &strFileName, std::string &strTitle, std::string &strTitleAndYear, std::string &strYear, bool bRemoveExtension=false, bool bCleanChars=true)
 
static bool GetFilenameIdentifier (const std::string &fileName, std::string &identifierType, std::string &identifier)
 
static bool GetFilenameIdentifier (const std::string &fileName, std::string &identifierType, std::string &identifier, std::string &match)
 
static bool HasFilenameIdentifier (const std::string &fileName)
 
static std::string GetTitleFromPath (const CURL &url, bool bIsFolder=false)
 
static std::string GetTitleFromPath (const std::string &strFileNameAndPath, bool bIsFolder=false)
 
static std::string GetDiscNumberFromPath (const std::string &path)
 Return the disc number in case the last segment of given path ends with 'Disc n'. Will look for 'Disc', 'Disk' and the locale specific spelling.
 
static std::string RemoveTrailingDiscNumberSegmentFromPath (std::string path)
 Remove last segment of the given path if it matches 'Disc n'. Will look for 'Disc', 'Disk' and the locale specific spelling.
 
static void GetQualifiedFilename (const std::string &strBasePath, std::string &strFilename)
 
static void RunShortcut (const char *szPath)
 
static std::string GetHomePath (const std::string &strTarget="KODI_HOME")
 
static bool ExcludeFileOrFolder (const std::string &strFileOrFolder, const std::vector< std::string > &regexps)
 
static void GetFileAndProtocol (const std::string &strURL, std::string &strDir)
 
static int GetDVDIfoTitle (const std::string &strPathFile)
 
static bool IsPicture (const std::string &strFile)
 
static std::string GetSplashPath ()
 Get resolved filesystem location of splash image.
 
static std::string GetFileDigest (const std::string &strPath, KODI::UTILITY::CDigest::Type type)
 retrieve MD5sum of a file
 
static bool GetDirectoryName (const std::string &strFileName, std::string &strDescription)
 
static void GetDVDDriveIcon (const std::string &strPath, std::string &strIcon)
 
static void RemoveTempFiles ()
 
static void ClearSubtitles ()
 
static void ScanForExternalSubtitles (const std::string &strMovie, std::vector< std::string > &vecSubtitles)
 
static ExternalStreamInfo GetExternalStreamDetailsFromFilename (const std::string &videoPath, const std::string &associatedFile)
 Retrieves stream info of external associated files, e.g., subtitles, for a given video.
 
static bool FindVobSubPair (const std::vector< std::string > &vecSubtitles, const std::string &strIdxPath, std::string &strSubPath)
 in a vector of subtitles finds the corresponding .sub file for a given .idx file
 
static bool IsVobSub (const std::vector< std::string > &vecSubtitles, const std::string &strSubPath)
 checks if in the vector of subtitles the given .sub file has a corresponding idx and hence is a vobsub file
 
static std::string GetVobSubSubFromIdx (const std::string &vobSubIdx)
 find a plain or archived vobsub .sub file corresponding to an .idx file
 
static std::string GetVobSubIdxFromSub (const std::string &vobSub)
 find a .idx file from a path of a plain or archived vobsub .sub file
 
static void ScanForExternalAudio (const std::string &videoPath, std::vector< std::string > &vecAudio)
 Retrieves paths of external audio files for a given video.
 
static int64_t ToInt64 (uint32_t high, uint32_t low)
 
static std::string GetNextFilename (const std::string &fn_template, int max)
 Finds next unused filename that matches padded int format identifier provided.
 
static std::string GetNextPathname (const std::string &path_template, int max)
 
static void StatToStatI64 (struct _stati64 *result, struct stat *stat)
 
static void StatToStat64 (struct __stat64 *result, const struct stat *stat)
 
static void Stat64ToStatI64 (struct _stati64 *result, struct __stat64 *stat)
 
static void StatI64ToStat64 (struct __stat64 *result, struct _stati64 *stat)
 
static void Stat64ToStat (struct stat *result, struct __stat64 *stat)
 
static bool CreateDirectoryEx (const std::string &strPath)
 
static std::string MakeLegalFileName (std::string strFile, int LegalType=LEGAL_NONE)
 
static std::string MakeLegalPath (std::string strPath, int LegalType=LEGAL_NONE)
 
static std::string ValidatePath (std::string path, bool bFixDoubleSlashes=false)
 return a validated path, with correct directory separators.
 
static bool IsSupportedFontExtension (const std::string &fileName)
 Check if a filename contains a supported font extension.
 
static void SplitParams (const std::string &paramString, std::vector< std::string > &parameters)
 Split a comma separated parameter list into separate parameters. Takes care of the case where we may have a quoted string containing commas, or we may have a function (i.e. parentheses) with multiple parameters as a single parameter.
 
static int GetMatchingSource (const std::string &strPath, VECSOURCES &VECSOURCES, bool &bIsSourceName)
 
static std::string TranslateSpecialSource (const std::string &strSpecial)
 
static void DeleteDirectoryCache (const std::string &prefix="")
 
static void DeleteMusicDatabaseDirectoryCache ()
 
static void DeleteVideoDatabaseDirectoryCache ()
 
static std::string MusicPlaylistsLocation ()
 
static std::string VideoPlaylistsLocation ()
 
static void GetSkinThemes (std::vector< std::string > &vecTheme)
 
static void GetRecursiveListing (const std::string &strPath, CFileItemList &items, const std::string &strMask, unsigned int flags=0)
 
static void GetRecursiveDirsListing (const std::string &strPath, CFileItemList &items, unsigned int flags=0)
 
static void ForceForwardSlashes (std::string &strPath)
 
static double AlbumRelevance (const std::string &strAlbumTemp1, const std::string &strAlbum1, const std::string &strArtistTemp1, const std::string &strArtist1)
 
static bool MakeShortenPath (std::string StrInput, std::string &StrOutput, size_t iTextMaxLength)
 
static bool SupportsWriteFileOperations (const std::string &strPath)
 Checks whether the supplied path supports Write file operations (e.g. Rename, Delete, ...)
 
static bool SupportsReadFileOperations (const std::string &strPath)
 Checks whether the supplied path supports Read file operations (e.g. Copy, ...)
 
static std::string GetDefaultFolderThumb (const std::string &folderThumb)
 
static void InitRandomSeed ()
 
static int LookupRomanDigit (char roman_digit)
 
static int TranslateRomanNumeral (const char *roman_numeral)
 
static std::string ResolveExecutablePath ()
 
static std::string GetFrameworksPath (bool forPython=false)
 
static bool CanBindPrivileged ()
 
static bool ValidatePort (int port)
 
static int GetRandomNumber ()
 Thread-safe random number generation.
 
static int64_t ConvertSecsToMilliSecs (double secs)
 
static double ConvertMilliSecsToSecs (int64_t offset)
 
static int64_t ConvertMilliSecsToSecsInt (int64_t offset)
 
static int64_t ConvertMilliSecsToSecsIntRounded (int64_t offset)
 
static void CopyUserDataIfNeeded (const std::string &strPath, const std::string &file, const std::string &destname="")
 Copy files from the application bundle over to the user data directory in Application Support/Kodi.
 

Static Protected Member Functions

static void GetVideoBasePathAndFileName (const std::string &videoPath, std::string &basePath, std::string &videoFileName)
 Retrieves the base path and the filename of a given video.
 
static void GetItemsToScan (const std::string &videoPath, const std::string &item_exts, const std::vector< std::string > &sub_dirs, CFileItemList &items)
 Retrieves FileItems that could contain associated files of a given video.
 
static void ScanPathsForAssociatedItems (const std::string &videoName, const CFileItemList &items, const std::vector< std::string > &item_exts, std::vector< std::string > &associatedFiles)
 Searches for associated files of a given video.
 
static int ScanArchiveForAssociatedItems (const std::string &strArchivePath, const std::string &videoNameNoExt, const std::vector< std::string > &item_exts, std::vector< std::string > &associatedFiles)
 Searches in an archive for associated files of a given video.
 

Member Function Documentation

◆ AlbumRelevance()

double CUtil::AlbumRelevance ( const std::string & strAlbumTemp1,
const std::string & strAlbum1,
const std::string & strArtistTemp1,
const std::string & strArtist1 )
static

◆ CanBindPrivileged()

bool CUtil::CanBindPrivileged ( )
static

◆ CleanString()

void CUtil::CleanString ( const std::string & strFileName,
std::string & strTitle,
std::string & strTitleAndYear,
std::string & strYear,
bool bRemoveExtension = false,
bool bCleanChars = true )
static

◆ ClearSubtitles()

void CUtil::ClearSubtitles ( )
static

◆ ConvertMilliSecsToSecs()

static double CUtil::ConvertMilliSecsToSecs ( int64_t offset)
inlinestatic

◆ ConvertMilliSecsToSecsInt()

static int64_t CUtil::ConvertMilliSecsToSecsInt ( int64_t offset)
inlinestatic

◆ ConvertMilliSecsToSecsIntRounded()

static int64_t CUtil::ConvertMilliSecsToSecsIntRounded ( int64_t offset)
inlinestatic

◆ ConvertSecsToMilliSecs()

static int64_t CUtil::ConvertSecsToMilliSecs ( double secs)
inlinestatic

◆ CopyUserDataIfNeeded()

void CUtil::CopyUserDataIfNeeded ( const std::string & strPath,
const std::string & file,
const std::string & destname = "" )
static

Copy files from the application bundle over to the user data directory in Application Support/Kodi.

◆ CreateDirectoryEx()

bool CUtil::CreateDirectoryEx ( const std::string & strPath)
static

◆ DeleteDirectoryCache()

void CUtil::DeleteDirectoryCache ( const std::string & prefix = "")
static

◆ DeleteMusicDatabaseDirectoryCache()

void CUtil::DeleteMusicDatabaseDirectoryCache ( )
static

◆ DeleteVideoDatabaseDirectoryCache()

void CUtil::DeleteVideoDatabaseDirectoryCache ( )
static

◆ ExcludeFileOrFolder()

bool CUtil::ExcludeFileOrFolder ( const std::string & strFileOrFolder,
const std::vector< std::string > & regexps )
static

◆ FindVobSubPair()

bool CUtil::FindVobSubPair ( const std::vector< std::string > & vecSubtitles,
const std::string & strIdxPath,
std::string & strSubPath )
static

in a vector of subtitles finds the corresponding .sub file for a given .idx file

◆ ForceForwardSlashes()

void CUtil::ForceForwardSlashes ( std::string & strPath)
static

◆ GetDefaultFolderThumb()

std::string CUtil::GetDefaultFolderThumb ( const std::string & folderThumb)
static

◆ GetDirectoryName()

bool CUtil::GetDirectoryName ( const std::string & strFileName,
std::string & strDescription )
static

◆ GetDiscNumberFromPath()

std::string CUtil::GetDiscNumberFromPath ( const std::string & path)
static

Return the disc number in case the last segment of given path ends with 'Disc n'. Will look for 'Disc', 'Disk' and the locale specific spelling.

Returns
the disc number as string if found, empty string otherwise.

◆ GetDVDDriveIcon()

void CUtil::GetDVDDriveIcon ( const std::string & strPath,
std::string & strIcon )
static

◆ GetDVDIfoTitle()

int CUtil::GetDVDIfoTitle ( const std::string & strPathFile)
static

◆ GetExternalStreamDetailsFromFilename()

ExternalStreamInfo CUtil::GetExternalStreamDetailsFromFilename ( const std::string & videoPath,
const std::string & associatedFile )
static

Retrieves stream info of external associated files, e.g., subtitles, for a given video.

Parameters
[in]videoPathThe full path of the video file.
[in]associatedFileA file that provides additional streams for the given video file.
Returns
stream info for the given associatedFile

◆ GetFileAndProtocol()

void CUtil::GetFileAndProtocol ( const std::string & strURL,
std::string & strDir )
static

◆ GetFileDigest()

std::string CUtil::GetFileDigest ( const std::string & strPath,
KODI::UTILITY::CDigest::Type type )
static

retrieve MD5sum of a file

Parameters
strPath- path to the file to MD5sum
Returns
md5 sum of the file

◆ GetFilenameIdentifier() [1/2]

bool CUtil::GetFilenameIdentifier ( const std::string & fileName,
std::string & identifierType,
std::string & identifier )
static

◆ GetFilenameIdentifier() [2/2]

bool CUtil::GetFilenameIdentifier ( const std::string & fileName,
std::string & identifierType,
std::string & identifier,
std::string & match )
static

◆ GetFrameworksPath()

std::string CUtil::GetFrameworksPath ( bool forPython = false)
static

◆ GetHomePath()

std::string CUtil::GetHomePath ( const std::string & strTarget = "KODI_HOME")
static

◆ GetItemsToScan()

void CUtil::GetItemsToScan ( const std::string & videoPath,
const std::string & item_exts,
const std::vector< std::string > & sub_dirs,
CFileItemList & items )
staticprotected

Retrieves FileItems that could contain associated files of a given video.

Parameters
[in]videoPathThe full path of the video file.
[in]item_extsA | separated string of extensions specifying the associated files.
[in]sub_dirsA vector of sub directory names to look for.
[out]itemsA List of FileItems to scan for associated files.

◆ GetMatchingSource()

int CUtil::GetMatchingSource ( const std::string & strPath,
VECSOURCES & VECSOURCES,
bool & bIsSourceName )
static

◆ GetNextFilename()

std::string CUtil::GetNextFilename ( const std::string & fn_template,
int max )
static

Finds next unused filename that matches padded int format identifier provided.

Parameters
[in]fn_templatefilename template consisting of a padded int format identifier (eg screenshot%03d)
[in]maxmaximum number to search for available name
Returns
"" on failure, string next available name matching format identifier on success

◆ GetNextPathname()

std::string CUtil::GetNextPathname ( const std::string & path_template,
int max )
static

◆ GetQualifiedFilename()

void CUtil::GetQualifiedFilename ( const std::string & strBasePath,
std::string & strFilename )
static

◆ GetRandomNumber()

int CUtil::GetRandomNumber ( )
static

Thread-safe random number generation.

◆ GetRecursiveDirsListing()

void CUtil::GetRecursiveDirsListing ( const std::string & strPath,
CFileItemList & items,
unsigned int flags = 0 )
static

◆ GetRecursiveListing()

void CUtil::GetRecursiveListing ( const std::string & strPath,
CFileItemList & items,
const std::string & strMask,
unsigned int flags = 0 )
static

◆ GetSkinThemes()

void CUtil::GetSkinThemes ( std::vector< std::string > & vecTheme)
static

◆ GetSplashPath()

std::string CUtil::GetSplashPath ( )
static

Get resolved filesystem location of splash image.

◆ GetTitleFromPath() [1/2]

std::string CUtil::GetTitleFromPath ( const CURL & url,
bool bIsFolder = false )
static

◆ GetTitleFromPath() [2/2]

std::string CUtil::GetTitleFromPath ( const std::string & strFileNameAndPath,
bool bIsFolder = false )
static

◆ GetVideoBasePathAndFileName()

void CUtil::GetVideoBasePathAndFileName ( const std::string & videoPath,
std::string & basePath,
std::string & videoFileName )
staticprotected

Retrieves the base path and the filename of a given video.

Parameters
[in]videoPathThe full path of the video file.
[out]basePathThe base path of the given video.
[out]videoFileNameThe file name of the given video..

◆ GetVobSubIdxFromSub()

std::string CUtil::GetVobSubIdxFromSub ( const std::string & vobSub)
static

find a .idx file from a path of a plain or archived vobsub .sub file

◆ GetVobSubSubFromIdx()

std::string CUtil::GetVobSubSubFromIdx ( const std::string & vobSubIdx)
static

find a plain or archived vobsub .sub file corresponding to an .idx file

◆ HasFilenameIdentifier()

bool CUtil::HasFilenameIdentifier ( const std::string & fileName)
static

◆ InitRandomSeed()

void CUtil::InitRandomSeed ( )
static

◆ IsPicture()

bool CUtil::IsPicture ( const std::string & strFile)
static

◆ IsSupportedFontExtension()

static bool CUtil::IsSupportedFontExtension ( const std::string & fileName)
static

Check if a filename contains a supported font extension.

Parameters
filenameThe filename to check
Returns
True if it is supported, otherwise false

◆ IsVobSub()

bool CUtil::IsVobSub ( const std::vector< std::string > & vecSubtitles,
const std::string & strSubPath )
static

checks if in the vector of subtitles the given .sub file has a corresponding idx and hence is a vobsub file

◆ LookupRomanDigit()

int CUtil::LookupRomanDigit ( char roman_digit)
static

◆ MakeLegalFileName()

std::string CUtil::MakeLegalFileName ( std::string strFile,
int LegalType = LEGAL_NONE )
static

◆ MakeLegalPath()

std::string CUtil::MakeLegalPath ( std::string strPath,
int LegalType = LEGAL_NONE )
static

◆ MakeShortenPath()

bool CUtil::MakeShortenPath ( std::string StrInput,
std::string & StrOutput,
size_t iTextMaxLength )
static

◆ MusicPlaylistsLocation()

std::string CUtil::MusicPlaylistsLocation ( )
static

◆ RemoveTempFiles()

void CUtil::RemoveTempFiles ( )
static

◆ RemoveTrailingDiscNumberSegmentFromPath()

std::string CUtil::RemoveTrailingDiscNumberSegmentFromPath ( std::string path)
static

Remove last segment of the given path if it matches 'Disc n'. Will look for 'Disc', 'Disk' and the locale specific spelling.

Returns
the given path with last segment removed if it matches 'Disc n', unchanged path otherwise.

◆ ResolveExecutablePath()

std::string CUtil::ResolveExecutablePath ( )
static

◆ RunShortcut()

void CUtil::RunShortcut ( const char * szPath)
static

◆ ScanArchiveForAssociatedItems()

int CUtil::ScanArchiveForAssociatedItems ( const std::string & strArchivePath,
const std::string & videoNameNoExt,
const std::vector< std::string > & item_exts,
std::vector< std::string > & associatedFiles )
staticprotected

Searches in an archive for associated files of a given video.

Parameters
[in]strArchivePathThe full path of the archive.
[in]videoNameNoExtThe filename of the video without extension for which associated files should be retrieved.
[in]item_extsA vector of extensions specifying the associated files.
[out]associatedFilesA vector containing the full paths of all found associated files.

◆ ScanForExternalAudio()

void CUtil::ScanForExternalAudio ( const std::string & videoPath,
std::vector< std::string > & vecAudio )
static

Retrieves paths of external audio files for a given video.

Parameters
[in]videoPathThe full path of the video file.
[out]vecAudioA vector containing the full paths of all found external audio files.

◆ ScanForExternalSubtitles()

void CUtil::ScanForExternalSubtitles ( const std::string & strMovie,
std::vector< std::string > & vecSubtitles )
static

◆ ScanPathsForAssociatedItems()

void CUtil::ScanPathsForAssociatedItems ( const std::string & videoName,
const CFileItemList & items,
const std::vector< std::string > & item_exts,
std::vector< std::string > & associatedFiles )
staticprotected

Searches for associated files of a given video.

Parameters
[in]videoNameThe name of the video file.
[in]itemsA List of FileItems to scan for associated files.
[in]item_extsA vector of extensions specifying the associated files.
[out]associatedFilesA vector containing the full paths of all found associated files.

◆ SplitParams()

void CUtil::SplitParams ( const std::string & paramString,
std::vector< std::string > & parameters )
static

Split a comma separated parameter list into separate parameters. Takes care of the case where we may have a quoted string containing commas, or we may have a function (i.e. parentheses) with multiple parameters as a single parameter.

eg:

foo, bar(param1, param2), foo

will return:

"foo", "bar(param1, param2)", and "foo".

Parameters
paramStringthe string to break up
parametersthe returned parameters

◆ Stat64ToStat()

void CUtil::Stat64ToStat ( struct stat * result,
struct __stat64 * stat )
static

◆ Stat64ToStatI64()

void CUtil::Stat64ToStatI64 ( struct _stati64 * result,
struct __stat64 * stat )
static

◆ StatI64ToStat64()

void CUtil::StatI64ToStat64 ( struct __stat64 * result,
struct _stati64 * stat )
static

◆ StatToStat64()

void CUtil::StatToStat64 ( struct __stat64 * result,
const struct stat * stat )
static

◆ StatToStatI64()

void CUtil::StatToStatI64 ( struct _stati64 * result,
struct stat * stat )
static

◆ SupportsReadFileOperations()

bool CUtil::SupportsReadFileOperations ( const std::string & strPath)
static

Checks whether the supplied path supports Read file operations (e.g. Copy, ...)

Parameters
strPaththe path to be checked
Returns
true if Read file operations are supported, false otherwise

◆ SupportsWriteFileOperations()

bool CUtil::SupportsWriteFileOperations ( const std::string & strPath)
static

Checks whether the supplied path supports Write file operations (e.g. Rename, Delete, ...)

Parameters
strPaththe path to be checked
Returns
true if Write file operations are supported, false otherwise

◆ ToInt64()

int64_t CUtil::ToInt64 ( uint32_t high,
uint32_t low )
static

◆ TranslateRomanNumeral()

int CUtil::TranslateRomanNumeral ( const char * roman_numeral)
static

◆ TranslateSpecialSource()

std::string CUtil::TranslateSpecialSource ( const std::string & strSpecial)
static

◆ ValidatePath()

std::string CUtil::ValidatePath ( std::string path,
bool bFixDoubleSlashes = false )
static

return a validated path, with correct directory separators.

◆ ValidatePort()

bool CUtil::ValidatePort ( int port)
static

◆ VideoPlaylistsLocation()

std::string CUtil::VideoPlaylistsLocation ( )
static

The documentation for this class was generated from the following files: