public class Theme
The Theme class models an anime theme song indexed on themes.moe.
It consists of a short description as displayed on themes.moe, as well as a URL to the video file of the theme song
Constructor and Description |
---|
Theme(java.lang.String description,
java.lang.String url)
The Theme class models an anime theme song indexed on themes.moe.
|
Modifier and Type | Method and Description |
---|---|
void |
abortDownload(java.lang.String target)
Aborts the download. Resets the
Theme.getDownloading flag and deletes the target file |
void |
download(java.lang.String targetDir,
java.util.List<? extends net.namibsun.anitheme.dl.lib.parsing.FileTypes> fileTypes,
java.lang.String prefix,
java.lang.String suffix,
int retriesAllowed)
Downloads the theme song file to the specified target directory using an automatic naming scheme
|
void |
downloadFile(java.lang.String target,
int retriesAllowed)
Downloads the file from the URL to a local file.
Starts a separate thread that prints the current progress to the terminal
Handles retries of downloads
|
java.lang.String |
getDescription()
The description of the theme song
|
boolean |
getDownloading()
Instance variable that is set to true whenever a download is progressing.
|
java.util.logging.Logger |
getLogger() |
java.lang.String |
getUrl()
The URL to the theme song file
|
void |
handleConversion(java.lang.String name,
java.lang.String webmFile,
java.util.List<? extends net.namibsun.anitheme.dl.lib.parsing.FileTypes> fileTypes)
Handles the conversion of the WEBM files to the various specified formats
|
void |
handleDownload(java.lang.String targetFile,
java.util.List<? extends net.namibsun.anitheme.dl.lib.parsing.FileTypes> fileTypes,
int retriesAllowed)
Handles the different cases of the existing file structure's state and delegates
downloading and converting.
|
void |
handleExceptionInDownload(java.lang.Exception exception,
java.lang.String target,
int retries,
int maxRetries)
Handles an exception caught in the
Theme.downloadFile method
Allows for retries, if the maximum amount of retries is exceeded, throws the exception again, after
aborting the download. |
void |
printDownloadProgress(java.lang.String target,
int size)
Starts a new thread which continuously prints the current progress to the terminal
|
void |
setDownloading(boolean p)
Instance variable that is set to true whenever a download is progressing.
|
java.lang.String |
toString()
Formats the
class Theme object for printing to the console |
public Theme(java.lang.String description, java.lang.String url)
The Theme class models an anime theme song indexed on themes.moe.
It consists of a short description as displayed on themes.moe, as well as a URL to the video file of the theme song
description
- The description of the theme songurl
- The URL to the theme song filedescription
- The description of the theme songurl
- The URL to the theme song filepublic java.util.logging.Logger getLogger()
public boolean getDownloading()
Instance variable that is set to true whenever a download is progressing.
public void setDownloading(boolean p)
Instance variable that is set to true whenever a download is progressing.
public void download(java.lang.String targetDir, java.util.List<? extends net.namibsun.anitheme.dl.lib.parsing.FileTypes> fileTypes, java.lang.String prefix, java.lang.String suffix, int retriesAllowed)
Downloads the theme song file to the specified target directory using an automatic naming scheme
The description is used as the file name, a suffix and prefix may also be supplied The downloader can automatically convert the file into different file types. By default, only the original .webm file is kept
This method only generates a filename based off the information provided, then delegates
the file download and conversion to the Theme.handleDownload
method
targetDir
- The target directory in which the file should be savedfileTypes
- The filetypes to convert the file into. Defaults to only .webmprefix
- An optional prefix for the generated file namesuffix
- An optional suffix for the generated file nameretriesAllowed
- The amount of times the download should be retried before giving up.Theme.handleDownload
public void handleDownload(java.lang.String targetFile, java.util.List<? extends net.namibsun.anitheme.dl.lib.parsing.FileTypes> fileTypes, int retriesAllowed)
Handles the different cases of the existing file structure's state and delegates downloading and converting.
The fileTypes parameter specifies which media formats the file should be converted to. By default, only the original .webm file is downloaded and left as-is.
targetFile
- The file name of the target file, without any file type associated suffixes like .webm etc.fileTypes
- The types of media files to convert the theme song into once downloadedretriesAllowed
- The amount of times the download should be retried before giving up.public void downloadFile(java.lang.String target, int retriesAllowed)
Downloads the file from the URL to a local file. Starts a separate thread that prints the current progress to the terminal Handles retries of downloads
target
- The target file of the download in the local file systemretriesAllowed
- The amount of retries that are allowedpublic void handleExceptionInDownload(java.lang.Exception exception, java.lang.String target, int retries, int maxRetries)
Handles an exception caught in the Theme.downloadFile
method
Allows for retries, if the maximum amount of retries is exceeded, throws the exception again, after
aborting the download.
exception
- The caught exceptiontarget
- The target file to which is being downloadedretries
- The amount of retries already attemptedmaxRetries
- The maximum amount of retries allowedTheme.downloadFile
public void abortDownload(java.lang.String target)
Aborts the download. Resets the Theme.getDownloading
flag and deletes the target file
target
- The target file to delete on abortTheme.getDownloading
public void printDownloadProgress(java.lang.String target, int size)
Starts a new thread which continuously prints the current progress to the terminal
target
- The target file. Used to check the current sizesize
- The total size of the download target in bytespublic void handleConversion(java.lang.String name, java.lang.String webmFile, java.util.List<? extends net.namibsun.anitheme.dl.lib.parsing.FileTypes> fileTypes)
Handles the conversion of the WEBM files to the various specified formats
name
- The name of the downloaded file without any extensionwebmFile
- the path to the original webm filefileTypes
- The file types to which to convert topublic java.lang.String toString()
Formats the class Theme
object for printing to the console
This is done in the following format:
Description: URL
class Theme
public java.lang.String getDescription()
The description of the theme song
public java.lang.String getUrl()
The URL to the theme song file