Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Changed to requiring a personal API key for YouTube, also updated dep…
Browse files Browse the repository at this point in the history
…endencies.
  • Loading branch information
Stekeblad committed May 22, 2021
1 parent 538e117 commit 05f8c0a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .idea/modules/videouploader.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ privacy policy can be found here:
Downloads can be found under "Releases" in the right sidebar
[or by clicking here](https://github.com/Stekeblad/Stekeblads-Video-Uploader/releases)

Note that you need Java 8 to use Stekeblads Video Uploader.
Note that you need Java 8 **and your own YouTube API key** to use
Stekeblads Video Uploader.
[Help on creating your own API key.](https://github.com/Stekeblad/Stekeblads-Video-Uploader/wiki/Personal-API-key)<!-- @IGNORE PREVIOUS: link -->

### Images
Images are taken from the 1.1 release, several things have changed since
Expand All @@ -55,5 +57,5 @@ Managing playlists:

### Videos
I have made a few short videos introducing the program and how to use it
(The videos are pretty outdated, a updated series is in planning phase):
(The videos are pretty outdated but much is still the same):
[Playlist](https://www.youtube.com/playlist?list=PLAA2832YwTI9mddiWDeZ_RDnIjaBa8dP-)
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'io.github.stekeblad'
version '1.4.2'
version '1.4.4'

apply plugin: 'idea'
apply plugin: 'java'
Expand Down Expand Up @@ -55,15 +55,15 @@ repositories {

dependencies {
// The YouTube API and its requirements
compile 'com.google.api-client:google-api-client:1.31.1'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.31.2'
compile 'com.google.apis:google-api-services-youtube:v3-rev20201202-1.31.0'
compile 'com.google.api-client:google-api-client:1.31.4'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.31.5'
compile 'com.google.apis:google-api-services-youtube:v3-rev20210410-1.31.0'
// For the metadata-related features
compile 'org.jcodec:jcodec:0.2.5'
// Verifying downloaded updates are real and not from someone else
compile 'com.google.crypto.tink:tink:1.3.0'
compile 'com.google.crypto.tink:tink:1.5.0'
// A better HTTP-client than the one built into Java
compile 'com.squareup.okhttp3:okhttp:4.5.0'
compile 'com.squareup.okhttp3:okhttp:4.9.1'
}

// https://developers.google.com/api-client-library/java/apis/youtube/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ playlists and deciding if they should be visible or not (playlists can
be renamed, but ID is always the same.)

#### Lower priority things to do
- Applying for higher quota limit
- Setting for start folder when:
- selecting video files
- selecting thumbnail
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/io/github/stekeblad/videouploader/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.stekeblad.videouploader.utils.AlertUtils;
import io.github.stekeblad.videouploader.utils.ConfigManager;
import io.github.stekeblad.videouploader.utils.Constants;
import io.github.stekeblad.videouploader.utils.background.OpenInBrowser;
import io.github.stekeblad.videouploader.utils.translation.TranslationBundles;
import io.github.stekeblad.videouploader.utils.translation.Translations;
import io.github.stekeblad.videouploader.utils.translation.TranslationsManager;
Expand All @@ -18,8 +19,12 @@

import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;

import static io.github.stekeblad.videouploader.utils.Constants.AUTH_DIR;

/**
* The program starts here, opens MainWindow and waits for all windows to close
*/
Expand All @@ -33,18 +38,49 @@ public void start(Stage primaryStage) {
configManager.configManager();
} catch (Exception e) {
e.printStackTrace();
AlertUtils.exceptionDialog("ERROR",
AlertUtils.exceptionDialog("ERROR - Stekeblads Video Uploader",
"Failed to load settings or other configurations file, unable to launch.", e);
}
try {
loadTranslations();
} catch (Exception e) {
e.printStackTrace();
AlertUtils.exceptionDialog("ERROR",
AlertUtils.exceptionDialog("ERROR - Stekeblads Video Uploader",
"Failed to load translations, unable to launch. Your detected language: " + Locale.getDefault(), e);
return;
}

try {
if (!Files.exists(Paths.get(AUTH_DIR)))
Files.createDirectories(Paths.get(AUTH_DIR));

if (!Files.exists(Paths.get(AUTH_DIR, "client_secrets.json"))) {

if (!Files.exists(Paths.get(AUTH_DIR, "place your own client_secrets.json file here")))
Files.createFile(Paths.get(AUTH_DIR, "place your own client_secrets.json file here"));

String choice = AlertUtils.threeButtons("Missing API key - Stekeblads Video Uploader",
"You need your own YouTube Data API v3 key to use " +
"Stekeblads Video Uploader. Please create one and save it to " +
Paths.get(AUTH_DIR, "client_secrets.json").toAbsolutePath().toString() +
"\r\n\r\nClick look around to try Stekeblads Video Uploader with all YouTube-related features " +
"inaccessible or read how to create a API key for free.",
"Read how",
"Look around",
"Exit");
if ("Read how".equals(choice)) {
OpenInBrowser.openInBrowser("https://github.com/Stekeblad/Stekeblads-Video-Uploader/wiki/Personal-API-key");
return;
} else if ("Exit".equals(choice))
return;
// else Look around, continue program, be prepared for exceptions
}
} catch (Exception e) {
AlertUtils.simpleClose("ERROR - Stekeblads Video Uploader",
"Failed while checking for an API key").showAndWait();
return;
}

// Set the default exception handler, hopefully it can catch some of the exceptions that is not already caught
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> AlertUtils.unhandledExceptionDialog(exception));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.YouTubeScopes;
import com.google.api.services.youtube.model.Channel;
import com.google.api.services.youtube.model.ChannelListResponse;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -34,14 +31,15 @@
public class Auth {

public static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
public static final JsonFactory JSON_FACTORY = new JacksonFactory();
public static final JsonFactory JSON_FACTORY = new GsonFactory();

public static Credential authUser() throws IOException {
List<String> scope = new ArrayList<>();
scope.add(YouTubeScopes.YOUTUBE_UPLOAD);
scope.add(YouTubeScopes.YOUTUBE);

Reader clientSecretReader = new InputStreamReader(Auth.class.getClassLoader().getResourceAsStream(".auth/client_secrets.json"));
Reader clientSecretReader = new InputStreamReader(new FileInputStream(
new File(Paths.get(AUTH_DIR, "client_secrets.json").toUri())));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
FileDataStoreFactory fileFactory = new FileDataStoreFactory(new File(AUTH_DIR));

Expand Down
Empty file.

0 comments on commit 05f8c0a

Please sign in to comment.