diff --git a/app/build.gradle b/app/build.gradle index a08ece6..f6f39a8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,12 +5,19 @@ android { buildToolsVersion "30.0.2" defaultConfig { - applicationId "pl.jakubweg" + applicationId "vanced.integrations" minSdkVersion 21 targetSdkVersion 30 versionCode 1 versionName "1.0" multiDexEnabled false + + Properties properties = new Properties() + if (rootProject.file("local.properties").exists()) { + properties.load(rootProject.file("local.properties").newDataInputStream()) + } + + buildConfigField "String", "YT_API_KEY", "\"${properties.getProperty("youtubeAPIKey", "")}\"" } buildTypes { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 430ba65..7609a74 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ + package="vanced.integrations"> \ No newline at end of file diff --git a/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java b/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java index 968055b..e11d541 100644 --- a/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java +++ b/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java @@ -10,22 +10,29 @@ public class VideoInformation { private static final String TAG = "VI - VideoInfo"; public static String currentVideoId; - public static Integer dislikeCount = null; - public static String channelName = null; + public static Integer dislikeCount; + public static String channelName; public static long lastKnownVideoTime = -1L; + private static boolean tempInfoSaved = false; + private static String tempVideoId; + private static Integer tempDislikeCount; + // Call hook in the YT code when the video changes public static void setCurrentVideoId(final String videoId) { if (videoId == null) { if (debug) { Log.d(TAG, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId); } - currentVideoId = null; - dislikeCount = null; - channelName = null; + clearInformation(); return; } + // Restore temporary information that was stored from the last watched video + if (tempInfoSaved) { + restoreTempInformation(); + } + if (videoId.equals(currentVideoId)) { if (debug) { Log.d(TAG, "setCurrentVideoId - new and current video were equal - " + videoId); @@ -42,4 +49,36 @@ public class VideoInformation { // New video ReturnYouTubeDislikes.newVideoLoaded(videoId); } + + // Call hook in the YT code when the video ends + public static void videoEnded() { + saveTempInformation(); + clearInformation(); + } + + // Information is cleared once a video ends + // It's cleared because the setCurrentVideoId isn't called for Shorts + // so Shorts would otherwise use the information from the last watched video + private static void clearInformation() { + currentVideoId = null; + dislikeCount = null; + channelName = null; + } + + // Temporary information is saved once a video ends + // so that if the user watches the same video again, + // the information can be restored without having to fetch again + private static void saveTempInformation() { + tempVideoId = currentVideoId; + tempDislikeCount = dislikeCount; + tempInfoSaved = true; + } + + private static void restoreTempInformation() { + currentVideoId = tempVideoId; + dislikeCount = tempDislikeCount; + tempVideoId = null; + tempDislikeCount = null; + tempInfoSaved = false; + } } diff --git a/app/src/main/java/fi/vanced/libraries/youtube/whitelisting/requests/WhitelistRequester.java b/app/src/main/java/fi/vanced/libraries/youtube/whitelisting/requests/WhitelistRequester.java index ab8fe04..8f1bbe4 100644 --- a/app/src/main/java/fi/vanced/libraries/youtube/whitelisting/requests/WhitelistRequester.java +++ b/app/src/main/java/fi/vanced/libraries/youtube/whitelisting/requests/WhitelistRequester.java @@ -22,8 +22,10 @@ import java.nio.charset.StandardCharsets; import fi.vanced.libraries.youtube.player.ChannelModel; import fi.vanced.libraries.youtube.whitelisting.Whitelist; import fi.vanced.libraries.youtube.whitelisting.WhitelistType; +import fi.vanced.utils.VancedUtils; import fi.vanced.utils.requests.Requester; import fi.vanced.utils.requests.Route; +import vanced.integrations.BuildConfig; public class WhitelistRequester { private static final String YT_API_URL = "https://www.youtube.com/youtubei/v1/"; @@ -32,14 +34,14 @@ public class WhitelistRequester { public static void addChannelToWhitelist(WhitelistType whitelistType, View view, ImageView buttonIcon, Context context) { try { - HttpURLConnection connection = getConnectionFromRoute(WhitelistRoutes.GET_CHANNEL_DETAILS, "replaceMeWithTheYouTubeAPIKey"); + HttpURLConnection connection = getConnectionFromRoute(WhitelistRoutes.GET_CHANNEL_DETAILS, BuildConfig.YT_API_KEY); connection.setRequestProperty("Content-Type", "application/json; utf-8"); connection.setRequestProperty("Accept", "application/json"); connection.setDoOutput(true); connection.setConnectTimeout(2 * 1000); - // TODO: Actually fetch the version - String jsonInputString = "{\"context\": {\"client\": { \"clientName\": \"Android\", \"clientVersion\": \"16.49.37\" } }, \"videoId\": \"" + currentVideoId + "\"}"; + String versionName = VancedUtils.getVersionName(context); + String jsonInputString = "{\"context\": {\"client\": { \"clientName\": \"Android\", \"clientVersion\": \"" + versionName + "\" } }, \"videoId\": \"" + currentVideoId + "\"}"; try(OutputStream os = connection.getOutputStream()) { byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); diff --git a/app/src/main/java/fi/vanced/utils/VancedUtils.java b/app/src/main/java/fi/vanced/utils/VancedUtils.java index 0c7820f..0333f64 100644 --- a/app/src/main/java/fi/vanced/utils/VancedUtils.java +++ b/app/src/main/java/fi/vanced/utils/VancedUtils.java @@ -2,6 +2,8 @@ package fi.vanced.utils; import android.content.Context; import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.os.Handler; import android.os.Looper; @@ -43,6 +45,18 @@ public class VancedUtils { return count; } + public static String getVersionName(Context context) { + try { + PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + String version = pInfo.versionName; + return (version); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + + return ("17.03.35"); + } + public static void runOnMainThread(Runnable runnable) { new Handler(Looper.getMainLooper()).post(runnable); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2ea7ed..2485350 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -320,9 +320,9 @@ Stats Loading.. SponsorBlock is disabled - Your username: <b>%s</b> + Your username: <b>%s</b> Click to change your username - Unable to change username: Status: %d %s + Unable to change username: Status: %d %s Username successfully changed Submissions: <b>%s</b> You\'ve saved people from <b>%s</b> segments. @@ -339,8 +339,8 @@ Change Reset - Copy - TCopy + Copy link + Timestamp Ads Segments @@ -359,10 +359,14 @@ In player Under player Both - RYD settings + Return YouTube Dislike settings Uses the RYD API Enable RYD Switch this on to see the dislike counts again Return YouTube Dislike Integration This integration uses the RYD API from https://returnyoutubedislike.com. Tap to learn more + + Tablet style + Tablet style is turned on. For example suggested videos are only partially working + Tablet style is turned off