Skip to content

Commit

Permalink
Merge pull request #73 from mattwright324/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mattwright324 authored Feb 6, 2021
2 parents 43dfd3c + 46608f0 commit 1e11eed
Show file tree
Hide file tree
Showing 134 changed files with 3,925 additions and 2,353 deletions.
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Maven will also insert these values into `Settings.fxml` during the build.

There are two ways to run this application from your IDE

1. **From in IDE** Right click on file and run `src/main/java/io.mattw.youtube.commentsuite/FXMLSuite.java`
1. **From in IDE** Right click on file and run `src/main/java/io.mattw.youtube.commentsuite/CommentSuite.java`
2. **From package** Double click the jar at `target/package/youtube-comment-suite-#.#.#.jar`

*Note: My YouTube API key provided in the application is not restricted at all given it isn't a website.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.mattw.youtube</groupId>
<artifactId>youtube-comment-suite</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -44,7 +44,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>io.mattw.youtube.commentsuite.FXMLSuite</mainClass>
<mainClass>io.mattw.youtube.commentsuite.CommentSuite</mainClass>
</manifest>
</archive>
</configuration>
Expand Down
Binary file modified resources/GroupRefresh.vsdx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.api.services.youtube.YouTube;
import com.google.common.eventbus.EventBus;
import io.mattw.youtube.commentsuite.db.CommentDatabase;
import io.mattw.youtube.commentsuite.oauth2.OAuth2Manager;
import io.mattw.youtube.commentsuite.util.IpApiProvider;
import io.mattw.youtube.commentsuite.util.Location;
import javafx.application.Application;
Expand All @@ -23,31 +24,47 @@
/**
* Application Window
*
* @author mattwright324
*/
public class FXMLSuite extends Application {
public class CommentSuite extends Application {

private static final Logger logger = LogManager.getLogger();

private static final ConfigFile<ConfigData> config = new ConfigFile<>("commentsuite.json", new ConfigData());
private static final EventBus eventBus = new EventBus();
private static final Location<IpApiProvider, IpApiProvider.Location> location = new Location<>(new IpApiProvider(), IpApiProvider.Location.class);
private static final OAuth2Handler oauth2 = new OAuth2Handler("972416191049-htqcmg31u2t7hbd1ncen2e2jsg68cnqn.apps.googleusercontent.com", "QuTdoA-KArupKMWwDrrxOcoS", "urn:ietf:wg:oauth:2.0:oob");

private static CommentDatabase database;
private static YouTube youTube;
private static String youTubeApiKey;
private static OAuth2Manager oauth2Manager;

public static void main(String[] args) {
logger.debug("Starting Application");

/*
* Setting this system property is a fix for the JavaFX Webview behaving improperly.
* The 'Tap Yes' authentication when signing in from {@link mattw.youtube.commentsuite.fxml.Settings)
* would do nothing and the icon would flicker when not set, requiring the user to use SMS
* authentication instead.
*/
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");

/*
* https://stackoverflow.com/a/24419312/2650847
*/
System.setProperty("prism.lcdtext", "false");

launch(args);
}

public void start(final Stage stage) {
try {
youTube = new YouTube.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), null)
.setApplicationName("youtube-comment-suite")
.build();

// System.setProperty("glass.win.uiScale", "100%");
youTubeApiKey = config.getDataObject().getYoutubeApiKey();

database = new CommentDatabase("commentsuite.sqlite3");
oauth2Manager = new OAuth2Manager();

final Parent parent = FXMLLoader.load(getClass().getResource("/io/mattw/youtube/commentsuite/fxml/Main.fxml"));

Expand Down Expand Up @@ -78,6 +95,10 @@ public void start(final Stage stage) {
}
}

public static void postEvent(Object event) {
eventBus.post(event);
}

public static ConfigFile<ConfigData> getConfig() {
return config;
}
Expand All @@ -90,8 +111,8 @@ public static Location<IpApiProvider, IpApiProvider.Location> getLocation() {
return location;
}

public static OAuth2Handler getOauth2() {
return oauth2;
public static OAuth2Manager getOauth2Manager() {
return oauth2Manager;
}

public static CommentDatabase getDatabase() {
Expand All @@ -103,24 +124,7 @@ public static YouTube getYouTube() {
}

public static String getYouTubeApiKey() {
return youTubeApiKey;
}

public static void setYouTubeApiKey(String apiKey) {
youTubeApiKey = apiKey;
return getConfig().getDataObject().getApiKeyOrDefault();
}

public static void main(String[] args) {
logger.debug("Starting Application");

/*
* Setting this system property is a fix for the JavaFX Webview behaving improperly.
* The 'Tap Yes' authentication when signing in from {@link mattw.youtube.commentsuite.fxml.Settings)
* would do nothing and the icon would flicker when not set, requiring the user to use SMS
* authentication instead.
*/
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");

launch(args);
}
}
133 changes: 67 additions & 66 deletions src/main/java/io/mattw/youtube/commentsuite/ConfigData.java
Original file line number Diff line number Diff line change
@@ -1,90 +1,86 @@
package io.mattw.youtube.commentsuite;

import io.mattw.youtube.commentsuite.events.AccountAddEvent;
import io.mattw.youtube.commentsuite.events.AccountDeleteEvent;
import io.mattw.youtube.commentsuite.oauth2.YouTubeAccount;
import io.mattw.youtube.commentsuite.refresh.RefreshOptions;
import javafx.beans.property.ReadOnlyIntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static javafx.application.Platform.runLater;
import static io.mattw.youtube.commentsuite.CommentSuite.*;

/**
* @author mattwright324
*/
public class ConfigData implements Serializable {

private transient String defaultApiKey = "AIzaSyD9SzQFnmOn08ESZC-7gIhnHWVn0asfrKQ";
private transient SimpleIntegerProperty accountListChanged = new SimpleIntegerProperty(0);

public static final transient String DEFAULT_API_KEY = "AIzaSyD9SzQFnmOn08ESZC-7gIhnHWVn0asfrKQ";
public static final transient String FAST_GROUP_ADD_THUMB_PLACEHOLDER = "~";

private boolean autoLoadStats = true;
private boolean prefixReplies = true;
private List<YouTubeAccount> accounts = new ArrayList<>();
private boolean archiveThumbs = false;
private boolean fastGroupAdd = false;
private boolean autoLoadStats = true;
private boolean customApiKey = false;
private boolean fastGroupAdd = false;
private boolean filterDuplicatesOnCopy = true;
private List<YouTubeAccount> accounts = new ArrayList<>();
private String youtubeApiKey = defaultApiKey;
private boolean grabHeldForReview = false;
private boolean prefixReplies = true;
private RefreshOptions refreshOptions = new RefreshOptions();
private String youtubeApiKey = DEFAULT_API_KEY;

public ConfigData() {
// empty constructor
public List<YouTubeAccount> getAccounts() {
return accounts;
}

public String getDefaultApiKey() {
return defaultApiKey;
public void setAccounts(List<YouTubeAccount> accounts) {
this.accounts = accounts;
}

public String getYoutubeApiKey() {
return customApiKey ? youtubeApiKey : defaultApiKey;
public boolean isArchiveThumbs() {
return archiveThumbs;
}

public void setYoutubeApiKey(String apiKey) {
this.youtubeApiKey = apiKey;
public void setArchiveThumbs(boolean archiveThumbs) {
this.archiveThumbs = archiveThumbs;
}

public List<YouTubeAccount> getAccounts() {
return accounts;
public boolean isAutoLoadStats() {
return autoLoadStats;
}

public void refreshAccounts() {
accounts.forEach(YouTubeAccount::updateData);
public void setAutoLoadStats(boolean autoLoadStats) {
this.autoLoadStats = autoLoadStats;
}

public void addAccount(YouTubeAccount account) {
if (accounts.stream().noneMatch(ac -> ac.getChannelId().equals(account.getChannelId()))) {
accounts.add(account);
triggerAccountListChanged();
}
public boolean isCustomApiKey() {
return customApiKey;
}

public void removeAccount(YouTubeAccount account) {
if (accounts.removeIf(acc -> acc.getChannelId() != null && acc.getChannelId().equals(account.getChannelId()))) {
triggerAccountListChanged();
}
public void setCustomApiKey(boolean customApiKey) {
this.customApiKey = customApiKey;
}

public boolean isSignedIn(String channelId) {
return accounts.stream().anyMatch(acc -> channelId.equals(acc.getChannelId()));
public boolean isFastGroupAdd() {
return fastGroupAdd;
}

public ReadOnlyIntegerProperty accountListChangedProperty() {
return accountListChanged;
public void setFastGroupAdd(boolean fastGroupAdd) {
this.fastGroupAdd = fastGroupAdd;
}

public void triggerAccountListChanged() {
runLater(() -> accountListChanged.setValue(accountListChanged.getValue() + 1));
public boolean isFilterDuplicatesOnCopy() {
return filterDuplicatesOnCopy;
}

public boolean isAutoLoadStats() {
return autoLoadStats;
public void setFilterDuplicatesOnCopy(boolean filterDuplicatesOnCopy) {
this.filterDuplicatesOnCopy = filterDuplicatesOnCopy;
}

public void setAutoLoadStats(boolean autoLoadStats) {
this.autoLoadStats = autoLoadStats;
public boolean isGrabHeldForReview() {
return grabHeldForReview;
}

public void setGrabHeldForReview(boolean grabHeldForReview) {
this.grabHeldForReview = grabHeldForReview;
}

public boolean isPrefixReplies() {
Expand All @@ -95,43 +91,48 @@ public void setPrefixReplies(boolean prefixReplies) {
this.prefixReplies = prefixReplies;
}

public boolean isArchiveThumbs() {
return archiveThumbs;
public RefreshOptions getRefreshOptions() {
return refreshOptions;
}

public void setArchiveThumbs(boolean archiveThumbs) {
this.archiveThumbs = archiveThumbs;
public void setRefreshOptions(RefreshOptions refreshOptions) {
this.refreshOptions = refreshOptions;
}

public boolean isFastGroupAdd() {
return fastGroupAdd;
public String getYoutubeApiKey() {
return youtubeApiKey;
}

public void setFastGroupAdd(boolean fastGroupAdd) {
this.fastGroupAdd = fastGroupAdd;
public void setYoutubeApiKey(String youtubeApiKey) {
this.youtubeApiKey = youtubeApiKey;
}

public boolean isCustomApiKey() {
return customApiKey;
public void addAccount(final YouTubeAccount account) {
if (accounts.stream().noneMatch(ac -> ac.getChannelId().equals(account.getChannelId()))) {
accounts.add(account);
postEvent(new AccountAddEvent(account));
}
}

public void setCustomApiKey(boolean customApiKey) {
this.customApiKey = customApiKey;
public void removeAccount(final YouTubeAccount account) {
if (accounts.removeIf(acc -> acc.getChannelId() != null && acc.getChannelId().equals(account.getChannelId()))) {
postEvent(new AccountDeleteEvent(account));
}
}

public boolean isFilterDuplicatesOnCopy() {
return filterDuplicatesOnCopy;
public boolean isSignedIn(final String channelId) {
return accounts.stream().anyMatch(acc -> channelId.equals(acc.getChannelId()));
}

public void setFilterDuplicatesOnCopy(boolean filterDuplicatesOnCopy) {
this.filterDuplicatesOnCopy = filterDuplicatesOnCopy;
public YouTubeAccount getAccount(final String channelId) {
return accounts.stream()
.filter(acc -> channelId.equals(acc.getChannelId()))
.findFirst()
.orElse(null);
}

public RefreshOptions getRefreshOptions() {
return refreshOptions;
public String getApiKeyOrDefault() {
return isCustomApiKey() ? getYoutubeApiKey() : DEFAULT_API_KEY;
}

public void setRefreshOptions(RefreshOptions refreshOptions) {
this.refreshOptions = refreshOptions;
}
}
17 changes: 8 additions & 9 deletions src/main/java/io/mattw/youtube/commentsuite/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
* Can take any object as long as it has fields that Gson is configured to read.
*
* @param <T> data object JSON (de)serialized
* @author mattwright324
*/
public class ConfigFile<T> {

private static final Logger logger = LogManager.getLogger();

private Gson gson = new Gson();
private final Gson gson = new Gson();

private T defaultObject;
private final File file;
private final T defaultObject;
private T dataObject;
private File file;

public ConfigFile(String fileName, T defaultObject) {
public ConfigFile(final String fileName, final T defaultObject) {
logger.debug("Initialize ConfigFile<{}> [fileName={}]", defaultObject.getClass().getSimpleName(), fileName);
this.defaultObject = defaultObject;
this.dataObject = defaultObject;
Expand All @@ -39,8 +38,8 @@ public ConfigFile(String fileName, T defaultObject) {

public void load() {
logger.debug("Loading Config File");
try (FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr)) {
try (final FileReader fr = new FileReader(file);
final BufferedReader br = new BufferedReader(fr)) {
String line;
StringBuilder data = new StringBuilder();
while ((line = br.readLine()) != null) {
Expand All @@ -60,8 +59,8 @@ public void load() {

public void save() {
logger.debug("Saving Config File");
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
try (final FileOutputStream fos = new FileOutputStream(file);
final OutputStreamWriter writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
writer.write(gson.toJson(dataObject));
} catch (Exception e) {
logger.error(e);
Expand Down
Loading

0 comments on commit 1e11eed

Please sign in to comment.