diff --git a/.github/checkrun.py b/.github/checkrun.py new file mode 100644 index 000000000..496a11b32 --- /dev/null +++ b/.github/checkrun.py @@ -0,0 +1,13 @@ +from json import load +from os import system + +f = open('commit.json') +data = load(f) +f.close() + +message = data['commit']['message'] + +if "\n\n" in message: + if message.split("\n\n",1)[-1].split()[0] == "[SILENT]": + system('killall -9 python') + diff --git a/.github/compiler.sh b/.github/compiler.sh new file mode 100644 index 000000000..7a65710f8 --- /dev/null +++ b/.github/compiler.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +cd ~ +sudo apt-get update -y +sudo apt-get upgrade -y +sudo apt-get install -y make git zlib1g-dev libssl-dev gperf cmake clang-10 libc++-dev libc++abi-dev +git clone --recursive https://github.com/tdlib/telegram-bot-api.git +rm -rf telegram-bot-api/build +mkdir -p telegram-bot-api/build +cd telegram-bot-api/build +CXXFLAGS="-stdlib=libc++" CC=/usr/bin/clang-10 CXX=/usr/bin/clang++-10 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=.. .. +cmake --build . --target install \ No newline at end of file diff --git a/.github/tg.py b/.github/tg.py index befaab722..dc68d1166 100644 --- a/.github/tg.py +++ b/.github/tg.py @@ -1,21 +1,33 @@ import telegram -from tgconfig import TG_TOKEN +from tgconfig import * from json import load +import multiprocessing +from os import system +from time import sleep as wait -f = open('commit.json') -data = load(f) -f.close() +def deploy(): + system(f'~/bot-api --local --api-id={TG_API_ID} --api-hash={TG_API_HASH}') -TG_CHAT_ID = "-1001537505605" -bot = telegram.Bot(TG_TOKEN) +def bot(): + wait(10) + f = open('commit.json') + data = load(f) + f.close() -bot.send_photo(TG_CHAT_ID, open('alpha.png', 'rb'), f'''*Libretube {data['sha'][0:7]} // Alpha* + bot = telegram.Bot(TG_TOKEN, base_url="http://0.0.0.0:8081/bot") + bot.send_photo(TG_POST_ID, open('alpha.png', 'rb'), f'''*Libretube {data['sha'][0:7]} // Alpha* -{data['commit']['message']} +[{data['commit']['message']}]({data['html_url']}) Signed-off-by: {data['commit']['author']['name']} ''', parse_mode=telegram.ParseMode.MARKDOWN) -bot.send_document(TG_CHAT_ID, open('app-arm64-v8a-debug.apk', 'rb')) -bot.send_document(TG_CHAT_ID, open('app-armeabi-v7a-debug.apk', 'rb')) -bot.send_document(TG_CHAT_ID, open('app-x86_64-debug.apk', 'rb')) -bot.send_document(TG_CHAT_ID, open('app-x86-debug.apk', 'rb')) + bot.send_media_group(TG_POST_ID, [telegram.InputMediaDocument(open('app-x86-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-x86_64-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-armeabi-v7a-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-arm64-v8a-debug.apk', 'rb'))]) + system('killall -9 python') + +if __name__ == '__main__': + multideploy = multiprocessing.Process(target=deploy) + multibot = multiprocessing.Process(target=bot) + multideploy.start() + multibot.start() + multideploy.join() + multibot.join() diff --git a/.github/workflows/api-compiler.yml b/.github/workflows/api-compiler.yml new file mode 100644 index 000000000..176c2d079 --- /dev/null +++ b/.github/workflows/api-compiler.yml @@ -0,0 +1,32 @@ +name: Bot API Compiler + +on: + workflow_dispatch: + +jobs: + debug-builds: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Prepare for Compilation + run: | + git config --global user.name "XelXen" + git config --global user.email "78258352+XelXen@users.noreply.github.com" + git config --global credential.helper store + echo "https://XelXen:${{ secrets.GH_TOKEN }}@github.com" > ~/.git-credentials + + - name: Run Script + run: | + chmod 755 .github/compiler.sh + .github/compiler.sh + + - name: Binary Archive + run: | + git clone https://github.com/LibreTubeAlpha/Telegram-BotAPI bot-api + rm -rf bot-api/* + mv ~/telegram-bot-api/bin/telegram-bot-api bot-api/exec + cd bot-api + git add -f * + git commit -m "WORKFLOW: BUILD BINARIES" + git push -u \ No newline at end of file diff --git a/.github/workflows/tg-bot.yml b/.github/workflows/tg-bot.yml index 016f443ed..961d4d403 100644 --- a/.github/workflows/tg-bot.yml +++ b/.github/workflows/tg-bot.yml @@ -1,4 +1,4 @@ -name: Telegram Builder +name: Telegram Bot on: workflow_dispatch: @@ -20,6 +20,13 @@ jobs: python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified + - name: Check for Execution Orders + run: | + cd .github + curl https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} > commit.json + python checkrun.py + cd .. + - name: set up JDK 11 uses: actions/setup-java@v3 with: @@ -35,12 +42,17 @@ jobs: ./gradlew assembleDebug - name: Telegram Bot + continue-on-error: true run: | mv ./app/build/outputs/apk/debug/*.apk .github/ cd .github curl https://libre-tube.github.io/assets/LibreAlpha.png --output alpha.png + curl https://raw.githubusercontent.com/LibreTubeAlpha/Telegram-BotAPI/main/exec --output ~/bot-api + chmod 755 ~/bot-api echo "TG_TOKEN = '${{ secrets.TG_TOKEN }}'" > tgconfig.py - curl https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} > commit.json + echo "TG_API_ID = '${{ secrets.TG_API_ID }}'" >> tgconfig.py + echo "TG_POST_ID = '${{ secrets.TG_POST_ID }}'" >> tgconfig.py + echo "TG_API_HASH = '${{ secrets.TG_API_HASH }}'" >> tgconfig.py python -m pip install --upgrade pip pip install python-telegram-bot python tg.py diff --git a/README.md b/README.md index ea9c659f7..1f9427f71 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,11 @@ ## Contributing -Whether you have ideas, translations, design changes, code cleaning, or real heavy code changes, help is always welcome. The more is done the better it gets! If creating a pr, please make sure to format the code with ktlint before. +Whether you have ideas, translations, design changes, code cleaning, or real heavy code changes, help is always welcome.The more is done the better it gets! + +If creating a pull request, please make sure to format your code (preferred ktlint) before. + +If opening an issue without following the issue template, we will ignore the issue and force close it. WARNING: THIS IS A BETA VERSION, THEREFORE YOU MAY ENCOUNTER BUGS. IF YOU DO, OPEN AN ISSUE VIA OUR GITHUB REPOSITORY. diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f24097dde..88ea6ba64 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ - + @@ -15,7 +16,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.MY" + android:theme="@style/Theme.Purple" android:name=".MyApp" android:networkSecurityConfig="@xml/network_security_config" android:largeHeap="true" @@ -34,7 +35,8 @@ android:supportsPictureInPicture="true" android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" android:hardwareAccelerated="true" - android:screenOrientation="userPortrait"> + android:screenOrientation="userPortrait" + android:launchMode="singleTop"> diff --git a/app/src/main/java/com/github/libretube/BackgroundMode.kt b/app/src/main/java/com/github/libretube/BackgroundMode.kt index ebd851e01..79ff8a319 100644 --- a/app/src/main/java/com/github/libretube/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/BackgroundMode.kt @@ -77,7 +77,8 @@ class BackgroundMode { DescriptionAdapter( response?.title!!, response?.uploader!!, - response?.thumbnailUrl!! + response?.thumbnailUrl!!, + c ) ) .build() diff --git a/app/src/main/java/com/github/libretube/Constants.kt b/app/src/main/java/com/github/libretube/Constants.kt index 521bc3a7c..52a5d0ef3 100644 --- a/app/src/main/java/com/github/libretube/Constants.kt +++ b/app/src/main/java/com/github/libretube/Constants.kt @@ -5,3 +5,4 @@ const val WEBSITE_URL = "https://libre-tube.github.io/" const val AUTHORS_URL = "https://github.com/libre-tube/LibreTube/graphs/contributors" const val DONATE_URL = "https://libre-tube.github.io/#donate" const val CONTRIBUTING_URL = "https://github.com/libre-tube/LibreTube#donate" +const val PIPED_GITHUB_URL = "https://github.com/TeamPiped/Piped" diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index 217a7f99a..e13b766b5 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -113,15 +113,30 @@ class DownloadService : Service() { "mux" -> { audioDir = File(tempDir, "$videoId-audio") videoDir = File(tempDir, "$videoId-video") - downloadId = downloadManagerRequest("Video", "Downloading", videoUrl, videoDir) + downloadId = downloadManagerRequest( + getString(R.string.video), + getString(R.string.downloading), + videoUrl, + videoDir + ) } "video" -> { videoDir = File(libretubeDir, "$videoId-video") - downloadId = downloadManagerRequest("Video", "Downloading", videoUrl, videoDir) + downloadId = downloadManagerRequest( + getString(R.string.video), + getString(R.string.downloading), + videoUrl, + videoDir + ) } "audio" -> { audioDir = File(libretubeDir, "$videoId-audio") - downloadId = downloadManagerRequest("Audio", "Downloading", audioUrl, audioDir) + downloadId = downloadManagerRequest( + getString(R.string.audio), + getString(R.string.downloading), + audioUrl, + audioDir + ) } } } catch (e: IllegalArgumentException) { @@ -136,7 +151,12 @@ class DownloadService : Service() { // Checking if the received broadcast is for our enqueued download by matching download id if (downloadId == id) { if (downloadType == "mux") { - downloadManagerRequest("Audio", "Downloading", audioUrl, audioDir) + downloadManagerRequest( + getString(R.string.audio), + getString(R.string.downloading), + audioUrl, + audioDir + ) } else { downloadSucceededNotification() onDestroy() @@ -178,7 +198,7 @@ class DownloadService : Service() { NotificationCompat.Builder(this@DownloadService, "download_service") .setSmallIcon(R.drawable.ic_download) .setContentTitle("LibreTube") - .setContentText("Downloading") + .setContentText(getString(R.string.downloading)) .setPriority(NotificationCompat.PRIORITY_LOW) .setOngoing(true) .setOnlyAlertOnce(true) @@ -192,7 +212,7 @@ class DownloadService : Service() { val builder = NotificationCompat.Builder(this@DownloadService, "download_service") .setSmallIcon(R.drawable.ic_download) .setContentTitle(resources.getString(R.string.downloadfailed)) - .setContentText("failure") + .setContentText(getString(R.string.fail)) .setPriority(NotificationCompat.PRIORITY_HIGH) with(NotificationManagerCompat.from(this@DownloadService)) { // notificationId is a unique int for each notification that you must define @@ -205,7 +225,7 @@ class DownloadService : Service() { val builder = NotificationCompat.Builder(this@DownloadService, "download_service") .setSmallIcon(R.drawable.ic_download) .setContentTitle(resources.getString(R.string.success)) - .setContentText("success") + .setContentText(getString(R.string.fail)) .setPriority(NotificationCompat.PRIORITY_HIGH) with(NotificationManagerCompat.from(this@DownloadService)) { // notificationId is a unique int for each notification that you must define diff --git a/app/src/main/java/com/github/libretube/MainActivity.kt b/app/src/main/java/com/github/libretube/MainActivity.kt index db9894118..e6e7beee0 100644 --- a/app/src/main/java/com/github/libretube/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/MainActivity.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.content.pm.ActivityInfo import android.content.res.Configuration import android.net.ConnectivityManager +import android.net.NetworkCapabilities import android.net.Uri import android.os.Build import android.os.Bundle @@ -44,8 +45,9 @@ import com.google.android.material.color.DynamicColors class MainActivity : AppCompatActivity() { val TAG = "MainActivity" + lateinit var bottomNavigationView: BottomNavigationView - lateinit var toolbar: Toolbar + private lateinit var toolbar: Toolbar lateinit var navController: NavController override fun onCreate(savedInstanceState: Bundle?) { @@ -56,9 +58,9 @@ class MainActivity : AppCompatActivity() { RetrofitInstance.url = sharedPreferences.getString("selectInstance", "https://pipedapi.kavin.rocks/")!! SponsorBlockSettings.sponsorBlockEnabled = - sharedPreferences.getBoolean("sb_enabled_key", false) + sharedPreferences.getBoolean("sb_enabled_key", true) SponsorBlockSettings.sponsorNotificationsEnabled = - sharedPreferences.getBoolean("sb_notifications_key", false) + sharedPreferences.getBoolean("sb_notifications_key", true) SponsorBlockSettings.introEnabled = sharedPreferences.getBoolean("intro_category_key", false) SponsorBlockSettings.selfPromoEnabled = @@ -66,7 +68,7 @@ class MainActivity : AppCompatActivity() { SponsorBlockSettings.interactionEnabled = sharedPreferences.getBoolean("interaction_category_key", false) SponsorBlockSettings.sponsorsEnabled = - sharedPreferences.getBoolean("sponsors_category_key", false) + sharedPreferences.getBoolean("sponsors_category_key", true) SponsorBlockSettings.outroEnabled = sharedPreferences.getBoolean("outro_category_key", false) SponsorBlockSettings.fillerEnabled = @@ -79,12 +81,8 @@ class MainActivity : AppCompatActivity() { ThemeHelper().updateTheme(this) LocaleHelper().updateLanguage(this) - val connectivityManager = - this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - val networkInfo = connectivityManager.activeNetworkInfo - val isConnected = networkInfo != null && networkInfo.isConnected - - if (!isConnected) { + // show noInternet Activity if no internet available on app startup + if (!isNetworkAvailable(this)) { setContentView(R.layout.activity_nointernet) findViewById