Methods
(async, package, static) createCache(vInfo, cacheOptionsopt) → {Promise.<string>}
Creates a cache for the given YouTube video information.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
vInfo |
ytdl.videoInfo | The YouTube video information object. |
|||||||||||||
cacheOptions |
Object | string |
<optional> |
The options for creating the cache. If a string is provided, it will be treated as the path to the cache directory. Properties
|
Throws:
-
If the provided video information is not a plain object or the cache options type is invalid.
- Type
- InvalidTypeError
Returns:
The path to the cached video information.
- Type
- Promise.<string>
(async, package, static) deleteCache(id, cacheOptions) → {Promise.<boolean>}
Deletes the stored cache for a given video ID.
The function will delete the cache file for the specified video ID if it exists.
If you specified the cacheOptions.cacheDir
option, the function will use the provided path
to locate the cache file. Otherwise, it will use the default cache directory path.
Parameters:
Name | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
id |
string | The video ID to delete the cache for. |
||||||||
cacheOptions |
Object | Options for the cache. Properties
|
Throws:
-
If the given cache options is not a plain object.
- Type
- InvalidTypeError
Returns:
A promise that resolves to true
if the cache is deleted successfully,
or false
if the cache does not exist.
- Type
- Promise.<boolean>
(async, package, static) getAllCaches(cacheOptionsopt) → {Promise.<(Array.<ExtractedVideoInfoCacheObject>|string)>}
Retrieves all caches from the specified cache directory.
This function ensures that the cache directory exists, lists all files matching the specified pattern, and reads the content of each cache file. Returns an empty array if no caches are found in the cache directory.
If cacheOptions.humanReadable
option is enabled, the function formats the cache
contents into a simple human-readable string.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cacheOptions |
Object | string |
<optional> |
The options for retrieving the cache. If a string is provided, it will be treated as the path to the cache directory. Properties
|
Throws:
-
-
If the cache path is not a string.
- Type
- InvalidTypeError
-
-
-
If the parsed cache object does not meet the expected format or it is invalid.
- Type
- CacheValidationError
-
-
-
If there is an issue reading the cache directory or files.
- Type
- Error
-
Returns:
A promise that resolves to an array of cache contents, a cache formatted into a simple human-readable string
if the cacheOptions.humanReadable
option is enabled, or an empty array if no caches are found and cacheOptions.humanReadable
option is disabled; otherwise, returns a null
.
- Type
- Promise.<(Array.<ExtractedVideoInfoCacheObject>|string)>
(async, package, static) getCache(id, cacheOptionsopt) → {Promise.<(ExtractedVideoInfoCacheObject|string|null)>}
Retrieves the cached video information for a given video ID.
If the cacheOptions.humanReadable
option is enabled, the function will return a cache formatted into a
simple human-readable string instead of the cached video information object, which can be useful for
checking the stored cache information without having to parse it.
If the cacheOptions.validate
option is enabled, the function will validate the cache object before returning it
and throw a CacheValidationError
if the cache object is invalid.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | The unique identifier for the YouTube video. |
|||||||||||||||||
cacheOptions |
Object | string |
<optional> |
The options for retrieving the cYTMP3_VINFO_CACHEDIRache. If a string is provided, it will be treated as the path to the cache directory. Properties
|
Throws:
-
-
If the given ID is not a string or the cache options type is invalid.
- Type
- InvalidTypeError
-
-
-
If the given ID is not a valid YouTube video ID.
- Type
- IDValidationError
-
-
-
If the parsed cache object does not meet the expected format or it is invalid.
- Type
- CacheValidationError
-
-
-
If there is an error reading the cache file.
- Type
- Error
-
Returns:
A promise that resolves to the cached video information object, a cache formatted into a simple human-readable string
if the cacheOptions.humanReadable
option is enabled, or null
if the cache does not exist.
- Type
- Promise.<(ExtractedVideoInfoCacheObject|string|null)>