mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-29 11:03:01 +02:00
Compare commits
160 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a1060a15be | |||
| dc7b2f420b | |||
| b35390a4bb | |||
| 3b253ad2b6 | |||
| 06c39ce973 | |||
| 11b8914615 | |||
| e45c8617df | |||
| 9075a2599c | |||
| dd8d50e0e2 | |||
| 55a11d82ac | |||
| 7ee4f411cb | |||
| c9d5508018 | |||
| bef8fc682c | |||
| c37d464403 | |||
| cbf2712654 | |||
| 08134b4427 | |||
| f90290c4ec | |||
| 7cde8ed538 | |||
| 585cf090d6 | |||
| 23d1085755 | |||
| fc5888d57e | |||
| c5541b1747 | |||
| 0fd8ba28bb | |||
| 6d9f4959e0 | |||
| 4be4bb631f | |||
| 948f5a2a6d | |||
| baad342aec | |||
| aeb29c54cd | |||
| a5dfa653ad | |||
| 3387c727d1 | |||
| c806ff2e33 | |||
| 1db4d427fc | |||
| 3bf73ed5e8 | |||
| db44aa2c4d | |||
| 0e6e381800 | |||
| 69e43dc533 | |||
| ee4442d553 | |||
| c49b9f7841 | |||
| 8a35cd0e82 | |||
| 0ae90ecf03 | |||
| 3d2840fe15 | |||
| b6ad3fd991 | |||
| 2ee3c30b0e | |||
| 662e94bcee | |||
| f3c9e0196e | |||
| f15eb9bf9e | |||
| 12b2552185 | |||
| d245e20b14 | |||
| e47349d010 | |||
| eb3dd854d4 | |||
| c529446219 | |||
| fa2f8c3447 | |||
| 840d1ae534 | |||
| 2530c6eb58 | |||
| 869789f0e2 | |||
| ee3761c780 | |||
| e4c89e9aa9 | |||
| 9d5888ddf7 | |||
| ecc94920d7 | |||
| 5cafbf243e | |||
| f3fa208680 | |||
| 502602e27a | |||
| 5054b093a4 | |||
| 0ffaec6bc2 | |||
| ef8ea9eecf | |||
| b09d22e479 | |||
| 01787b6229 | |||
| 4c022698d3 | |||
| bfdcab0e84 | |||
| aaea5cc963 | |||
| 23d9c33406 | |||
| fad1b216df | |||
| e221b508d3 | |||
| dfafac7d99 | |||
| 2246f8cee2 | |||
| b65fc594dc | |||
| f52b731615 | |||
| 8661ff88c0 | |||
| 99c06c516f | |||
| 0bba7fa373 | |||
| 0c1822b118 | |||
| 10e3d2122f | |||
| 6df8f84421 | |||
| 7fa80ec048 | |||
| b3f9b81984 | |||
| 1393c489c1 | |||
| 640c2cbed0 | |||
| e55509f549 | |||
| 27c7fb0c12 | |||
| 88f3815585 | |||
| 2e9405cfdb | |||
| 9c1b543ed6 | |||
| d34cb0f9c1 | |||
| 116dc90d21 | |||
| 17b9853bb6 | |||
| 8bfb8abd20 | |||
| 9ee3f1f26e | |||
| 5dcff29d8d | |||
| 6cfbd0c8bf | |||
| 01d96cce16 | |||
| 58c376f011 | |||
| 439d339330 | |||
| 44eacc2a47 | |||
| 8135d61398 | |||
| 66208f8265 | |||
| f52251e23a | |||
| dbea93efe5 | |||
| 3bf0740bd1 | |||
| fa7f1b11f3 | |||
| ff914bbdf4 | |||
| b822078d4b | |||
| 290d2ceb50 | |||
| 8ec9025990 | |||
| c4cf856dcd | |||
| 38bb4e25d3 | |||
| 0de996d91c | |||
| 1f38c9b27d | |||
| 234f31b02d | |||
| 00e40e8cd6 | |||
| 0bc6a43dc1 | |||
| e7e0157fbc | |||
| 4cae1a41a5 | |||
| 4fa61e7f52 | |||
| f02ac796f5 | |||
| 22146a6bdc | |||
| 5285eae01d | |||
| c47ca369e4 | |||
| f0b1f62bb1 | |||
| f7aa6d006e | |||
| 6b67cd549f | |||
| fc6bf85822 | |||
| fbd9345cf8 | |||
| 63137b4c4d | |||
| e28dc7a3a6 | |||
| 6e14acc685 | |||
| ba64153f1d | |||
| 72c04e7556 | |||
| 54f37ee5b2 | |||
| 4fbb325313 | |||
| e1d3b95f73 | |||
| 8f7b4b8257 | |||
| 9d906025ea | |||
| d7f4dd65e8 | |||
| 599b119e62 | |||
| 41176464db | |||
| dd0ad19fb9 | |||
| 430625d2fb | |||
| 796cd1a776 | |||
| baa26af0c0 | |||
| ea0c27936e | |||
| 4aade35d19 | |||
| 251a5701af | |||
| 2da3116111 | |||
| 4c82fa1a4a | |||
| 7eef6eece2 | |||
| 570f32e980 | |||
| 16a0351125 | |||
| 2fa9005806 | |||
| 25527997fa | |||
| 4655d8369d |
+8
-1
@@ -5,6 +5,7 @@ plugins {
|
|||||||
id 'org.ajoberstar.grgit' version '1.7.2'
|
id 'org.ajoberstar.grgit' version '1.7.2'
|
||||||
id 'com.google.protobuf'
|
id 'com.google.protobuf'
|
||||||
id 'kotlin-parcelize'
|
id 'kotlin-parcelize'
|
||||||
|
id 'kotlin-kapt'
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
@@ -38,7 +39,7 @@ protobuf {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace 'com.futo.platformplayer'
|
namespace 'com.futo.platformplayer'
|
||||||
compileSdk 33
|
compileSdk 34
|
||||||
flavorDimensions "buildType"
|
flavorDimensions "buildType"
|
||||||
productFlavors {
|
productFlavors {
|
||||||
stable {
|
stable {
|
||||||
@@ -194,6 +195,12 @@ dependencies {
|
|||||||
implementation 'androidx.work:work-runtime-ktx:2.8.1'
|
implementation 'androidx.work:work-runtime-ktx:2.8.1'
|
||||||
implementation 'androidx.concurrent:concurrent-futures-ktx:1.1.0'
|
implementation 'androidx.concurrent:concurrent-futures-ktx:1.1.0'
|
||||||
|
|
||||||
|
//Database
|
||||||
|
implementation("androidx.room:room-runtime:2.6.0")
|
||||||
|
annotationProcessor("androidx.room:room-compiler:2.6.0")
|
||||||
|
kapt("androidx.room:room-compiler:2.6.0")
|
||||||
|
implementation("androidx.room:room-ktx:2.6.0")
|
||||||
|
|
||||||
//Payment
|
//Payment
|
||||||
implementation 'com.stripe:stripe-android:20.28.3'
|
implementation 'com.stripe:stripe-android:20.28.3'
|
||||||
|
|
||||||
|
|||||||
+29
-13
@@ -1,13 +1,14 @@
|
|||||||
package com.futo.platformplayer
|
package com.futo.platformplayer
|
||||||
|
|
||||||
import com.futo.platformplayer.encryption.EncryptionProvider
|
import com.futo.platformplayer.encryption.GEncryptionProviderV0
|
||||||
|
import com.futo.platformplayer.encryption.GEncryptionProviderV1
|
||||||
import junit.framework.TestCase.assertEquals
|
import junit.framework.TestCase.assertEquals
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class EncryptionProviderTests {
|
class GEncryptionProviderTests {
|
||||||
@Test
|
@Test
|
||||||
fun testEncryptDecrypt() {
|
fun testEncryptDecryptV1() {
|
||||||
val encryptionProvider = EncryptionProvider.instance
|
val encryptionProvider = GEncryptionProviderV1.instance
|
||||||
val plaintext = "This is a test string."
|
val plaintext = "This is a test string."
|
||||||
|
|
||||||
// Encrypt the plaintext
|
// Encrypt the plaintext
|
||||||
@@ -22,8 +23,8 @@ class EncryptionProviderTests {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testEncryptDecryptBytes() {
|
fun testEncryptDecryptBytesV1() {
|
||||||
val encryptionProvider = EncryptionProvider.instance
|
val encryptionProvider = GEncryptionProviderV1.instance
|
||||||
val bytes = "This is a test string.".toByteArray();
|
val bytes = "This is a test string.".toByteArray();
|
||||||
|
|
||||||
// Encrypt the plaintext
|
// Encrypt the plaintext
|
||||||
@@ -36,21 +37,36 @@ class EncryptionProviderTests {
|
|||||||
assertArrayEquals(bytes, decrypted);
|
assertArrayEquals(bytes, decrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testEncryptDecryptBytesPassword() {
|
fun testEncryptDecryptV0() {
|
||||||
val encryptionProvider = EncryptionProvider.instance
|
val encryptionProvider = GEncryptionProviderV0.instance
|
||||||
val bytes = "This is a test string.".toByteArray();
|
val plaintext = "This is a test string."
|
||||||
val password = "1234".padStart(32, '9');
|
|
||||||
|
|
||||||
// Encrypt the plaintext
|
// Encrypt the plaintext
|
||||||
val ciphertext = encryptionProvider.encrypt(bytes, password)
|
val ciphertext = encryptionProvider.encrypt(plaintext)
|
||||||
|
|
||||||
// Decrypt the ciphertext
|
// Decrypt the ciphertext
|
||||||
val decrypted = encryptionProvider.decrypt(ciphertext, password)
|
val decrypted = encryptionProvider.decrypt(ciphertext)
|
||||||
|
|
||||||
|
// The decrypted string should be equal to the original plaintext
|
||||||
|
assertEquals(plaintext, decrypted)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testEncryptDecryptBytesV0() {
|
||||||
|
val encryptionProvider = GEncryptionProviderV0.instance
|
||||||
|
val bytes = "This is a test string.".toByteArray();
|
||||||
|
|
||||||
|
// Encrypt the plaintext
|
||||||
|
val ciphertext = encryptionProvider.encrypt(bytes)
|
||||||
|
|
||||||
|
// Decrypt the ciphertext
|
||||||
|
val decrypted = encryptionProvider.decrypt(ciphertext)
|
||||||
|
|
||||||
// The decrypted string should be equal to the original plaintext
|
// The decrypted string should be equal to the original plaintext
|
||||||
assertArrayEquals(bytes, decrypted);
|
assertArrayEquals(bytes, decrypted);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertArrayEquals(a: ByteArray, b: ByteArray) {
|
private fun assertArrayEquals(a: ByteArray, b: ByteArray) {
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.futo.platformplayer
|
||||||
|
|
||||||
|
import com.futo.platformplayer.encryption.GPasswordEncryptionProviderV0
|
||||||
|
import com.futo.platformplayer.encryption.GPasswordEncryptionProviderV1
|
||||||
|
import junit.framework.TestCase.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class GPasswordEncryptionProviderTests {
|
||||||
|
@Test
|
||||||
|
fun testEncryptDecryptBytesPasswordV1() {
|
||||||
|
val encryptionProvider = GPasswordEncryptionProviderV1();
|
||||||
|
val bytes = "This is a test string.".toByteArray();
|
||||||
|
|
||||||
|
// Encrypt the plaintext
|
||||||
|
val ciphertext = encryptionProvider.encrypt(bytes, "1234")
|
||||||
|
|
||||||
|
// Decrypt the ciphertext
|
||||||
|
val decrypted = encryptionProvider.decrypt(ciphertext, "1234")
|
||||||
|
|
||||||
|
// The decrypted string should be equal to the original plaintext
|
||||||
|
assertArrayEquals(bytes, decrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testEncryptDecryptBytesPasswordV0() {
|
||||||
|
val encryptionProvider = GPasswordEncryptionProviderV0("1234".padStart(32, '9'));
|
||||||
|
val bytes = "This is a test string.".toByteArray();
|
||||||
|
|
||||||
|
// Encrypt the plaintext
|
||||||
|
val ciphertext = encryptionProvider.encrypt(bytes)
|
||||||
|
|
||||||
|
// Decrypt the ciphertext
|
||||||
|
val decrypted = encryptionProvider.decrypt(ciphertext)
|
||||||
|
|
||||||
|
// The decrypted string should be equal to the original plaintext
|
||||||
|
assertArrayEquals(bytes, decrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertArrayEquals(a: ByteArray, b: ByteArray) {
|
||||||
|
assertEquals(a.size, b.size);
|
||||||
|
for(i in 0 until a.size) {
|
||||||
|
assertEquals(a[i], b[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,368 @@
|
|||||||
|
package com.futo.platformplayer
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
||||||
|
import com.futo.platformplayer.stores.db.ManagedDBDescriptor
|
||||||
|
import com.futo.platformplayer.stores.db.ManagedDBStore
|
||||||
|
import com.futo.platformplayer.testing.DBTOs
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Test
|
||||||
|
import java.util.UUID
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import java.util.concurrent.ConcurrentMap
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
class ManagedDBStoreTests {
|
||||||
|
val context = InstrumentationRegistry.getInstrumentation().targetContext;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun startup() {
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun insert() {
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testObj = DBTOs.TestObject();
|
||||||
|
createAndAssert(store, testObj);
|
||||||
|
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun update() {
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testObj = DBTOs.TestObject();
|
||||||
|
val obj = createAndAssert(store, testObj);
|
||||||
|
|
||||||
|
testObj.someStr = "Testing";
|
||||||
|
store.update(obj.id!!, testObj);
|
||||||
|
val obj2 = store.get(obj.id!!);
|
||||||
|
assertIndexEquals(obj2, testObj);
|
||||||
|
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun delete() {
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testObj = DBTOs.TestObject();
|
||||||
|
val obj = createAndAssert(store, testObj);
|
||||||
|
store.delete(obj.id!!);
|
||||||
|
|
||||||
|
Assert.assertEquals(store.count(), 0);
|
||||||
|
Assert.assertNull(store.getOrNull(obj.id!!));
|
||||||
|
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun withIndex() {
|
||||||
|
val index = ConcurrentHashMap<Any, DBTOs.TestIndex>();
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.withIndex({it.someString}, index, true)
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testObj1 = DBTOs.TestObject();
|
||||||
|
val testObj2 = DBTOs.TestObject();
|
||||||
|
val testObj3 = DBTOs.TestObject();
|
||||||
|
val obj1 = createAndAssert(store, testObj1);
|
||||||
|
val obj2 = createAndAssert(store, testObj2);
|
||||||
|
val obj3 = createAndAssert(store, testObj3);
|
||||||
|
Assert.assertEquals(store.count(), 3);
|
||||||
|
|
||||||
|
Assert.assertTrue(index.containsKey(testObj1.someStr));
|
||||||
|
Assert.assertTrue(index.containsKey(testObj2.someStr));
|
||||||
|
Assert.assertTrue(index.containsKey(testObj3.someStr));
|
||||||
|
Assert.assertEquals(index.size, 3);
|
||||||
|
|
||||||
|
val oldStr = testObj1.someStr;
|
||||||
|
testObj1.someStr = UUID.randomUUID().toString();
|
||||||
|
store.update(obj1.id!!, testObj1);
|
||||||
|
|
||||||
|
Assert.assertEquals(index.size, 3);
|
||||||
|
Assert.assertFalse(index.containsKey(oldStr));
|
||||||
|
Assert.assertTrue(index.containsKey(testObj1.someStr));
|
||||||
|
Assert.assertTrue(index.containsKey(testObj2.someStr));
|
||||||
|
Assert.assertTrue(index.containsKey(testObj3.someStr));
|
||||||
|
|
||||||
|
store.delete(obj2.id!!);
|
||||||
|
Assert.assertEquals(index.size, 2);
|
||||||
|
|
||||||
|
Assert.assertFalse(index.containsKey(oldStr));
|
||||||
|
Assert.assertTrue(index.containsKey(testObj1.someStr));
|
||||||
|
Assert.assertFalse(index.containsKey(testObj2.someStr));
|
||||||
|
Assert.assertTrue(index.containsKey(testObj3.someStr));
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun withUnique() {
|
||||||
|
val index = ConcurrentHashMap<Any, DBTOs.TestIndex>();
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.withIndex({it.someString}, index, false, true)
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testObj1 = DBTOs.TestObject();
|
||||||
|
val testObj2 = DBTOs.TestObject();
|
||||||
|
val testObj3 = DBTOs.TestObject();
|
||||||
|
val obj1 = createAndAssert(store, testObj1);
|
||||||
|
val obj2 = createAndAssert(store, testObj2);
|
||||||
|
|
||||||
|
testObj3.someStr = testObj2.someStr;
|
||||||
|
Assert.assertEquals(store.insert(testObj3), obj2.id!!);
|
||||||
|
Assert.assertEquals(store.count(), 2);
|
||||||
|
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun getPage() {
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testObjs = createSequence(store, 25);
|
||||||
|
|
||||||
|
val page1 = store.getPage(0, 10);
|
||||||
|
val page2 = store.getPage(1, 10);
|
||||||
|
val page3 = store.getPage(2, 10);
|
||||||
|
Assert.assertEquals(10, page1.size);
|
||||||
|
Assert.assertEquals(10, page2.size);
|
||||||
|
Assert.assertEquals(5, page3.size);
|
||||||
|
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun query() {
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testStr = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
val testObj1 = DBTOs.TestObject();
|
||||||
|
val testObj2 = DBTOs.TestObject();
|
||||||
|
val testObj3 = DBTOs.TestObject();
|
||||||
|
val testObj4 = DBTOs.TestObject();
|
||||||
|
testObj3.someStr = testStr;
|
||||||
|
testObj4.someStr = testStr;
|
||||||
|
val obj1 = createAndAssert(store, testObj1);
|
||||||
|
val obj2 = createAndAssert(store, testObj2);
|
||||||
|
val obj3 = createAndAssert(store, testObj3);
|
||||||
|
val obj4 = createAndAssert(store, testObj4);
|
||||||
|
|
||||||
|
val results = store.query(DBTOs.TestIndex::someString, testStr);
|
||||||
|
|
||||||
|
Assert.assertEquals(2, results.size);
|
||||||
|
for(result in results) {
|
||||||
|
if(result.someNum == obj3.someNum)
|
||||||
|
assertIndexEquals(obj3, result);
|
||||||
|
else
|
||||||
|
assertIndexEquals(obj4, result);
|
||||||
|
}
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun queryPage() {
|
||||||
|
val index = ConcurrentHashMap<Any, DBTOs.TestIndex>();
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.withIndex({ it.someNum }, index)
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
|
||||||
|
val testStr = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
val testResults = createSequence(store, 40, { i, testObject ->
|
||||||
|
if(i % 2 == 0)
|
||||||
|
testObject.someStr = testStr;
|
||||||
|
});
|
||||||
|
val page1 = store.queryPage(DBTOs.TestIndex::someString, testStr, 0,10);
|
||||||
|
val page2 = store.queryPage(DBTOs.TestIndex::someString, testStr, 1,10);
|
||||||
|
val page3 = store.queryPage(DBTOs.TestIndex::someString, testStr, 2,10);
|
||||||
|
|
||||||
|
Assert.assertEquals(10, page1.size);
|
||||||
|
Assert.assertEquals(10, page2.size);
|
||||||
|
Assert.assertEquals(0, page3.size);
|
||||||
|
|
||||||
|
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun queryPager() {
|
||||||
|
val testStr = UUID.randomUUID().toString();
|
||||||
|
testQuery(100, { i, testObject ->
|
||||||
|
if(i % 2 == 0)
|
||||||
|
testObject.someStr = testStr;
|
||||||
|
}) {
|
||||||
|
val pager = it.queryPager(DBTOs.TestIndex::someString, testStr, 10);
|
||||||
|
|
||||||
|
val items = pager.getResults().toMutableList();
|
||||||
|
while(pager.hasMorePages()) {
|
||||||
|
pager.nextPage();
|
||||||
|
items.addAll(pager.getResults());
|
||||||
|
}
|
||||||
|
Assert.assertEquals(50, items.size);
|
||||||
|
for(i in 0 until 50) {
|
||||||
|
val k = i * 2;
|
||||||
|
Assert.assertEquals(k, items[i].someNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun queryLike() {
|
||||||
|
val testStr = UUID.randomUUID().toString();
|
||||||
|
val testStrLike = testStr.substring(0, 8) + "Testing" + testStr.substring(8, testStr.length);
|
||||||
|
testQuery(100, { i, testObject ->
|
||||||
|
if(i % 2 == 0)
|
||||||
|
testObject.someStr = testStrLike;
|
||||||
|
}) {
|
||||||
|
val results = it.queryLike(DBTOs.TestIndex::someString, "%Testing%");
|
||||||
|
|
||||||
|
Assert.assertEquals(50, results.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun queryLikePager() {
|
||||||
|
val testStr = UUID.randomUUID().toString();
|
||||||
|
val testStrLike = testStr.substring(0, 8) + "Testing" + testStr.substring(8, testStr.length);
|
||||||
|
testQuery(100, { i, testObject ->
|
||||||
|
if(i % 2 == 0)
|
||||||
|
testObject.someStr = testStrLike;
|
||||||
|
|
||||||
|
}) {
|
||||||
|
val pager = it.queryLikePager(DBTOs.TestIndex::someString, "%Testing%", 10);
|
||||||
|
val items = pager.getResults().toMutableList();
|
||||||
|
while(pager.hasMorePages()) {
|
||||||
|
pager.nextPage();
|
||||||
|
items.addAll(pager.getResults());
|
||||||
|
}
|
||||||
|
Assert.assertEquals(50, items.size);
|
||||||
|
for(i in 0 until 50) {
|
||||||
|
val k = i * 2;
|
||||||
|
Assert.assertEquals(k, items[i].someNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun queryGreater() {
|
||||||
|
testQuery(100, { i, testObject ->
|
||||||
|
testObject.someNum = i;
|
||||||
|
}) {
|
||||||
|
val results = it.queryGreater(DBTOs.TestIndex::someNum, 51);
|
||||||
|
Assert.assertEquals(48, results.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun querySmaller() {
|
||||||
|
testQuery(100, { i, testObject ->
|
||||||
|
testObject.someNum = i;
|
||||||
|
}) {
|
||||||
|
val results = it.querySmaller(DBTOs.TestIndex::someNum, 30);
|
||||||
|
Assert.assertEquals(30, results.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun queryBetween() {
|
||||||
|
testQuery(100, { i, testObject ->
|
||||||
|
testObject.someNum = i;
|
||||||
|
}) {
|
||||||
|
val results = it.queryBetween(DBTOs.TestIndex::someNum, 30, 65);
|
||||||
|
Assert.assertEquals(34, results.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun queryIn() {
|
||||||
|
val ids = mutableListOf<String>()
|
||||||
|
testQuery(1100, { i, testObject ->
|
||||||
|
testObject.someNum = i;
|
||||||
|
ids.add(testObject.someStr);
|
||||||
|
}) {
|
||||||
|
val pager = it.queryInPager(DBTOs.TestIndex::someString, ids.take(1000), 65);
|
||||||
|
val list = mutableListOf<Any>();
|
||||||
|
list.addAll(pager.getResults());
|
||||||
|
while(pager.hasMorePages())
|
||||||
|
{
|
||||||
|
pager.nextPage();
|
||||||
|
list.addAll(pager.getResults());
|
||||||
|
}
|
||||||
|
Assert.assertEquals(1000, list.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun testQuery(items: Int, modifier: (Int, DBTOs.TestObject)->Unit, testing: (ManagedDBStore<DBTOs.TestIndex, DBTOs.TestObject, DBTOs.DB, DBTOs.DBDAO>)->Unit) {
|
||||||
|
val store = ManagedDBStore.create("test", Descriptor())
|
||||||
|
.load(context, true);
|
||||||
|
store.deleteAll();
|
||||||
|
createSequence(store, items, modifier);
|
||||||
|
try {
|
||||||
|
testing(store);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
store.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun createSequence(store: ManagedDBStore<DBTOs.TestIndex, DBTOs.TestObject, DBTOs.DB, DBTOs.DBDAO>, count: Int, modifier: ((Int, DBTOs.TestObject)->Unit)? = null): List<DBTOs.TestIndex> {
|
||||||
|
val list = mutableListOf<DBTOs.TestIndex>();
|
||||||
|
for(i in 0 until count) {
|
||||||
|
val obj = DBTOs.TestObject();
|
||||||
|
obj.someNum = i;
|
||||||
|
modifier?.invoke(i, obj);
|
||||||
|
list.add(createAndAssert(store, obj));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createAndAssert(store: ManagedDBStore<DBTOs.TestIndex, DBTOs.TestObject, DBTOs.DB, DBTOs.DBDAO>, obj: DBTOs.TestObject): DBTOs.TestIndex {
|
||||||
|
val id = store.insert(obj);
|
||||||
|
Assert.assertTrue(id > 0);
|
||||||
|
|
||||||
|
val dbObj = store.get(id);
|
||||||
|
assertIndexEquals(dbObj, obj);
|
||||||
|
return dbObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertObjectEquals(obj1: DBTOs.TestObject, obj2: DBTOs.TestObject) {
|
||||||
|
Assert.assertEquals(obj1.someStr, obj2.someStr);
|
||||||
|
Assert.assertEquals(obj1.someNum, obj2.someNum);
|
||||||
|
}
|
||||||
|
private fun assertIndexEquals(obj1: DBTOs.TestIndex, obj2: DBTOs.TestObject) {
|
||||||
|
Assert.assertEquals(obj1.someString, obj2.someStr);
|
||||||
|
Assert.assertEquals(obj1.someNum, obj2.someNum);
|
||||||
|
assertObjectEquals(obj1.obj, obj2);
|
||||||
|
}
|
||||||
|
private fun assertIndexEquals(obj1: DBTOs.TestIndex, obj2: DBTOs.TestIndex) {
|
||||||
|
Assert.assertEquals(obj1.someString, obj2.someString);
|
||||||
|
Assert.assertEquals(obj1.someNum, obj2.someNum);
|
||||||
|
assertIndexEquals(obj1, obj2.obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Descriptor: ManagedDBDescriptor<DBTOs.TestObject, DBTOs.TestIndex, DBTOs.DB, DBTOs.DBDAO>() {
|
||||||
|
override val table_name: String = "testing";
|
||||||
|
override fun indexClass(): KClass<DBTOs.TestIndex> = DBTOs.TestIndex::class;
|
||||||
|
override fun dbClass(): KClass<DBTOs.DB> = DBTOs.DB::class;
|
||||||
|
override fun create(obj: DBTOs.TestObject): DBTOs.TestIndex = DBTOs.TestIndex(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -39,6 +41,7 @@
|
|||||||
|
|
||||||
<receiver android:name=".receivers.MediaControlReceiver" />
|
<receiver android:name=".receivers.MediaControlReceiver" />
|
||||||
<receiver android:name=".receivers.AudioNoisyReceiver" />
|
<receiver android:name=".receivers.AudioNoisyReceiver" />
|
||||||
|
<receiver android:name=".receivers.PlannedNotificationReceiver" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.MainActivity"
|
android:name=".activities.MainActivity"
|
||||||
@@ -58,6 +61,14 @@
|
|||||||
|
|
||||||
<data android:scheme="grayjay" />
|
<data android:scheme="grayjay" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:scheme="fcast" />
|
||||||
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
@@ -92,6 +103,26 @@
|
|||||||
<data android:host="*" />
|
<data android:host="*" />
|
||||||
<data android:scheme="file" />
|
<data android:scheme="file" />
|
||||||
|
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter android:autoVerify="true">
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<data android:host="*" />
|
||||||
|
<data android:scheme="content" />
|
||||||
|
|
||||||
|
<data android:mimeType="text/plain" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter android:autoVerify="true">
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<data android:host="*" />
|
||||||
|
<data android:scheme="file" />
|
||||||
|
|
||||||
<data android:mimeType="application/zip" />
|
<data android:mimeType="application/zip" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter android:autoVerify="true">
|
<intent-filter android:autoVerify="true">
|
||||||
@@ -187,5 +218,9 @@
|
|||||||
android:name=".activities.QRCaptureActivity"
|
android:name=".activities.QRCaptureActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:theme="@style/Theme.FutoVideo.NoActionBar" />
|
android:theme="@style/Theme.FutoVideo.NoActionBar" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.FCastGuideActivity"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
android:theme="@style/Theme.FutoVideo.NoActionBar" />
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -540,6 +540,8 @@
|
|||||||
<script>
|
<script>
|
||||||
IS_TESTING = true;
|
IS_TESTING = true;
|
||||||
let lastScriptTag = null;
|
let lastScriptTag = null;
|
||||||
|
let shouldDevLog = true;
|
||||||
|
let shouldLoginCheck = true;
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data: {
|
data: {
|
||||||
@@ -603,7 +605,7 @@
|
|||||||
};
|
};
|
||||||
setInterval(()=>{
|
setInterval(()=>{
|
||||||
try{
|
try{
|
||||||
if(!this.Plugin.currentPlugin)
|
if(!this.Plugin.currentPlugin || !shouldDevLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
getDevLogs(this.Integration.lastLogIndex, (newLogs)=> {
|
getDevLogs(this.Integration.lastLogIndex, (newLogs)=> {
|
||||||
@@ -638,7 +640,8 @@
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
setInterval(()=>{
|
setInterval(()=>{
|
||||||
try{
|
try{
|
||||||
this.isTestLoggedIn();
|
if(shouldLoginCheck)
|
||||||
|
this.isTestLoggedIn();
|
||||||
}catch(ex){}
|
}catch(ex){}
|
||||||
}, 2500);
|
}, 2500);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ let Type = {
|
|||||||
Videos: "VIDEOS",
|
Videos: "VIDEOS",
|
||||||
Streams: "STREAMS",
|
Streams: "STREAMS",
|
||||||
Mixed: "MIXED",
|
Mixed: "MIXED",
|
||||||
Live: "LIVE"
|
Live: "LIVE",
|
||||||
|
Subscriptions: "SUBSCRIPTIONS"
|
||||||
},
|
},
|
||||||
Order: {
|
Order: {
|
||||||
Chronological: "CHRONOLOGICAL"
|
Chronological: "CHRONOLOGICAL"
|
||||||
@@ -159,13 +160,27 @@ class FilterCapability {
|
|||||||
|
|
||||||
|
|
||||||
class PlatformAuthorLink {
|
class PlatformAuthorLink {
|
||||||
constructor(id, name, url, thumbnail, subscribers) {
|
constructor(id, name, url, thumbnail, subscribers, membershipUrl) {
|
||||||
this.id = id ?? PlatformID(); //PlatformID
|
this.id = id ?? PlatformID(); //PlatformID
|
||||||
this.name = name ?? ""; //string
|
this.name = name ?? ""; //string
|
||||||
this.url = url ?? ""; //string
|
this.url = url ?? ""; //string
|
||||||
this.thumbnail = thumbnail; //string
|
this.thumbnail = thumbnail; //string
|
||||||
if(subscribers)
|
if(subscribers)
|
||||||
this.subscribers = subscribers;
|
this.subscribers = subscribers;
|
||||||
|
if(membershipUrl)
|
||||||
|
this.membershipUrl = membershipUrl ?? null; //string (for backcompat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class PlatformAuthorMembershipLink {
|
||||||
|
constructor(id, name, url, thumbnail, subscribers, membershipUrl) {
|
||||||
|
this.id = id ?? PlatformID(); //PlatformID
|
||||||
|
this.name = name ?? ""; //string
|
||||||
|
this.url = url ?? ""; //string
|
||||||
|
this.thumbnail = thumbnail; //string
|
||||||
|
if(subscribers)
|
||||||
|
this.subscribers = subscribers;
|
||||||
|
if(membershipUrl)
|
||||||
|
this.membershipUrl = membershipUrl ?? null; //string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class PlatformContent {
|
class PlatformContent {
|
||||||
@@ -196,6 +211,16 @@ class PlatformNestedMediaContent extends PlatformContent {
|
|||||||
this.contentThumbnails = obj.contentThumbnails ?? new Thumbnails();
|
this.contentThumbnails = obj.contentThumbnails ?? new Thumbnails();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class PlatformLockedContent extends PlatformContent {
|
||||||
|
constructor(obj) {
|
||||||
|
super(obj, 70);
|
||||||
|
obj = obj ?? {};
|
||||||
|
this.contentName = obj.contentName;
|
||||||
|
this.contentThumbnails = obj.contentThumbnails ?? new Thumbnails();
|
||||||
|
this.unlockUrl = obj.unlockUrl ?? "";
|
||||||
|
this.lockDescription = obj.lockDescription;
|
||||||
|
}
|
||||||
|
}
|
||||||
class PlatformVideo extends PlatformContent {
|
class PlatformVideo extends PlatformContent {
|
||||||
constructor(obj) {
|
constructor(obj) {
|
||||||
super(obj, 1);
|
super(obj, 1);
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package com.futo.platformplayer
|
package com.futo.platformplayer
|
||||||
|
|
||||||
import com.google.common.base.CharMatcher
|
import com.google.common.base.CharMatcher
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.Socket
|
import java.net.Socket
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
|
|
||||||
private const val IPV4_PART_COUNT = 4;
|
private const val IPV4_PART_COUNT = 4;
|
||||||
@@ -273,3 +277,46 @@ fun getConnectedSocket(addresses: List<InetAddress>, port: Int): Socket? {
|
|||||||
|
|
||||||
return connectedSocket;
|
return connectedSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun InputStream.readHttpHeaderBytes() : ByteArray {
|
||||||
|
val headerBytes = ByteArrayOutputStream()
|
||||||
|
var crlfCount = 0
|
||||||
|
|
||||||
|
while (crlfCount < 4) {
|
||||||
|
val b = read()
|
||||||
|
if (b == -1) {
|
||||||
|
throw IOException("Unexpected end of stream while reading headers")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b == 0x0D || b == 0x0A) { // CR or LF
|
||||||
|
crlfCount++
|
||||||
|
} else {
|
||||||
|
crlfCount = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
headerBytes.write(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
return headerBytes.toByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun InputStream.readLine() : String? {
|
||||||
|
val line = ByteArrayOutputStream()
|
||||||
|
var crlfCount = 0
|
||||||
|
|
||||||
|
while (crlfCount < 2) {
|
||||||
|
val b = read()
|
||||||
|
if (b == -1) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b == 0x0D || b == 0x0A) { // CR or LF
|
||||||
|
crlfCount++
|
||||||
|
} else {
|
||||||
|
crlfCount = 0
|
||||||
|
line.write(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(line.toByteArray(), Charsets.UTF_8)
|
||||||
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.futo.platformplayer
|
package com.futo.platformplayer
|
||||||
|
|
||||||
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.states.AnnouncementType
|
||||||
|
import com.futo.platformplayer.states.StateAnnouncement
|
||||||
import com.futo.platformplayer.states.StatePlatform
|
import com.futo.platformplayer.states.StatePlatform
|
||||||
|
import com.futo.platformplayer.views.adapters.CommentViewHolder
|
||||||
|
import com.futo.polycentric.core.ProcessHandle
|
||||||
import userpackage.Protocol
|
import userpackage.Protocol
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
@@ -39,4 +44,21 @@ fun Protocol.Claim.resolveChannelUrl(): String? {
|
|||||||
|
|
||||||
fun Protocol.Claim.resolveChannelUrls(): List<String> {
|
fun Protocol.Claim.resolveChannelUrls(): List<String> {
|
||||||
return StatePlatform.instance.resolveChannelUrlsByClaimTemplates(this.claimType.toInt(), this.claimFieldsList.associate { Pair(it.key.toInt(), it.value) })
|
return StatePlatform.instance.resolveChannelUrlsByClaimTemplates(this.claimType.toInt(), this.claimFieldsList.associate { Pair(it.key.toInt(), it.value) })
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun ProcessHandle.fullyBackfillServersAnnounceExceptions() {
|
||||||
|
val exceptions = fullyBackfillServers()
|
||||||
|
for (pair in exceptions) {
|
||||||
|
val server = pair.key
|
||||||
|
val exception = pair.value
|
||||||
|
|
||||||
|
StateAnnouncement.instance.registerAnnouncement(
|
||||||
|
"backfill-failed",
|
||||||
|
"Backfill failed",
|
||||||
|
"Failed to backfill server $server. $exception",
|
||||||
|
AnnouncementType.SESSION_RECURRING
|
||||||
|
);
|
||||||
|
|
||||||
|
Logger.e("Backfill", "Failed to backfill server $server.", exception)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
package com.futo.platformplayer
|
package com.futo.platformplayer
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import java.net.URI
|
||||||
|
import java.net.URISyntaxException
|
||||||
|
import java.net.URLEncoder
|
||||||
|
|
||||||
//Syntax sugaring
|
//Syntax sugaring
|
||||||
inline fun <reified T> Any.assume(): T?{
|
inline fun <reified T> Any.assume(): T?{
|
||||||
if(this is T)
|
if(this is T)
|
||||||
@@ -12,4 +17,12 @@ inline fun <reified T, R> Any.assume(cb: (T) -> R): R? {
|
|||||||
if(result != null)
|
if(result != null)
|
||||||
return cb(result);
|
return cb(result);
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String?.yesNoToBoolean(): Boolean {
|
||||||
|
return this?.uppercase() == "YES"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Boolean?.toYesNo(): String {
|
||||||
|
return if (this == true) "YES" else "NO"
|
||||||
}
|
}
|
||||||
@@ -109,11 +109,29 @@ inline fun <reified T> V8Value.expectV8Variant(config: IV8PluginConfig, contextN
|
|||||||
else
|
else
|
||||||
return this.expectOrThrow<V8ValueLong>(config, contextName).value.toLong() as T
|
return this.expectOrThrow<V8ValueLong>(config, contextName).value.toLong() as T
|
||||||
};
|
};
|
||||||
|
Float::class -> {
|
||||||
|
if(this is V8ValueDouble)
|
||||||
|
return this.value.toFloat() as T;
|
||||||
|
else if(this is V8ValueInteger)
|
||||||
|
return this.value.toFloat() as T;
|
||||||
|
else if(this is V8ValueLong)
|
||||||
|
return this.value.toFloat() as T;
|
||||||
|
else
|
||||||
|
return this.expectOrThrow<V8ValueDouble>(config, contextName).value.toDouble() as T
|
||||||
|
};
|
||||||
|
Double::class -> {
|
||||||
|
if(this is V8ValueDouble)
|
||||||
|
return this.value.toDouble() as T;
|
||||||
|
else if(this is V8ValueInteger)
|
||||||
|
return this.value.toDouble() as T;
|
||||||
|
else if(this is V8ValueLong)
|
||||||
|
return this.value.toDouble() as T;
|
||||||
|
else
|
||||||
|
return this.expectOrThrow<V8ValueDouble>(config, contextName).value.toDouble() as T
|
||||||
|
};
|
||||||
V8ValueObject::class -> this.expectOrThrow<V8ValueObject>(config, contextName) as T
|
V8ValueObject::class -> this.expectOrThrow<V8ValueObject>(config, contextName) as T
|
||||||
V8ValueArray::class -> this.expectOrThrow<V8ValueArray>(config, contextName) as T;
|
V8ValueArray::class -> this.expectOrThrow<V8ValueArray>(config, contextName) as T;
|
||||||
Boolean::class -> this.expectOrThrow<V8ValueBoolean>(config, contextName).value as T;
|
Boolean::class -> this.expectOrThrow<V8ValueBoolean>(config, contextName).value as T;
|
||||||
Float::class -> this.expectOrThrow<V8ValueDouble>(config, contextName).value.toFloat() as T;
|
|
||||||
Double::class -> this.expectOrThrow<V8ValueDouble>(config, contextName).value as T;
|
|
||||||
HashMap::class -> this.expectOrThrow<V8ValueObject>(config, contextName).let { V8ObjectToHashMap(it) } as T;
|
HashMap::class -> this.expectOrThrow<V8ValueObject>(config, contextName).let { V8ObjectToHashMap(it) } as T;
|
||||||
Map::class -> this.expectOrThrow<V8ValueObject>(config, contextName).let { V8ObjectToHashMap(it) } as T;
|
Map::class -> this.expectOrThrow<V8ValueObject>(config, contextName).let { V8ObjectToHashMap(it) } as T;
|
||||||
List::class -> this.expectOrThrow<V8ValueArray>(config, contextName).let { V8ArrayToStringList(it) } as T;
|
List::class -> this.expectOrThrow<V8ValueArray>(config, contextName).let { V8ArrayToStringList(it) } as T;
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.futo.platformplayer
|
||||||
|
|
||||||
|
import android.graphics.Rect
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
class HorizontalSpaceItemDecoration(private val startSpace: Int, private val betweenSpace: Int, private val endSpace: Int) : RecyclerView.ItemDecoration() {
|
||||||
|
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
|
||||||
|
outRect.left = betweenSpace
|
||||||
|
|
||||||
|
val position = parent.getChildAdapterPosition(view)
|
||||||
|
if (position == 0) {
|
||||||
|
outRect.left = startSpace
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (position == state.itemCount - 1) {
|
||||||
|
outRect.right = endSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,9 +4,7 @@ import android.content.ActivityNotFoundException
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import androidx.core.content.ContextCompat.startActivity
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.activities.*
|
import com.futo.platformplayer.activities.*
|
||||||
import com.futo.platformplayer.api.http.ManagedHttpClient
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
@@ -23,6 +21,8 @@ import com.futo.platformplayer.views.fields.DropdownFieldOptionsId
|
|||||||
import com.futo.platformplayer.views.fields.FormField
|
import com.futo.platformplayer.views.fields.FormField
|
||||||
import com.futo.platformplayer.views.fields.FieldForm
|
import com.futo.platformplayer.views.fields.FieldForm
|
||||||
import com.futo.platformplayer.views.fields.FormFieldButton
|
import com.futo.platformplayer.views.fields.FormFieldButton
|
||||||
|
import com.futo.platformplayer.views.fields.FormFieldWarning
|
||||||
|
import com.futo.platformplayer.views.overlays.slideup.SlideUpMenuItem
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -44,25 +44,23 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
@Transient
|
@Transient
|
||||||
val onTabsChanged = Event0();
|
val onTabsChanged = Event0();
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.manage_polycentric_identity, FieldForm.BUTTON, R.string.manage_your_polycentric_identity, -6)
|
||||||
R.string.manage_polycentric_identity, FieldForm.BUTTON,
|
|
||||||
R.string.manage_your_polycentric_identity, -4
|
|
||||||
)
|
|
||||||
@FormFieldButton(R.drawable.ic_person)
|
@FormFieldButton(R.drawable.ic_person)
|
||||||
fun managePolycentricIdentity() {
|
fun managePolycentricIdentity() {
|
||||||
SettingsActivity.getActivity()?.let {
|
SettingsActivity.getActivity()?.let {
|
||||||
if (StatePolycentric.instance.processHandle != null) {
|
if (StatePolycentric.instance.enabled) {
|
||||||
it.startActivity(Intent(it, PolycentricProfileActivity::class.java));
|
if (StatePolycentric.instance.processHandle != null) {
|
||||||
|
it.startActivity(Intent(it, PolycentricProfileActivity::class.java));
|
||||||
|
} else {
|
||||||
|
it.startActivity(Intent(it, PolycentricHomeActivity::class.java));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
it.startActivity(Intent(it, PolycentricHomeActivity::class.java));
|
UIDialogs.toast(it, "Polycentric is disabled")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.show_faq, FieldForm.BUTTON, R.string.get_answers_to_common_questions, -5)
|
||||||
R.string.show_faq, FieldForm.BUTTON,
|
|
||||||
R.string.get_answers_to_common_questions, -3
|
|
||||||
)
|
|
||||||
@FormFieldButton(R.drawable.ic_quiz)
|
@FormFieldButton(R.drawable.ic_quiz)
|
||||||
fun openFAQ() {
|
fun openFAQ() {
|
||||||
try {
|
try {
|
||||||
@@ -72,10 +70,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
//Ignored
|
//Ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@FormField(
|
@FormField(R.string.show_issues, FieldForm.BUTTON, R.string.a_list_of_user_reported_and_self_reported_issues, -4)
|
||||||
R.string.show_issues, FieldForm.BUTTON,
|
|
||||||
R.string.a_list_of_user_reported_and_self_reported_issues, -2
|
|
||||||
)
|
|
||||||
@FormFieldButton(R.drawable.ic_data_alert)
|
@FormFieldButton(R.drawable.ic_data_alert)
|
||||||
fun openIssues() {
|
fun openIssues() {
|
||||||
try {
|
try {
|
||||||
@@ -107,10 +102,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.manage_tabs, FieldForm.BUTTON, R.string.change_tabs_visible_on_the_home_screen, -3)
|
||||||
R.string.manage_tabs, FieldForm.BUTTON,
|
|
||||||
R.string.change_tabs_visible_on_the_home_screen, -1
|
|
||||||
)
|
|
||||||
@FormFieldButton(R.drawable.ic_tabs)
|
@FormFieldButton(R.drawable.ic_tabs)
|
||||||
fun manageTabs() {
|
fun manageTabs() {
|
||||||
try {
|
try {
|
||||||
@@ -122,11 +114,58 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@FormField(R.string.import_data, FieldForm.BUTTON, R.string.import_data_description, -2)
|
||||||
|
@FormFieldButton(R.drawable.ic_move_up)
|
||||||
|
fun import() {
|
||||||
|
val act = SettingsActivity.getActivity() ?: return;
|
||||||
|
val intent = MainActivity.getImportOptionsIntent(act);
|
||||||
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||||
|
act.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.link_handling, FieldForm.BUTTON, R.string.allow_grayjay_to_handle_links, -1)
|
||||||
|
@FormFieldButton(R.drawable.ic_link)
|
||||||
|
fun manageLinks() {
|
||||||
|
try {
|
||||||
|
SettingsActivity.getActivity()?.let { UIDialogs.showUrlHandlingPrompt(it) }
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.e(TAG, "Failed to show url handling prompt", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.language, "group", -1, 0)
|
||||||
|
var language = LanguageSettings();
|
||||||
|
@Serializable
|
||||||
|
class LanguageSettings {
|
||||||
|
@FormField(R.string.app_language, FieldForm.DROPDOWN, R.string.may_require_restart, 5, "app_language")
|
||||||
|
@DropdownFieldOptionsId(R.array.app_languages)
|
||||||
|
var appLanguage: Int = 0;
|
||||||
|
|
||||||
|
fun getAppLanguageLocaleString(): String? {
|
||||||
|
return when(appLanguage) {
|
||||||
|
0 -> null
|
||||||
|
1 -> "en";
|
||||||
|
2 -> "de";
|
||||||
|
3 -> "es";
|
||||||
|
4 -> "pt";
|
||||||
|
5 -> "fr"
|
||||||
|
6 -> "ja";
|
||||||
|
7 -> "ko";
|
||||||
|
8 -> "zh";
|
||||||
|
9 -> "ru";
|
||||||
|
10 -> "ar";
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FormField(R.string.home, "group", R.string.configure_how_your_home_tab_works_and_feels, 1)
|
@FormField(R.string.home, "group", R.string.configure_how_your_home_tab_works_and_feels, 1)
|
||||||
var home = HomeSettings();
|
var home = HomeSettings();
|
||||||
@Serializable
|
@Serializable
|
||||||
class HomeSettings {
|
class HomeSettings {
|
||||||
@FormField(R.string.feed_style, FieldForm.DROPDOWN, -1, 5)
|
@FormField(R.string.feed_style, FieldForm.DROPDOWN, R.string.may_require_restart, 5)
|
||||||
@DropdownFieldOptionsId(R.array.feed_style)
|
@DropdownFieldOptionsId(R.array.feed_style)
|
||||||
var homeFeedStyle: Int = 1;
|
var homeFeedStyle: Int = 1;
|
||||||
|
|
||||||
@@ -136,21 +175,45 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
else
|
else
|
||||||
return FeedStyle.THUMBNAIL;
|
return FeedStyle.THUMBNAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.preview_feed_items, FieldForm.TOGGLE, R.string.preview_feed_items_description, 6)
|
||||||
|
var previewFeedItems: Boolean = true;
|
||||||
|
|
||||||
|
|
||||||
|
@FormField(R.string.progress_bar, FieldForm.TOGGLE, R.string.progress_bar_description, 6)
|
||||||
|
var progressBar: Boolean = false;
|
||||||
|
|
||||||
|
|
||||||
|
@FormField(R.string.clear_hidden, FieldForm.BUTTON, R.string.clear_hidden_description, 8)
|
||||||
|
@FormFieldButton(R.drawable.ic_visibility_off)
|
||||||
|
fun clearHidden() {
|
||||||
|
StateMeta.instance.removeAllHiddenCreators();
|
||||||
|
StateMeta.instance.removeAllHiddenVideos();
|
||||||
|
SettingsActivity.getActivity()?.let {
|
||||||
|
UIDialogs.toast(it, "Creators and videos should show up again");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.search, "group", -1, 2)
|
@FormField(R.string.search, "group", -1, 2)
|
||||||
var search = SearchSettings();
|
var search = SearchSettings();
|
||||||
@Serializable
|
@Serializable
|
||||||
class SearchSettings {
|
class SearchSettings {
|
||||||
@FormField(R.string.search_history, FieldForm.TOGGLE, -1, 4)
|
@FormField(R.string.search_history, FieldForm.TOGGLE, R.string.may_require_restart, 3)
|
||||||
@Serializable(with = FlexibleBooleanSerializer::class)
|
@Serializable(with = FlexibleBooleanSerializer::class)
|
||||||
var searchHistory: Boolean = true;
|
var searchHistory: Boolean = true;
|
||||||
|
|
||||||
|
|
||||||
@FormField(R.string.feed_style, FieldForm.DROPDOWN, -1, 5)
|
@FormField(R.string.feed_style, FieldForm.DROPDOWN, -1, 4)
|
||||||
@DropdownFieldOptionsId(R.array.feed_style)
|
@DropdownFieldOptionsId(R.array.feed_style)
|
||||||
var searchFeedStyle: Int = 1;
|
var searchFeedStyle: Int = 1;
|
||||||
|
|
||||||
|
@FormField(R.string.preview_feed_items, FieldForm.TOGGLE, R.string.preview_feed_items_description, 5)
|
||||||
|
var previewFeedItems: Boolean = true;
|
||||||
|
|
||||||
|
@FormField(R.string.progress_bar, FieldForm.TOGGLE, R.string.progress_bar_description, 6)
|
||||||
|
var progressBar: Boolean = false;
|
||||||
|
|
||||||
|
|
||||||
fun getSearchFeedStyle(): FeedStyle {
|
fun getSearchFeedStyle(): FeedStyle {
|
||||||
if(searchFeedStyle == 0)
|
if(searchFeedStyle == 0)
|
||||||
@@ -160,11 +223,21 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.subscriptions, "group", R.string.configure_how_your_subscriptions_works_and_feels, 3)
|
|
||||||
|
@FormField(R.string.channel, "group", -1, 3)
|
||||||
|
var channel = ChannelSettings();
|
||||||
|
@Serializable
|
||||||
|
class ChannelSettings {
|
||||||
|
|
||||||
|
@FormField(R.string.progress_bar, FieldForm.TOGGLE, R.string.progress_bar_description, 6)
|
||||||
|
var progressBar: Boolean = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.subscriptions, "group", R.string.configure_how_your_subscriptions_works_and_feels, 4)
|
||||||
var subscriptions = SubscriptionsSettings();
|
var subscriptions = SubscriptionsSettings();
|
||||||
@Serializable
|
@Serializable
|
||||||
class SubscriptionsSettings {
|
class SubscriptionsSettings {
|
||||||
@FormField(R.string.feed_style, FieldForm.DROPDOWN, -1, 5)
|
@FormField(R.string.feed_style, FieldForm.DROPDOWN, R.string.may_require_restart, 4)
|
||||||
@DropdownFieldOptionsId(R.array.feed_style)
|
@DropdownFieldOptionsId(R.array.feed_style)
|
||||||
var subscriptionsFeedStyle: Int = 1;
|
var subscriptionsFeedStyle: Int = 1;
|
||||||
|
|
||||||
@@ -175,11 +248,20 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
return FeedStyle.THUMBNAIL;
|
return FeedStyle.THUMBNAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.fetch_on_app_boot, FieldForm.TOGGLE, R.string.shortly_after_opening_the_app_start_fetching_subscriptions, 6)
|
@FormField(R.string.preview_feed_items, FieldForm.TOGGLE, R.string.preview_feed_items_description, 5)
|
||||||
|
var previewFeedItems: Boolean = true;
|
||||||
|
|
||||||
|
@FormField(R.string.progress_bar, FieldForm.TOGGLE, R.string.progress_bar_description, 6)
|
||||||
|
var progressBar: Boolean = false;
|
||||||
|
|
||||||
|
@FormField(R.string.fetch_on_app_boot, FieldForm.TOGGLE, R.string.shortly_after_opening_the_app_start_fetching_subscriptions, 7)
|
||||||
@Serializable(with = FlexibleBooleanSerializer::class)
|
@Serializable(with = FlexibleBooleanSerializer::class)
|
||||||
var fetchOnAppBoot: Boolean = true;
|
var fetchOnAppBoot: Boolean = true;
|
||||||
|
|
||||||
@FormField(R.string.background_update, FieldForm.DROPDOWN, R.string.experimental_background_update_for_subscriptions_cache, 7)
|
@FormField(R.string.fetch_on_tab_opened, FieldForm.TOGGLE, R.string.fetch_on_tab_opened_description, 8)
|
||||||
|
var fetchOnTabOpen: Boolean = true;
|
||||||
|
|
||||||
|
@FormField(R.string.background_update, FieldForm.DROPDOWN, R.string.experimental_background_update_for_subscriptions_cache, 9)
|
||||||
@DropdownFieldOptionsId(R.array.background_interval)
|
@DropdownFieldOptionsId(R.array.background_interval)
|
||||||
var subscriptionsBackgroundUpdateInterval: Int = 0;
|
var subscriptionsBackgroundUpdateInterval: Int = 0;
|
||||||
|
|
||||||
@@ -195,7 +277,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@FormField(R.string.subscription_concurrency, FieldForm.DROPDOWN, R.string.specify_how_many_threads_are_used_to_fetch_channels, 8)
|
@FormField(R.string.subscription_concurrency, FieldForm.DROPDOWN, R.string.specify_how_many_threads_are_used_to_fetch_channels, 10)
|
||||||
@DropdownFieldOptionsId(R.array.thread_count)
|
@DropdownFieldOptionsId(R.array.thread_count)
|
||||||
var subscriptionConcurrency: Int = 3;
|
var subscriptionConcurrency: Int = 3;
|
||||||
|
|
||||||
@@ -203,22 +285,33 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
return threadIndexToCount(subscriptionConcurrency);
|
return threadIndexToCount(subscriptionConcurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.show_watch_metrics, FieldForm.TOGGLE, R.string.show_watch_metrics_description, 9)
|
@FormField(R.string.show_watch_metrics, FieldForm.TOGGLE, R.string.show_watch_metrics_description, 11)
|
||||||
var showWatchMetrics: Boolean = false;
|
var showWatchMetrics: Boolean = false;
|
||||||
|
|
||||||
@FormField(R.string.track_playtime_locally, FieldForm.TOGGLE, R.string.track_playtime_locally_description, 10)
|
@FormField(R.string.track_playtime_locally, FieldForm.TOGGLE, R.string.track_playtime_locally_description, 12)
|
||||||
var allowPlaytimeTracking: Boolean = true;
|
var allowPlaytimeTracking: Boolean = true;
|
||||||
|
|
||||||
|
|
||||||
|
@FormField(R.string.always_reload_from_cache, FieldForm.TOGGLE, R.string.always_reload_from_cache_description, 13)
|
||||||
|
var alwaysReloadFromCache: Boolean = false;
|
||||||
|
|
||||||
|
@FormField(R.string.clear_channel_cache, FieldForm.BUTTON, R.string.clear_channel_cache_description, 14)
|
||||||
|
fun clearChannelCache() {
|
||||||
|
UIDialogs.toast(SettingsActivity.getActivity()!!, "Started clearing..");
|
||||||
|
StateCache.instance.clear();
|
||||||
|
UIDialogs.toast(SettingsActivity.getActivity()!!, "Finished clearing");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.player, "group", R.string.change_behavior_of_the_player, 4)
|
@FormField(R.string.player, "group", R.string.change_behavior_of_the_player, 5)
|
||||||
var playback = PlaybackSettings();
|
var playback = PlaybackSettings();
|
||||||
@Serializable
|
@Serializable
|
||||||
class PlaybackSettings {
|
class PlaybackSettings {
|
||||||
@FormField(R.string.primary_language, FieldForm.DROPDOWN, -1, 0)
|
@FormField(R.string.primary_language, FieldForm.DROPDOWN, -1, 0)
|
||||||
@DropdownFieldOptionsId(R.array.languages)
|
@DropdownFieldOptionsId(R.array.audio_languages)
|
||||||
var primaryLanguage: Int = 0;
|
var primaryLanguage: Int = 0;
|
||||||
|
|
||||||
fun getPrimaryLanguage(context: Context) = context.resources.getStringArray(R.array.languages)[primaryLanguage];
|
fun getPrimaryLanguage(context: Context) = context.resources.getStringArray(R.array.audio_languages)[primaryLanguage];
|
||||||
|
|
||||||
@FormField(R.string.default_playback_speed, FieldForm.DROPDOWN, -1, 1)
|
@FormField(R.string.default_playback_speed, FieldForm.DROPDOWN, -1, 1)
|
||||||
@DropdownFieldOptionsId(R.array.playback_speeds)
|
@DropdownFieldOptionsId(R.array.playback_speeds)
|
||||||
@@ -236,29 +329,29 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
else -> 1.0f;
|
else -> 1.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
@FormField(R.string.preferred_quality, FieldForm.DROPDOWN, -1, 2)
|
@FormField(R.string.preferred_quality, FieldForm.DROPDOWN, R.string.preferred_quality_description, 2)
|
||||||
@DropdownFieldOptionsId(R.array.preferred_quality_array)
|
@DropdownFieldOptionsId(R.array.preferred_quality_array)
|
||||||
var preferredQuality: Int = 0;
|
var preferredQuality: Int = 0;
|
||||||
|
|
||||||
@FormField(R.string.preferred_metered_quality, FieldForm.DROPDOWN, -1, 2)
|
@FormField(R.string.preferred_metered_quality, FieldForm.DROPDOWN, R.string.preferred_metered_quality_description, 3)
|
||||||
@DropdownFieldOptionsId(R.array.preferred_quality_array)
|
@DropdownFieldOptionsId(R.array.preferred_quality_array)
|
||||||
var preferredMeteredQuality: Int = 0;
|
var preferredMeteredQuality: Int = 0;
|
||||||
fun getPreferredQualityPixelCount(): Int = preferedQualityToPixels(preferredQuality);
|
fun getPreferredQualityPixelCount(): Int = preferedQualityToPixels(preferredQuality);
|
||||||
fun getPreferredMeteredQualityPixelCount(): Int = preferedQualityToPixels(preferredMeteredQuality);
|
fun getPreferredMeteredQualityPixelCount(): Int = preferedQualityToPixels(preferredMeteredQuality);
|
||||||
fun getCurrentPreferredQualityPixelCount(): Int = if(!StateApp.instance.isCurrentMetered()) getPreferredQualityPixelCount() else getPreferredMeteredQualityPixelCount();
|
fun getCurrentPreferredQualityPixelCount(): Int = if(!StateApp.instance.isCurrentMetered()) getPreferredQualityPixelCount() else getPreferredMeteredQualityPixelCount();
|
||||||
|
|
||||||
@FormField(R.string.preferred_preview_quality, FieldForm.DROPDOWN, -1, 3)
|
@FormField(R.string.preferred_preview_quality, FieldForm.DROPDOWN, R.string.preferred_preview_quality_description, 4)
|
||||||
@DropdownFieldOptionsId(R.array.preferred_quality_array)
|
@DropdownFieldOptionsId(R.array.preferred_quality_array)
|
||||||
var preferredPreviewQuality: Int = 5;
|
var preferredPreviewQuality: Int = 5;
|
||||||
fun getPreferredPreviewQualityPixelCount(): Int = preferedQualityToPixels(preferredPreviewQuality);
|
fun getPreferredPreviewQualityPixelCount(): Int = preferedQualityToPixels(preferredPreviewQuality);
|
||||||
|
|
||||||
@FormField(R.string.auto_rotate, FieldForm.DROPDOWN, -1, 4)
|
@FormField(R.string.auto_rotate, FieldForm.DROPDOWN, -1, 5)
|
||||||
@DropdownFieldOptionsId(R.array.system_enabled_disabled_array)
|
@DropdownFieldOptionsId(R.array.system_enabled_disabled_array)
|
||||||
var autoRotate: Int = 2;
|
var autoRotate: Int = 2;
|
||||||
|
|
||||||
fun isAutoRotate() = autoRotate == 1 || (autoRotate == 2 && StateApp.instance.getCurrentSystemAutoRotate());
|
fun isAutoRotate() = autoRotate == 1 || (autoRotate == 2 && StateApp.instance.getCurrentSystemAutoRotate());
|
||||||
|
|
||||||
@FormField(R.string.auto_rotate_dead_zone, FieldForm.DROPDOWN, R.string.this_prevents_the_device_from_rotating_within_the_given_amount_of_degrees, 5)
|
@FormField(R.string.auto_rotate_dead_zone, FieldForm.DROPDOWN, R.string.this_prevents_the_device_from_rotating_within_the_given_amount_of_degrees, 6)
|
||||||
@DropdownFieldOptionsId(R.array.auto_rotate_dead_zone)
|
@DropdownFieldOptionsId(R.array.auto_rotate_dead_zone)
|
||||||
var autoRotateDeadZone: Int = 0;
|
var autoRotateDeadZone: Int = 0;
|
||||||
|
|
||||||
@@ -266,7 +359,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
return autoRotateDeadZone * 5;
|
return autoRotateDeadZone * 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.background_behavior, FieldForm.DROPDOWN, -1, 6)
|
@FormField(R.string.background_behavior, FieldForm.DROPDOWN, -1, 7)
|
||||||
@DropdownFieldOptionsId(R.array.player_background_behavior)
|
@DropdownFieldOptionsId(R.array.player_background_behavior)
|
||||||
var backgroundPlay: Int = 2;
|
var backgroundPlay: Int = 2;
|
||||||
|
|
||||||
@@ -277,10 +370,6 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
@DropdownFieldOptionsId(R.array.resume_after_preview)
|
@DropdownFieldOptionsId(R.array.resume_after_preview)
|
||||||
var resumeAfterPreview: Int = 1;
|
var resumeAfterPreview: Int = 1;
|
||||||
|
|
||||||
|
|
||||||
@FormField(R.string.live_chat_webview, FieldForm.TOGGLE, R.string.use_the_live_chat_web_window_when_available_over_native_implementation, 8)
|
|
||||||
var useLiveChatWindow: Boolean = true;
|
|
||||||
|
|
||||||
fun shouldResumePreview(previewedPosition: Long): Boolean{
|
fun shouldResumePreview(previewedPosition: Long): Boolean{
|
||||||
if(resumeAfterPreview == 2)
|
if(resumeAfterPreview == 2)
|
||||||
return true;
|
return true;
|
||||||
@@ -288,9 +377,51 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.chapter_update_fps_title, FieldForm.DROPDOWN, R.string.chapter_update_fps_description, 8)
|
||||||
|
@DropdownFieldOptionsId(R.array.chapter_fps)
|
||||||
|
var chapterUpdateFPS: Int = 0;
|
||||||
|
|
||||||
|
fun getChapterUpdateFrames(): Int {
|
||||||
|
return when(chapterUpdateFPS) {
|
||||||
|
0 -> 24
|
||||||
|
1 -> 30
|
||||||
|
2 -> 60
|
||||||
|
3 -> 120
|
||||||
|
else -> 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.live_chat_webview, FieldForm.TOGGLE, R.string.use_the_live_chat_web_window_when_available_over_native_implementation, 9)
|
||||||
|
var useLiveChatWindow: Boolean = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@FormField(R.string.background_switch_audio, FieldForm.TOGGLE, R.string.background_switch_audio_description, 10)
|
||||||
|
var backgroundSwitchToAudio: Boolean = true;
|
||||||
|
|
||||||
|
@FormField(R.string.restart_after_audio_focus_loss, FieldForm.DROPDOWN, R.string.restart_playback_when_gaining_audio_focus_after_a_loss, 11)
|
||||||
|
@DropdownFieldOptionsId(R.array.restart_playback_after_loss)
|
||||||
|
var restartPlaybackAfterLoss: Int = 1;
|
||||||
|
|
||||||
|
@FormField(R.string.restart_after_connectivity_loss, FieldForm.DROPDOWN, R.string.restart_playback_when_gaining_connectivity_after_a_loss, 12)
|
||||||
|
@DropdownFieldOptionsId(R.array.restart_playback_after_loss)
|
||||||
|
var restartPlaybackAfterConnectivityLoss: Int = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.downloads, "group", R.string.configure_downloading_of_videos, 5)
|
@FormField(R.string.comments, "group", R.string.comments_description, 6)
|
||||||
|
var comments = CommentSettings();
|
||||||
|
@Serializable
|
||||||
|
class CommentSettings {
|
||||||
|
@FormField(R.string.default_comment_section, FieldForm.DROPDOWN, -1, 0)
|
||||||
|
@DropdownFieldOptionsId(R.array.comment_sections)
|
||||||
|
var defaultCommentSection: Int = 0;
|
||||||
|
|
||||||
|
@FormField(R.string.bad_reputation_comments_fading, FieldForm.TOGGLE, R.string.bad_reputation_comments_fading_description, 0)
|
||||||
|
var badReputationCommentsFading: Boolean = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.downloads, "group", R.string.configure_downloading_of_videos, 7)
|
||||||
var downloads = Downloads();
|
var downloads = Downloads();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Downloads {
|
class Downloads {
|
||||||
@@ -330,7 +461,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.browsing, "group", R.string.configure_browsing_behavior, 6)
|
@FormField(R.string.browsing, "group", R.string.configure_browsing_behavior, 8)
|
||||||
var browsing = Browsing();
|
var browsing = Browsing();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Browsing {
|
class Browsing {
|
||||||
@@ -339,7 +470,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
var videoCache: Boolean = true;
|
var videoCache: Boolean = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.casting, "group", R.string.configure_casting, 7)
|
@FormField(R.string.casting, "group", R.string.configure_casting, 9)
|
||||||
var casting = Casting();
|
var casting = Casting();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Casting {
|
class Casting {
|
||||||
@@ -347,6 +478,9 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
@Serializable(with = FlexibleBooleanSerializer::class)
|
@Serializable(with = FlexibleBooleanSerializer::class)
|
||||||
var enabled: Boolean = true;
|
var enabled: Boolean = true;
|
||||||
|
|
||||||
|
@FormField(R.string.keep_screen_on, FieldForm.TOGGLE, R.string.keep_screen_on_while_casting, 1)
|
||||||
|
@Serializable(with = FlexibleBooleanSerializer::class)
|
||||||
|
var keepScreenOn: Boolean = true;
|
||||||
|
|
||||||
/*TODO: Should we have a different casting quality?
|
/*TODO: Should we have a different casting quality?
|
||||||
@FormField("Preferred Casting Quality", FieldForm.DROPDOWN, "", 3)
|
@FormField("Preferred Casting Quality", FieldForm.DROPDOWN, "", 3)
|
||||||
@@ -364,8 +498,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.logging, FieldForm.GROUP, -1, 10)
|
||||||
@FormField(R.string.logging, FieldForm.GROUP, -1, 8)
|
|
||||||
var logging = Logging();
|
var logging = Logging();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Logging {
|
class Logging {
|
||||||
@@ -373,10 +506,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
@DropdownFieldOptionsId(R.array.log_levels)
|
@DropdownFieldOptionsId(R.array.log_levels)
|
||||||
var logLevel: Int = 0;
|
var logLevel: Int = 0;
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.submit_logs, FieldForm.BUTTON, R.string.submit_logs_to_help_us_narrow_down_issues, 1)
|
||||||
R.string.submit_logs, FieldForm.BUTTON,
|
|
||||||
R.string.submit_logs_to_help_us_narrow_down_issues, 1
|
|
||||||
)
|
|
||||||
fun submitLogs() {
|
fun submitLogs() {
|
||||||
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
@@ -392,23 +522,26 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.announcement, FieldForm.GROUP, -1, 11)
|
||||||
|
|
||||||
@FormField(R.string.announcement, FieldForm.GROUP, -1, 10)
|
|
||||||
var announcementSettings = AnnouncementSettings();
|
var announcementSettings = AnnouncementSettings();
|
||||||
@Serializable
|
@Serializable
|
||||||
class AnnouncementSettings {
|
class AnnouncementSettings {
|
||||||
@FormField(
|
@FormField(R.string.reset_announcements, FieldForm.BUTTON, R.string.reset_hidden_announcements, 1)
|
||||||
R.string.reset_announcements, FieldForm.BUTTON,
|
|
||||||
R.string.reset_hidden_announcements, 1
|
|
||||||
)
|
|
||||||
fun resetAnnouncements() {
|
fun resetAnnouncements() {
|
||||||
StateAnnouncement.instance.resetAnnouncements();
|
StateAnnouncement.instance.resetAnnouncements();
|
||||||
SettingsActivity.getActivity()?.let { UIDialogs.toast(it, it.getString(R.string.announcements_reset)); };
|
SettingsActivity.getActivity()?.let { UIDialogs.toast(it, it.getString(R.string.announcements_reset)); };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.plugins, FieldForm.GROUP, -1, 11)
|
@FormField(R.string.notifications, FieldForm.GROUP, -1, 12)
|
||||||
|
var notifications = NotificationSettings();
|
||||||
|
@Serializable
|
||||||
|
class NotificationSettings {
|
||||||
|
@FormField(R.string.planned_content_notifications, FieldForm.TOGGLE, R.string.planned_content_notifications_description, 1)
|
||||||
|
var plannedContentNotification: Boolean = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.plugins, FieldForm.GROUP, -1, 13)
|
||||||
@Transient
|
@Transient
|
||||||
var plugins = Plugins();
|
var plugins = Plugins();
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -417,18 +550,12 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
@FormField(R.string.clear_cookies_on_logout, FieldForm.TOGGLE, R.string.clears_cookies_when_you_log_out, 0)
|
@FormField(R.string.clear_cookies_on_logout, FieldForm.TOGGLE, R.string.clears_cookies_when_you_log_out, 0)
|
||||||
var clearCookiesOnLogout: Boolean = true;
|
var clearCookiesOnLogout: Boolean = true;
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.clear_cookies, FieldForm.BUTTON, R.string.clears_in_app_browser_cookies, 1)
|
||||||
R.string.clear_cookies, FieldForm.BUTTON,
|
|
||||||
R.string.clears_in_app_browser_cookies, 1
|
|
||||||
)
|
|
||||||
fun clearCookies() {
|
fun clearCookies() {
|
||||||
val cookieManager: CookieManager = CookieManager.getInstance();
|
val cookieManager: CookieManager = CookieManager.getInstance();
|
||||||
cookieManager.removeAllCookies(null);
|
cookieManager.removeAllCookies(null);
|
||||||
}
|
}
|
||||||
@FormField(
|
@FormField(R.string.reinstall_embedded_plugins, FieldForm.BUTTON, R.string.also_removes_any_data_related_plugin_like_login_or_settings, 1)
|
||||||
R.string.reinstall_embedded_plugins, FieldForm.BUTTON,
|
|
||||||
R.string.also_removes_any_data_related_plugin_like_login_or_settings, 1
|
|
||||||
)
|
|
||||||
fun reinstallEmbedded() {
|
fun reinstallEmbedded() {
|
||||||
StateApp.instance.scopeOrNull!!.launch(Dispatchers.IO) {
|
StateApp.instance.scopeOrNull!!.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
@@ -451,7 +578,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FormField(R.string.external_storage, FieldForm.GROUP, -1, 12)
|
@FormField(R.string.external_storage, FieldForm.GROUP, -1, 14)
|
||||||
var storage = Storage();
|
var storage = Storage();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Storage {
|
class Storage {
|
||||||
@@ -475,10 +602,17 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
StateApp.instance.changeExternalDownloadDirectory(it);
|
StateApp.instance.changeExternalDownloadDirectory(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.clear_external_downloads_directory, FieldForm.BUTTON, R.string.clear_the_external_storage_for_download_files, 5)
|
||||||
|
fun clearStorageDownload() {
|
||||||
|
Settings.instance.storage.storage_download = null;
|
||||||
|
Settings.instance.save();
|
||||||
|
SettingsActivity.getActivity()?.let { UIDialogs.toast(it, "Cleared download storage directory") };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FormField(R.string.auto_update, "group", R.string.configure_the_auto_updater, 12)
|
@FormField(R.string.auto_update, "group", R.string.configure_the_auto_updater, 15)
|
||||||
var autoUpdate = AutoUpdate();
|
var autoUpdate = AutoUpdate();
|
||||||
@Serializable
|
@Serializable
|
||||||
class AutoUpdate {
|
class AutoUpdate {
|
||||||
@@ -507,10 +641,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
return check == 0 && !BuildConfig.IS_PLAYSTORE_BUILD;
|
return check == 0 && !BuildConfig.IS_PLAYSTORE_BUILD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.manual_check, FieldForm.BUTTON, R.string.manually_check_for_updates, 3)
|
||||||
R.string.manual_check, FieldForm.BUTTON,
|
|
||||||
R.string.manually_check_for_updates, 3
|
|
||||||
)
|
|
||||||
fun manualCheck() {
|
fun manualCheck() {
|
||||||
if (!BuildConfig.IS_PLAYSTORE_BUILD) {
|
if (!BuildConfig.IS_PLAYSTORE_BUILD) {
|
||||||
SettingsActivity.getActivity()?.let {
|
SettingsActivity.getActivity()?.let {
|
||||||
@@ -527,10 +658,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.view_changelog, FieldForm.BUTTON, R.string.review_the_current_and_past_changelogs, 4)
|
||||||
R.string.view_changelog, FieldForm.BUTTON,
|
|
||||||
R.string.review_the_current_and_past_changelogs, 4
|
|
||||||
)
|
|
||||||
fun viewChangelog() {
|
fun viewChangelog() {
|
||||||
SettingsActivity.getActivity()?.let {
|
SettingsActivity.getActivity()?.let {
|
||||||
UIDialogs.toast(it.getString(R.string.retrieving_changelog));
|
UIDialogs.toast(it.getString(R.string.retrieving_changelog));
|
||||||
@@ -550,10 +678,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(
|
@FormField(R.string.remove_cached_version, FieldForm.BUTTON, R.string.remove_the_last_downloaded_version, 5)
|
||||||
R.string.remove_cached_version, FieldForm.BUTTON,
|
|
||||||
R.string.remove_the_last_downloaded_version, 5
|
|
||||||
)
|
|
||||||
fun removeCachedVersion() {
|
fun removeCachedVersion() {
|
||||||
StateApp.withContext {
|
StateApp.withContext {
|
||||||
val outputDirectory = File(it.filesDir, "autoupdate");
|
val outputDirectory = File(it.filesDir, "autoupdate");
|
||||||
@@ -569,7 +694,7 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.backup, FieldForm.GROUP, -1, 13)
|
@FormField(R.string.backup, FieldForm.GROUP, -1, 16)
|
||||||
var backup = Backup();
|
var backup = Backup();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Backup {
|
class Backup {
|
||||||
@@ -601,11 +726,19 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
|
|
||||||
@FormField(R.string.export_data, FieldForm.BUTTON, R.string.creates_a_zip_file_with_your_data_which_can_be_imported_by_opening_it_with_grayjay, 3)
|
@FormField(R.string.export_data, FieldForm.BUTTON, R.string.creates_a_zip_file_with_your_data_which_can_be_imported_by_opening_it_with_grayjay, 3)
|
||||||
fun export() {
|
fun export() {
|
||||||
StateBackup.startExternalBackup();
|
val activity = SettingsActivity.getActivity() ?: return;
|
||||||
|
UISlideOverlays.showOverlay(activity.overlay, "Select export type", null, {},
|
||||||
|
SlideUpMenuItem(activity, R.drawable.ic_share, "Share", "", null, {
|
||||||
|
StateBackup.shareExternalBackup();
|
||||||
|
}),
|
||||||
|
SlideUpMenuItem(activity, R.drawable.ic_download, "File", "", null, {
|
||||||
|
StateBackup.saveExternalBackup(activity);
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.payment, FieldForm.GROUP, -1, 14)
|
@FormField(R.string.payment, FieldForm.GROUP, -1, 17)
|
||||||
var payment = Payment();
|
var payment = Payment();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Payment {
|
class Payment {
|
||||||
@@ -622,7 +755,19 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.info, FieldForm.GROUP, -1, 15)
|
@FormField(R.string.other, FieldForm.GROUP, -1, 18)
|
||||||
|
var other = Other();
|
||||||
|
@Serializable
|
||||||
|
class Other {
|
||||||
|
@FormField(R.string.bypass_rotation_prevention, FieldForm.TOGGLE, R.string.bypass_rotation_prevention_description, 1)
|
||||||
|
@FormFieldWarning(R.string.bypass_rotation_prevention_warning)
|
||||||
|
var bypassRotationPrevention: Boolean = false;
|
||||||
|
|
||||||
|
@FormField(R.string.enable_polycentric, FieldForm.TOGGLE, R.string.can_be_disabled_when_you_are_experiencing_issues, 1)
|
||||||
|
var polycentricEnabled: Boolean = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.info, FieldForm.GROUP, -1, 19)
|
||||||
var info = Info();
|
var info = Info();
|
||||||
@Serializable
|
@Serializable
|
||||||
class Info {
|
class Info {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.futo.platformplayer
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.work.Constraints
|
import androidx.work.Constraints
|
||||||
import androidx.work.Data
|
import androidx.work.Data
|
||||||
import androidx.work.ExistingPeriodicWorkPolicy
|
import androidx.work.ExistingPeriodicWorkPolicy
|
||||||
@@ -12,9 +13,11 @@ import androidx.work.WorkManager
|
|||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
import com.caoccao.javet.values.primitive.V8ValueInteger
|
import com.caoccao.javet.values.primitive.V8ValueInteger
|
||||||
import com.caoccao.javet.values.primitive.V8ValueString
|
import com.caoccao.javet.values.primitive.V8ValueString
|
||||||
|
import com.futo.platformplayer.activities.DeveloperActivity
|
||||||
import com.futo.platformplayer.activities.SettingsActivity
|
import com.futo.platformplayer.activities.SettingsActivity
|
||||||
import com.futo.platformplayer.api.http.ManagedHttpClient
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
||||||
|
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
||||||
import com.futo.platformplayer.api.media.platforms.js.JSClient
|
import com.futo.platformplayer.api.media.platforms.js.JSClient
|
||||||
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||||
import com.futo.platformplayer.api.media.platforms.js.SourcePluginDescriptor
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginDescriptor
|
||||||
@@ -25,11 +28,16 @@ import com.futo.platformplayer.logging.Logger
|
|||||||
import com.futo.platformplayer.serializers.FlexibleBooleanSerializer
|
import com.futo.platformplayer.serializers.FlexibleBooleanSerializer
|
||||||
import com.futo.platformplayer.states.StateAnnouncement
|
import com.futo.platformplayer.states.StateAnnouncement
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
|
import com.futo.platformplayer.states.StateCache
|
||||||
import com.futo.platformplayer.states.StateDeveloper
|
import com.futo.platformplayer.states.StateDeveloper
|
||||||
import com.futo.platformplayer.states.StateDownloads
|
import com.futo.platformplayer.states.StateDownloads
|
||||||
|
import com.futo.platformplayer.states.StateHistory
|
||||||
|
import com.futo.platformplayer.states.StatePlatform
|
||||||
import com.futo.platformplayer.states.StateSubscriptions
|
import com.futo.platformplayer.states.StateSubscriptions
|
||||||
import com.futo.platformplayer.stores.FragmentedStorage
|
import com.futo.platformplayer.stores.FragmentedStorage
|
||||||
import com.futo.platformplayer.stores.FragmentedStorageFileJson
|
import com.futo.platformplayer.stores.FragmentedStorageFileJson
|
||||||
|
import com.futo.platformplayer.stores.db.types.DBHistory
|
||||||
|
import com.futo.platformplayer.views.fields.ButtonField
|
||||||
import com.futo.platformplayer.views.fields.FieldForm
|
import com.futo.platformplayer.views.fields.FieldForm
|
||||||
import com.futo.platformplayer.views.fields.FormField
|
import com.futo.platformplayer.views.fields.FormField
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
@@ -38,6 +46,7 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import java.time.OffsetDateTime
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.stream.IntStream.range
|
import java.util.stream.IntStream.range
|
||||||
@@ -81,26 +90,153 @@ class SettingsDev : FragmentedStorageFileJson() {
|
|||||||
var backgroundSubscriptionFetching: Boolean = false;
|
var backgroundSubscriptionFetching: Boolean = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@FormField(R.string.cache, FieldForm.GROUP, -1, 3)
|
||||||
|
val cache: Cache = Cache();
|
||||||
|
@Serializable
|
||||||
|
class Cache {
|
||||||
|
|
||||||
|
@FormField(R.string.subscriptions_cache_5000, FieldForm.BUTTON, -1, 1, "subscription_cache_button")
|
||||||
|
fun subscriptionsCache5000() {
|
||||||
|
Logger.i("SettingsDev", "Started caching 5000 sub items");
|
||||||
|
UIDialogs.toast(
|
||||||
|
SettingsActivity.getActivity()!!,
|
||||||
|
"Started caching 5000 sub items"
|
||||||
|
);
|
||||||
|
val button = DeveloperActivity.getActivity()?.getField("subscription_cache_button");
|
||||||
|
if(button is ButtonField)
|
||||||
|
button.setButtonEnabled(false);
|
||||||
|
StateApp.instance.scope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
val subsCache =
|
||||||
|
StateSubscriptions.instance.getSubscriptionsFeedWithExceptions(cacheScope = this)?.first;
|
||||||
|
|
||||||
|
var total = 0;
|
||||||
|
var page = 0;
|
||||||
|
var lastToast = System.currentTimeMillis();
|
||||||
|
while(subsCache!!.hasMorePages() && total < 5000) {
|
||||||
|
subsCache!!.nextPage();
|
||||||
|
total += subsCache!!.getResults().size;
|
||||||
|
page++;
|
||||||
|
|
||||||
|
if(page % 10 == 0)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
val diff = System.currentTimeMillis() - lastToast;
|
||||||
|
lastToast = System.currentTimeMillis();
|
||||||
|
UIDialogs.toast(
|
||||||
|
SettingsActivity.getActivity()!!,
|
||||||
|
"Page: ${page}, Total: ${total}, Speed: ${diff}ms"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
UIDialogs.toast(
|
||||||
|
SettingsActivity.getActivity()!!,
|
||||||
|
"FINISHED Page: ${page}, Total: ${total}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(ex: Throwable) {
|
||||||
|
Logger.e("SettingsDev", ex.message, ex);
|
||||||
|
Logger.i("SettingsDev", "Failed: ${ex.message}");
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if(button is ButtonField)
|
||||||
|
button.setButtonEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.history_cache_100, FieldForm.BUTTON, -1, 1, "history_cache_button")
|
||||||
|
fun historyCache100() {
|
||||||
|
Logger.i("SettingsDev", "Started caching 100 history items (from home)");
|
||||||
|
UIDialogs.toast(
|
||||||
|
SettingsActivity.getActivity()!!,
|
||||||
|
"Started caching 100 history items (from home)"
|
||||||
|
);
|
||||||
|
val button = DeveloperActivity.getActivity()?.getField("history_cache_button");
|
||||||
|
if(button is ButtonField)
|
||||||
|
button.setButtonEnabled(false);
|
||||||
|
StateApp.instance.scope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
val subsCache = StatePlatform.instance.getHome();
|
||||||
|
|
||||||
|
var num = 0;
|
||||||
|
for(item in subsCache.getResults().filterIsInstance<IPlatformVideo>()) {
|
||||||
|
StateHistory.instance.getHistoryByVideo(item, true, OffsetDateTime.now().minusHours(num.toLong() * 4))
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var total = 0;
|
||||||
|
var page = 0;
|
||||||
|
var lastToast = System.currentTimeMillis();
|
||||||
|
while(subsCache!!.hasMorePages() && total < 5000) {
|
||||||
|
subsCache!!.nextPage();
|
||||||
|
total += subsCache!!.getResults().size;
|
||||||
|
page++;
|
||||||
|
|
||||||
|
for(item in subsCache.getResults().filterIsInstance<IPlatformVideo>()) {
|
||||||
|
StateHistory.instance.getHistoryByVideo(item, true, OffsetDateTime.now().minusHours(num.toLong() * 4))
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(page % 4 == 0)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
val diff = System.currentTimeMillis() - lastToast;
|
||||||
|
lastToast = System.currentTimeMillis();
|
||||||
|
UIDialogs.toast(
|
||||||
|
SettingsActivity.getActivity()!!,
|
||||||
|
"Page: ${page}, Total: ${total}, Speed: ${diff}ms"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Thread.sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
UIDialogs.toast(
|
||||||
|
SettingsActivity.getActivity()!!,
|
||||||
|
"FINISHED Page: ${page}, Total: ${total}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(ex: Throwable) {
|
||||||
|
Logger.e("SettingsDev", ex.message, ex);
|
||||||
|
Logger.i("SettingsDev", "Failed: ${ex.message}");
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if(button is ButtonField)
|
||||||
|
button.setButtonEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FormField(R.string.crash_me, FieldForm.BUTTON,
|
@FormField(R.string.crash_me, FieldForm.BUTTON,
|
||||||
R.string.crashes_the_application_on_purpose, 2)
|
R.string.crashes_the_application_on_purpose, 3)
|
||||||
fun crashMe() {
|
fun crashMe() {
|
||||||
throw java.lang.IllegalStateException("This is an uncaught exception triggered on purpose!");
|
throw java.lang.IllegalStateException("This is an uncaught exception triggered on purpose!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.delete_announcements, FieldForm.BUTTON,
|
@FormField(R.string.delete_announcements, FieldForm.BUTTON,
|
||||||
R.string.delete_all_announcements, 2)
|
R.string.delete_all_announcements, 3)
|
||||||
fun deleteAnnouncements() {
|
fun deleteAnnouncements() {
|
||||||
StateAnnouncement.instance.deleteAllAnnouncements();
|
StateAnnouncement.instance.deleteAllAnnouncements();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FormField(R.string.clear_cookies, FieldForm.BUTTON,
|
@FormField(R.string.clear_cookies, FieldForm.BUTTON,
|
||||||
R.string.clear_all_cookies_from_the_cookieManager, 2)
|
R.string.clear_all_cookies_from_the_cookieManager, 3)
|
||||||
fun clearCookies() {
|
fun clearCookies() {
|
||||||
val cookieManager: CookieManager = CookieManager.getInstance()
|
val cookieManager: CookieManager = CookieManager.getInstance()
|
||||||
cookieManager.removeAllCookies(null);
|
cookieManager.removeAllCookies(null);
|
||||||
}
|
}
|
||||||
@FormField(R.string.test_background_worker, FieldForm.BUTTON,
|
@FormField(R.string.test_background_worker, FieldForm.BUTTON,
|
||||||
R.string.test_background_worker_description, 3)
|
R.string.test_background_worker_description, 4)
|
||||||
fun triggerBackgroundUpdate() {
|
fun triggerBackgroundUpdate() {
|
||||||
val act = SettingsActivity.getActivity()!!;
|
val act = SettingsActivity.getActivity()!!;
|
||||||
UIDialogs.toast(SettingsActivity.getActivity()!!, "Starting test background worker");
|
UIDialogs.toast(SettingsActivity.getActivity()!!, "Starting test background worker");
|
||||||
@@ -111,6 +247,14 @@ class SettingsDev : FragmentedStorageFileJson() {
|
|||||||
.build();
|
.build();
|
||||||
wm.enqueue(req);
|
wm.enqueue(req);
|
||||||
}
|
}
|
||||||
|
@FormField(R.string.clear_channel_cache, FieldForm.BUTTON,
|
||||||
|
R.string.test_background_worker_description, 4)
|
||||||
|
fun clearChannelContentCache() {
|
||||||
|
UIDialogs.toast(SettingsActivity.getActivity()!!, "Clearing cache");
|
||||||
|
StateCache.instance.clearToday();
|
||||||
|
UIDialogs.toast(SettingsActivity.getActivity()!!, "Cleared");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Contextual
|
@Contextual
|
||||||
@Transient
|
@Transient
|
||||||
@@ -354,6 +498,17 @@ class SettingsDev : FragmentedStorageFileJson() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Contextual
|
||||||
|
@Transient
|
||||||
|
@FormField(R.string.info, FieldForm.GROUP, -1, 19)
|
||||||
|
var info = Info();
|
||||||
|
@Serializable
|
||||||
|
class Info {
|
||||||
|
@FormField(R.string.dev_info_channel_cache_size, FieldForm.READONLYTEXT, -1, 1, "channelCacheSize")
|
||||||
|
var channelCacheStartupCount = StateCache.instance.channelCacheStartupCount;
|
||||||
|
}
|
||||||
|
|
||||||
//region BOILERPLATE
|
//region BOILERPLATE
|
||||||
override fun encode(): String {
|
override fun encode(): String {
|
||||||
return Json.encodeToString(this);
|
return Json.encodeToString(this);
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.futo.platformplayer
|
package com.futo.platformplayer
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.net.Uri
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -10,12 +13,12 @@ import android.view.View
|
|||||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
import com.futo.platformplayer.api.media.models.comments.IPlatformComment
|
import com.futo.platformplayer.api.media.models.comments.IPlatformComment
|
||||||
import com.futo.platformplayer.casting.StateCasting
|
import com.futo.platformplayer.casting.StateCasting
|
||||||
import com.futo.platformplayer.dialogs.*
|
import com.futo.platformplayer.dialogs.*
|
||||||
import com.futo.platformplayer.engine.exceptions.PluginException
|
import com.futo.platformplayer.engine.exceptions.PluginException
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.states.StateAnnouncement
|
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StateBackup
|
import com.futo.platformplayer.states.StateBackup
|
||||||
import com.futo.platformplayer.stores.v2.ManagedStore
|
import com.futo.platformplayer.stores.v2.ManagedStore
|
||||||
@@ -91,6 +94,50 @@ class UIDialogs {
|
|||||||
}.toTypedArray());
|
}.toTypedArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showUrlHandlingPrompt(context: Context, onYes: (() -> Unit)? = null) {
|
||||||
|
val builder = AlertDialog.Builder(context)
|
||||||
|
val view = LayoutInflater.from(context).inflate(R.layout.dialog_url_handling, null)
|
||||||
|
builder.setView(view)
|
||||||
|
|
||||||
|
val dialog = builder.create()
|
||||||
|
registerDialogOpened(dialog)
|
||||||
|
|
||||||
|
view.findViewById<TextView>(R.id.button_no).apply {
|
||||||
|
this.setOnClickListener {
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
view.findViewById<LinearLayout>(R.id.button_yes).apply {
|
||||||
|
this.setOnClickListener {
|
||||||
|
if (BuildConfig.IS_PLAYSTORE_BUILD) {
|
||||||
|
dialog.dismiss()
|
||||||
|
showDialogOk(context, R.drawable.ic_error_pred, context.getString(R.string.play_store_version_does_not_support_default_url_handling)) {
|
||||||
|
onYes?.invoke()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val intent =
|
||||||
|
Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||||
|
val uri = Uri.fromParts("package", context.packageName, null)
|
||||||
|
intent.data = uri
|
||||||
|
context.startActivity(intent)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
toast(context, context.getString(R.string.failed_to_show_settings))
|
||||||
|
}
|
||||||
|
|
||||||
|
onYes?.invoke()
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.setOnDismissListener {
|
||||||
|
registerDialogClosed(dialog)
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
fun showAutomaticBackupDialog(context: Context, skipRestoreCheck: Boolean = false, onClosed: (()->Unit)? = null) {
|
fun showAutomaticBackupDialog(context: Context, skipRestoreCheck: Boolean = false, onClosed: (()->Unit)? = null) {
|
||||||
val dialogAction: ()->Unit = {
|
val dialogAction: ()->Unit = {
|
||||||
@@ -107,7 +154,8 @@ class UIDialogs {
|
|||||||
}, UIDialogs.ActionStyle.DANGEROUS),
|
}, UIDialogs.ActionStyle.DANGEROUS),
|
||||||
UIDialogs.Action(context.getString(R.string.restore), {
|
UIDialogs.Action(context.getString(R.string.restore), {
|
||||||
UIDialogs.showAutomaticRestoreDialog(context, StateApp.instance.scope);
|
UIDialogs.showAutomaticRestoreDialog(context, StateApp.instance.scope);
|
||||||
}, UIDialogs.ActionStyle.PRIMARY));
|
}, UIDialogs.ActionStyle.PRIMARY)
|
||||||
|
);
|
||||||
else {
|
else {
|
||||||
dialogAction();
|
dialogAction();
|
||||||
}
|
}
|
||||||
@@ -142,8 +190,10 @@ class UIDialogs {
|
|||||||
view.findViewById<TextView>(R.id.dialog_text_code).apply {
|
view.findViewById<TextView>(R.id.dialog_text_code).apply {
|
||||||
if(code == null)
|
if(code == null)
|
||||||
this.visibility = View.GONE;
|
this.visibility = View.GONE;
|
||||||
else
|
else {
|
||||||
this.text = code;
|
this.text = code;
|
||||||
|
this.visibility = View.VISIBLE;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
view.findViewById<LinearLayout>(R.id.dialog_buttons).apply {
|
view.findViewById<LinearLayout>(R.id.dialog_buttons).apply {
|
||||||
val buttons = actions.map<Action, TextView> { act ->
|
val buttons = actions.map<Action, TextView> { act ->
|
||||||
@@ -279,6 +329,12 @@ class UIDialogs {
|
|||||||
dialog.setOnDismissListener { registerDialogClosed(dialog) };
|
dialog.setOnDismissListener { registerDialogClosed(dialog) };
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
fun showImportOptionsDialog(context: MainActivity) {
|
||||||
|
val dialog = ImportOptionsDialog(context);
|
||||||
|
registerDialogOpened(dialog);
|
||||||
|
dialog.setOnDismissListener { registerDialogClosed(dialog) };
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun showCastingDialog(context: Context) {
|
fun showCastingDialog(context: Context) {
|
||||||
@@ -291,11 +347,22 @@ class UIDialogs {
|
|||||||
} else {
|
} else {
|
||||||
val dialog = ConnectCastingDialog(context);
|
val dialog = ConnectCastingDialog(context);
|
||||||
registerDialogOpened(dialog);
|
registerDialogOpened(dialog);
|
||||||
|
val c = context
|
||||||
|
if (c is Activity) {
|
||||||
|
dialog.setOwnerActivity(c);
|
||||||
|
}
|
||||||
dialog.setOnDismissListener { registerDialogClosed(dialog) };
|
dialog.setOnDismissListener { registerDialogClosed(dialog) };
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showCastingTutorialDialog(context: Context) {
|
||||||
|
val dialog = CastingHelpDialog(context);
|
||||||
|
registerDialogOpened(dialog);
|
||||||
|
dialog.setOnDismissListener { registerDialogClosed(dialog) };
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
fun showCastingAddDialog(context: Context) {
|
fun showCastingAddDialog(context: Context) {
|
||||||
val dialog = CastingAddDialog(context);
|
val dialog = CastingAddDialog(context);
|
||||||
registerDialogOpened(dialog);
|
registerDialogOpened(dialog);
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package com.futo.platformplayer
|
package com.futo.platformplayer
|
||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.graphics.Color
|
|
||||||
import android.util.TypedValue
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.LinearLayout
|
|
||||||
import android.widget.TextView
|
|
||||||
import com.futo.platformplayer.api.http.ManagedHttpClient
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
|
import com.futo.platformplayer.api.media.models.ResultCapabilities
|
||||||
import com.futo.platformplayer.api.media.models.streams.VideoUnMuxedSourceDescriptor
|
import com.futo.platformplayer.api.media.models.streams.VideoUnMuxedSourceDescriptor
|
||||||
|
import com.futo.platformplayer.api.media.models.streams.sources.HLSVariantAudioUrlSource
|
||||||
|
import com.futo.platformplayer.api.media.models.streams.sources.HLSVariantVideoUrlSource
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.IAudioUrlSource
|
import com.futo.platformplayer.api.media.models.streams.sources.IAudioUrlSource
|
||||||
|
import com.futo.platformplayer.api.media.models.streams.sources.IHLSManifestAudioSource
|
||||||
|
import com.futo.platformplayer.api.media.models.streams.sources.IHLSManifestSource
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.IVideoUrlSource
|
import com.futo.platformplayer.api.media.models.streams.sources.IVideoUrlSource
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.SubtitleRawSource
|
|
||||||
import com.futo.platformplayer.api.media.models.subtitles.ISubtitleSource
|
import com.futo.platformplayer.api.media.models.subtitles.ISubtitleSource
|
||||||
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
||||||
import com.futo.platformplayer.api.media.models.video.IPlatformVideoDetails
|
import com.futo.platformplayer.api.media.models.video.IPlatformVideoDetails
|
||||||
@@ -21,8 +21,9 @@ import com.futo.platformplayer.helpers.VideoHelper
|
|||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.models.Playlist
|
import com.futo.platformplayer.models.Playlist
|
||||||
import com.futo.platformplayer.models.Subscription
|
import com.futo.platformplayer.models.Subscription
|
||||||
|
import com.futo.platformplayer.parsers.HLS
|
||||||
import com.futo.platformplayer.states.*
|
import com.futo.platformplayer.states.*
|
||||||
import com.futo.platformplayer.views.Loader
|
import com.futo.platformplayer.views.LoaderView
|
||||||
import com.futo.platformplayer.views.overlays.slideup.SlideUpMenuGroup
|
import com.futo.platformplayer.views.overlays.slideup.SlideUpMenuGroup
|
||||||
import com.futo.platformplayer.views.overlays.slideup.SlideUpMenuItem
|
import com.futo.platformplayer.views.overlays.slideup.SlideUpMenuItem
|
||||||
import com.futo.platformplayer.views.overlays.slideup.SlideUpMenuOverlay
|
import com.futo.platformplayer.views.overlays.slideup.SlideUpMenuOverlay
|
||||||
@@ -52,7 +53,6 @@ class UISlideOverlays {
|
|||||||
|
|
||||||
fun showSubscriptionOptionsOverlay(subscription: Subscription, container: ViewGroup) {
|
fun showSubscriptionOptionsOverlay(subscription: Subscription, container: ViewGroup) {
|
||||||
val items = arrayListOf<View>();
|
val items = arrayListOf<View>();
|
||||||
var menu: SlideUpMenuOverlay? = null;
|
|
||||||
|
|
||||||
val originalNotif = subscription.doNotifications;
|
val originalNotif = subscription.doNotifications;
|
||||||
val originalLive = subscription.doFetchLive;
|
val originalLive = subscription.doFetchLive;
|
||||||
@@ -60,52 +60,164 @@ class UISlideOverlays {
|
|||||||
val originalVideo = subscription.doFetchVideos;
|
val originalVideo = subscription.doFetchVideos;
|
||||||
val originalPosts = subscription.doFetchPosts;
|
val originalPosts = subscription.doFetchPosts;
|
||||||
|
|
||||||
items.addAll(listOf(
|
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO){
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_notifications, "Notifications", "", "notifications", {
|
val plugin = StatePlatform.instance.getChannelClient(subscription.channel.url);
|
||||||
subscription.doNotifications = menu?.selectOption(null, "notifications", true, true) ?: subscription.doNotifications;
|
val capabilities = plugin.getChannelCapabilities();
|
||||||
}, false),
|
|
||||||
SlideUpMenuGroup(container.context, "Fetch Settings",
|
|
||||||
"Depending on the platform you might not need to enable a type for it to be available.",
|
|
||||||
-1, listOf()),
|
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_live_tv, "Livestreams", "Check for livestreams", "fetchLive", {
|
|
||||||
subscription.doFetchLive = menu?.selectOption(null, "fetchLive", true, true) ?: subscription.doFetchLive;
|
|
||||||
}, false),
|
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_play, "Streams", "Check for finished streams", "fetchStreams", {
|
|
||||||
subscription.doFetchStreams = menu?.selectOption(null, "fetchStreams", true, true) ?: subscription.doFetchLive;
|
|
||||||
}, false),
|
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_play, "Videos", "Check for videos", "fetchVideos", {
|
|
||||||
subscription.doFetchVideos = menu?.selectOption(null, "fetchVideos", true, true) ?: subscription.doFetchLive;
|
|
||||||
}, false),
|
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_chat, "Posts", "Check for posts", "fetchPosts", {
|
|
||||||
subscription.doFetchPosts = menu?.selectOption(null, "fetchPosts", true, true) ?: subscription.doFetchLive;
|
|
||||||
}, false)));
|
|
||||||
|
|
||||||
menu = SlideUpMenuOverlay(container.context, container, "Subscription Settings", null, true, items);
|
withContext(Dispatchers.Main) {
|
||||||
|
|
||||||
if(subscription.doFetchLive)
|
var menu: SlideUpMenuOverlay? = null;
|
||||||
menu.selectOption(null, "fetchLive", true, true);
|
|
||||||
if(subscription.doFetchStreams)
|
|
||||||
menu.selectOption(null, "fetchStreams", true, true);
|
|
||||||
if(subscription.doFetchVideos)
|
|
||||||
menu.selectOption(null, "fetchVideos", true, true);
|
|
||||||
if(subscription.doFetchPosts)
|
|
||||||
menu.selectOption(null, "fetchPosts", true, true);
|
|
||||||
|
|
||||||
menu.onOK.subscribe {
|
|
||||||
subscription.save();
|
|
||||||
menu.hide(true);
|
|
||||||
};
|
|
||||||
menu.onCancel.subscribe {
|
|
||||||
subscription.doNotifications = originalNotif;
|
|
||||||
subscription.doFetchLive = originalLive;
|
|
||||||
subscription.doFetchStreams = originalStream;
|
|
||||||
subscription.doFetchVideos = originalVideo;
|
|
||||||
subscription.doFetchPosts = originalPosts;
|
|
||||||
};
|
|
||||||
|
|
||||||
menu.setOk("Save");
|
items.addAll(listOf(
|
||||||
|
SlideUpMenuItem(container.context, R.drawable.ic_notifications, "Notifications", "", "notifications", {
|
||||||
|
subscription.doNotifications = menu?.selectOption(null, "notifications", true, true) ?: subscription.doNotifications;
|
||||||
|
}, false),
|
||||||
|
SlideUpMenuGroup(container.context, "Fetch Settings",
|
||||||
|
"Depending on the platform you might not need to enable a type for it to be available.",
|
||||||
|
-1, listOf()),
|
||||||
|
if(capabilities.hasType(ResultCapabilities.TYPE_LIVE)) SlideUpMenuItem(container.context, R.drawable.ic_live_tv, "Livestreams", "Check for livestreams", "fetchLive", {
|
||||||
|
subscription.doFetchLive = menu?.selectOption(null, "fetchLive", true, true) ?: subscription.doFetchLive;
|
||||||
|
}, false) else null,
|
||||||
|
if(capabilities.hasType(ResultCapabilities.TYPE_STREAMS)) SlideUpMenuItem(container.context, R.drawable.ic_play, "Streams", "Check for streams", "fetchStreams", {
|
||||||
|
subscription.doFetchStreams = menu?.selectOption(null, "fetchStreams", true, true) ?: subscription.doFetchStreams;
|
||||||
|
}, false) else null,
|
||||||
|
if(capabilities.hasType(ResultCapabilities.TYPE_VIDEOS))
|
||||||
|
SlideUpMenuItem(container.context, R.drawable.ic_play, "Videos", "Check for videos", "fetchVideos", {
|
||||||
|
subscription.doFetchVideos = menu?.selectOption(null, "fetchVideos", true, true) ?: subscription.doFetchVideos;
|
||||||
|
}, false) else if(capabilities.hasType(ResultCapabilities.TYPE_MIXED) || capabilities.types.isEmpty())
|
||||||
|
SlideUpMenuItem(container.context, R.drawable.ic_play, "Content", "Check for content", "fetchVideos", {
|
||||||
|
subscription.doFetchVideos = menu?.selectOption(null, "fetchVideos", true, true) ?: subscription.doFetchVideos;
|
||||||
|
}, false) else null,
|
||||||
|
if(capabilities.hasType(ResultCapabilities.TYPE_POSTS)) SlideUpMenuItem(container.context, R.drawable.ic_chat, "Posts", "Check for posts", "fetchPosts", {
|
||||||
|
subscription.doFetchPosts = menu?.selectOption(null, "fetchPosts", true, true) ?: subscription.doFetchPosts;
|
||||||
|
}, false) else null).filterNotNull());
|
||||||
|
|
||||||
|
menu = SlideUpMenuOverlay(container.context, container, "Subscription Settings", null, true, items);
|
||||||
|
|
||||||
|
if(subscription.doNotifications)
|
||||||
|
menu.selectOption(null, "notifications", true, true);
|
||||||
|
if(subscription.doFetchLive)
|
||||||
|
menu.selectOption(null, "fetchLive", true, true);
|
||||||
|
if(subscription.doFetchStreams)
|
||||||
|
menu.selectOption(null, "fetchStreams", true, true);
|
||||||
|
if(subscription.doFetchVideos)
|
||||||
|
menu.selectOption(null, "fetchVideos", true, true);
|
||||||
|
if(subscription.doFetchPosts)
|
||||||
|
menu.selectOption(null, "fetchPosts", true, true);
|
||||||
|
|
||||||
|
menu.onOK.subscribe {
|
||||||
|
subscription.save();
|
||||||
|
menu.hide(true);
|
||||||
|
};
|
||||||
|
menu.onCancel.subscribe {
|
||||||
|
subscription.doNotifications = originalNotif;
|
||||||
|
subscription.doFetchLive = originalLive;
|
||||||
|
subscription.doFetchStreams = originalStream;
|
||||||
|
subscription.doFetchVideos = originalVideo;
|
||||||
|
subscription.doFetchPosts = originalPosts;
|
||||||
|
};
|
||||||
|
|
||||||
|
menu.setOk("Save");
|
||||||
|
|
||||||
|
menu.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showHlsPicker(video: IPlatformVideoDetails, source: Any, sourceUrl: String, container: ViewGroup): SlideUpMenuOverlay {
|
||||||
|
val items = arrayListOf<View>(LoaderView(container.context))
|
||||||
|
val slideUpMenuOverlay = SlideUpMenuOverlay(container.context, container, container.context.getString(R.string.download_video), null, true, items)
|
||||||
|
|
||||||
|
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
||||||
|
val masterPlaylistResponse = ManagedHttpClient().get(sourceUrl)
|
||||||
|
check(masterPlaylistResponse.isOk) { "Failed to get master playlist: ${masterPlaylistResponse.code}" }
|
||||||
|
|
||||||
|
val masterPlaylistContent = masterPlaylistResponse.body?.string()
|
||||||
|
?: throw Exception("Master playlist content is empty")
|
||||||
|
|
||||||
|
val videoButtons = arrayListOf<SlideUpMenuItem>()
|
||||||
|
val audioButtons = arrayListOf<SlideUpMenuItem>()
|
||||||
|
//TODO: Implement subtitles
|
||||||
|
//val subtitleButtons = arrayListOf<SlideUpMenuItem>()
|
||||||
|
|
||||||
|
var selectedVideoVariant: HLSVariantVideoUrlSource? = null
|
||||||
|
var selectedAudioVariant: HLSVariantAudioUrlSource? = null
|
||||||
|
//TODO: Implement subtitles
|
||||||
|
//var selectedSubtitleVariant: HLSVariantSubtitleUrlSource? = null
|
||||||
|
|
||||||
|
val masterPlaylist: HLS.MasterPlaylist
|
||||||
|
try {
|
||||||
|
masterPlaylist = HLS.parseMasterPlaylist(masterPlaylistContent, sourceUrl)
|
||||||
|
|
||||||
|
masterPlaylist.getAudioSources().forEach { it ->
|
||||||
|
audioButtons.add(SlideUpMenuItem(container.context, R.drawable.ic_music, it.name, listOf(it.language, it.codec).mapNotNull { x -> x.ifEmpty { null } }.joinToString(", "), it, {
|
||||||
|
selectedAudioVariant = it
|
||||||
|
slideUpMenuOverlay.selectOption(audioButtons, it)
|
||||||
|
slideUpMenuOverlay.setOk(container.context.getString(R.string.download))
|
||||||
|
}, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
/*masterPlaylist.getSubtitleSources().forEach { it ->
|
||||||
|
subtitleButtons.add(SlideUpMenuItem(container.context, R.drawable.ic_music, it.name, listOf(it.format).mapNotNull { x -> x.ifEmpty { null } }.joinToString(", "), it, {
|
||||||
|
selectedSubtitleVariant = it
|
||||||
|
slideUpMenuOverlay.selectOption(subtitleButtons, it)
|
||||||
|
slideUpMenuOverlay.setOk(container.context.getString(R.string.download))
|
||||||
|
}, false))
|
||||||
|
}*/
|
||||||
|
|
||||||
|
masterPlaylist.getVideoSources().forEach {
|
||||||
|
videoButtons.add(SlideUpMenuItem(container.context, R.drawable.ic_movie, it.name, "${it.width}x${it.height}", it, {
|
||||||
|
selectedVideoVariant = it
|
||||||
|
slideUpMenuOverlay.selectOption(videoButtons, it)
|
||||||
|
slideUpMenuOverlay.setOk(container.context.getString(R.string.download))
|
||||||
|
}, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
val newItems = arrayListOf<View>()
|
||||||
|
if (videoButtons.isNotEmpty()) {
|
||||||
|
newItems.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.video), videoButtons, videoButtons))
|
||||||
|
}
|
||||||
|
if (audioButtons.isNotEmpty()) {
|
||||||
|
newItems.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.audio), audioButtons, audioButtons))
|
||||||
|
}
|
||||||
|
//TODO: Implement subtitles
|
||||||
|
/*if (subtitleButtons.isNotEmpty()) {
|
||||||
|
newItems.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.subtitles), subtitleButtons, subtitleButtons))
|
||||||
|
}*/
|
||||||
|
|
||||||
|
slideUpMenuOverlay.onOK.subscribe {
|
||||||
|
//TODO: Fix SubtitleRawSource issue
|
||||||
|
StateDownloads.instance.download(video, selectedVideoVariant, selectedAudioVariant, null);
|
||||||
|
slideUpMenuOverlay.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
slideUpMenuOverlay.setItems(newItems)
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
if (masterPlaylistContent.lines().any { it.startsWith("#EXTINF:") }) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (source is IHLSManifestSource) {
|
||||||
|
StateDownloads.instance.download(video, HLSVariantVideoUrlSource("variant", 0, 0, "application/vnd.apple.mpegurl", "", null, 0, false, sourceUrl), null, null)
|
||||||
|
UIDialogs.toast(container.context, "Variant video HLS playlist download started")
|
||||||
|
slideUpMenuOverlay.hide()
|
||||||
|
} else if (source is IHLSManifestAudioSource) {
|
||||||
|
StateDownloads.instance.download(video, null, HLSVariantAudioUrlSource("variant", 0, "application/vnd.apple.mpegurl", "", "", null, false, sourceUrl), null)
|
||||||
|
UIDialogs.toast(container.context, "Variant audio HLS playlist download started")
|
||||||
|
slideUpMenuOverlay.hide()
|
||||||
|
} else {
|
||||||
|
throw NotImplementedError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return slideUpMenuOverlay.apply { show() }
|
||||||
|
|
||||||
menu.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showDownloadVideoOverlay(video: IPlatformVideoDetails, container: ViewGroup, contentResolver: ContentResolver? = null): SlideUpMenuOverlay? {
|
fun showDownloadVideoOverlay(video: IPlatformVideoDetails, container: ViewGroup, contentResolver: ContentResolver? = null): SlideUpMenuOverlay? {
|
||||||
@@ -147,30 +259,49 @@ class UISlideOverlays {
|
|||||||
videoSources
|
videoSources
|
||||||
.filter { it.isDownloadable() }
|
.filter { it.isDownloadable() }
|
||||||
.map {
|
.map {
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_movie, it.name, "${it.width}x${it.height}", it, {
|
if (it is IVideoUrlSource) {
|
||||||
selectedVideo = it as IVideoUrlSource;
|
SlideUpMenuItem(container.context, R.drawable.ic_movie, it.name, "${it.width}x${it.height}", it, {
|
||||||
menu?.selectOption(videoSources, it);
|
selectedVideo = it
|
||||||
if(selectedAudio != null || !requiresAudio)
|
menu?.selectOption(videoSources, it);
|
||||||
menu?.setOk(container.context.getString(R.string.download));
|
if(selectedAudio != null || !requiresAudio)
|
||||||
}, false)
|
menu?.setOk(container.context.getString(R.string.download));
|
||||||
|
}, false)
|
||||||
|
} else if (it is IHLSManifestSource) {
|
||||||
|
SlideUpMenuItem(container.context, R.drawable.ic_movie, it.name, "HLS", it, {
|
||||||
|
showHlsPicker(video, it, it.url, container)
|
||||||
|
}, false)
|
||||||
|
} else {
|
||||||
|
throw Exception("Unhandled source type")
|
||||||
|
}
|
||||||
}).flatten().toList()
|
}).flatten().toList()
|
||||||
));
|
));
|
||||||
|
|
||||||
if(Settings.instance.downloads.getDefaultVideoQualityPixels() > 0 && videoSources.size > 0)
|
if(Settings.instance.downloads.getDefaultVideoQualityPixels() > 0 && videoSources.size > 0) {
|
||||||
selectedVideo = VideoHelper.selectBestVideoSource(videoSources.filter { it.isDownloadable() }.asIterable(),
|
//TODO: Add HLS support here
|
||||||
|
selectedVideo = VideoHelper.selectBestVideoSource(
|
||||||
|
videoSources.filter { it is IVideoUrlSource && it.isDownloadable() }.asIterable(),
|
||||||
Settings.instance.downloads.getDefaultVideoQualityPixels(),
|
Settings.instance.downloads.getDefaultVideoQualityPixels(),
|
||||||
FutoVideoPlayerBase.PREFERED_VIDEO_CONTAINERS) as IVideoUrlSource;
|
FutoVideoPlayerBase.PREFERED_VIDEO_CONTAINERS
|
||||||
|
) as IVideoUrlSource;
|
||||||
|
}
|
||||||
|
|
||||||
audioSources?.let { audioSources ->
|
audioSources?.let { audioSources ->
|
||||||
items.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.audio), audioSources, audioSources
|
items.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.audio), audioSources, audioSources
|
||||||
.filter { VideoHelper.isDownloadable(it) }
|
.filter { VideoHelper.isDownloadable(it) }
|
||||||
.map {
|
.map {
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_music, it.name, "${it.bitrate}", it, {
|
if (it is IAudioUrlSource) {
|
||||||
selectedAudio = it as IAudioUrlSource;
|
SlideUpMenuItem(container.context, R.drawable.ic_music, it.name, "${it.bitrate}", it, {
|
||||||
menu?.selectOption(audioSources, it);
|
selectedAudio = it
|
||||||
menu?.setOk(container.context.getString(R.string.download));
|
menu?.selectOption(audioSources, it);
|
||||||
}, false);
|
menu?.setOk(container.context.getString(R.string.download));
|
||||||
|
}, false);
|
||||||
|
} else if (it is IHLSManifestAudioSource) {
|
||||||
|
SlideUpMenuItem(container.context, R.drawable.ic_movie, it.name, "HLS Audio", it, {
|
||||||
|
showHlsPicker(video, it, it.url, container)
|
||||||
|
}, false)
|
||||||
|
} else {
|
||||||
|
throw Exception("Unhandled source type")
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
val asources = audioSources;
|
val asources = audioSources;
|
||||||
val preferredAudioSource = VideoHelper.selectBestAudioSource(asources.asIterable(),
|
val preferredAudioSource = VideoHelper.selectBestAudioSource(asources.asIterable(),
|
||||||
@@ -179,15 +310,15 @@ class UISlideOverlays {
|
|||||||
if(Settings.instance.downloads.isHighBitrateDefault()) 99999999 else 1);
|
if(Settings.instance.downloads.isHighBitrateDefault()) 99999999 else 1);
|
||||||
menu?.selectOption(asources, preferredAudioSource);
|
menu?.selectOption(asources, preferredAudioSource);
|
||||||
|
|
||||||
|
//TODO: Add HLS support here
|
||||||
selectedAudio = VideoHelper.selectBestAudioSource(audioSources.filter { it.isDownloadable() }.asIterable(),
|
selectedAudio = VideoHelper.selectBestAudioSource(audioSources.filter { it is IAudioUrlSource && it.isDownloadable() }.asIterable(),
|
||||||
FutoVideoPlayerBase.PREFERED_AUDIO_CONTAINERS,
|
FutoVideoPlayerBase.PREFERED_AUDIO_CONTAINERS,
|
||||||
Settings.instance.playback.getPrimaryLanguage(container.context),
|
Settings.instance.playback.getPrimaryLanguage(container.context),
|
||||||
if(Settings.instance.downloads.isHighBitrateDefault()) 9999999 else 1) as IAudioUrlSource?;
|
if(Settings.instance.downloads.isHighBitrateDefault()) 9999999 else 1) as IAudioUrlSource?;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ContentResolver is required for subtitles..
|
//ContentResolver is required for subtitles..
|
||||||
if(contentResolver != null) {
|
if(contentResolver != null && subtitleSources.isNotEmpty()) {
|
||||||
items.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.subtitles), subtitleSources, subtitleSources
|
items.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.subtitles), subtitleSources, subtitleSources
|
||||||
.map {
|
.map {
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_edit, it.name, "", it, {
|
SlideUpMenuItem(container.context, R.drawable.ic_edit, it.name, "", it, {
|
||||||
@@ -359,7 +490,7 @@ class UISlideOverlays {
|
|||||||
val dp70 = 70.dp(container.context.resources);
|
val dp70 = 70.dp(container.context.resources);
|
||||||
val dp15 = 15.dp(container.context.resources);
|
val dp15 = 15.dp(container.context.resources);
|
||||||
val overlay = SlideUpMenuOverlay(container.context, container, text, null, true, listOf(
|
val overlay = SlideUpMenuOverlay(container.context, container, text, null, true, listOf(
|
||||||
Loader(container.context, true, dp70).apply {
|
LoaderView(container.context, true, dp70).apply {
|
||||||
this.setPadding(0, dp15, 0, dp15);
|
this.setPadding(0, dp15, 0, dp15);
|
||||||
}
|
}
|
||||||
), true);
|
), true);
|
||||||
@@ -367,6 +498,33 @@ class UISlideOverlays {
|
|||||||
return overlay;
|
return overlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showCreatePlaylistOverlay(container: ViewGroup, onCreate: (String) -> Unit): SlideUpMenuOverlay {
|
||||||
|
val nameInput = SlideUpMenuTextInput(container.context, container.context.getString(R.string.name));
|
||||||
|
val addPlaylistOverlay = SlideUpMenuOverlay(container.context, container, container.context.getString(R.string.create_new_playlist), container.context.getString(R.string.ok), false, nameInput);
|
||||||
|
|
||||||
|
addPlaylistOverlay.onOK.subscribe {
|
||||||
|
val text = nameInput.text;
|
||||||
|
if (text.isBlank()) {
|
||||||
|
return@subscribe;
|
||||||
|
}
|
||||||
|
|
||||||
|
addPlaylistOverlay.hide();
|
||||||
|
nameInput.deactivate();
|
||||||
|
nameInput.clear();
|
||||||
|
onCreate(text)
|
||||||
|
};
|
||||||
|
|
||||||
|
addPlaylistOverlay.onCancel.subscribe {
|
||||||
|
nameInput.deactivate();
|
||||||
|
nameInput.clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
addPlaylistOverlay.show();
|
||||||
|
nameInput.activate();
|
||||||
|
|
||||||
|
return addPlaylistOverlay
|
||||||
|
}
|
||||||
|
|
||||||
fun showVideoOptionsOverlay(video: IPlatformVideo, container: ViewGroup, vararg actions: SlideUpMenuItem): SlideUpMenuOverlay {
|
fun showVideoOptionsOverlay(video: IPlatformVideo, container: ViewGroup, vararg actions: SlideUpMenuItem): SlideUpMenuOverlay {
|
||||||
val items = arrayListOf<View>();
|
val items = arrayListOf<View>();
|
||||||
val lastUpdated = StatePlaylists.instance.getLastUpdatedPlaylist();
|
val lastUpdated = StatePlaylists.instance.getLastUpdatedPlaylist();
|
||||||
@@ -387,8 +545,13 @@ class UISlideOverlays {
|
|||||||
val watchLater = StatePlaylists.instance.getWatchLater();
|
val watchLater = StatePlaylists.instance.getWatchLater();
|
||||||
items.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.actions), "actions",
|
items.add(SlideUpMenuGroup(container.context, container.context.getString(R.string.actions), "actions",
|
||||||
(listOf(
|
(listOf(
|
||||||
SlideUpMenuItem(container.context, R.drawable.ic_download, container.context.getString(R.string.download), container.context.getString(R.string.download_the_video), container.context.getString(R.string.download),
|
SlideUpMenuItem(container.context, R.drawable.ic_download, container.context.getString(R.string.download), container.context.getString(R.string.download_the_video), container.context.getString(R.string.download), {
|
||||||
{ showDownloadVideoOverlay(video, container, true); }, false))
|
showDownloadVideoOverlay(video, container, true);
|
||||||
|
}, false),
|
||||||
|
SlideUpMenuItem(container.context, R.drawable.ic_visibility_off, container.context.getString(R.string.hide_creator_from_home), "", "hide_creator", {
|
||||||
|
StateMeta.instance.addHiddenCreator(video.author.url);
|
||||||
|
UIDialogs.toast(container.context, "[${video.author.name}] hidden, you may need to reload home");
|
||||||
|
}))
|
||||||
+ actions)
|
+ actions)
|
||||||
));
|
));
|
||||||
items.add(
|
items.add(
|
||||||
@@ -400,6 +563,13 @@ class UISlideOverlays {
|
|||||||
));
|
));
|
||||||
|
|
||||||
val playlistItems = arrayListOf<SlideUpMenuItem>();
|
val playlistItems = arrayListOf<SlideUpMenuItem>();
|
||||||
|
playlistItems.add(SlideUpMenuItem(container.context, R.drawable.ic_playlist_add, container.context.getString(R.string.new_playlist), container.context.getString(R.string.add_to_new_playlist), "add_to_new_playlist", {
|
||||||
|
showCreatePlaylistOverlay(container) {
|
||||||
|
val playlist = Playlist(it, arrayListOf(SerializedPlatformVideo.fromVideo(video)));
|
||||||
|
StatePlaylists.instance.createOrUpdatePlaylist(playlist);
|
||||||
|
};
|
||||||
|
}, false))
|
||||||
|
|
||||||
for (playlist in allPlaylists) {
|
for (playlist in allPlaylists) {
|
||||||
playlistItems.add(SlideUpMenuItem(container.context, R.drawable.ic_playlist_add, "${container.context.getString(R.string.add_to)} " + playlist.name + "", "${playlist.videos.size} " + container.context.getString(R.string.videos), "",
|
playlistItems.add(SlideUpMenuItem(container.context, R.drawable.ic_playlist_add, "${container.context.getString(R.string.add_to)} " + playlist.name + "", "${playlist.videos.size} " + container.context.getString(R.string.videos), "",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -164,9 +164,7 @@ fun Int.sp(resources: Resources): Int {
|
|||||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, this.toFloat(), resources.displayMetrics).toInt()
|
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, this.toFloat(), resources.displayMetrics).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun File.share(context: Context) {
|
fun DocumentFile.share(context: Context) {
|
||||||
val uri = FileProvider.getUriForFile(context, context.resources.getString(R.string.authority), this);
|
|
||||||
|
|
||||||
val shareIntent = Intent();
|
val shareIntent = Intent();
|
||||||
shareIntent.action = Intent.ACTION_SEND;
|
shareIntent.action = Intent.ACTION_SEND;
|
||||||
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.drawable.Animatable
|
import android.graphics.drawable.Animatable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -45,6 +46,10 @@ class AddSourceActivity : AppCompatActivity() {
|
|||||||
private var _config: SourcePluginConfig? = null;
|
private var _config: SourcePluginConfig? = null;
|
||||||
private var _script: String? = null;
|
private var _script: String? = null;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -7,6 +8,7 @@ import android.widget.*
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.views.buttons.BigButton
|
import com.futo.platformplayer.views.buttons.BigButton
|
||||||
import com.google.zxing.integration.android.IntentIntegrator
|
import com.google.zxing.integration.android.IntentIntegrator
|
||||||
import com.journeyapps.barcodescanner.CaptureActivity
|
import com.journeyapps.barcodescanner.CaptureActivity
|
||||||
@@ -43,6 +45,10 @@ class AddSourceOptionsActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_add_source_options);
|
setContentView(R.layout.activity_add_source_options);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.futo.platformplayer.engine.IV8PluginConfig
|
|||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.others.CaptchaWebViewClient
|
import com.futo.platformplayer.others.CaptchaWebViewClient
|
||||||
import com.futo.platformplayer.others.LoginWebViewClient
|
import com.futo.platformplayer.others.LoginWebViewClient
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
@@ -31,6 +32,10 @@ class CaptchaActivity : AppCompatActivity() {
|
|||||||
private lateinit var _webView: WebView;
|
private lateinit var _webView: WebView;
|
||||||
private lateinit var _buttonClose: Button;
|
private lateinit var _buttonClose: Button;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_captcha);
|
setContentView(R.layout.activity_captcha);
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
import com.futo.platformplayer.views.fields.FieldForm
|
import com.futo.platformplayer.views.fields.FieldForm
|
||||||
|
import com.futo.platformplayer.views.fields.IField
|
||||||
|
|
||||||
class DeveloperActivity : AppCompatActivity() {
|
class DeveloperActivity : AppCompatActivity() {
|
||||||
private lateinit var _form: FieldForm;
|
private lateinit var _form: FieldForm;
|
||||||
private lateinit var _buttonBack: ImageButton;
|
private lateinit var _buttonBack: ImageButton;
|
||||||
|
|
||||||
|
fun getField(id: String): IField? {
|
||||||
|
return _form.findField(id);
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
DeveloperActivity._lastActivity = this;
|
||||||
setContentView(R.layout.activity_dev);
|
setContentView(R.layout.activity_dev);
|
||||||
setNavigationBarColorAndIcons();
|
setNavigationBarColorAndIcons();
|
||||||
|
|
||||||
@@ -33,4 +40,19 @@ class DeveloperActivity : AppCompatActivity() {
|
|||||||
super.finish()
|
super.finish()
|
||||||
overridePendingTransition(R.anim.slide_lighten, R.anim.slide_out_up)
|
overridePendingTransition(R.anim.slide_lighten, R.anim.slide_out_up)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
//TODO: Temporary for solving Settings issues
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
private var _lastActivity: DeveloperActivity? = null;
|
||||||
|
|
||||||
|
fun getActivity(): DeveloperActivity? {
|
||||||
|
val act = _lastActivity;
|
||||||
|
if(act != null)
|
||||||
|
return act;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -11,6 +12,7 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
import com.futo.platformplayer.logging.LogLevel
|
import com.futo.platformplayer.logging.LogLevel
|
||||||
import com.futo.platformplayer.logging.Logging
|
import com.futo.platformplayer.logging.Logging
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -27,6 +29,10 @@ class ExceptionActivity : AppCompatActivity() {
|
|||||||
private var _file: File? = null;
|
private var _file: File? = null;
|
||||||
private var _submitted = false;
|
private var _submitted = false;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_exception);
|
setContentView(R.layout.activity_exception);
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.text.Html
|
||||||
|
import android.widget.ImageButton
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import com.futo.platformplayer.R
|
||||||
|
import com.futo.platformplayer.UIDialogs
|
||||||
|
import com.futo.platformplayer.dialogs.CastingHelpDialog
|
||||||
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
|
import com.futo.platformplayer.views.buttons.BigButton
|
||||||
|
|
||||||
|
class FCastGuideActivity : AppCompatActivity() {
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_fcast_guide);
|
||||||
|
setNavigationBarColorAndIcons();
|
||||||
|
|
||||||
|
findViewById<TextView>(R.id.text_explanation).apply {
|
||||||
|
val guideText = """
|
||||||
|
<h3>1. Install FCast Receiver:</h3>
|
||||||
|
<p>- Open Play Store, FireStore, or FCast website on your TV/desktop.<br>
|
||||||
|
- Search for "FCast Receiver", install and open it.</p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>2. Prepare the Grayjay App:</h3>
|
||||||
|
<p>- Ensure it's connected to the same network as the FCast Receiver.</p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>3. Initiate Casting from Grayjay:</h3>
|
||||||
|
<p>- Click the cast button in Grayjay.</p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>4. Connect to FCast Receiver:</h3>
|
||||||
|
<p>- Wait for your device to show in the list or add it manually with its IP address.</p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>5. Confirm Connection:</h3>
|
||||||
|
<p>- Click "OK" to confirm your device selection.</p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>6. Start Casting:</h3>
|
||||||
|
<p>- Press "start" next to the device you've added.</p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>7. Play Your Video:</h3>
|
||||||
|
<p>- Start any video in Grayjay to cast.</p>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3>Finding Your IP Address:</h3>
|
||||||
|
<p><b>On FCast Receiver (Android):</b> Displayed on the main screen.<br>
|
||||||
|
<b>On Windows:</b> Use 'ipconfig' in Command Prompt.<br>
|
||||||
|
<b>On Linux:</b> Use 'hostname -I' or 'ip addr' in Terminal.<br>
|
||||||
|
<b>On MacOS:</b> System Preferences > Network.</p>
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
text = Html.fromHtml(guideText, Html.FROM_HTML_MODE_COMPACT)
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<ImageButton>(R.id.button_back).setOnClickListener {
|
||||||
|
UIDialogs.showCastingTutorialDialog(this)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_close).onClick.subscribe {
|
||||||
|
UIDialogs.showCastingTutorialDialog(this)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_website).onClick.subscribe {
|
||||||
|
try {
|
||||||
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://fcast.org/"))
|
||||||
|
startActivity(browserIntent);
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to open browser.", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_technical).onClick.subscribe {
|
||||||
|
try {
|
||||||
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://gitlab.com/futo-org/fcast/-/wikis/Protocol-version-1"))
|
||||||
|
startActivity(browserIntent);
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to open browser.", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
UIDialogs.showCastingTutorialDialog(this)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "FCastGuideActivity";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ import android.webkit.ConsoleMessage
|
|||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import android.webkit.WebChromeClient
|
import android.webkit.WebChromeClient
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
import android.widget.ImageButton
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
@@ -15,6 +17,7 @@ import com.futo.platformplayer.api.media.platforms.js.SourcePluginAuthConfig
|
|||||||
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.others.LoginWebViewClient
|
import com.futo.platformplayer.others.LoginWebViewClient
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
@@ -23,13 +26,25 @@ import kotlinx.serialization.json.Json
|
|||||||
|
|
||||||
class LoginActivity : AppCompatActivity() {
|
class LoginActivity : AppCompatActivity() {
|
||||||
private lateinit var _webView: WebView;
|
private lateinit var _webView: WebView;
|
||||||
|
private lateinit var _textUrl: TextView;
|
||||||
|
private lateinit var _buttonClose: ImageButton;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_login);
|
setContentView(R.layout.activity_login);
|
||||||
setNavigationBarColorAndIcons();
|
setNavigationBarColorAndIcons();
|
||||||
|
|
||||||
|
_textUrl = findViewById(R.id.text_url);
|
||||||
|
_buttonClose = findViewById(R.id.button_close);
|
||||||
|
_buttonClose.setOnClickListener {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_webView = findViewById(R.id.web_view);
|
_webView = findViewById(R.id.web_view);
|
||||||
_webView.settings.javaScriptEnabled = true;
|
_webView.settings.javaScriptEnabled = true;
|
||||||
CookieManager.getInstance().setAcceptCookie(true);
|
CookieManager.getInstance().setAcceptCookie(true);
|
||||||
@@ -60,6 +75,8 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
};
|
};
|
||||||
var isFirstLoad = true;
|
var isFirstLoad = true;
|
||||||
webViewClient.onPageLoaded.subscribe { view, url ->
|
webViewClient.onPageLoaded.subscribe { view, url ->
|
||||||
|
_textUrl.setText(url ?: "");
|
||||||
|
|
||||||
if(!isFirstLoad)
|
if(!isFirstLoad)
|
||||||
return@subscribe;
|
return@subscribe;
|
||||||
isFirstLoad = false;
|
isFirstLoad = false;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.pm.ActivityInfo
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
@@ -23,11 +24,9 @@ import androidx.fragment.app.FragmentContainerView
|
|||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
import com.futo.platformplayer.api.media.PlatformID
|
|
||||||
import com.futo.platformplayer.api.media.models.channels.SerializedChannel
|
|
||||||
import com.futo.platformplayer.casting.StateCasting
|
import com.futo.platformplayer.casting.StateCasting
|
||||||
import com.futo.platformplayer.constructs.Event1
|
import com.futo.platformplayer.constructs.Event1
|
||||||
import com.futo.platformplayer.constructs.Event3
|
import com.futo.platformplayer.dialogs.ConnectCastingDialog
|
||||||
import com.futo.platformplayer.fragment.mainactivity.bottombar.MenuBottomBarFragment
|
import com.futo.platformplayer.fragment.mainactivity.bottombar.MenuBottomBarFragment
|
||||||
import com.futo.platformplayer.fragment.mainactivity.main.*
|
import com.futo.platformplayer.fragment.mainactivity.main.*
|
||||||
import com.futo.platformplayer.fragment.mainactivity.topbar.AddTopBarFragment
|
import com.futo.platformplayer.fragment.mainactivity.topbar.AddTopBarFragment
|
||||||
@@ -43,6 +42,7 @@ import com.futo.platformplayer.stores.FragmentedStorage
|
|||||||
import com.futo.platformplayer.stores.SubscriptionStorage
|
import com.futo.platformplayer.stores.SubscriptionStorage
|
||||||
import com.futo.platformplayer.stores.v2.ManagedStore
|
import com.futo.platformplayer.stores.v2.ManagedStore
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
|
import com.google.zxing.integration.android.IntentIntegrator
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
@@ -88,6 +88,7 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
lateinit var _fragMainPlaylistSearchResults: PlaylistSearchResultsFragment;
|
lateinit var _fragMainPlaylistSearchResults: PlaylistSearchResultsFragment;
|
||||||
lateinit var _fragMainSuggestions: SuggestionsFragment;
|
lateinit var _fragMainSuggestions: SuggestionsFragment;
|
||||||
lateinit var _fragMainSubscriptions: CreatorsFragment;
|
lateinit var _fragMainSubscriptions: CreatorsFragment;
|
||||||
|
lateinit var _fragMainComments: CommentsFragment;
|
||||||
lateinit var _fragMainSubscriptionsFeed: SubscriptionsFeedFragment;
|
lateinit var _fragMainSubscriptionsFeed: SubscriptionsFeedFragment;
|
||||||
lateinit var _fragMainChannel: ChannelFragment;
|
lateinit var _fragMainChannel: ChannelFragment;
|
||||||
lateinit var _fragMainSources: SourcesFragment;
|
lateinit var _fragMainSources: SourcesFragment;
|
||||||
@@ -121,6 +122,24 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
private var _isVisible = true;
|
private var _isVisible = true;
|
||||||
private var _wasStopped = false;
|
private var _wasStopped = false;
|
||||||
|
|
||||||
|
private val _urlQrCodeResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
|
val scanResult = IntentIntegrator.parseActivityResult(result.resultCode, result.data)
|
||||||
|
scanResult?.let {
|
||||||
|
val content = it.contents
|
||||||
|
if (content == null) {
|
||||||
|
UIDialogs.toast(this, getString(R.string.failed_to_scan_qr_code))
|
||||||
|
return@let
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
handleUrlAll(content)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to handle URL.", e)
|
||||||
|
UIDialogs.toast(this, "Failed to handle URL: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constructor() : super() {
|
constructor() : super() {
|
||||||
Thread.setDefaultUncaughtExceptionHandler { _, throwable ->
|
Thread.setDefaultUncaughtExceptionHandler { _, throwable ->
|
||||||
val writer = StringWriter();
|
val writer = StringWriter();
|
||||||
@@ -154,6 +173,11 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
Logger.i(TAG, "MainActivity.attachBaseContext")
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
StateApp.instance.setGlobalContext(this, lifecycleScope);
|
StateApp.instance.setGlobalContext(this, lifecycleScope);
|
||||||
StateApp.instance.mainAppStarting(this);
|
StateApp.instance.mainAppStarting(this);
|
||||||
@@ -198,6 +222,7 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
_fragMainCreatorSearchResults = CreatorSearchResultsFragment.newInstance();
|
_fragMainCreatorSearchResults = CreatorSearchResultsFragment.newInstance();
|
||||||
_fragMainPlaylistSearchResults = PlaylistSearchResultsFragment.newInstance();
|
_fragMainPlaylistSearchResults = PlaylistSearchResultsFragment.newInstance();
|
||||||
_fragMainSubscriptions = CreatorsFragment.newInstance();
|
_fragMainSubscriptions = CreatorsFragment.newInstance();
|
||||||
|
_fragMainComments = CommentsFragment.newInstance();
|
||||||
_fragMainChannel = ChannelFragment.newInstance();
|
_fragMainChannel = ChannelFragment.newInstance();
|
||||||
_fragMainSubscriptionsFeed = SubscriptionsFeedFragment.newInstance();
|
_fragMainSubscriptionsFeed = SubscriptionsFeedFragment.newInstance();
|
||||||
_fragMainSources = SourcesFragment.newInstance();
|
_fragMainSources = SourcesFragment.newInstance();
|
||||||
@@ -275,6 +300,7 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
//Set top bars
|
//Set top bars
|
||||||
_fragMainHome.topBar = _fragTopBarGeneral;
|
_fragMainHome.topBar = _fragTopBarGeneral;
|
||||||
_fragMainSubscriptions.topBar = _fragTopBarGeneral;
|
_fragMainSubscriptions.topBar = _fragTopBarGeneral;
|
||||||
|
_fragMainComments.topBar = _fragTopBarGeneral;
|
||||||
_fragMainSuggestions.topBar = _fragTopBarSearch;
|
_fragMainSuggestions.topBar = _fragTopBarSearch;
|
||||||
_fragMainVideoSearchResults.topBar = _fragTopBarSearch;
|
_fragMainVideoSearchResults.topBar = _fragTopBarSearch;
|
||||||
_fragMainCreatorSearchResults.topBar = _fragTopBarSearch;
|
_fragMainCreatorSearchResults.topBar = _fragTopBarSearch;
|
||||||
@@ -321,6 +347,15 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
fragCurrent.onOrientationChanged(it);
|
fragCurrent.onOrientationChanged(it);
|
||||||
if(_fragVideoDetail.state == VideoDetailFragment.State.MAXIMIZED)
|
if(_fragVideoDetail.state == VideoDetailFragment.State.MAXIMIZED)
|
||||||
_fragVideoDetail.onOrientationChanged(it);
|
_fragVideoDetail.onOrientationChanged(it);
|
||||||
|
else if(Settings.instance.other.bypassRotationPrevention)
|
||||||
|
{
|
||||||
|
requestedOrientation = when(orientation) {
|
||||||
|
OrientationManager.Orientation.PORTRAIT -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
|
OrientationManager.Orientation.LANDSCAPE -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||||
|
OrientationManager.Orientation.REVERSED_PORTRAIT -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
|
||||||
|
OrientationManager.Orientation.REVERSED_LANDSCAPE -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
_orientationManager.enable();
|
_orientationManager.enable();
|
||||||
|
|
||||||
@@ -390,6 +425,23 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
UIDialogs.toast(this, "No external file permissions\nExporting and auto backups will not work");
|
UIDialogs.toast(this, "No external file permissions\nExporting and auto backups will not work");
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
fun showUrlQrCodeScanner() {
|
||||||
|
try {
|
||||||
|
val integrator = IntentIntegrator(this)
|
||||||
|
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
|
||||||
|
integrator.setPrompt(getString(R.string.scan_a_qr_code))
|
||||||
|
integrator.setOrientationLocked(true);
|
||||||
|
integrator.setCameraId(0)
|
||||||
|
integrator.setBeepEnabled(false)
|
||||||
|
integrator.setBarcodeImageEnabled(true)
|
||||||
|
integrator.captureActivity = QRCaptureActivity::class.java
|
||||||
|
_urlQrCodeResultLauncher.launch(integrator.createScanIntent())
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to handle show QR scanner.", e)
|
||||||
|
UIDialogs.toast(this, "Failed to show QR scanner: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Logger.v(TAG, "onResume")
|
Logger.v(TAG, "onResume")
|
||||||
@@ -463,6 +515,9 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
val url = intent.getStringExtra("VIDEO");
|
val url = intent.getStringExtra("VIDEO");
|
||||||
navigate(_fragVideoDetail, url);
|
navigate(_fragVideoDetail, url);
|
||||||
}
|
}
|
||||||
|
"IMPORT_OPTIONS" -> {
|
||||||
|
UIDialogs.showImportOptionsDialog(this);
|
||||||
|
}
|
||||||
"TAB" -> {
|
"TAB" -> {
|
||||||
when(intent.getStringExtra("TAB")){
|
when(intent.getStringExtra("TAB")){
|
||||||
"Sources" -> {
|
"Sources" -> {
|
||||||
@@ -477,68 +532,7 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (targetData != null) {
|
if (targetData != null) {
|
||||||
when(intent.scheme) {
|
handleUrlAll(targetData)
|
||||||
"grayjay" -> {
|
|
||||||
if(targetData.startsWith("grayjay://license/")) {
|
|
||||||
if(StatePayment.instance.setPaymentLicenseUrl(targetData))
|
|
||||||
{
|
|
||||||
UIDialogs.showDialogOk(this, R.drawable.ic_check, getString(R.string.your_license_key_has_been_set_an_app_restart_might_be_required));
|
|
||||||
|
|
||||||
if(fragCurrent is BuyFragment)
|
|
||||||
closeSegment(fragCurrent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
UIDialogs.toast(getString(R.string.invalid_license_format));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(targetData.startsWith("grayjay://plugin/")) {
|
|
||||||
val intent = Intent(this, AddSourceActivity::class.java).apply {
|
|
||||||
data = Uri.parse(targetData.substring("grayjay://plugin/".length));
|
|
||||||
};
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"content" -> {
|
|
||||||
if(!handleContent(targetData, intent.type)) {
|
|
||||||
UIDialogs.showSingleButtonDialog(
|
|
||||||
this,
|
|
||||||
R.drawable.ic_play,
|
|
||||||
getString(R.string.unknown_content_format) + " [${targetData}]",
|
|
||||||
"Ok",
|
|
||||||
{ });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"file" -> {
|
|
||||||
if(!handleFile(targetData)) {
|
|
||||||
UIDialogs.showSingleButtonDialog(
|
|
||||||
this,
|
|
||||||
R.drawable.ic_play,
|
|
||||||
getString(R.string.unknown_file_format) + " [${targetData}]",
|
|
||||||
"Ok",
|
|
||||||
{ });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"polycentric" -> {
|
|
||||||
if(!handlePolycentric(targetData)) {
|
|
||||||
UIDialogs.showSingleButtonDialog(
|
|
||||||
this,
|
|
||||||
R.drawable.ic_play,
|
|
||||||
getString(R.string.unknown_polycentric_format) + " [${targetData}]",
|
|
||||||
"Ok",
|
|
||||||
{ });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
if (!handleUrl(targetData)) {
|
|
||||||
UIDialogs.showSingleButtonDialog(
|
|
||||||
this,
|
|
||||||
R.drawable.ic_play,
|
|
||||||
getString(R.string.unknown_url_format) + " [${targetData}]",
|
|
||||||
"Ok",
|
|
||||||
{ });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(ex: Throwable) {
|
catch(ex: Throwable) {
|
||||||
@@ -546,6 +540,90 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleUrlAll(url: String) {
|
||||||
|
val uri = Uri.parse(url)
|
||||||
|
when (uri.scheme) {
|
||||||
|
"grayjay" -> {
|
||||||
|
if(url.startsWith("grayjay://license/")) {
|
||||||
|
if(StatePayment.instance.setPaymentLicenseUrl(url))
|
||||||
|
{
|
||||||
|
UIDialogs.showDialogOk(this, R.drawable.ic_check, getString(R.string.your_license_key_has_been_set_an_app_restart_might_be_required));
|
||||||
|
|
||||||
|
if(fragCurrent is BuyFragment)
|
||||||
|
closeSegment(fragCurrent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
UIDialogs.toast(getString(R.string.invalid_license_format));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(url.startsWith("grayjay://plugin/")) {
|
||||||
|
val intent = Intent(this, AddSourceActivity::class.java).apply {
|
||||||
|
data = Uri.parse(url.substring("grayjay://plugin/".length));
|
||||||
|
};
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
else if(url.startsWith("grayjay://video/")) {
|
||||||
|
val videoUrl = url.substring("grayjay://video/".length);
|
||||||
|
navigate(_fragVideoDetail, videoUrl);
|
||||||
|
}
|
||||||
|
else if(url.startsWith("grayjay://channel/")) {
|
||||||
|
val channelUrl = url.substring("grayjay://channel/".length);
|
||||||
|
navigate(_fragMainChannel, channelUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"content" -> {
|
||||||
|
if(!handleContent(url, intent.type)) {
|
||||||
|
UIDialogs.showSingleButtonDialog(
|
||||||
|
this,
|
||||||
|
R.drawable.ic_play,
|
||||||
|
getString(R.string.unknown_content_format) + " [${url}]",
|
||||||
|
"Ok",
|
||||||
|
{ });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"file" -> {
|
||||||
|
if(!handleFile(url)) {
|
||||||
|
UIDialogs.showSingleButtonDialog(
|
||||||
|
this,
|
||||||
|
R.drawable.ic_play,
|
||||||
|
getString(R.string.unknown_file_format) + " [${url}]",
|
||||||
|
"Ok",
|
||||||
|
{ });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"polycentric" -> {
|
||||||
|
if(!handlePolycentric(url)) {
|
||||||
|
UIDialogs.showSingleButtonDialog(
|
||||||
|
this,
|
||||||
|
R.drawable.ic_play,
|
||||||
|
getString(R.string.unknown_polycentric_format) + " [${url}]",
|
||||||
|
"Ok",
|
||||||
|
{ });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"fcast" -> {
|
||||||
|
if(!handleFCast(url)) {
|
||||||
|
UIDialogs.showSingleButtonDialog(
|
||||||
|
this,
|
||||||
|
R.drawable.ic_cast,
|
||||||
|
"Unknown FCast format [${url}]",
|
||||||
|
"Ok",
|
||||||
|
{ });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
if (!handleUrl(url)) {
|
||||||
|
UIDialogs.showSingleButtonDialog(
|
||||||
|
this,
|
||||||
|
R.drawable.ic_play,
|
||||||
|
getString(R.string.unknown_url_format) + " [${url}]",
|
||||||
|
"Ok",
|
||||||
|
{ });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun handleUrl(url: String): Boolean {
|
fun handleUrl(url: String): Boolean {
|
||||||
Logger.i(TAG, "handleUrl(url=$url)")
|
Logger.i(TAG, "handleUrl(url=$url)")
|
||||||
|
|
||||||
@@ -583,6 +661,9 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
StateBackup.importZipBytes(this, lifecycleScope, data);
|
StateBackup.importZipBytes(this, lifecycleScope, data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if(file.lowercase().endsWith(".txt") || mime == "text/plain") {
|
||||||
|
return handleUnknownText(String(data));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fun handleFile(file: String): Boolean {
|
fun handleFile(file: String): Boolean {
|
||||||
@@ -600,6 +681,9 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
StateBackup.importZipBytes(this, lifecycleScope, readSharedFile(file));
|
StateBackup.importZipBytes(this, lifecycleScope, readSharedFile(file));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if(file.lowercase().endsWith(".txt")) {
|
||||||
|
return handleUnknownText(String(readSharedFile(file)));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fun handleReconstruction(recon: String) {
|
fun handleReconstruction(recon: String) {
|
||||||
@@ -625,6 +709,20 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleUnknownText(text: String): Boolean {
|
||||||
|
try {
|
||||||
|
if(text.startsWith("@/Subscription") || text.startsWith("Subscriptions")) {
|
||||||
|
val lines = text.split("\n").map { it.trim() }.drop(1).filter { it.isNotEmpty() };
|
||||||
|
navigate(_fragImportSubscriptions, lines);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(ex: Throwable) {
|
||||||
|
Logger.e(TAG, ex.message, ex);
|
||||||
|
UIDialogs.showGeneralErrorDialog(this, getString(R.string.failed_to_parse_text_file), ex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
fun handleUnknownJson(name: String?, json: String): Boolean {
|
fun handleUnknownJson(name: String?, json: String): Boolean {
|
||||||
|
|
||||||
val context = this;
|
val context = this;
|
||||||
@@ -635,18 +733,7 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
if (!newPipeSubsParsed.has("subscriptions") || !newPipeSubsParsed["subscriptions"].isJsonArray)
|
if (!newPipeSubsParsed.has("subscriptions") || !newPipeSubsParsed["subscriptions"].isJsonArray)
|
||||||
return false;//throw IllegalArgumentException("Invalid NewPipe json structure found");
|
return false;//throw IllegalArgumentException("Invalid NewPipe json structure found");
|
||||||
|
|
||||||
val jsonSubs = newPipeSubsParsed["subscriptions"]
|
StateBackup.importNewPipeSubs(this, newPipeSubsParsed);
|
||||||
val jsonSubsArray = jsonSubs.asJsonArray;
|
|
||||||
val jsonSubsArrayItt = jsonSubsArray.iterator();
|
|
||||||
val subs = mutableListOf<String>()
|
|
||||||
while(jsonSubsArrayItt.hasNext()) {
|
|
||||||
val jsonSubObj = jsonSubsArrayItt.next().asJsonObject;
|
|
||||||
|
|
||||||
if(jsonSubObj.has("url"))
|
|
||||||
subs.add(jsonSubObj["url"].asString);
|
|
||||||
}
|
|
||||||
|
|
||||||
navigate(_fragImportSubscriptions, subs);
|
|
||||||
}
|
}
|
||||||
catch(ex: Exception) {
|
catch(ex: Exception) {
|
||||||
Logger.e(TAG, ex.message, ex);
|
Logger.e(TAG, ex.message, ex);
|
||||||
@@ -672,6 +759,20 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
startActivity(Intent(this, PolycentricImportProfileActivity::class.java).apply { putExtra("url", url) })
|
startActivity(Intent(this, PolycentricImportProfileActivity::class.java).apply { putExtra("url", url) })
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleFCast(url: String): Boolean {
|
||||||
|
Logger.i(TAG, "handleFCast");
|
||||||
|
|
||||||
|
try {
|
||||||
|
StateCasting.instance.handleUrl(this, url)
|
||||||
|
return true;
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.e(TAG, "Failed to parse FCast URL '${url}'.", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
private fun readSharedContent(contentPath: String): ByteArray {
|
private fun readSharedContent(contentPath: String): ByteArray {
|
||||||
return contentResolver.openInputStream(Uri.parse(contentPath))?.use {
|
return contentResolver.openInputStream(Uri.parse(contentPath))?.use {
|
||||||
return it.readBytes();
|
return it.readBytes();
|
||||||
@@ -745,6 +846,9 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
StateSaved.instance.setVideoToOpenBlocking(null);
|
StateSaved.instance.setVideoToOpenBlocking(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <reified T> isFragmentActive(): Boolean {
|
||||||
|
return fragCurrent is T;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate takes a MainFragment, and makes them the current main visible view
|
* Navigate takes a MainFragment, and makes them the current main visible view
|
||||||
@@ -838,15 +942,20 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
|
|
||||||
if((fragment?.isOverlay ?: false) && fragBeforeOverlay != null) {
|
if((fragment?.isOverlay ?: false) && fragBeforeOverlay != null) {
|
||||||
navigate(fragBeforeOverlay!!, null, false, true);
|
navigate(fragBeforeOverlay!!, null, false, true);
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
val last = _queue.lastOrNull();
|
val last = _queue.lastOrNull();
|
||||||
if (last != null) {
|
if (last != null) {
|
||||||
_queue.remove(last);
|
_queue.remove(last);
|
||||||
navigate(last.first, last.second, false, true);
|
navigate(last.first, last.second, false, true);
|
||||||
} else
|
} else {
|
||||||
finish();
|
if (_fragVideoDetail.state == VideoDetailFragment.State.CLOSED) {
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
UIDialogs.showConfirmationDialog(this, "There is a video playing, are you sure you want to exit the app?", {
|
||||||
|
finish();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,6 +973,7 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
GeneralTopBarFragment::class -> _fragTopBarGeneral as T;
|
GeneralTopBarFragment::class -> _fragTopBarGeneral as T;
|
||||||
SearchTopBarFragment::class -> _fragTopBarSearch as T;
|
SearchTopBarFragment::class -> _fragTopBarSearch as T;
|
||||||
CreatorsFragment::class -> _fragMainSubscriptions as T;
|
CreatorsFragment::class -> _fragMainSubscriptions as T;
|
||||||
|
CommentsFragment::class -> _fragMainComments as T;
|
||||||
SubscriptionsFeedFragment::class -> _fragMainSubscriptionsFeed as T;
|
SubscriptionsFeedFragment::class -> _fragMainSubscriptionsFeed as T;
|
||||||
PlaylistSearchResultsFragment::class -> _fragMainPlaylistSearchResults as T;
|
PlaylistSearchResultsFragment::class -> _fragMainPlaylistSearchResults as T;
|
||||||
ChannelFragment::class -> _fragMainChannel as T;
|
ChannelFragment::class -> _fragMainChannel as T;
|
||||||
@@ -936,5 +1046,12 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
|
|||||||
sourcesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
sourcesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
return sourcesIntent;
|
return sourcesIntent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getImportOptionsIntent(context: Context): Intent {
|
||||||
|
val sourcesIntent = Intent(context, MainActivity::class.java);
|
||||||
|
sourcesIntent.action = "IMPORT_OPTIONS";
|
||||||
|
sourcesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
return sourcesIntent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@@ -10,6 +11,7 @@ import com.futo.platformplayer.R
|
|||||||
import com.futo.platformplayer.Settings
|
import com.futo.platformplayer.Settings
|
||||||
import com.futo.platformplayer.fragment.mainactivity.bottombar.MenuBottomBarFragment
|
import com.futo.platformplayer.fragment.mainactivity.bottombar.MenuBottomBarFragment
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.views.AnyAdapterView
|
import com.futo.platformplayer.views.AnyAdapterView
|
||||||
import com.futo.platformplayer.views.AnyAdapterView.Companion.asAny
|
import com.futo.platformplayer.views.AnyAdapterView.Companion.asAny
|
||||||
import com.futo.platformplayer.views.adapters.ItemMoveCallback
|
import com.futo.platformplayer.views.adapters.ItemMoveCallback
|
||||||
@@ -23,6 +25,10 @@ class ManageTabsActivity : AppCompatActivity() {
|
|||||||
private lateinit var _recyclerTabs: RecyclerView;
|
private lateinit var _recyclerTabs: RecyclerView;
|
||||||
private lateinit var _touchHelper: ItemTouchHelper;
|
private lateinit var _touchHelper: ItemTouchHelper;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_manage_tabs);
|
setContentView(R.layout.activity_manage_tabs);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StatePolycentric
|
import com.futo.platformplayer.states.StatePolycentric
|
||||||
import com.futo.platformplayer.views.buttons.BigButton
|
import com.futo.platformplayer.views.buttons.BigButton
|
||||||
import com.futo.polycentric.core.*
|
import com.futo.polycentric.core.*
|
||||||
@@ -33,6 +34,10 @@ class PolycentricBackupActivity : AppCompatActivity() {
|
|||||||
private lateinit var _exportBundle: String;
|
private lateinit var _exportBundle: String;
|
||||||
private lateinit var _textQR: TextView;
|
private lateinit var _textQR: TextView;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_polycentric_backup);
|
setContentView(R.layout.activity_polycentric_backup);
|
||||||
|
|||||||
+8
-1
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
@@ -9,8 +10,10 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.UIDialogs
|
import com.futo.platformplayer.UIDialogs
|
||||||
|
import com.futo.platformplayer.fullyBackfillServersAnnounceExceptions
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StatePolycentric
|
import com.futo.platformplayer.states.StatePolycentric
|
||||||
import com.futo.polycentric.core.ProcessHandle
|
import com.futo.polycentric.core.ProcessHandle
|
||||||
import com.futo.polycentric.core.Store
|
import com.futo.polycentric.core.Store
|
||||||
@@ -28,6 +31,10 @@ class PolycentricCreateProfileActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private var _creating = false;
|
private var _creating = false;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_polycentric_create_profile);
|
setContentView(R.layout.activity_polycentric_create_profile);
|
||||||
@@ -76,7 +83,7 @@ class PolycentricCreateProfileActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Logger.i(TAG, "Started backfill");
|
Logger.i(TAG, "Started backfill");
|
||||||
processHandle.fullyBackfillServers();
|
processHandle.fullyBackfillServersAnnounceExceptions();
|
||||||
Logger.i(TAG, "Finished backfill");
|
Logger.i(TAG, "Finished backfill");
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Logger.e(TAG, getString(R.string.failed_to_fully_backfill_servers), e);
|
Logger.e(TAG, getString(R.string.failed_to_fully_backfill_servers), e);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
@@ -15,6 +16,7 @@ import com.futo.platformplayer.R
|
|||||||
import com.futo.platformplayer.dp
|
import com.futo.platformplayer.dp
|
||||||
import com.futo.platformplayer.selectBestImage
|
import com.futo.platformplayer.selectBestImage
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StatePolycentric
|
import com.futo.platformplayer.states.StatePolycentric
|
||||||
import com.futo.platformplayer.views.buttons.BigButton
|
import com.futo.platformplayer.views.buttons.BigButton
|
||||||
import com.futo.polycentric.core.Store
|
import com.futo.polycentric.core.Store
|
||||||
@@ -27,6 +29,10 @@ class PolycentricHomeActivity : AppCompatActivity() {
|
|||||||
private lateinit var _buttonImportProfile: BigButton;
|
private lateinit var _buttonImportProfile: BigButton;
|
||||||
private lateinit var _layoutButtons: LinearLayout;
|
private lateinit var _layoutButtons: LinearLayout;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_polycentric_home);
|
setContentView(R.layout.activity_polycentric_home);
|
||||||
|
|||||||
+6
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
@@ -12,6 +13,7 @@ import com.futo.platformplayer.R
|
|||||||
import com.futo.platformplayer.UIDialogs
|
import com.futo.platformplayer.UIDialogs
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StatePolycentric
|
import com.futo.platformplayer.states.StatePolycentric
|
||||||
import com.futo.polycentric.core.*
|
import com.futo.polycentric.core.*
|
||||||
import com.google.zxing.integration.android.IntentIntegrator
|
import com.google.zxing.integration.android.IntentIntegrator
|
||||||
@@ -39,6 +41,10 @@ class PolycentricImportProfileActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_polycentric_import_profile);
|
setContentView(R.layout.activity_polycentric_import_profile);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.futo.platformplayer.activities
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
@@ -18,6 +19,7 @@ import com.futo.platformplayer.R
|
|||||||
import com.futo.platformplayer.UIDialogs
|
import com.futo.platformplayer.UIDialogs
|
||||||
import com.futo.platformplayer.dialogs.CommentDialog
|
import com.futo.platformplayer.dialogs.CommentDialog
|
||||||
import com.futo.platformplayer.dp
|
import com.futo.platformplayer.dp
|
||||||
|
import com.futo.platformplayer.fullyBackfillServersAnnounceExceptions
|
||||||
import com.futo.platformplayer.images.GlideHelper.Companion.crossfade
|
import com.futo.platformplayer.images.GlideHelper.Companion.crossfade
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.selectBestImage
|
import com.futo.platformplayer.selectBestImage
|
||||||
@@ -29,6 +31,7 @@ import com.futo.polycentric.core.Store
|
|||||||
import com.futo.polycentric.core.Synchronization
|
import com.futo.polycentric.core.Synchronization
|
||||||
import com.futo.polycentric.core.SystemState
|
import com.futo.polycentric.core.SystemState
|
||||||
import com.futo.polycentric.core.toURLInfoDataLink
|
import com.futo.polycentric.core.toURLInfoDataLink
|
||||||
|
import com.futo.polycentric.core.toURLInfoSystemLinkUrl
|
||||||
import com.github.dhaval2404.imagepicker.ImagePicker
|
import com.github.dhaval2404.imagepicker.ImagePicker
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -47,6 +50,10 @@ class PolycentricProfileActivity : AppCompatActivity() {
|
|||||||
private lateinit var _imagePolycentric: ImageView;
|
private lateinit var _imagePolycentric: ImageView;
|
||||||
private var _avatarUri: Uri? = null;
|
private var _avatarUri: Uri? = null;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_polycentric_profile);
|
setContentView(R.layout.activity_polycentric_profile);
|
||||||
@@ -188,7 +195,7 @@ class PolycentricProfileActivity : AppCompatActivity() {
|
|||||||
if (hasChanges) {
|
if (hasChanges) {
|
||||||
try {
|
try {
|
||||||
Logger.i(TAG, "Started backfill");
|
Logger.i(TAG, "Started backfill");
|
||||||
processHandle.fullyBackfillServers();
|
processHandle.fullyBackfillServersAnnounceExceptions();
|
||||||
Logger.i(TAG, "Finished backfill");
|
Logger.i(TAG, "Finished backfill");
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
UIDialogs.toast(this@PolycentricProfileActivity, getString(R.string.changes_have_been_saved));
|
UIDialogs.toast(this@PolycentricProfileActivity, getString(R.string.changes_have_been_saved));
|
||||||
@@ -222,7 +229,7 @@ class PolycentricProfileActivity : AppCompatActivity() {
|
|||||||
val avatar = systemState.avatar.selectBestImage(dp_80 * dp_80);
|
val avatar = systemState.avatar.selectBestImage(dp_80 * dp_80);
|
||||||
|
|
||||||
Glide.with(_imagePolycentric)
|
Glide.with(_imagePolycentric)
|
||||||
.load(avatar?.toURLInfoDataLink(processHandle.system.toProto(), processHandle.processSecret.process.toProto(), systemState.servers.toList()))
|
.load(avatar?.toURLInfoSystemLinkUrl(processHandle.system.toProto(), avatar.process, systemState.servers.toList()))
|
||||||
.placeholder(R.drawable.placeholder_profile)
|
.placeholder(R.drawable.placeholder_profile)
|
||||||
.crossfade()
|
.crossfade()
|
||||||
.into(_imagePolycentric)
|
.into(_imagePolycentric)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -7,12 +8,17 @@ import android.widget.ImageButton
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
import com.futo.platformplayer.setNavigationBarColorAndIcons
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.views.buttons.BigButton
|
import com.futo.platformplayer.views.buttons.BigButton
|
||||||
|
|
||||||
class PolycentricWhyActivity : AppCompatActivity() {
|
class PolycentricWhyActivity : AppCompatActivity() {
|
||||||
private lateinit var _buttonVideo: BigButton;
|
private lateinit var _buttonVideo: BigButton;
|
||||||
private lateinit var _buttonTechnical: BigButton;
|
private lateinit var _buttonTechnical: BigButton;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_polycentric_why);
|
setContentView(R.layout.activity_polycentric_why);
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.futo.platformplayer.activities
|
package com.futo.platformplayer.activities
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.FrameLayout
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.activity.result.ActivityResult
|
import androidx.activity.result.ActivityResult
|
||||||
@@ -13,7 +15,8 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.views.Loader
|
import com.futo.platformplayer.states.StateApp
|
||||||
|
import com.futo.platformplayer.views.LoaderView
|
||||||
import com.futo.platformplayer.views.fields.FieldForm
|
import com.futo.platformplayer.views.fields.FieldForm
|
||||||
import com.futo.platformplayer.views.fields.ReadOnlyTextField
|
import com.futo.platformplayer.views.fields.ReadOnlyTextField
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
@@ -21,13 +24,19 @@ import com.google.android.material.button.MaterialButton
|
|||||||
class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
||||||
private lateinit var _form: FieldForm;
|
private lateinit var _form: FieldForm;
|
||||||
private lateinit var _buttonBack: ImageButton;
|
private lateinit var _buttonBack: ImageButton;
|
||||||
private lateinit var _loader: Loader;
|
private lateinit var _loaderView: LoaderView;
|
||||||
|
|
||||||
private lateinit var _devSets: LinearLayout;
|
private lateinit var _devSets: LinearLayout;
|
||||||
private lateinit var _buttonDev: MaterialButton;
|
private lateinit var _buttonDev: MaterialButton;
|
||||||
|
|
||||||
private var _isFinished = false;
|
private var _isFinished = false;
|
||||||
|
|
||||||
|
lateinit var overlay: FrameLayout;
|
||||||
|
|
||||||
|
override fun attachBaseContext(newBase: Context?) {
|
||||||
|
Logger.i("SettingsActivity", "SettingsActivity.attachBaseContext")
|
||||||
|
super.attachBaseContext(StateApp.instance.getLocaleContext(newBase))
|
||||||
|
}
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_settings);
|
setContentView(R.layout.activity_settings);
|
||||||
@@ -37,12 +46,18 @@ class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
|||||||
_buttonBack = findViewById(R.id.button_back);
|
_buttonBack = findViewById(R.id.button_back);
|
||||||
_buttonDev = findViewById(R.id.button_dev);
|
_buttonDev = findViewById(R.id.button_dev);
|
||||||
_devSets = findViewById(R.id.dev_settings);
|
_devSets = findViewById(R.id.dev_settings);
|
||||||
_loader = findViewById(R.id.loader);
|
_loaderView = findViewById(R.id.loader);
|
||||||
|
overlay = findViewById(R.id.overlay_container);
|
||||||
|
|
||||||
_form.onChanged.subscribe { field, value ->
|
_form.onChanged.subscribe { field, value ->
|
||||||
Logger.i("SettingsActivity", "Setting [${field.field?.name}] changed, saving");
|
Logger.i("SettingsActivity", "Setting [${field.field?.name}] changed, saving");
|
||||||
_form.setObjectValues();
|
_form.setObjectValues();
|
||||||
Settings.instance.save();
|
Settings.instance.save();
|
||||||
|
|
||||||
|
if(field.descriptor?.id == "app_language") {
|
||||||
|
Logger.i("SettingsActivity", "App language change detected, propogating to shared preferences");
|
||||||
|
StateApp.instance.setLocaleSetting(this, Settings.instance.language.getAppLanguageLocaleString());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
_buttonBack.setOnClickListener {
|
_buttonBack.setOnClickListener {
|
||||||
finish();
|
finish();
|
||||||
@@ -58,9 +73,11 @@ class SettingsActivity : AppCompatActivity(), IWithResultLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun reloadSettings() {
|
fun reloadSettings() {
|
||||||
_loader.start();
|
_form.setSearchVisible(false);
|
||||||
|
_loaderView.start();
|
||||||
_form.fromObject(lifecycleScope, Settings.instance) {
|
_form.fromObject(lifecycleScope, Settings.instance) {
|
||||||
_loader.stop();
|
_loaderView.stop();
|
||||||
|
_form.setSearchVisible(true);
|
||||||
|
|
||||||
var devCounter = 0;
|
var devCounter = 0;
|
||||||
_form.findField("code")?.assume<ReadOnlyTextField>()?.setOnClickListener {
|
_form.findField("code")?.assume<ReadOnlyTextField>()?.setOnClickListener {
|
||||||
|
|||||||
@@ -8,16 +8,20 @@ import kotlinx.serialization.decodeFromString
|
|||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.io.StringWriter
|
import java.io.StringWriter
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
|
|
||||||
class HttpContext : AutoCloseable {
|
class HttpContext : AutoCloseable {
|
||||||
private val _stream: BufferedReader;
|
private val _inputStream: InputStream;
|
||||||
private var _responseStream: OutputStream? = null;
|
private var _responseStream: OutputStream? = null;
|
||||||
|
|
||||||
var id: String? = null;
|
var id: String? = null;
|
||||||
|
|
||||||
var head: String = "";
|
var head: String = "";
|
||||||
var headers: HttpHeaders = HttpHeaders();
|
var headers: HttpHeaders = HttpHeaders();
|
||||||
|
|
||||||
@@ -39,76 +43,130 @@ class HttpContext : AutoCloseable {
|
|||||||
private val _responseHeaders: HttpHeaders = HttpHeaders();
|
private val _responseHeaders: HttpHeaders = HttpHeaders();
|
||||||
|
|
||||||
|
|
||||||
constructor(stream: BufferedReader, responseStream: OutputStream? = null, requestId: String? = null, timeout: Int? = null) {
|
constructor(inputStream: InputStream, responseStream: OutputStream? = null, requestId: String? = null, timeout: Int? = null) {
|
||||||
_stream = stream;
|
_inputStream = inputStream;
|
||||||
_responseStream = responseStream;
|
_responseStream = responseStream;
|
||||||
this.id = requestId;
|
this.id = requestId;
|
||||||
|
|
||||||
try {
|
val headerBytes = readHeaderBytes()
|
||||||
head = stream.readLine() ?: throw EmptyRequestException("No head found");
|
ByteArrayInputStream(headerBytes).use {
|
||||||
}
|
val reader = it.bufferedReader(Charsets.UTF_8)
|
||||||
catch(ex: SocketTimeoutException) {
|
try {
|
||||||
if((timeout ?: 0) > 0)
|
head = reader.readLine() ?: throw EmptyRequestException("No head found");
|
||||||
throw KeepAliveTimeoutException("Keep-Alive timedout", ex);
|
}
|
||||||
throw ex;
|
catch(ex: SocketTimeoutException) {
|
||||||
}
|
if((timeout ?: 0) > 0)
|
||||||
|
throw KeepAliveTimeoutException("Keep-Alive timedout", ex);
|
||||||
val methodEndIndex = head.indexOf(' ');
|
throw ex;
|
||||||
val urlEndIndex = head.indexOf(' ', methodEndIndex + 1);
|
|
||||||
if (methodEndIndex == -1 || urlEndIndex == -1) {
|
|
||||||
Logger.w(TAG, "Skipped request, wrong format.");
|
|
||||||
throw IllegalStateException("Invalid request");
|
|
||||||
}
|
|
||||||
|
|
||||||
method = head.substring(0, methodEndIndex);
|
|
||||||
path = head.substring(methodEndIndex + 1, urlEndIndex);
|
|
||||||
|
|
||||||
if (path.contains("?")) {
|
|
||||||
val queryPartIndex = path.indexOf("?");
|
|
||||||
val queryParts = path.substring(queryPartIndex + 1).split("&");
|
|
||||||
path = path.substring(0, queryPartIndex);
|
|
||||||
|
|
||||||
for(queryPart in queryParts) {
|
|
||||||
val eqIndex = queryPart.indexOf("=");
|
|
||||||
if(eqIndex > 0)
|
|
||||||
query.put(queryPart.substring(0, eqIndex), queryPart.substring(eqIndex + 1));
|
|
||||||
else
|
|
||||||
query.put(queryPart, "");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
val methodEndIndex = head.indexOf(' ');
|
||||||
val line = stream.readLine();
|
val urlEndIndex = head.indexOf(' ', methodEndIndex + 1);
|
||||||
val headerEndIndex = line.indexOf(":");
|
if (methodEndIndex == -1 || urlEndIndex == -1) {
|
||||||
if (headerEndIndex == -1)
|
Logger.w(TAG, "Skipped request, wrong format.");
|
||||||
break;
|
throw IllegalStateException("Invalid request");
|
||||||
|
}
|
||||||
|
|
||||||
val headerKey = line.substring(0, headerEndIndex).lowercase()
|
method = head.substring(0, methodEndIndex);
|
||||||
val headerValue = line.substring(headerEndIndex + 1).trim();
|
path = head.substring(methodEndIndex + 1, urlEndIndex);
|
||||||
headers[headerKey] = headerValue;
|
|
||||||
|
|
||||||
when(headerKey) {
|
if (path.contains("?")) {
|
||||||
"content-length" -> contentLength = headerValue.toLong();
|
val queryPartIndex = path.indexOf("?");
|
||||||
"content-type" -> contentType = headerValue;
|
val queryParts = path.substring(queryPartIndex + 1).split("&");
|
||||||
"connection" -> keepAlive = headerValue.lowercase() == "keep-alive";
|
path = path.substring(0, queryPartIndex);
|
||||||
"keep-alive" -> {
|
|
||||||
val keepAliveParams = headerValue.split(",");
|
for(queryPart in queryParts) {
|
||||||
for(keepAliveParam in keepAliveParams) {
|
val eqIndex = queryPart.indexOf("=");
|
||||||
val eqIndex = keepAliveParam.indexOf("=");
|
if(eqIndex > 0)
|
||||||
if(eqIndex > 0){
|
query.put(queryPart.substring(0, eqIndex), queryPart.substring(eqIndex + 1));
|
||||||
when(keepAliveParam.substring(0, eqIndex)) {
|
else
|
||||||
"timeout" -> keepAliveTimeout = keepAliveParam.substring(eqIndex+1).toInt();
|
query.put(queryPart, "");
|
||||||
"max" -> keepAliveTimeout = keepAliveParam.substring(eqIndex+1).toInt();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
val line = reader.readLine();
|
||||||
|
val headerEndIndex = line.indexOf(":");
|
||||||
|
if (headerEndIndex == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
val headerKey = line.substring(0, headerEndIndex).lowercase()
|
||||||
|
val headerValue = line.substring(headerEndIndex + 1).trim();
|
||||||
|
headers[headerKey] = headerValue;
|
||||||
|
|
||||||
|
when(headerKey) {
|
||||||
|
"content-length" -> contentLength = headerValue.toLong();
|
||||||
|
"content-type" -> contentType = headerValue;
|
||||||
|
"connection" -> keepAlive = headerValue.lowercase() == "keep-alive";
|
||||||
|
"keep-alive" -> {
|
||||||
|
val keepAliveParams = headerValue.split(",");
|
||||||
|
for(keepAliveParam in keepAliveParams) {
|
||||||
|
val eqIndex = keepAliveParam.indexOf("=");
|
||||||
|
if(eqIndex > 0){
|
||||||
|
when(keepAliveParam.substring(0, eqIndex)) {
|
||||||
|
"timeout" -> keepAliveTimeout = keepAliveParam.substring(eqIndex+1).toInt();
|
||||||
|
"max" -> keepAliveTimeout = keepAliveParam.substring(eqIndex+1).toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(line.isNullOrEmpty())
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(line.isNullOrEmpty())
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun readHeaderBytes(): ByteArray {
|
||||||
|
val headerBytes = ByteArrayOutputStream()
|
||||||
|
var crlfCount = 0
|
||||||
|
|
||||||
|
while (crlfCount < 4) {
|
||||||
|
val b = _inputStream.read()
|
||||||
|
if (b == -1) {
|
||||||
|
throw IOException("Unexpected end of stream while reading headers")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b == 0x0D || b == 0x0A) { // CR or LF
|
||||||
|
crlfCount++
|
||||||
|
} else {
|
||||||
|
crlfCount = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
headerBytes.write(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
return headerBytes.toByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun readContentBytes(buffer: ByteArray, length: Int): Int {
|
||||||
|
val remainingBytes = (contentLength - _totalRead).coerceAtMost(length.toLong()).toInt()
|
||||||
|
val read = _inputStream.read(buffer, 0, remainingBytes);
|
||||||
|
if (read > 0) {
|
||||||
|
_totalRead += read
|
||||||
|
}
|
||||||
|
|
||||||
|
return read;
|
||||||
|
}
|
||||||
|
fun readContentString(): String {
|
||||||
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
|
val buffer = ByteArray(4096)
|
||||||
|
var read: Int
|
||||||
|
while (true) {
|
||||||
|
read = readContentBytes(buffer, buffer.size)
|
||||||
|
if (read <= 0) break
|
||||||
|
byteArrayOutputStream.write(buffer, 0, read)
|
||||||
|
}
|
||||||
|
return byteArrayOutputStream.toString(Charsets.UTF_8.name())
|
||||||
|
}
|
||||||
|
inline fun <reified T> readContentJson() : T {
|
||||||
|
return Serializer.json.decodeFromString(readContentString());
|
||||||
|
}
|
||||||
|
fun skipBody() {
|
||||||
|
if (contentLength > 0)
|
||||||
|
_inputStream.skip(contentLength - _totalRead)
|
||||||
|
}
|
||||||
|
|
||||||
fun getHttpHeaderString(): String {
|
fun getHttpHeaderString(): String {
|
||||||
val writer = StringWriter();
|
val writer = StringWriter();
|
||||||
writer.write(head + "\r\n");
|
writer.write(head + "\r\n");
|
||||||
@@ -139,8 +197,13 @@ class HttpContext : AutoCloseable {
|
|||||||
}
|
}
|
||||||
fun respondCode(status: Int, headers: HttpHeaders, body: String? = null) {
|
fun respondCode(status: Int, headers: HttpHeaders, body: String? = null) {
|
||||||
val bytes = body?.toByteArray(Charsets.UTF_8);
|
val bytes = body?.toByteArray(Charsets.UTF_8);
|
||||||
if(body != null && headers.get("content-length").isNullOrEmpty())
|
if(headers.get("content-length").isNullOrEmpty()) {
|
||||||
headers.put("content-length", bytes!!.size.toString());
|
if (body != null) {
|
||||||
|
headers.put("content-length", bytes!!.size.toString());
|
||||||
|
} else {
|
||||||
|
headers.put("content-length", "0")
|
||||||
|
}
|
||||||
|
}
|
||||||
respond(status, headers) { responseStream ->
|
respond(status, headers) { responseStream ->
|
||||||
if(body != null) {
|
if(body != null) {
|
||||||
responseStream.write(bytes!!);
|
responseStream.write(bytes!!);
|
||||||
@@ -161,8 +224,7 @@ class HttpContext : AutoCloseable {
|
|||||||
headersToRespond.put("keep-alive", "timeout=5, max=1000");
|
headersToRespond.put("keep-alive", "timeout=5, max=1000");
|
||||||
}
|
}
|
||||||
|
|
||||||
val responseHeader = HttpResponse(status, headers);
|
val responseHeader = HttpResponse(status, headersToRespond);
|
||||||
|
|
||||||
responseStream.write(responseHeader.getHttpHeaderBytes());
|
responseStream.write(responseHeader.getHttpHeaderBytes());
|
||||||
|
|
||||||
if(method != "HEAD") {
|
if(method != "HEAD") {
|
||||||
@@ -172,38 +234,9 @@ class HttpContext : AutoCloseable {
|
|||||||
statusCode = status;
|
statusCode = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readContentBytes(buffer: CharArray, length: Int) : Int {
|
|
||||||
val reading = Math.min(length, (contentLength - _totalRead).toInt());
|
|
||||||
val read = _stream.read(buffer, 0, reading);
|
|
||||||
_totalRead += read;
|
|
||||||
|
|
||||||
//TODO: Fix this properly
|
|
||||||
if(contentLength - _totalRead < 400 && read < length) {
|
|
||||||
_totalRead = contentLength;
|
|
||||||
}
|
|
||||||
return read;
|
|
||||||
}
|
|
||||||
fun readContentString() : String{
|
|
||||||
val writer = StringWriter();
|
|
||||||
var read = 0;
|
|
||||||
val buffer = CharArray(4096);
|
|
||||||
do {
|
|
||||||
read = readContentBytes(buffer, buffer.size);
|
|
||||||
writer.write(buffer, 0, read);
|
|
||||||
} while(read > 0);
|
|
||||||
return writer.toString();
|
|
||||||
}
|
|
||||||
inline fun <reified T> readContentJson() : T {
|
|
||||||
return Serializer.json.decodeFromString(readContentString());
|
|
||||||
}
|
|
||||||
fun skipBody() {
|
|
||||||
if(contentLength > 0)
|
|
||||||
_stream.skip(contentLength - _totalRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
if(!keepAlive) {
|
if(!keepAlive) {
|
||||||
_stream?.close();
|
_inputStream.close();
|
||||||
_responseStream?.close();
|
_responseStream?.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import com.futo.platformplayer.api.http.ManagedHttpClient
|
|||||||
import com.futo.platformplayer.api.http.server.exceptions.EmptyRequestException
|
import com.futo.platformplayer.api.http.server.exceptions.EmptyRequestException
|
||||||
import com.futo.platformplayer.api.http.server.handlers.HttpFuntionHandler
|
import com.futo.platformplayer.api.http.server.handlers.HttpFuntionHandler
|
||||||
import com.futo.platformplayer.api.http.server.handlers.HttpHandler
|
import com.futo.platformplayer.api.http.server.handlers.HttpHandler
|
||||||
import java.io.BufferedReader
|
import com.futo.platformplayer.api.http.server.handlers.HttpOptionsAllowHandler
|
||||||
import java.io.InputStreamReader
|
import java.io.BufferedInputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
@@ -18,6 +18,7 @@ import java.util.*
|
|||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import java.util.stream.IntStream.range
|
import java.util.stream.IntStream.range
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
class ManagedHttpServer(private val _requestedPort: Int = 0) {
|
class ManagedHttpServer(private val _requestedPort: Int = 0) {
|
||||||
private val _client : ManagedHttpClient = ManagedHttpClient();
|
private val _client : ManagedHttpClient = ManagedHttpClient();
|
||||||
@@ -29,7 +30,8 @@ class ManagedHttpServer(private val _requestedPort: Int = 0) {
|
|||||||
var port = 0
|
var port = 0
|
||||||
private set;
|
private set;
|
||||||
|
|
||||||
private val _handlers = mutableListOf<HttpHandler>();
|
private val _handlers = hashMapOf<String, HashMap<String, HttpHandler>>()
|
||||||
|
private val _headHandlers = hashMapOf<String, HttpHandler>()
|
||||||
private var _workerPool: ExecutorService? = null;
|
private var _workerPool: ExecutorService? = null;
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@@ -76,12 +78,12 @@ class ManagedHttpServer(private val _requestedPort: Int = 0) {
|
|||||||
|
|
||||||
private fun handleClientRequest(socket: Socket) {
|
private fun handleClientRequest(socket: Socket) {
|
||||||
_workerPool?.submit {
|
_workerPool?.submit {
|
||||||
val requestReader = BufferedReader(InputStreamReader(socket.getInputStream()))
|
val requestStream = BufferedInputStream(socket.getInputStream());
|
||||||
val responseStream = socket.getOutputStream();
|
val responseStream = socket.getOutputStream();
|
||||||
|
|
||||||
val requestId = UUID.randomUUID().toString().substring(0, 5);
|
val requestId = UUID.randomUUID().toString().substring(0, 5);
|
||||||
try {
|
try {
|
||||||
keepAliveLoop(requestReader, responseStream, requestId) { req ->
|
keepAliveLoop(requestStream, responseStream, requestId) { req ->
|
||||||
req.use { httpContext ->
|
req.use { httpContext ->
|
||||||
if(!httpContext.path.startsWith("/plugin/"))
|
if(!httpContext.path.startsWith("/plugin/"))
|
||||||
Logger.i(TAG, "[${req.id}] ${httpContext.method}: ${httpContext.path}")
|
Logger.i(TAG, "[${req.id}] ${httpContext.method}: ${httpContext.path}")
|
||||||
@@ -107,7 +109,7 @@ class ManagedHttpServer(private val _requestedPort: Int = 0) {
|
|||||||
Logger.e(TAG, "Failed to handle client request.", e);
|
Logger.e(TAG, "Failed to handle client request.", e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
requestReader.close();
|
requestStream.close();
|
||||||
responseStream.close();
|
responseStream.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -115,32 +117,78 @@ class ManagedHttpServer(private val _requestedPort: Int = 0) {
|
|||||||
|
|
||||||
fun getHandler(method: String, path: String) : HttpHandler? {
|
fun getHandler(method: String, path: String) : HttpHandler? {
|
||||||
synchronized(_handlers) {
|
synchronized(_handlers) {
|
||||||
//TODO: Support regex paths?
|
if (method == "HEAD") {
|
||||||
if(method == "HEAD")
|
return _headHandlers[path]
|
||||||
return _handlers.firstOrNull { it.path == path && (it.allowHEAD || it.method == "HEAD") }
|
}
|
||||||
return _handlers.firstOrNull { it.method == method && it.path == path };
|
|
||||||
|
val handlerMap = _handlers[method] ?: return null
|
||||||
|
return handlerMap[path]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun addHandler(handler: HttpHandler, withHEAD: Boolean = false) : HttpHandler {
|
fun addHandler(handler: HttpHandler, withHEAD: Boolean = false) : HttpHandler {
|
||||||
synchronized(_handlers) {
|
synchronized(_handlers) {
|
||||||
_handlers.add(handler);
|
|
||||||
handler.allowHEAD = withHEAD;
|
handler.allowHEAD = withHEAD;
|
||||||
|
|
||||||
|
var handlerMap: HashMap<String, HttpHandler>? = _handlers[handler.method];
|
||||||
|
if (handlerMap == null) {
|
||||||
|
handlerMap = hashMapOf()
|
||||||
|
_handlers[handler.method] = handlerMap
|
||||||
|
}
|
||||||
|
|
||||||
|
handlerMap[handler.path] = handler;
|
||||||
|
if (handler.allowHEAD || handler.method == "HEAD") {
|
||||||
|
_headHandlers[handler.path] = handler
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addHandlerWithAllowAllOptions(handler: HttpHandler, withHEAD: Boolean = false) : HttpHandler {
|
||||||
|
val allowedMethods = arrayListOf(handler.method, "OPTIONS")
|
||||||
|
if (withHEAD) {
|
||||||
|
allowedMethods.add("HEAD")
|
||||||
|
}
|
||||||
|
|
||||||
|
val tag = handler.tag
|
||||||
|
if (tag != null) {
|
||||||
|
addHandler(HttpOptionsAllowHandler(handler.path, allowedMethods).withTag(tag))
|
||||||
|
} else {
|
||||||
|
addHandler(HttpOptionsAllowHandler(handler.path, allowedMethods))
|
||||||
|
}
|
||||||
|
|
||||||
|
return addHandler(handler, withHEAD)
|
||||||
|
}
|
||||||
|
|
||||||
fun removeHandler(method: String, path: String) {
|
fun removeHandler(method: String, path: String) {
|
||||||
synchronized(_handlers) {
|
synchronized(_handlers) {
|
||||||
val handler = getHandler(method, path);
|
val handlerMap = _handlers[method] ?: return
|
||||||
if(handler != null)
|
val handler = handlerMap.remove(path) ?: return
|
||||||
_handlers.remove(handler);
|
if (method == "HEAD" || handler.allowHEAD) {
|
||||||
|
_headHandlers.remove(path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun removeAllHandlers(tag: String? = null) {
|
fun removeAllHandlers(tag: String? = null) {
|
||||||
synchronized(_handlers) {
|
synchronized(_handlers) {
|
||||||
if(tag == null)
|
if(tag == null)
|
||||||
_handlers.clear();
|
_handlers.clear();
|
||||||
else
|
else {
|
||||||
_handlers.removeIf { it.tag == tag };
|
for (pair in _handlers) {
|
||||||
|
val toRemove = ArrayList<String>()
|
||||||
|
for (innerPair in pair.value) {
|
||||||
|
if (innerPair.value.tag == tag) {
|
||||||
|
toRemove.add(innerPair.key)
|
||||||
|
|
||||||
|
if (pair.key == "HEAD" || innerPair.value.allowHEAD) {
|
||||||
|
_headHandlers.remove(innerPair.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x in toRemove)
|
||||||
|
pair.value.remove(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun addBridgeHandlers(obj: Any, tag: String? = null) {
|
fun addBridgeHandlers(obj: Any, tag: String? = null) {
|
||||||
@@ -188,7 +236,7 @@ class ManagedHttpServer(private val _requestedPort: Int = 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun keepAliveLoop(requestReader: BufferedReader, responseStream: OutputStream, requestId: String, handler: (HttpContext)->Unit) {
|
private fun keepAliveLoop(requestReader: BufferedInputStream, responseStream: OutputStream, requestId: String, handler: (HttpContext)->Unit) {
|
||||||
val stopCount = _stopCount;
|
val stopCount = _stopCount;
|
||||||
var keepAlive = false;
|
var keepAlive = false;
|
||||||
var requestsMax = 0;
|
var requestsMax = 0;
|
||||||
|
|||||||
-1
@@ -7,7 +7,6 @@ class HttpConstantHandler(method: String, path: String, val content: String, val
|
|||||||
val headers = this.headers.clone();
|
val headers = this.headers.clone();
|
||||||
if(contentType != null)
|
if(contentType != null)
|
||||||
headers["Content-Type"] = contentType;
|
headers["Content-Type"] = contentType;
|
||||||
headers["Content-Length"] = content.length.toString();
|
|
||||||
|
|
||||||
httpContext.respondCode(200, headers, content);
|
httpContext.respondCode(200, headers, content);
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-22
@@ -1,14 +1,16 @@
|
|||||||
package com.futo.platformplayer.api.http.server.handlers
|
package com.futo.platformplayer.api.http.server.handlers
|
||||||
|
|
||||||
import com.futo.platformplayer.api.http.server.HttpContext
|
import com.futo.platformplayer.api.http.server.HttpContext
|
||||||
|
import com.futo.platformplayer.api.http.server.HttpHeaders
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.GZIPOutputStream
|
import java.util.zip.GZIPOutputStream
|
||||||
|
|
||||||
class HttpFileHandler(method: String, path: String, private val contentType: String, private val filePath: String, private val closeAfterRequest: Boolean = false): HttpHandler(method, path) {
|
class HttpFileHandler(method: String, path: String, private val contentType: String, private val filePath: String): HttpHandler(method, path) {
|
||||||
override fun handle(httpContext: HttpContext) {
|
override fun handle(httpContext: HttpContext) {
|
||||||
val requestHeaders = httpContext.headers;
|
val requestHeaders = httpContext.headers;
|
||||||
val responseHeaders = this.headers.clone();
|
val responseHeaders = this.headers.clone();
|
||||||
@@ -30,19 +32,13 @@ class HttpFileHandler(method: String, path: String, private val contentType: Str
|
|||||||
|
|
||||||
responseHeaders["Content-Disposition"] = "attachment; filename=\"${file.name.replace("\"", "\\\"")}\""
|
responseHeaders["Content-Disposition"] = "attachment; filename=\"${file.name.replace("\"", "\\\"")}\""
|
||||||
|
|
||||||
val acceptEncoding = requestHeaders["Accept-Encoding"]
|
|
||||||
val shouldGzip = acceptEncoding != null && acceptEncoding.split(',').any { it.trim().equals("gzip", ignoreCase = true) || it == "*" }
|
|
||||||
if (shouldGzip) {
|
|
||||||
responseHeaders["Content-Encoding"] = "gzip"
|
|
||||||
}
|
|
||||||
|
|
||||||
val range = requestHeaders["Range"]
|
val range = requestHeaders["Range"]
|
||||||
var start: Long
|
val start: Long
|
||||||
val end: Long
|
val end: Long
|
||||||
if (range != null && range.startsWith("bytes=")) {
|
if (range != null && range.startsWith("bytes=")) {
|
||||||
val parts = range.substring(6).split("-")
|
val parts = range.substring(6).split("-")
|
||||||
start = parts[0].toLong()
|
start = parts[0].toLong()
|
||||||
end = parts.getOrNull(1)?.toLong() ?: (file.length() - 1)
|
end = parts.getOrNull(1)?.toLongOrNull() ?: (file.length() - 1)
|
||||||
responseHeaders["Content-Range"] = "bytes $start-$end/${file.length()}"
|
responseHeaders["Content-Range"] = "bytes $start-$end/${file.length()}"
|
||||||
} else {
|
} else {
|
||||||
start = 0
|
start = 0
|
||||||
@@ -51,18 +47,19 @@ class HttpFileHandler(method: String, path: String, private val contentType: Str
|
|||||||
|
|
||||||
var totalBytesSent = 0
|
var totalBytesSent = 0
|
||||||
val contentLength = end - start + 1
|
val contentLength = end - start + 1
|
||||||
Logger.i(TAG, "Sending $contentLength bytes (start: $start, end: $end, shouldGzip: $shouldGzip)")
|
|
||||||
responseHeaders["Content-Length"] = contentLength.toString()
|
responseHeaders["Content-Length"] = contentLength.toString()
|
||||||
|
Logger.i(TAG, "Sending $contentLength bytes (start: $start, end: $end)")
|
||||||
|
|
||||||
file.inputStream().use { inputStream ->
|
file.inputStream().use { inputStream ->
|
||||||
httpContext.respond(if (range == null) 200 else 206, responseHeaders) { responseStream ->
|
httpContext.respond(if (range != null) 206 else 200, responseHeaders) { responseStream ->
|
||||||
try {
|
try {
|
||||||
val buffer = ByteArray(8192)
|
val buffer = ByteArray(8192)
|
||||||
inputStream.skip(start)
|
inputStream.skip(start)
|
||||||
|
var current = start
|
||||||
|
|
||||||
val outputStream = if (shouldGzip) GZIPOutputStream(responseStream) else responseStream
|
val outputStream = responseStream
|
||||||
while (true) {
|
while (true) {
|
||||||
val expectedBytesRead = (end - start + 1).coerceAtMost(buffer.size.toLong());
|
val expectedBytesRead = (end - current + 1).coerceAtMost(buffer.size.toLong());
|
||||||
val bytesRead = inputStream.read(buffer);
|
val bytesRead = inputStream.read(buffer);
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
Logger.i(TAG, "End of file reached")
|
Logger.i(TAG, "End of file reached")
|
||||||
@@ -73,27 +70,21 @@ class HttpFileHandler(method: String, path: String, private val contentType: Str
|
|||||||
outputStream.write(buffer, 0, bytesToSend)
|
outputStream.write(buffer, 0, bytesToSend)
|
||||||
|
|
||||||
totalBytesSent += bytesToSend
|
totalBytesSent += bytesToSend
|
||||||
Logger.v(TAG, "Sent bytes $start-${start + bytesToSend}, totalBytesSent=$totalBytesSent")
|
Logger.v(TAG, "Sent bytes $current-${current + bytesToSend}, totalBytesSent=$totalBytesSent")
|
||||||
|
|
||||||
start += bytesToSend.toLong()
|
current += bytesToSend.toLong()
|
||||||
if (start >= end) {
|
if (current >= end) {
|
||||||
Logger.i(TAG, "Expected amount of bytes sent")
|
Logger.i(TAG, "Expected amount of bytes sent")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.i(TAG, "Finished sending file (segment)")
|
Logger.i(TAG, "Finished sending file (segment)")
|
||||||
|
|
||||||
if (shouldGzip) (outputStream as GZIPOutputStream).finish()
|
|
||||||
outputStream.flush()
|
outputStream.flush()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
httpContext.respondCode(500, headers)
|
httpContext.respondCode(500, headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeAfterRequest) {
|
|
||||||
httpContext.keepAlive = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ abstract class HttpHandler(val method: String, val path: String) {
|
|||||||
headers.put(key, value);
|
headers.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withContentType(contentType: String) = withHeader("Content-Type", contentType);
|
fun withContentType(contentType: String) = withHeader("Content-Type", contentType);
|
||||||
|
|
||||||
fun withTag(tag: String) : HttpHandler {
|
fun withTag(tag: String) : HttpHandler {
|
||||||
|
|||||||
+9
-10
@@ -2,19 +2,18 @@ package com.futo.platformplayer.api.http.server.handlers
|
|||||||
|
|
||||||
import com.futo.platformplayer.api.http.server.HttpContext
|
import com.futo.platformplayer.api.http.server.HttpContext
|
||||||
|
|
||||||
class HttpOptionsAllowHandler(path: String) : HttpHandler("OPTIONS", path) {
|
class HttpOptionsAllowHandler(path: String, val allowedMethods: List<String> = listOf()) : HttpHandler("OPTIONS", path) {
|
||||||
override fun handle(httpContext: HttpContext) {
|
override fun handle(httpContext: HttpContext) {
|
||||||
//Just allow whatever is requested
|
val newHeaders = headers.clone()
|
||||||
|
newHeaders.put("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
val requestedOrigin = httpContext.headers.getOrDefault("Access-Control-Request-Origin", "");
|
if (allowedMethods.isNotEmpty()) {
|
||||||
val requestedMethods = httpContext.headers.getOrDefault("Access-Control-Request-Method", "");
|
newHeaders.put("Access-Control-Allow-Methods", allowedMethods.map { it.uppercase() }.joinToString(", "))
|
||||||
val requestedHeaders = httpContext.headers.getOrDefault("Access-Control-Request-Headers", "");
|
} else {
|
||||||
|
newHeaders.put("Access-Control-Allow-Methods", "*")
|
||||||
val newHeaders = headers.clone();
|
}
|
||||||
newHeaders.put("Allow", requestedMethods);
|
|
||||||
newHeaders.put("Access-Control-Allow-Methods", requestedMethods);
|
|
||||||
newHeaders.put("Access-Control-Allow-Headers", "*");
|
|
||||||
|
|
||||||
|
newHeaders.put("Access-Control-Allow-Headers", "*")
|
||||||
httpContext.respondCode(200, newHeaders);
|
httpContext.respondCode(200, newHeaders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+160
-6
@@ -1,11 +1,20 @@
|
|||||||
package com.futo.platformplayer.api.http.server.handlers
|
package com.futo.platformplayer.api.http.server.handlers
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.util.Log
|
||||||
import com.futo.platformplayer.api.http.server.HttpContext
|
import com.futo.platformplayer.api.http.server.HttpContext
|
||||||
import com.futo.platformplayer.api.http.server.HttpHeaders
|
import com.futo.platformplayer.api.http.server.HttpHeaders
|
||||||
import com.futo.platformplayer.api.http.ManagedHttpClient
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.parsers.HttpResponseParser
|
||||||
|
import com.futo.platformplayer.readLine
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
import java.lang.Exception
|
||||||
|
import java.net.Socket
|
||||||
|
import javax.net.ssl.SSLSocketFactory
|
||||||
|
|
||||||
class HttpProxyHandler(method: String, path: String, val targetUrl: String): HttpHandler(method, path) {
|
class HttpProxyHandler(method: String, path: String, val targetUrl: String, private val useTcp: Boolean = false): HttpHandler(method, path) {
|
||||||
var content: String? = null;
|
var content: String? = null;
|
||||||
var contentType: String? = null;
|
var contentType: String? = null;
|
||||||
|
|
||||||
@@ -17,10 +26,17 @@ class HttpProxyHandler(method: String, path: String, val targetUrl: String): Htt
|
|||||||
private var _injectHost = false;
|
private var _injectHost = false;
|
||||||
private var _injectReferer = false;
|
private var _injectReferer = false;
|
||||||
|
|
||||||
|
|
||||||
private val _client = ManagedHttpClient();
|
private val _client = ManagedHttpClient();
|
||||||
|
|
||||||
override fun handle(context: HttpContext) {
|
override fun handle(context: HttpContext) {
|
||||||
|
if (useTcp) {
|
||||||
|
handleWithTcp(context)
|
||||||
|
} else {
|
||||||
|
handleWithOkHttp(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleWithOkHttp(context: HttpContext) {
|
||||||
val proxyHeaders = HashMap<String, String>();
|
val proxyHeaders = HashMap<String, String>();
|
||||||
for (header in context.headers.filter { !_ignoreRequestHeaders.contains(it.key.lowercase()) })
|
for (header in context.headers.filter { !_ignoreRequestHeaders.contains(it.key.lowercase()) })
|
||||||
proxyHeaders[header.key] = header.value;
|
proxyHeaders[header.key] = header.value;
|
||||||
@@ -34,8 +50,8 @@ class HttpProxyHandler(method: String, path: String, val targetUrl: String): Htt
|
|||||||
proxyHeaders.put("Referer", targetUrl);
|
proxyHeaders.put("Referer", targetUrl);
|
||||||
|
|
||||||
val useMethod = if (method == "inherit") context.method else method;
|
val useMethod = if (method == "inherit") context.method else method;
|
||||||
//Logger.i(TAG, "Proxied Request ${useMethod}: ${targetUrl}");
|
Logger.i(TAG, "handleWithOkHttp Proxied Request ${useMethod}: ${targetUrl}");
|
||||||
//Logger.i(TAG, "Headers:" + proxyHeaders.map { "${it.key}: ${it.value}" }.joinToString("\n"));
|
Logger.i(TAG, "handleWithOkHttp Headers:" + proxyHeaders.map { "${it.key}: ${it.value}" }.joinToString("\n"));
|
||||||
|
|
||||||
val resp = when (useMethod) {
|
val resp = when (useMethod) {
|
||||||
"GET" -> _client.get(targetUrl, proxyHeaders);
|
"GET" -> _client.get(targetUrl, proxyHeaders);
|
||||||
@@ -44,8 +60,8 @@ class HttpProxyHandler(method: String, path: String, val targetUrl: String): Htt
|
|||||||
else -> _client.requestMethod(useMethod, targetUrl, proxyHeaders);
|
else -> _client.requestMethod(useMethod, targetUrl, proxyHeaders);
|
||||||
};
|
};
|
||||||
|
|
||||||
//Logger.i(TAG, "Proxied Response [${resp.code}]");
|
Logger.i(TAG, "Proxied Response [${resp.code}]");
|
||||||
val headersFiltered = HttpHeaders(resp.getHeadersFlat().filter { !_ignoreRequestHeaders.contains(it.key.lowercase()) });
|
val headersFiltered = HttpHeaders(resp.getHeadersFlat().filter { !_ignoreResponseHeaders.contains(it.key.lowercase()) });
|
||||||
for(newHeader in headers)
|
for(newHeader in headers)
|
||||||
headersFiltered.put(newHeader.key, newHeader.value);
|
headersFiltered.put(newHeader.key, newHeader.value);
|
||||||
|
|
||||||
@@ -65,6 +81,140 @@ class HttpProxyHandler(method: String, path: String, val targetUrl: String): Htt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleWithTcp(context: HttpContext) {
|
||||||
|
if (content != null)
|
||||||
|
throw NotImplementedError("Content body is not supported")
|
||||||
|
|
||||||
|
val proxyHeaders = HashMap<String, String>();
|
||||||
|
for (header in context.headers.filter { !_ignoreRequestHeaders.contains(it.key.lowercase()) })
|
||||||
|
proxyHeaders[header.key] = header.value;
|
||||||
|
for (injectHeader in _injectRequestHeader)
|
||||||
|
proxyHeaders[injectHeader.first] = injectHeader.second;
|
||||||
|
|
||||||
|
val parsed = Uri.parse(targetUrl);
|
||||||
|
if(_injectHost)
|
||||||
|
proxyHeaders.put("Host", parsed.host!!);
|
||||||
|
if(_injectReferer)
|
||||||
|
proxyHeaders.put("Referer", targetUrl);
|
||||||
|
|
||||||
|
val useMethod = if (method == "inherit") context.method else method;
|
||||||
|
Logger.i(TAG, "handleWithTcp Proxied Request ${useMethod}: ${parsed}");
|
||||||
|
Logger.i(TAG, "handleWithTcp Headers:" + proxyHeaders.map { "${it.key}: ${it.value}" }.joinToString("\n"));
|
||||||
|
|
||||||
|
makeTcpRequest(proxyHeaders, useMethod, parsed, context)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun makeTcpRequest(proxyHeaders: HashMap<String, String>, useMethod: String, parsed: Uri, context: HttpContext) {
|
||||||
|
val requestBuilder = StringBuilder()
|
||||||
|
requestBuilder.append("$useMethod $parsed HTTP/1.1\r\n")
|
||||||
|
proxyHeaders.forEach { (key, value) -> requestBuilder.append("$key: $value\r\n") }
|
||||||
|
requestBuilder.append("\r\n")
|
||||||
|
|
||||||
|
val port = if (parsed.port == -1) {
|
||||||
|
when (parsed.scheme) {
|
||||||
|
"https" -> 443
|
||||||
|
"http" -> 80
|
||||||
|
else -> throw Exception("Unhandled scheme")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
parsed.port
|
||||||
|
}
|
||||||
|
|
||||||
|
val socket = if (parsed.scheme == "https") {
|
||||||
|
val sslSocketFactory = SSLSocketFactory.getDefault() as SSLSocketFactory
|
||||||
|
sslSocketFactory.createSocket(parsed.host, port)
|
||||||
|
} else {
|
||||||
|
Socket(parsed.host, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.use { s ->
|
||||||
|
s.getOutputStream().write(requestBuilder.toString().encodeToByteArray())
|
||||||
|
|
||||||
|
val inputStream = s.getInputStream()
|
||||||
|
val resp = HttpResponseParser(inputStream)
|
||||||
|
if (resp.statusCode == 302) {
|
||||||
|
val location = resp.location!!
|
||||||
|
Logger.i(TAG, "handleWithTcp Proxied ${resp.statusCode} following redirect to $location");
|
||||||
|
makeTcpRequest(proxyHeaders, useMethod, Uri.parse(location)!!, context)
|
||||||
|
} else {
|
||||||
|
val isChunked = resp.transferEncoding.equals("chunked", ignoreCase = true)
|
||||||
|
val contentLength = resp.contentLength.toInt()
|
||||||
|
|
||||||
|
val headersFiltered = HttpHeaders(resp.headers.filter { !_ignoreResponseHeaders.contains(it.key.lowercase()) });
|
||||||
|
for (newHeader in headers)
|
||||||
|
headersFiltered.put(newHeader.key, newHeader.value);
|
||||||
|
|
||||||
|
context.respond(resp.statusCode, headersFiltered) { responseStream ->
|
||||||
|
if (isChunked) {
|
||||||
|
Logger.i(TAG, "handleWithTcp handleChunkedTransfer");
|
||||||
|
handleChunkedTransfer(inputStream, responseStream)
|
||||||
|
} else if (contentLength > 0) {
|
||||||
|
Logger.i(TAG, "handleWithTcp transferFixedLengthContent $contentLength");
|
||||||
|
transferFixedLengthContent(inputStream, responseStream, contentLength)
|
||||||
|
} else if (contentLength == -1) {
|
||||||
|
Logger.i(TAG, "handleWithTcp transferUntilEndOfStream");
|
||||||
|
transferUntilEndOfStream(inputStream, responseStream)
|
||||||
|
} else {
|
||||||
|
Logger.i(TAG, "handleWithTcp no content");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleChunkedTransfer(inputStream: InputStream, responseStream: OutputStream) {
|
||||||
|
var line: String?
|
||||||
|
val buffer = ByteArray(8192)
|
||||||
|
|
||||||
|
while (inputStream.readLine().also { line = it } != null) {
|
||||||
|
val size = line!!.trim().toInt(16)
|
||||||
|
|
||||||
|
responseStream.write(line!!.encodeToByteArray())
|
||||||
|
responseStream.write("\r\n".encodeToByteArray())
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
inputStream.skip(2)
|
||||||
|
responseStream.write("\r\n".encodeToByteArray())
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalRead = 0
|
||||||
|
while (totalRead < size) {
|
||||||
|
val read = inputStream.read(buffer, 0, minOf(buffer.size, size - totalRead))
|
||||||
|
if (read == -1) break
|
||||||
|
responseStream.write(buffer, 0, read)
|
||||||
|
totalRead += read
|
||||||
|
}
|
||||||
|
|
||||||
|
inputStream.skip(2)
|
||||||
|
responseStream.write("\r\n".encodeToByteArray())
|
||||||
|
responseStream.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun transferFixedLengthContent(inputStream: InputStream, responseStream: OutputStream, contentLength: Int) {
|
||||||
|
val buffer = ByteArray(8192)
|
||||||
|
var totalRead = 0
|
||||||
|
while (totalRead < contentLength) {
|
||||||
|
val read = inputStream.read(buffer, 0, minOf(buffer.size, contentLength - totalRead))
|
||||||
|
if (read == -1) break
|
||||||
|
responseStream.write(buffer, 0, read)
|
||||||
|
totalRead += read
|
||||||
|
}
|
||||||
|
|
||||||
|
responseStream.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun transferUntilEndOfStream(inputStream: InputStream, responseStream: OutputStream) {
|
||||||
|
val buffer = ByteArray(8192)
|
||||||
|
var read: Int
|
||||||
|
while (inputStream.read(buffer).also { read = it } >= 0) {
|
||||||
|
responseStream.write(buffer, 0, read)
|
||||||
|
}
|
||||||
|
|
||||||
|
responseStream.flush()
|
||||||
|
}
|
||||||
|
|
||||||
fun withContent(body: String) : HttpProxyHandler {
|
fun withContent(body: String) : HttpProxyHandler {
|
||||||
this.content = body;
|
this.content = body;
|
||||||
return this;
|
return this;
|
||||||
@@ -92,4 +242,8 @@ class HttpProxyHandler(method: String, path: String, val targetUrl: String): Htt
|
|||||||
_ignoreRequestHeaders.add("referer");
|
_ignoreRequestHeaders.add("referer");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "HttpProxyHandler"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import com.futo.platformplayer.getOrThrow
|
|||||||
* A link to a channel, often with its own name and thumbnail
|
* A link to a channel, often with its own name and thumbnail
|
||||||
*/
|
*/
|
||||||
@kotlinx.serialization.Serializable
|
@kotlinx.serialization.Serializable
|
||||||
class PlatformAuthorLink {
|
open class PlatformAuthorLink {
|
||||||
val id: PlatformID;
|
val id: PlatformID;
|
||||||
val name: String;
|
val name: String;
|
||||||
val url: String;
|
val url: String;
|
||||||
@@ -28,6 +28,9 @@ class PlatformAuthorLink {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromV8(config: SourcePluginConfig, value: V8ValueObject): PlatformAuthorLink {
|
fun fromV8(config: SourcePluginConfig, value: V8ValueObject): PlatformAuthorLink {
|
||||||
|
if(value.has("membershipUrl"))
|
||||||
|
return PlatformAuthorMembershipLink.fromV8(config, value);
|
||||||
|
|
||||||
val context = "AuthorLink"
|
val context = "AuthorLink"
|
||||||
return PlatformAuthorLink(PlatformID.fromV8(config, value.getOrThrow(config, "id", context, false)),
|
return PlatformAuthorLink(PlatformID.fromV8(config, value.getOrThrow(config, "id", context, false)),
|
||||||
value.getOrThrow(config ,"name", context),
|
value.getOrThrow(config ,"name", context),
|
||||||
|
|||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.futo.platformplayer.api.media.models
|
||||||
|
|
||||||
|
import com.caoccao.javet.values.reference.V8ValueObject
|
||||||
|
import com.futo.platformplayer.api.media.PlatformID
|
||||||
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||||
|
import com.futo.platformplayer.getOrDefault
|
||||||
|
import com.futo.platformplayer.getOrThrow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A link to a channel, often with its own name and thumbnail
|
||||||
|
*/
|
||||||
|
@kotlinx.serialization.Serializable
|
||||||
|
class PlatformAuthorMembershipLink: PlatformAuthorLink {
|
||||||
|
val membershipUrl: String?;
|
||||||
|
|
||||||
|
constructor(id: PlatformID, name: String, url: String, thumbnail: String? = null, subscribers: Long? = null, membershipUrl: String? = null): super(id, name, url, thumbnail, subscribers)
|
||||||
|
{
|
||||||
|
this.membershipUrl = membershipUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromV8(config: SourcePluginConfig, value: V8ValueObject): PlatformAuthorMembershipLink {
|
||||||
|
val context = "AuthorMembershipLink"
|
||||||
|
return PlatformAuthorMembershipLink(PlatformID.fromV8(config, value.getOrThrow(config, "id", context, false)),
|
||||||
|
value.getOrThrow(config ,"name", context),
|
||||||
|
value.getOrThrow(config, "url", context),
|
||||||
|
value.getOrDefault<String>(config, "thumbnail", context, null),
|
||||||
|
if(value.has("subscribers")) value.getOrThrow(config,"subscribers", context) else null,
|
||||||
|
if(value.has("membershipUrl")) value.getOrThrow(config, "membershipUrl", context) else null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ class ResultCapabilities(
|
|||||||
const val TYPE_LIVE = "LIVE";
|
const val TYPE_LIVE = "LIVE";
|
||||||
const val TYPE_POSTS = "POSTS";
|
const val TYPE_POSTS = "POSTS";
|
||||||
const val TYPE_MIXED = "MIXED";
|
const val TYPE_MIXED = "MIXED";
|
||||||
|
const val TYPE_SUBSCRIPTIONS = "SUBSCRIPTIONS";
|
||||||
|
|
||||||
const val ORDER_CHONOLOGICAL = "CHRONOLOGICAL";
|
const val ORDER_CHONOLOGICAL = "CHRONOLOGICAL";
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ class Thumbnails {
|
|||||||
fun getLQThumbnail() : String? {
|
fun getLQThumbnail() : String? {
|
||||||
return sources.firstOrNull()?.url;
|
return sources.firstOrNull()?.url;
|
||||||
}
|
}
|
||||||
|
fun getMinimumThumbnail(quality: Int): String? {
|
||||||
|
return sources.firstOrNull { it.quality >= quality }?.url ?: getHQThumbnail();
|
||||||
|
}
|
||||||
|
|
||||||
fun hasMultiple() = sources.size > 1;
|
fun hasMultiple() = sources.size > 1;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import com.futo.platformplayer.api.media.models.contents.ContentType
|
|||||||
interface IChapter {
|
interface IChapter {
|
||||||
val name: String;
|
val name: String;
|
||||||
val type: ChapterType;
|
val type: ChapterType;
|
||||||
val timeStart: Int;
|
val timeStart: Double;
|
||||||
val timeEnd: Int;
|
val timeEnd: Double;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ChapterType(val value: Int) {
|
enum class ChapterType(val value: Int) {
|
||||||
|
|||||||
+5
-6
@@ -4,10 +4,7 @@ import com.futo.platformplayer.api.media.IPlatformClient
|
|||||||
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
|
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
|
||||||
import com.futo.platformplayer.api.media.models.ratings.IRating
|
import com.futo.platformplayer.api.media.models.ratings.IRating
|
||||||
import com.futo.platformplayer.api.media.structures.IPager
|
import com.futo.platformplayer.api.media.structures.IPager
|
||||||
import com.futo.platformplayer.polycentric.PolycentricCache
|
|
||||||
import com.futo.platformplayer.states.StatePolycentric
|
|
||||||
import com.futo.polycentric.core.Pointer
|
import com.futo.polycentric.core.Pointer
|
||||||
import com.futo.polycentric.core.SignedEvent
|
|
||||||
import userpackage.Protocol.Reference
|
import userpackage.Protocol.Reference
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@@ -20,16 +17,18 @@ class PolycentricPlatformComment : IPlatformComment {
|
|||||||
|
|
||||||
override val replyCount: Int?;
|
override val replyCount: Int?;
|
||||||
|
|
||||||
|
val eventPointer: Pointer;
|
||||||
val reference: Reference;
|
val reference: Reference;
|
||||||
|
|
||||||
constructor(contextUrl: String, author: PlatformAuthorLink, msg: String, rating: IRating, date: OffsetDateTime, reference: Reference, replyCount: Int? = null) {
|
constructor(contextUrl: String, author: PlatformAuthorLink, msg: String, rating: IRating, date: OffsetDateTime, eventPointer: Pointer, replyCount: Int? = null) {
|
||||||
this.contextUrl = contextUrl;
|
this.contextUrl = contextUrl;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
this.rating = rating;
|
this.rating = rating;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.replyCount = replyCount;
|
this.replyCount = replyCount;
|
||||||
this.reference = reference;
|
this.eventPointer = eventPointer;
|
||||||
|
this.reference = eventPointer.toReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getReplies(client: IPlatformClient): IPager<IPlatformComment> {
|
override fun getReplies(client: IPlatformClient): IPager<IPlatformComment> {
|
||||||
@@ -37,7 +36,7 @@ class PolycentricPlatformComment : IPlatformComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun cloneWithUpdatedReplyCount(replyCount: Int?): PolycentricPlatformComment {
|
fun cloneWithUpdatedReplyCount(replyCount: Int?): PolycentricPlatformComment {
|
||||||
return PolycentricPlatformComment(contextUrl, author, message, rating, date, reference, replyCount);
|
return PolycentricPlatformComment(contextUrl, author, message, rating, date, eventPointer, replyCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ enum class ContentType(val value: Int) {
|
|||||||
|
|
||||||
NESTED_VIDEO(11),
|
NESTED_VIDEO(11),
|
||||||
|
|
||||||
|
LOCKED(70),
|
||||||
|
|
||||||
PLACEHOLDER(90),
|
PLACEHOLDER(90),
|
||||||
DEFERRED(91);
|
DEFERRED(91);
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.futo.platformplayer.api.media.models.locked
|
||||||
|
|
||||||
|
import com.futo.platformplayer.api.media.models.Thumbnails
|
||||||
|
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||||
|
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
||||||
|
|
||||||
|
interface IPlatformLockedContent: IPlatformContent {
|
||||||
|
val lockContentType: ContentType;
|
||||||
|
val lockDescription: String?;
|
||||||
|
val unlockUrl: String?;
|
||||||
|
val contentName: String?;
|
||||||
|
val contentThumbnails: Thumbnails;
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package com.futo.platformplayer.api.media.models.streams.sources
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import com.futo.platformplayer.api.media.models.subtitles.ISubtitleSource
|
||||||
|
|
||||||
|
class HLSVariantVideoUrlSource(
|
||||||
|
override val name: String,
|
||||||
|
override val width: Int,
|
||||||
|
override val height: Int,
|
||||||
|
override val container: String,
|
||||||
|
override val codec: String,
|
||||||
|
override val bitrate: Int?,
|
||||||
|
override val duration: Long,
|
||||||
|
override val priority: Boolean,
|
||||||
|
val url: String
|
||||||
|
) : IVideoUrlSource {
|
||||||
|
override fun getVideoUrl(): String {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class HLSVariantAudioUrlSource(
|
||||||
|
override val name: String,
|
||||||
|
override val bitrate: Int,
|
||||||
|
override val container: String,
|
||||||
|
override val codec: String,
|
||||||
|
override val language: String,
|
||||||
|
override val duration: Long?,
|
||||||
|
override val priority: Boolean,
|
||||||
|
val url: String
|
||||||
|
) : IAudioUrlSource {
|
||||||
|
override fun getAudioUrl(): String {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class HLSVariantSubtitleUrlSource(
|
||||||
|
override val name: String,
|
||||||
|
override val url: String,
|
||||||
|
override val format: String,
|
||||||
|
) : ISubtitleSource {
|
||||||
|
override val hasFetch: Boolean = false
|
||||||
|
|
||||||
|
override fun getSubtitles(): String? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun getSubtitlesURI(): Uri? {
|
||||||
|
return Uri.parse(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -2,12 +2,17 @@ package com.futo.platformplayer.api.media.models.video
|
|||||||
|
|
||||||
import com.futo.platformplayer.api.media.models.contents.ContentType
|
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||||
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
||||||
|
import com.futo.platformplayer.api.media.models.locked.IPlatformLockedContent
|
||||||
import com.futo.platformplayer.api.media.models.nested.IPlatformNestedContent
|
import com.futo.platformplayer.api.media.models.nested.IPlatformNestedContent
|
||||||
import com.futo.platformplayer.api.media.models.post.IPlatformPost
|
import com.futo.platformplayer.api.media.models.post.IPlatformPost
|
||||||
import com.futo.platformplayer.serializers.PlatformContentSerializer
|
import com.futo.platformplayer.serializers.PlatformContentSerializer
|
||||||
|
import kotlinx.serialization.EncodeDefault
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
|
||||||
@kotlinx.serialization.Serializable(with = PlatformContentSerializer::class)
|
@kotlinx.serialization.Serializable(with = PlatformContentSerializer::class)
|
||||||
interface SerializedPlatformContent: IPlatformContent {
|
interface SerializedPlatformContent: IPlatformContent {
|
||||||
|
override val contentType: ContentType;
|
||||||
|
|
||||||
fun toJson() : String;
|
fun toJson() : String;
|
||||||
fun fromJson(str : String) : SerializedPlatformContent;
|
fun fromJson(str : String) : SerializedPlatformContent;
|
||||||
fun fromJsonArray(str : String) : Array<SerializedPlatformContent>;
|
fun fromJsonArray(str : String) : Array<SerializedPlatformContent>;
|
||||||
@@ -18,6 +23,7 @@ interface SerializedPlatformContent: IPlatformContent {
|
|||||||
ContentType.MEDIA -> SerializedPlatformVideo.fromVideo(content as IPlatformVideo);
|
ContentType.MEDIA -> SerializedPlatformVideo.fromVideo(content as IPlatformVideo);
|
||||||
ContentType.NESTED_VIDEO -> SerializedPlatformNestedContent.fromNested(content as IPlatformNestedContent);
|
ContentType.NESTED_VIDEO -> SerializedPlatformNestedContent.fromNested(content as IPlatformNestedContent);
|
||||||
ContentType.POST -> SerializedPlatformPost.fromPost(content as IPlatformPost);
|
ContentType.POST -> SerializedPlatformPost.fromPost(content as IPlatformPost);
|
||||||
|
ContentType.LOCKED -> SerializedPlatformLockedContent.fromLocked(content as IPlatformLockedContent);
|
||||||
else -> throw NotImplementedError("Content type ${content.contentType} not implemented");
|
else -> throw NotImplementedError("Content type ${content.contentType} not implemented");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package com.futo.platformplayer.api.media.models.video
|
||||||
|
|
||||||
|
import com.futo.platformplayer.api.media.PlatformID
|
||||||
|
import com.futo.platformplayer.api.media.Serializer
|
||||||
|
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
|
||||||
|
import com.futo.platformplayer.api.media.models.Thumbnails
|
||||||
|
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||||
|
import com.futo.platformplayer.api.media.models.locked.IPlatformLockedContent
|
||||||
|
import com.futo.platformplayer.api.media.models.nested.IPlatformNestedContent
|
||||||
|
import com.futo.platformplayer.serializers.OffsetDateTimeNullableSerializer
|
||||||
|
import com.futo.platformplayer.states.StatePlatform
|
||||||
|
import com.futo.polycentric.core.combineHashCodes
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
|
@kotlinx.serialization.Serializable
|
||||||
|
open class SerializedPlatformLockedContent(
|
||||||
|
override val id: PlatformID,
|
||||||
|
override val name: String,
|
||||||
|
override val author: PlatformAuthorLink,
|
||||||
|
@kotlinx.serialization.Serializable(with = OffsetDateTimeNullableSerializer::class)
|
||||||
|
override val datetime: OffsetDateTime?,
|
||||||
|
override val url: String,
|
||||||
|
override val shareUrl: String,
|
||||||
|
override val lockContentType: ContentType,
|
||||||
|
override val contentName: String?,
|
||||||
|
override val lockDescription: String? = null,
|
||||||
|
override val unlockUrl: String? = null,
|
||||||
|
override val contentThumbnails: Thumbnails
|
||||||
|
) : IPlatformLockedContent, SerializedPlatformContent {
|
||||||
|
override val contentType: ContentType = ContentType.LOCKED;
|
||||||
|
|
||||||
|
override fun toJson() : String {
|
||||||
|
return Json.encodeToString(this);
|
||||||
|
}
|
||||||
|
override fun fromJson(str : String) : SerializedPlatformLockedContent {
|
||||||
|
return Serializer.json.decodeFromString<SerializedPlatformLockedContent>(str);
|
||||||
|
}
|
||||||
|
override fun fromJsonArray(str : String) : Array<SerializedPlatformContent> {
|
||||||
|
return Serializer.json.decodeFromString<Array<SerializedPlatformContent>>(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromLocked(content: IPlatformLockedContent) : SerializedPlatformLockedContent {
|
||||||
|
return SerializedPlatformLockedContent(
|
||||||
|
content.id,
|
||||||
|
content.name,
|
||||||
|
content.author,
|
||||||
|
content.datetime,
|
||||||
|
content.url,
|
||||||
|
content.shareUrl,
|
||||||
|
content.lockContentType,
|
||||||
|
content.contentName,
|
||||||
|
content.lockDescription,
|
||||||
|
content.unlockUrl,
|
||||||
|
content.contentThumbnails
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -30,7 +30,7 @@ open class SerializedPlatformNestedContent(
|
|||||||
override val contentProvider: String?,
|
override val contentProvider: String?,
|
||||||
override val contentThumbnails: Thumbnails
|
override val contentThumbnails: Thumbnails
|
||||||
) : IPlatformNestedContent, SerializedPlatformContent {
|
) : IPlatformNestedContent, SerializedPlatformContent {
|
||||||
final override val contentType: ContentType get() = ContentType.NESTED_VIDEO;
|
final override val contentType: ContentType = ContentType.NESTED_VIDEO;
|
||||||
|
|
||||||
override val contentPlugin: String? = StatePlatform.instance.getContentClientOrNull(contentUrl)?.id;
|
override val contentPlugin: String? = StatePlatform.instance.getContentClientOrNull(contentUrl)?.id;
|
||||||
override val contentSupported: Boolean get() = contentPlugin != null;
|
override val contentSupported: Boolean get() = contentPlugin != null;
|
||||||
|
|||||||
+2
-1
@@ -8,6 +8,7 @@ import com.futo.platformplayer.api.media.models.contents.ContentType
|
|||||||
import com.futo.platformplayer.api.media.models.post.IPlatformPost
|
import com.futo.platformplayer.api.media.models.post.IPlatformPost
|
||||||
import com.futo.platformplayer.serializers.OffsetDateTimeNullableSerializer
|
import com.futo.platformplayer.serializers.OffsetDateTimeNullableSerializer
|
||||||
import com.futo.polycentric.core.combineHashCodes
|
import com.futo.polycentric.core.combineHashCodes
|
||||||
|
import kotlinx.serialization.EncodeDefault
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
@@ -26,7 +27,7 @@ open class SerializedPlatformPost(
|
|||||||
override val thumbnails: List<Thumbnails?>,
|
override val thumbnails: List<Thumbnails?>,
|
||||||
override val images: List<String>
|
override val images: List<String>
|
||||||
) : IPlatformPost, SerializedPlatformContent {
|
) : IPlatformPost, SerializedPlatformContent {
|
||||||
final override val contentType: ContentType get() = ContentType.POST;
|
override val contentType: ContentType = ContentType.POST;
|
||||||
|
|
||||||
override fun toJson() : String {
|
override fun toJson() : String {
|
||||||
return Json.encodeToString(this);
|
return Json.encodeToString(this);
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ open class SerializedPlatformVideo(
|
|||||||
override val duration: Long,
|
override val duration: Long,
|
||||||
override val viewCount: Long,
|
override val viewCount: Long,
|
||||||
) : IPlatformVideo, SerializedPlatformContent {
|
) : IPlatformVideo, SerializedPlatformContent {
|
||||||
final override val contentType: ContentType get() = ContentType.MEDIA;
|
override val contentType: ContentType = ContentType.MEDIA;
|
||||||
|
|
||||||
override val isLive: Boolean = false;
|
override val isLive: Boolean = false;
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,19 @@ open class JSClient : IPlatformClient {
|
|||||||
val enableInSearch get() = descriptor.appSettings.tabEnabled.enableSearch ?: true
|
val enableInSearch get() = descriptor.appSettings.tabEnabled.enableSearch ?: true
|
||||||
val enableInHome get() = descriptor.appSettings.tabEnabled.enableHome ?: true
|
val enableInHome get() = descriptor.appSettings.tabEnabled.enableHome ?: true
|
||||||
|
|
||||||
|
fun getSubscriptionRateLimit(): Int? {
|
||||||
|
val pluginRateLimit = config.subscriptionRateLimit;
|
||||||
|
val settingsRateLimit = descriptor.appSettings.rateLimit.getSubRateLimit();
|
||||||
|
if(settingsRateLimit > 0) {
|
||||||
|
if(pluginRateLimit != null)
|
||||||
|
return settingsRateLimit.coerceAtMost(pluginRateLimit);
|
||||||
|
else
|
||||||
|
return settingsRateLimit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return pluginRateLimit;
|
||||||
|
}
|
||||||
|
|
||||||
val onDisabled = Event1<JSClient>();
|
val onDisabled = Event1<JSClient>();
|
||||||
val onCaptchaException = Event2<JSClient, ScriptCaptchaRequiredException>();
|
val onCaptchaException = Event2<JSClient, ScriptCaptchaRequiredException>();
|
||||||
|
|
||||||
@@ -571,7 +584,7 @@ open class JSClient : IPlatformClient {
|
|||||||
if(it.containsKey(claimType)) {
|
if(it.containsKey(claimType)) {
|
||||||
val templates = it[claimType];
|
val templates = it[claimType];
|
||||||
if(templates != null)
|
if(templates != null)
|
||||||
for(value in values.keys.sortedBy { it }) {
|
for(value in values.keys.sortedBy { if(it == config.primaryClaimFieldType) Int.MIN_VALUE else it }) {
|
||||||
if(templates.containsKey(value)) {
|
if(templates.containsKey(value)) {
|
||||||
return templates[value]!!.replace("{{CLAIMVALUE}}", values[value]!!);
|
return templates[value]!!.replace("{{CLAIMVALUE}}", values[value]!!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
package com.futo.platformplayer.api.media.platforms.js
|
package com.futo.platformplayer.api.media.platforms.js
|
||||||
|
|
||||||
import com.futo.platformplayer.encryption.EncryptionProvider
|
|
||||||
import com.futo.platformplayer.logging.Logger
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
|
||||||
data class SourceAuth(val cookieMap: HashMap<String, HashMap<String, String>>? = null, val headers: Map<String, Map<String, String>> = mapOf()) {
|
data class SourceAuth(val cookieMap: HashMap<String, HashMap<String, String>>? = null, val headers: Map<String, Map<String, String>> = mapOf()) {
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "(headers: '$headers', cookieString: '$cookieMap')";
|
return "(headers: '$headers', cookieString: '$cookieMap')";
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toEncrypted(): String{
|
fun toEncrypted(): String{
|
||||||
return EncryptionProvider.instance.encrypt(serialize());
|
return SourceEncrypted.fromDecrypted { serialize() }.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serialize(): String {
|
private fun serialize(): String {
|
||||||
@@ -25,20 +22,10 @@ data class SourceAuth(val cookieMap: HashMap<String, HashMap<String, String>>? =
|
|||||||
val TAG = "SourceAuth";
|
val TAG = "SourceAuth";
|
||||||
|
|
||||||
fun fromEncrypted(encrypted: String?): SourceAuth? {
|
fun fromEncrypted(encrypted: String?): SourceAuth? {
|
||||||
if(encrypted == null)
|
return SourceEncrypted.decryptEncrypted(encrypted) { deserialize(it) };
|
||||||
return null;
|
|
||||||
|
|
||||||
val decrypted = EncryptionProvider.instance.decrypt(encrypted);
|
|
||||||
try {
|
|
||||||
return deserialize(decrypted);
|
|
||||||
}
|
|
||||||
catch(ex: Throwable) {
|
|
||||||
Logger.e(TAG, "Failed to deserialize authentication", ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deserialize(str: String): SourceAuth {
|
private fun deserialize(str: String): SourceAuth {
|
||||||
val data = Json.decodeFromString<SerializedAuth>(str);
|
val data = Json.decodeFromString<SerializedAuth>(str);
|
||||||
return SourceAuth(data.cookieMap, data.headers);
|
return SourceAuth(data.cookieMap, data.headers);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-15
@@ -1,7 +1,5 @@
|
|||||||
package com.futo.platformplayer.api.media.platforms.js
|
package com.futo.platformplayer.api.media.platforms.js
|
||||||
|
|
||||||
import com.futo.platformplayer.encryption.EncryptionProvider
|
|
||||||
import com.futo.platformplayer.logging.Logger
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
@@ -13,7 +11,7 @@ data class SourceCaptchaData(val cookieMap: HashMap<String, HashMap<String, Stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun toEncrypted(): String{
|
fun toEncrypted(): String{
|
||||||
return EncryptionProvider.instance.encrypt(serialize());
|
return SourceEncrypted.fromDecrypted { serialize() }.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serialize(): String {
|
private fun serialize(): String {
|
||||||
@@ -21,20 +19,10 @@ data class SourceCaptchaData(val cookieMap: HashMap<String, HashMap<String, Stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val TAG = "SourceAuth";
|
val TAG = "SourceCaptchaData";
|
||||||
|
|
||||||
fun fromEncrypted(encrypted: String?): SourceCaptchaData? {
|
fun fromEncrypted(encrypted: String?): SourceCaptchaData? {
|
||||||
if(encrypted == null)
|
return SourceEncrypted.decryptEncrypted(encrypted) { deserialize(it) };
|
||||||
return null;
|
|
||||||
|
|
||||||
val decrypted = EncryptionProvider.instance.decrypt(encrypted);
|
|
||||||
try {
|
|
||||||
return deserialize(decrypted);
|
|
||||||
}
|
|
||||||
catch(ex: Throwable) {
|
|
||||||
Logger.e(TAG, "Failed to deserialize authentication", ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deserialize(str: String): SourceCaptchaData {
|
fun deserialize(str: String): SourceCaptchaData {
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.futo.platformplayer.api.media.platforms.js
|
||||||
|
|
||||||
|
import com.futo.platformplayer.encryption.GEncryptionProvider
|
||||||
|
import com.futo.platformplayer.encryption.GEncryptionProviderV0
|
||||||
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class SourceEncrypted(
|
||||||
|
val encrypted: String,
|
||||||
|
val version: Int = GEncryptionProvider.version
|
||||||
|
) {
|
||||||
|
fun toJson(): String {
|
||||||
|
return Json.encodeToString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromDecrypted(serializer: () -> String): SourceEncrypted {
|
||||||
|
return SourceEncrypted(GEncryptionProvider.instance.encrypt(serializer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> decryptEncrypted(encrypted: String?, deserializer: (decrypted: String) -> T): T? {
|
||||||
|
if(encrypted == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
val encryptedSourceAuth = Json.decodeFromString<SourceEncrypted>(encrypted)
|
||||||
|
if (encryptedSourceAuth.version != GEncryptionProvider.version) {
|
||||||
|
throw Exception("Invalid encryption version.");
|
||||||
|
}
|
||||||
|
|
||||||
|
val decrypted = GEncryptionProvider.instance.decrypt(encryptedSourceAuth.encrypted);
|
||||||
|
try {
|
||||||
|
return deserializer(decrypted);
|
||||||
|
} catch(ex: Throwable) {
|
||||||
|
Logger.e(SourceAuth.TAG, "Failed to deserialize SourceEncrypted<T>", ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
//Try to fall back to old mechanism, remove this eventually
|
||||||
|
if (!encrypted.contains("version")) {
|
||||||
|
val decrypted = GEncryptionProviderV0.instance.decrypt(encrypted);
|
||||||
|
try {
|
||||||
|
return deserializer(decrypted);
|
||||||
|
} catch (ex: Throwable) {
|
||||||
|
Logger.e(SourceAuth.TAG, "Failed to deserialize SourceEncrypted<T>", ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-2
@@ -41,10 +41,12 @@ class SourcePluginConfig(
|
|||||||
val constants: HashMap<String, String> = hashMapOf(),
|
val constants: HashMap<String, String> = hashMapOf(),
|
||||||
|
|
||||||
//TODO: These should be vals...but prob for serialization reasons cannot be changed.
|
//TODO: These should be vals...but prob for serialization reasons cannot be changed.
|
||||||
|
var platformUrl: String? = null,
|
||||||
var subscriptionRateLimit: Int? = null,
|
var subscriptionRateLimit: Int? = null,
|
||||||
var enableInSearch: Boolean = true,
|
var enableInSearch: Boolean = true,
|
||||||
var enableInHome: Boolean = true,
|
var enableInHome: Boolean = true,
|
||||||
var supportedClaimTypes: List<Int> = listOf()
|
var supportedClaimTypes: List<Int> = listOf(),
|
||||||
|
var primaryClaimFieldType: Int? = null
|
||||||
) : IV8PluginConfig {
|
) : IV8PluginConfig {
|
||||||
|
|
||||||
val absoluteIconUrl: String? get() = resolveAbsoluteUrl(iconUrl, sourceUrl);
|
val absoluteIconUrl: String? get() = resolveAbsoluteUrl(iconUrl, sourceUrl);
|
||||||
@@ -142,7 +144,10 @@ class SourcePluginConfig(
|
|||||||
val description: String,
|
val description: String,
|
||||||
val type: String,
|
val type: String,
|
||||||
val default: String? = null,
|
val default: String? = null,
|
||||||
val variable: String? = null
|
val variable: String? = null,
|
||||||
|
val dependency: String? = null,
|
||||||
|
val warningDialog: String? = null,
|
||||||
|
val options: List<String>? = null
|
||||||
) {
|
) {
|
||||||
@kotlinx.serialization.Transient
|
@kotlinx.serialization.Transient
|
||||||
val variableOrName: String get() = variable ?: name;
|
val variableOrName: String get() = variable ?: name;
|
||||||
|
|||||||
+24
@@ -3,6 +3,7 @@ package com.futo.platformplayer.api.media.platforms.js
|
|||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.constructs.Event0
|
import com.futo.platformplayer.constructs.Event0
|
||||||
import com.futo.platformplayer.serializers.FlexibleBooleanSerializer
|
import com.futo.platformplayer.serializers.FlexibleBooleanSerializer
|
||||||
|
import com.futo.platformplayer.views.fields.DropdownFieldOptions
|
||||||
import com.futo.platformplayer.views.fields.FieldForm
|
import com.futo.platformplayer.views.fields.FieldForm
|
||||||
import com.futo.platformplayer.views.fields.FormField
|
import com.futo.platformplayer.views.fields.FormField
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@@ -79,6 +80,29 @@ class SourcePluginDescriptor {
|
|||||||
var enableSearch: Boolean? = null;
|
var enableSearch: Boolean? = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FormField(R.string.ratelimit, "group", R.string.ratelimit_description, 3)
|
||||||
|
var rateLimit = RateLimit();
|
||||||
|
@Serializable
|
||||||
|
class RateLimit {
|
||||||
|
@FormField(R.string.subscriptions, FieldForm.DROPDOWN, R.string.ratelimit_sub_setting_description, 1)
|
||||||
|
@DropdownFieldOptions("Plugin defined", "25", "50", "75", "100", "125", "150", "200")
|
||||||
|
var rateLimitSubs: Int = 0;
|
||||||
|
|
||||||
|
fun getSubRateLimit(): Int {
|
||||||
|
return when(rateLimitSubs) {
|
||||||
|
0 -> -1
|
||||||
|
1 -> 25
|
||||||
|
2 -> 50
|
||||||
|
3 -> 75
|
||||||
|
4 -> 100
|
||||||
|
5 -> 125
|
||||||
|
6 -> 150
|
||||||
|
7 -> 200
|
||||||
|
else -> -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun loadDefaults(config: SourcePluginConfig) {
|
fun loadDefaults(config: SourcePluginConfig) {
|
||||||
|
|||||||
+10
-2
@@ -6,10 +6,13 @@ import com.futo.platformplayer.api.http.ManagedHttpClient
|
|||||||
import com.futo.platformplayer.api.media.platforms.js.JSClient
|
import com.futo.platformplayer.api.media.platforms.js.JSClient
|
||||||
import com.futo.platformplayer.api.media.platforms.js.SourceAuth
|
import com.futo.platformplayer.api.media.platforms.js.SourceAuth
|
||||||
import com.futo.platformplayer.api.media.platforms.js.SourceCaptchaData
|
import com.futo.platformplayer.api.media.platforms.js.SourceCaptchaData
|
||||||
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||||
|
import com.futo.platformplayer.engine.exceptions.ScriptImplementationException
|
||||||
import com.futo.platformplayer.matchesDomain
|
import com.futo.platformplayer.matchesDomain
|
||||||
|
|
||||||
class JSHttpClient : ManagedHttpClient {
|
class JSHttpClient : ManagedHttpClient {
|
||||||
private val _jsClient: JSClient?;
|
private val _jsClient: JSClient?;
|
||||||
|
private val _jsConfig: SourcePluginConfig?;
|
||||||
private val _auth: SourceAuth?;
|
private val _auth: SourceAuth?;
|
||||||
private val _captcha: SourceCaptchaData?;
|
private val _captcha: SourceCaptchaData?;
|
||||||
|
|
||||||
@@ -20,8 +23,9 @@ class JSHttpClient : ManagedHttpClient {
|
|||||||
|
|
||||||
private var _currentCookieMap: HashMap<String, HashMap<String, String>>;
|
private var _currentCookieMap: HashMap<String, HashMap<String, String>>;
|
||||||
|
|
||||||
constructor(jsClient: JSClient?, auth: SourceAuth? = null, captcha: SourceCaptchaData? = null) : super() {
|
constructor(jsClient: JSClient?, auth: SourceAuth? = null, captcha: SourceCaptchaData? = null, config: SourcePluginConfig? = null) : super() {
|
||||||
_jsClient = jsClient;
|
_jsClient = jsClient;
|
||||||
|
_jsConfig = config;
|
||||||
_auth = auth;
|
_auth = auth;
|
||||||
_captcha = captcha;
|
_captcha = captcha;
|
||||||
|
|
||||||
@@ -87,7 +91,11 @@ class JSHttpClient : ManagedHttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_jsClient?.validateUrlOrThrow(request.url.toString());
|
if(_jsClient != null)
|
||||||
|
_jsClient?.validateUrlOrThrow(request.url.toString());
|
||||||
|
else if (_jsConfig != null && !_jsConfig.isUrlAllowed(request.url.toString()))
|
||||||
|
throw ScriptImplementationException(_jsConfig, "Attempted to access non-whitelisted url: ${request.url.toString()}\nAdd it to your config");
|
||||||
|
|
||||||
return newBuilder?.let { it.build() } ?: request;
|
return newBuilder?.let { it.build() } ?: request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ interface IJSContent: IPlatformContent {
|
|||||||
ContentType.POST -> JSPost(config, obj);
|
ContentType.POST -> JSPost(config, obj);
|
||||||
ContentType.NESTED_VIDEO -> JSNestedMediaContent(config, obj);
|
ContentType.NESTED_VIDEO -> JSNestedMediaContent(config, obj);
|
||||||
ContentType.PLAYLIST -> JSPlaylist(config, obj);
|
ContentType.PLAYLIST -> JSPlaylist(config, obj);
|
||||||
|
ContentType.LOCKED -> JSLockedContent(config, obj);
|
||||||
else -> throw NotImplementedError("Unknown content type ${type}");
|
else -> throw NotImplementedError("Unknown content type ${type}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -12,10 +12,10 @@ import com.futo.platformplayer.getOrThrow
|
|||||||
class JSChapter : IChapter {
|
class JSChapter : IChapter {
|
||||||
override val name: String;
|
override val name: String;
|
||||||
override val type: ChapterType;
|
override val type: ChapterType;
|
||||||
override val timeStart: Int;
|
override val timeStart: Double;
|
||||||
override val timeEnd: Int;
|
override val timeEnd: Double;
|
||||||
|
|
||||||
constructor(name: String, timeStart: Int, timeEnd: Int, type: ChapterType = ChapterType.NORMAL) {
|
constructor(name: String, timeStart: Double, timeEnd: Double, type: ChapterType = ChapterType.NORMAL) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.timeStart = timeStart;
|
this.timeStart = timeStart;
|
||||||
this.timeEnd = timeEnd;
|
this.timeEnd = timeEnd;
|
||||||
@@ -29,8 +29,8 @@ class JSChapter : IChapter {
|
|||||||
|
|
||||||
val name = obj.getOrThrow<String>(config,"name", context);
|
val name = obj.getOrThrow<String>(config,"name", context);
|
||||||
val type = ChapterType.fromInt(obj.getOrDefault<Int>(config, "type", context, ChapterType.NORMAL.value) ?: ChapterType.NORMAL.value);
|
val type = ChapterType.fromInt(obj.getOrDefault<Int>(config, "type", context, ChapterType.NORMAL.value) ?: ChapterType.NORMAL.value);
|
||||||
val timeStart = obj.getOrThrow<Int>(config, "timeStart", context);
|
val timeStart = obj.getOrThrow<Double>(config, "timeStart", context);
|
||||||
val timeEnd = obj.getOrThrow<Int>(config, "timeEnd", context);
|
val timeEnd = obj.getOrThrow<Double>(config, "timeEnd", context);
|
||||||
|
|
||||||
return JSChapter(name, timeStart, timeEnd, type);
|
return JSChapter(name, timeStart, timeEnd, type);
|
||||||
}
|
}
|
||||||
|
|||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package com.futo.platformplayer.api.media.platforms.js.models
|
||||||
|
|
||||||
|
import com.caoccao.javet.values.reference.V8ValueObject
|
||||||
|
import com.futo.platformplayer.api.media.models.Thumbnails
|
||||||
|
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||||
|
import com.futo.platformplayer.api.media.models.locked.IPlatformLockedContent
|
||||||
|
import com.futo.platformplayer.api.media.models.nested.IPlatformNestedContent
|
||||||
|
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||||
|
import com.futo.platformplayer.getOrDefault
|
||||||
|
import com.futo.platformplayer.getOrThrow
|
||||||
|
import com.futo.platformplayer.states.StatePlatform
|
||||||
|
|
||||||
|
//TODO: Refactor into video-only
|
||||||
|
class JSLockedContent: IPlatformLockedContent, JSContent {
|
||||||
|
|
||||||
|
override val contentType: ContentType get() = ContentType.LOCKED;
|
||||||
|
override val lockContentType: ContentType get() = ContentType.MEDIA;
|
||||||
|
|
||||||
|
override val lockDescription: String?;
|
||||||
|
override val unlockUrl: String?;
|
||||||
|
|
||||||
|
override val contentName: String?;
|
||||||
|
override val contentThumbnails: Thumbnails;
|
||||||
|
|
||||||
|
constructor(config: SourcePluginConfig, obj: V8ValueObject): super(config, obj) {
|
||||||
|
val contextName = "PlatformLockedContent";
|
||||||
|
|
||||||
|
this.contentName = obj.getOrDefault(config, "contentName", contextName, null);
|
||||||
|
this.contentThumbnails = obj.getOrDefault<V8ValueObject?>(config, "contentThumbnails", contextName, null)?.let {
|
||||||
|
return@let Thumbnails.fromV8(config, it);
|
||||||
|
} ?: Thumbnails();
|
||||||
|
|
||||||
|
lockDescription = obj.getOrDefault(config, "lockDescription", contextName, null);
|
||||||
|
unlockUrl = obj.getOrDefault(config, "unlockUrl", contextName, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,8 +59,6 @@ abstract class JSPager<T> : IPager<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getResults(): List<T> {
|
override fun getResults(): List<T> {
|
||||||
warnIfMainThread("JSPager.getResults");
|
|
||||||
|
|
||||||
val previousResults = _lastResults?.let {
|
val previousResults = _lastResults?.let {
|
||||||
if(!_resultChanged)
|
if(!_resultChanged)
|
||||||
return@let it;
|
return@let it;
|
||||||
@@ -70,6 +68,7 @@ abstract class JSPager<T> : IPager<T> {
|
|||||||
if(previousResults != null)
|
if(previousResults != null)
|
||||||
return previousResults;
|
return previousResults;
|
||||||
|
|
||||||
|
warnIfMainThread("JSPager.getResults");
|
||||||
val items = pager.getOrThrow<V8ValueArray>(config, "results", "JSPager");
|
val items = pager.getOrThrow<V8ValueArray>(config, "results", "JSPager");
|
||||||
val newResults = items.toArray()
|
val newResults = items.toArray()
|
||||||
.map { convertResult(it as V8ValueObject) }
|
.map { convertResult(it as V8ValueObject) }
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.futo.platformplayer.api.media.structures
|
||||||
|
|
||||||
|
class AdhocPager<T>: IPager<T> {
|
||||||
|
private var _page = 0;
|
||||||
|
private val _nextPage: (Int) -> List<T>;
|
||||||
|
private var _currentResults: List<T> = listOf();
|
||||||
|
private var _hasMore = true;
|
||||||
|
|
||||||
|
constructor(nextPage: (Int) -> List<T>, initialResults: List<T>? = null){
|
||||||
|
_nextPage = nextPage;
|
||||||
|
if(initialResults != null)
|
||||||
|
_currentResults = initialResults;
|
||||||
|
else
|
||||||
|
nextPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hasMorePages(): Boolean {
|
||||||
|
return _hasMore;
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun nextPage() {
|
||||||
|
val newResults = _nextPage(++_page);
|
||||||
|
if(newResults.isEmpty())
|
||||||
|
_hasMore = false;
|
||||||
|
_currentResults = newResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getResults(): List<T> {
|
||||||
|
return _currentResults;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,7 +52,7 @@ class DedupContentPager : IPager<IPlatformContent>, IAsyncPager<IPlatformContent
|
|||||||
val sameItems = results.filter { isSameItem(result, it) };
|
val sameItems = results.filter { isSameItem(result, it) };
|
||||||
val platformItemMap = sameItems.groupBy { it.id.pluginId }.mapValues { (_, items) -> items.first() }
|
val platformItemMap = sameItems.groupBy { it.id.pluginId }.mapValues { (_, items) -> items.first() }
|
||||||
val bestPlatform = _preferredPlatform.map { it.lowercase() }.firstOrNull { platformItemMap.containsKey(it) }
|
val bestPlatform = _preferredPlatform.map { it.lowercase() }.firstOrNull { platformItemMap.containsKey(it) }
|
||||||
val bestItem = platformItemMap[bestPlatform] ?: sameItems.first()
|
val bestItem = platformItemMap[bestPlatform] ?: sameItems.firstOrNull();
|
||||||
|
|
||||||
resultsToRemove.addAll(sameItems.filter { it != bestItem });
|
resultsToRemove.addAll(sameItems.filter { it != bestItem });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,13 @@ import android.app.PendingIntent
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.media.MediaSession2Service.MediaNotification
|
|
||||||
import androidx.concurrent.futures.CallbackToFutureAdapter
|
|
||||||
import androidx.concurrent.futures.ResolvableFuture
|
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.work.CoroutineWorker
|
import androidx.work.CoroutineWorker
|
||||||
import androidx.work.ListenableWorker
|
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.request.target.CustomTarget
|
import com.bumptech.glide.request.target.CustomTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
|
import com.futo.platformplayer.Settings
|
||||||
import com.futo.platformplayer.activities.MainActivity
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
||||||
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
||||||
@@ -23,15 +20,11 @@ import com.futo.platformplayer.getNowDiffSeconds
|
|||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.models.Subscription
|
import com.futo.platformplayer.models.Subscription
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.states.StatePlatform
|
import com.futo.platformplayer.states.StateNotifications
|
||||||
import com.futo.platformplayer.states.StateSubscriptions
|
import com.futo.platformplayer.states.StateSubscriptions
|
||||||
import com.futo.platformplayer.views.adapters.viewholders.TabViewHolder
|
import com.futo.platformplayer.toHumanNowDiffString
|
||||||
import com.google.common.util.concurrent.ListenableFuture
|
import com.futo.platformplayer.toHumanNowDiffStringMinDay
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@@ -53,8 +46,10 @@ class BackgroundWorker(private val appContext: Context, private val workerParams
|
|||||||
this.setSound(null, null);
|
this.setSound(null, null);
|
||||||
};
|
};
|
||||||
notificationManager.createNotificationChannel(notificationChannel);
|
notificationManager.createNotificationChannel(notificationChannel);
|
||||||
|
val contentChannel = StateNotifications.instance.contentNotifChannel
|
||||||
|
notificationManager.createNotificationChannel(contentChannel);
|
||||||
try {
|
try {
|
||||||
doSubscriptionUpdating(notificationManager, notificationChannel);
|
doSubscriptionUpdating(notificationManager, notificationChannel, contentChannel);
|
||||||
}
|
}
|
||||||
catch(ex: Throwable) {
|
catch(ex: Throwable) {
|
||||||
exception = ex;
|
exception = ex;
|
||||||
@@ -76,13 +71,13 @@ class BackgroundWorker(private val appContext: Context, private val workerParams
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
suspend fun doSubscriptionUpdating(manager: NotificationManager, notificationChannel: NotificationChannel) {
|
suspend fun doSubscriptionUpdating(manager: NotificationManager, backgroundChannel: NotificationChannel, contentChannel: NotificationChannel) {
|
||||||
val notif = NotificationCompat.Builder(appContext, notificationChannel.id)
|
val notif = NotificationCompat.Builder(appContext, backgroundChannel.id)
|
||||||
.setSmallIcon(com.futo.platformplayer.R.drawable.foreground)
|
.setSmallIcon(com.futo.platformplayer.R.drawable.foreground)
|
||||||
.setContentTitle("Grayjay")
|
.setContentTitle("Grayjay")
|
||||||
.setContentText("Updating subscriptions...")
|
.setContentText("Updating subscriptions...")
|
||||||
.setSilent(true)
|
.setSilent(true)
|
||||||
.setChannelId(notificationChannel.id)
|
.setChannelId(backgroundChannel.id)
|
||||||
.setProgress(1, 0, true);
|
.setProgress(1, 0, true);
|
||||||
|
|
||||||
manager.notify(12, notif.build());
|
manager.notify(12, notif.build());
|
||||||
@@ -93,6 +88,7 @@ class BackgroundWorker(private val appContext: Context, private val workerParams
|
|||||||
val newItems = mutableListOf<IPlatformContent>();
|
val newItems = mutableListOf<IPlatformContent>();
|
||||||
|
|
||||||
val now = OffsetDateTime.now();
|
val now = OffsetDateTime.now();
|
||||||
|
val threeDays = now.minusDays(4);
|
||||||
val contentNotifs = mutableListOf<Pair<Subscription, IPlatformContent>>();
|
val contentNotifs = mutableListOf<Pair<Subscription, IPlatformContent>>();
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val results = StateSubscriptions.instance.getSubscriptionsFeedWithExceptions(true, false,this, { progress, total ->
|
val results = StateSubscriptions.instance.getSubscriptionsFeedWithExceptions(true, false,this, { progress, total ->
|
||||||
@@ -110,8 +106,14 @@ class BackgroundWorker(private val appContext: Context, private val workerParams
|
|||||||
synchronized(newSubChanges) {
|
synchronized(newSubChanges) {
|
||||||
if(!newSubChanges.contains(sub)) {
|
if(!newSubChanges.contains(sub)) {
|
||||||
newSubChanges.add(sub);
|
newSubChanges.add(sub);
|
||||||
if(sub.doNotifications && content.datetime?.let { it < now } == true)
|
if(sub.doNotifications) {
|
||||||
contentNotifs.add(Pair(sub, content));
|
if(content.datetime != null) {
|
||||||
|
if(content.datetime!! <= now.plusMinutes(StateNotifications.instance.plannedWarningMinutesEarly) && content.datetime!! > threeDays)
|
||||||
|
contentNotifs.add(Pair(sub, content));
|
||||||
|
else if(content.datetime!! > now.plusMinutes(StateNotifications.instance.plannedWarningMinutesEarly) && Settings.instance.notifications.plannedContentNotification)
|
||||||
|
StateNotifications.instance.scheduleContentNotification(applicationContext, content);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newItems.add(content);
|
newItems.add(content);
|
||||||
}
|
}
|
||||||
@@ -120,7 +122,7 @@ class BackgroundWorker(private val appContext: Context, private val workerParams
|
|||||||
//Only for testing notifications
|
//Only for testing notifications
|
||||||
val testNotifs = 0;
|
val testNotifs = 0;
|
||||||
if(contentNotifs.size == 0 && testNotifs > 0) {
|
if(contentNotifs.size == 0 && testNotifs > 0) {
|
||||||
results.first.getResults().filter { it is IPlatformVideo && it.datetime?.let { it < now } == true }
|
results.first.getResults().filter { it is IPlatformVideo }
|
||||||
.take(testNotifs).forEach {
|
.take(testNotifs).forEach {
|
||||||
contentNotifs.add(Pair(StateSubscriptions.instance.getSubscriptions().first(), it));
|
contentNotifs.add(Pair(StateSubscriptions.instance.getSubscriptions().first(), it));
|
||||||
}
|
}
|
||||||
@@ -134,22 +136,7 @@ class BackgroundWorker(private val appContext: Context, private val workerParams
|
|||||||
val items = contentNotifs.take(5).toList()
|
val items = contentNotifs.take(5).toList()
|
||||||
for(i in items.indices) {
|
for(i in items.indices) {
|
||||||
val contentNotif = items.get(i);
|
val contentNotif = items.get(i);
|
||||||
val thumbnail = if(contentNotif.second is IPlatformVideo) (contentNotif.second as IPlatformVideo).thumbnails.getHQThumbnail()
|
StateNotifications.instance.notifyNewContentWithThumbnail(appContext, manager, contentChannel, 13 + i, contentNotif.second);
|
||||||
else null;
|
|
||||||
if(thumbnail != null)
|
|
||||||
Glide.with(appContext).asBitmap()
|
|
||||||
.load(thumbnail)
|
|
||||||
.into(object: CustomTarget<Bitmap>() {
|
|
||||||
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
|
|
||||||
notifyNewContent(manager, notificationChannel, 13 + i, contentNotif.first, contentNotif.second, resource);
|
|
||||||
}
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {}
|
|
||||||
override fun onLoadFailed(errorDrawable: Drawable?) {
|
|
||||||
notifyNewContent(manager, notificationChannel, 13 + i, contentNotif.first, contentNotif.second, null);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
else
|
|
||||||
notifyNewContent(manager, notificationChannel, 13 + i, contentNotif.first, contentNotif.second, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(ex: Throwable) {
|
catch(ex: Throwable) {
|
||||||
@@ -164,20 +151,4 @@ class BackgroundWorker(private val appContext: Context, private val workerParams
|
|||||||
.setSilent(true)
|
.setSilent(true)
|
||||||
.setChannelId(notificationChannel.id).build());*/
|
.setChannelId(notificationChannel.id).build());*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fun notifyNewContent(manager: NotificationManager, notificationChannel: NotificationChannel, id: Int, sub: Subscription, content: IPlatformContent, thumbnail: Bitmap? = null) {
|
|
||||||
val notifBuilder = NotificationCompat.Builder(appContext, notificationChannel.id)
|
|
||||||
.setSmallIcon(com.futo.platformplayer.R.drawable.foreground)
|
|
||||||
.setContentTitle("New by [${sub.channel.name}]")
|
|
||||||
.setContentText("${content.name}")
|
|
||||||
.setSilent(true)
|
|
||||||
.setContentIntent(PendingIntent.getActivity(this.appContext, 0, MainActivity.getVideoIntent(this.appContext, content.url),
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE))
|
|
||||||
.setChannelId(notificationChannel.id);
|
|
||||||
if(thumbnail != null) {
|
|
||||||
//notifBuilder.setLargeIcon(thumbnail);
|
|
||||||
notifBuilder.setStyle(NotificationCompat.BigPictureStyle().bigPicture(thumbnail).bigLargeIcon(null as Bitmap?));
|
|
||||||
}
|
|
||||||
manager.notify(id, notifBuilder.build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package com.futo.platformplayer.builders
|
|
||||||
|
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.IAudioSource
|
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.IVideoSource
|
|
||||||
import com.futo.platformplayer.api.media.models.subtitles.ISubtitleSource
|
|
||||||
import java.io.PrintWriter
|
|
||||||
import java.io.StringWriter
|
|
||||||
|
|
||||||
class HlsBuilder {
|
|
||||||
companion object{
|
|
||||||
fun generateOnDemandHLS(vidSource: IVideoSource, vidUrl: String, audioSource: IAudioSource?, audioUrl: String?, subtitleSource: ISubtitleSource?, subtitleUrl: String?): String {
|
|
||||||
val hlsBuilder = StringWriter()
|
|
||||||
PrintWriter(hlsBuilder).use { writer ->
|
|
||||||
writer.println("#EXTM3U")
|
|
||||||
|
|
||||||
// Audio
|
|
||||||
if (audioSource != null && audioUrl != null) {
|
|
||||||
val audioFormat = audioSource.container.substringAfter("/")
|
|
||||||
writer.println("#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audio\",LANGUAGE=\"en\",NAME=\"English\",AUTOSELECT=YES,DEFAULT=YES,URI=\"${audioUrl.replace("&", "&")}\",FORMAT=\"$audioFormat\"")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subtitles
|
|
||||||
if (subtitleSource != null && subtitleUrl != null) {
|
|
||||||
val subtitleFormat = subtitleSource.format ?: "text/vtt"
|
|
||||||
writer.println("#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",LANGUAGE=\"en\",NAME=\"English\",AUTOSELECT=YES,DEFAULT=YES,URI=\"${subtitleUrl.replace("&", "&")}\",FORMAT=\"$subtitleFormat\"")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Video
|
|
||||||
val videoFormat = vidSource.container.substringAfter("/")
|
|
||||||
writer.println("#EXT-X-STREAM-INF:BANDWIDTH=100000,CODECS=\"${vidSource.codec}\",RESOLUTION=${vidSource.width}x${vidSource.height}${if (audioSource != null) ",AUDIO=\"audio\"" else ""}${if (subtitleSource != null) ",SUBTITLES=\"subs\"" else ""},FORMAT=\"$videoFormat\"")
|
|
||||||
writer.println(vidUrl.replace("&", "&"))
|
|
||||||
}
|
|
||||||
|
|
||||||
return hlsBuilder.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
package com.futo.platformplayer.cache
|
|
||||||
|
|
||||||
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
|
||||||
import com.futo.platformplayer.api.media.models.video.SerializedPlatformContent
|
|
||||||
import com.futo.platformplayer.api.media.structures.DedupContentPager
|
|
||||||
import com.futo.platformplayer.api.media.structures.IPager
|
|
||||||
import com.futo.platformplayer.api.media.structures.PlatformContentPager
|
|
||||||
import com.futo.platformplayer.logging.Logger
|
|
||||||
import com.futo.platformplayer.polycentric.PolycentricCache
|
|
||||||
import com.futo.platformplayer.resolveChannelUrl
|
|
||||||
import com.futo.platformplayer.serializers.PlatformContentSerializer
|
|
||||||
import com.futo.platformplayer.states.StatePlatform
|
|
||||||
import com.futo.platformplayer.states.StateSubscriptions
|
|
||||||
import com.futo.platformplayer.stores.FragmentedStorage
|
|
||||||
import com.futo.platformplayer.stores.v2.ManagedStore
|
|
||||||
import com.futo.platformplayer.toSafeFileName
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.time.OffsetDateTime
|
|
||||||
import kotlin.streams.toList
|
|
||||||
import kotlin.system.measureTimeMillis
|
|
||||||
|
|
||||||
class ChannelContentCache {
|
|
||||||
private val _targetCacheSize = 3000;
|
|
||||||
val _channelCacheDir = FragmentedStorage.getOrCreateDirectory("channelCache");
|
|
||||||
val _channelContents: HashMap<String, ManagedStore<SerializedPlatformContent>>;
|
|
||||||
init {
|
|
||||||
val allFiles = _channelCacheDir.listFiles() ?: arrayOf();
|
|
||||||
val initializeTime = measureTimeMillis {
|
|
||||||
_channelContents = HashMap(allFiles
|
|
||||||
.filter { it.isDirectory }
|
|
||||||
.parallelStream().map {
|
|
||||||
Pair(it.name, FragmentedStorage.storeJson(_channelCacheDir, it.name, PlatformContentSerializer())
|
|
||||||
.withoutBackup()
|
|
||||||
.load())
|
|
||||||
}.toList().associate { it })
|
|
||||||
}
|
|
||||||
val minDays = OffsetDateTime.now().minusDays(10);
|
|
||||||
val totalItems = _channelContents.map { it.value.count() }.sum();
|
|
||||||
val toTrim = totalItems - _targetCacheSize;
|
|
||||||
val trimmed: Int;
|
|
||||||
if(toTrim > 0) {
|
|
||||||
val redundantContent = _channelContents.flatMap { it.value.getItems().filter { it.datetime != null && it.datetime!!.isBefore(minDays) }.drop(9) }
|
|
||||||
.sortedBy { it.datetime!! }.take(toTrim);
|
|
||||||
for(content in redundantContent)
|
|
||||||
uncacheContent(content);
|
|
||||||
trimmed = redundantContent.size;
|
|
||||||
}
|
|
||||||
else trimmed = 0;
|
|
||||||
Logger.i(TAG, "ChannelContentCache time: ${initializeTime}ms channels: ${allFiles.size}, videos: ${totalItems}, trimmed: ${trimmed}, total: ${totalItems - trimmed}");
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getChannelCachePager(channelUrl: String): PlatformContentPager {
|
|
||||||
val validID = channelUrl.toSafeFileName();
|
|
||||||
|
|
||||||
val validStores = _channelContents
|
|
||||||
.filter { it.key == validID }
|
|
||||||
.map { it.value };
|
|
||||||
|
|
||||||
val items = validStores.flatMap { it.getItems() }
|
|
||||||
.sortedByDescending { it.datetime };
|
|
||||||
return PlatformContentPager(items, Math.min(150, items.size));
|
|
||||||
}
|
|
||||||
fun getSubscriptionCachePager(): DedupContentPager {
|
|
||||||
Logger.i(TAG, "Subscriptions CachePager get subscriptions");
|
|
||||||
val subs = StateSubscriptions.instance.getSubscriptions();
|
|
||||||
Logger.i(TAG, "Subscriptions CachePager polycentric urls");
|
|
||||||
val allUrls = subs.map {
|
|
||||||
val otherUrls = PolycentricCache.instance.getCachedProfile(it.channel.url)?.profile?.ownedClaims?.mapNotNull { c -> c.claim.resolveChannelUrl() } ?: listOf();
|
|
||||||
if(!otherUrls.contains(it.channel.url))
|
|
||||||
return@map listOf(listOf(it.channel.url), otherUrls).flatten();
|
|
||||||
else
|
|
||||||
return@map otherUrls;
|
|
||||||
}.flatten().distinct();
|
|
||||||
Logger.i(TAG, "Subscriptions CachePager compiling");
|
|
||||||
val validSubIds = allUrls.map { it.toSafeFileName() }.toHashSet();
|
|
||||||
|
|
||||||
val validStores = _channelContents
|
|
||||||
.filter { validSubIds.contains(it.key) }
|
|
||||||
.map { it.value };
|
|
||||||
|
|
||||||
val items = validStores.flatMap { it.getItems() }
|
|
||||||
.sortedByDescending { it.datetime };
|
|
||||||
|
|
||||||
return DedupContentPager(PlatformContentPager(items, Math.min(150, items.size)), StatePlatform.instance.getEnabledClients().map { it.id });
|
|
||||||
}
|
|
||||||
|
|
||||||
fun uncacheContent(content: SerializedPlatformContent) {
|
|
||||||
val store = getContentStore(content);
|
|
||||||
store?.delete(content);
|
|
||||||
}
|
|
||||||
fun cacheContents(contents: List<IPlatformContent>): List<IPlatformContent> {
|
|
||||||
return contents.filter { cacheContent(it) };
|
|
||||||
}
|
|
||||||
fun cacheContent(content: IPlatformContent, doUpdate: Boolean = false): Boolean {
|
|
||||||
if(content.author.url.isEmpty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
val channelId = content.author.url.toSafeFileName();
|
|
||||||
val store = getContentStore(channelId).let {
|
|
||||||
if(it == null) {
|
|
||||||
Logger.i(TAG, "New Channel Cache for channel ${content.author.name}");
|
|
||||||
val store = FragmentedStorage.storeJson<SerializedPlatformContent>(_channelCacheDir, channelId, PlatformContentSerializer()).load();
|
|
||||||
_channelContents.put(channelId, store);
|
|
||||||
return@let store;
|
|
||||||
}
|
|
||||||
else return@let it;
|
|
||||||
}
|
|
||||||
val serialized = SerializedPlatformContent.fromContent(content);
|
|
||||||
val existing = store.findItems { it.url == content.url };
|
|
||||||
|
|
||||||
if(existing.isEmpty() || doUpdate) {
|
|
||||||
if(existing.isNotEmpty())
|
|
||||||
existing.forEach { store.delete(it) };
|
|
||||||
|
|
||||||
store.save(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
return existing.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getContentStore(content: IPlatformContent): ManagedStore<SerializedPlatformContent>? {
|
|
||||||
val channelId = content.author.url.toSafeFileName();
|
|
||||||
return getContentStore(channelId);
|
|
||||||
}
|
|
||||||
private fun getContentStore(channelId: String): ManagedStore<SerializedPlatformContent>? {
|
|
||||||
return synchronized(_channelContents) {
|
|
||||||
var channelStore = _channelContents.get(channelId);
|
|
||||||
return@synchronized channelStore;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val TAG = "ChannelCache";
|
|
||||||
|
|
||||||
private val _lock = Object();
|
|
||||||
private var _instance: ChannelContentCache? = null;
|
|
||||||
val instance: ChannelContentCache get() {
|
|
||||||
synchronized(_lock) {
|
|
||||||
if(_instance == null) {
|
|
||||||
_instance = ChannelContentCache();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _instance!!;
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cachePagerResults(scope: CoroutineScope, pager: IPager<IPlatformContent>, onNewCacheHit: ((IPlatformContent)->Unit)? = null): IPager<IPlatformContent> {
|
|
||||||
return ChannelVideoCachePager(pager, scope, onNewCacheHit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChannelVideoCachePager(val pager: IPager<IPlatformContent>, private val scope: CoroutineScope, private val onNewCacheItem: ((IPlatformContent)->Unit)? = null): IPager<IPlatformContent> {
|
|
||||||
|
|
||||||
init {
|
|
||||||
val results = pager.getResults();
|
|
||||||
|
|
||||||
Logger.i(TAG, "Caching ${results.size} subscription initial results [${pager.hashCode()}]");
|
|
||||||
scope.launch(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
val newCacheItems = instance.cacheContents(results);
|
|
||||||
if(onNewCacheItem != null)
|
|
||||||
newCacheItems.forEach { onNewCacheItem!!(it) }
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
Logger.e(TAG, "Failed to cache videos.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasMorePages(): Boolean {
|
|
||||||
return pager.hasMorePages();
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun nextPage() {
|
|
||||||
pager.nextPage();
|
|
||||||
val results = pager.getResults();
|
|
||||||
|
|
||||||
Logger.i(TAG, "Caching ${results.size} subscription results");
|
|
||||||
scope.launch(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
val newCacheItems = instance.cacheContents(results);
|
|
||||||
if(onNewCacheItem != null)
|
|
||||||
newCacheItems.forEach { onNewCacheItem!!(it) }
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
Logger.e(TAG, "Failed to cache videos.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getResults(): List<IPlatformContent> {
|
|
||||||
val results = pager.getResults();
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package com.futo.platformplayer.casting
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.api.http.ManagedHttpClient
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
import com.futo.platformplayer.casting.models.FastCastSetVolumeMessage
|
|
||||||
import com.futo.platformplayer.getConnectedSocket
|
import com.futo.platformplayer.getConnectedSocket
|
||||||
import com.futo.platformplayer.models.CastingDeviceInfo
|
import com.futo.platformplayer.models.CastingDeviceInfo
|
||||||
import com.futo.platformplayer.toInetAddress
|
import com.futo.platformplayer.toInetAddress
|
||||||
@@ -49,7 +48,7 @@ class AirPlayCastingDevice : CastingDevice {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.i(FastCastCastingDevice.TAG, "Start streaming (streamType: $streamType, contentType: $contentType, contentId: $contentId, resumePosition: $resumePosition, duration: $duration)");
|
Logger.i(FCastCastingDevice.TAG, "Start streaming (streamType: $streamType, contentType: $contentType, contentId: $contentId, resumePosition: $resumePosition, duration: $duration)");
|
||||||
|
|
||||||
time = resumePosition;
|
time = resumePosition;
|
||||||
if (resumePosition > 0.0) {
|
if (resumePosition > 0.0) {
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.futo.platformplayer.casting
|
package com.futo.platformplayer.casting
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.futo.platformplayer.api.media.models.video.IPlatformVideoDetails
|
|
||||||
import com.futo.platformplayer.constructs.Event1
|
import com.futo.platformplayer.constructs.Event1
|
||||||
import com.futo.platformplayer.getNowDiffMiliseconds
|
import com.futo.platformplayer.getNowDiffMiliseconds
|
||||||
import com.futo.platformplayer.models.CastingDeviceInfo
|
import com.futo.platformplayer.models.CastingDeviceInfo
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
|
||||||
@@ -14,10 +19,27 @@ enum class CastConnectionState {
|
|||||||
CONNECTED
|
CONNECTED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable(with = CastProtocolType.CastProtocolTypeSerializer::class)
|
||||||
enum class CastProtocolType {
|
enum class CastProtocolType {
|
||||||
CHROMECAST,
|
CHROMECAST,
|
||||||
AIRPLAY,
|
AIRPLAY,
|
||||||
FASTCAST
|
FCAST;
|
||||||
|
|
||||||
|
object CastProtocolTypeSerializer : KSerializer<CastProtocolType> {
|
||||||
|
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("CastProtocolType", PrimitiveKind.STRING)
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: CastProtocolType) {
|
||||||
|
encoder.encodeString(value.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): CastProtocolType {
|
||||||
|
val name = decoder.decodeString()
|
||||||
|
return when (name) {
|
||||||
|
"FASTCAST" -> FCAST // Handle the renamed case
|
||||||
|
else -> CastProtocolType.valueOf(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class CastingDevice {
|
abstract class CastingDevice {
|
||||||
|
|||||||
@@ -2,18 +2,16 @@ package com.futo.platformplayer.casting
|
|||||||
|
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.futo.platformplayer.casting.models.FastCastSetVolumeMessage
|
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.getConnectedSocket
|
import com.futo.platformplayer.getConnectedSocket
|
||||||
import com.futo.platformplayer.models.CastingDeviceInfo
|
import com.futo.platformplayer.models.CastingDeviceInfo
|
||||||
import com.futo.platformplayer.protos.DeviceAuthMessageOuterClass
|
import com.futo.platformplayer.protos.ChromeCast
|
||||||
import com.futo.platformplayer.toHexString
|
import com.futo.platformplayer.toHexString
|
||||||
import com.futo.platformplayer.toInetAddress
|
import com.futo.platformplayer.toInetAddress
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
import java.io.IOException
|
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.security.cert.X509Certificate
|
import java.security.cert.X509Certificate
|
||||||
import javax.net.ssl.SSLContext
|
import javax.net.ssl.SSLContext
|
||||||
@@ -69,7 +67,7 @@ class ChromecastCastingDevice : CastingDevice {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.i(FastCastCastingDevice.TAG, "Start streaming (streamType: $streamType, contentType: $contentType, contentId: $contentId, resumePosition: $resumePosition, duration: $duration)");
|
Logger.i(TAG, "Start streaming (streamType: $streamType, contentType: $contentType, contentId: $contentId, resumePosition: $resumePosition, duration: $duration)");
|
||||||
|
|
||||||
time = resumePosition;
|
time = resumePosition;
|
||||||
_streamType = streamType;
|
_streamType = streamType;
|
||||||
@@ -314,6 +312,7 @@ class ChromecastCastingDevice : CastingDevice {
|
|||||||
connectionState = CastConnectionState.CONNECTING;
|
connectionState = CastConnectionState.CONNECTING;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
_socket?.close()
|
||||||
_socket = factory.createSocket(usedRemoteAddress, port) as SSLSocket;
|
_socket = factory.createSocket(usedRemoteAddress, port) as SSLSocket;
|
||||||
_socket?.startHandshake();
|
_socket?.startHandshake();
|
||||||
Logger.i(TAG, "Successfully connected to Chromecast at $usedRemoteAddress:$port");
|
Logger.i(TAG, "Successfully connected to Chromecast at $usedRemoteAddress:$port");
|
||||||
@@ -324,7 +323,7 @@ class ChromecastCastingDevice : CastingDevice {
|
|||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Logger.i(TAG, "Failed to authenticate to Chromecast.", e);
|
Logger.i(TAG, "Failed to authenticate to Chromecast.", e);
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: Throwable) {
|
||||||
_socket?.close();
|
_socket?.close();
|
||||||
Logger.i(TAG, "Failed to connect to Chromecast.", e);
|
Logger.i(TAG, "Failed to connect to Chromecast.", e);
|
||||||
|
|
||||||
@@ -375,7 +374,7 @@ class ChromecastCastingDevice : CastingDevice {
|
|||||||
//TODO: In the future perhaps this size-1 will cause issues, why is there a 0 on the end?
|
//TODO: In the future perhaps this size-1 will cause issues, why is there a 0 on the end?
|
||||||
val messageBytes = buffer.sliceArray(IntRange(0, size - 1));
|
val messageBytes = buffer.sliceArray(IntRange(0, size - 1));
|
||||||
Log.d(TAG, "Received $size bytes: ${messageBytes.toHexString()}.");
|
Log.d(TAG, "Received $size bytes: ${messageBytes.toHexString()}.");
|
||||||
val message = DeviceAuthMessageOuterClass.CastMessage.parseFrom(messageBytes);
|
val message = ChromeCast.CastMessage.parseFrom(messageBytes);
|
||||||
if (message.namespace != "urn:x-cast:com.google.cast.tp.heartbeat") {
|
if (message.namespace != "urn:x-cast:com.google.cast.tp.heartbeat") {
|
||||||
Logger.i(TAG, "Received message: $message");
|
Logger.i(TAG, "Received message: $message");
|
||||||
}
|
}
|
||||||
@@ -428,12 +427,12 @@ class ChromecastCastingDevice : CastingDevice {
|
|||||||
|
|
||||||
private fun sendChannelMessage(sourceId: String, destinationId: String, namespace: String, json: String) {
|
private fun sendChannelMessage(sourceId: String, destinationId: String, namespace: String, json: String) {
|
||||||
try {
|
try {
|
||||||
val castMessage = DeviceAuthMessageOuterClass.CastMessage.newBuilder()
|
val castMessage = ChromeCast.CastMessage.newBuilder()
|
||||||
.setProtocolVersion(DeviceAuthMessageOuterClass.CastMessage.ProtocolVersion.CASTV2_1_0)
|
.setProtocolVersion(ChromeCast.CastMessage.ProtocolVersion.CASTV2_1_0)
|
||||||
.setSourceId(sourceId)
|
.setSourceId(sourceId)
|
||||||
.setDestinationId(destinationId)
|
.setDestinationId(destinationId)
|
||||||
.setNamespace(namespace)
|
.setNamespace(namespace)
|
||||||
.setPayloadType(DeviceAuthMessageOuterClass.CastMessage.PayloadType.STRING)
|
.setPayloadType(ChromeCast.CastMessage.PayloadType.STRING)
|
||||||
.setPayloadUtf8(json)
|
.setPayloadUtf8(json)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -447,8 +446,8 @@ class ChromecastCastingDevice : CastingDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleMessage(message: DeviceAuthMessageOuterClass.CastMessage) {
|
private fun handleMessage(message: ChromeCast.CastMessage) {
|
||||||
if (message.payloadType == DeviceAuthMessageOuterClass.CastMessage.PayloadType.STRING) {
|
if (message.payloadType == ChromeCast.CastMessage.PayloadType.STRING) {
|
||||||
val jsonObject = JSONObject(message.payloadUtf8);
|
val jsonObject = JSONObject(message.payloadUtf8);
|
||||||
val type = jsonObject.getString("type");
|
val type = jsonObject.getString("type");
|
||||||
if (type == "RECEIVER_STATUS") {
|
if (type == "RECEIVER_STATUS") {
|
||||||
|
|||||||
+9
-9
@@ -30,10 +30,10 @@ enum class Opcode(val value: Byte) {
|
|||||||
SET_VOLUME(8)
|
SET_VOLUME(8)
|
||||||
}
|
}
|
||||||
|
|
||||||
class FastCastCastingDevice : CastingDevice {
|
class FCastCastingDevice : CastingDevice {
|
||||||
//See for more info: TODO
|
//See for more info: TODO
|
||||||
|
|
||||||
override val protocol: CastProtocolType get() = CastProtocolType.FASTCAST;
|
override val protocol: CastProtocolType get() = CastProtocolType.FCAST;
|
||||||
override val isReady: Boolean get() = name != null && addresses != null && addresses?.isNotEmpty() == true && port != 0;
|
override val isReady: Boolean get() = name != null && addresses != null && addresses?.isNotEmpty() == true && port != 0;
|
||||||
override var usedRemoteAddress: InetAddress? = null;
|
override var usedRemoteAddress: InetAddress? = null;
|
||||||
override var localAddress: InetAddress? = null;
|
override var localAddress: InetAddress? = null;
|
||||||
@@ -72,7 +72,7 @@ class FastCastCastingDevice : CastingDevice {
|
|||||||
Logger.i(TAG, "Start streaming (streamType: $streamType, contentType: $contentType, contentId: $contentId, resumePosition: $resumePosition, duration: $duration)");
|
Logger.i(TAG, "Start streaming (streamType: $streamType, contentType: $contentType, contentId: $contentId, resumePosition: $resumePosition, duration: $duration)");
|
||||||
|
|
||||||
time = resumePosition;
|
time = resumePosition;
|
||||||
sendMessage(Opcode.PLAY, FastCastPlayMessage(
|
sendMessage(Opcode.PLAY, FCastPlayMessage(
|
||||||
container = contentType,
|
container = contentType,
|
||||||
url = contentId,
|
url = contentId,
|
||||||
time = resumePosition.toInt()
|
time = resumePosition.toInt()
|
||||||
@@ -87,7 +87,7 @@ class FastCastCastingDevice : CastingDevice {
|
|||||||
Logger.i(TAG, "Start streaming content (contentType: $contentType, resumePosition: $resumePosition, duration: $duration)");
|
Logger.i(TAG, "Start streaming content (contentType: $contentType, resumePosition: $resumePosition, duration: $duration)");
|
||||||
|
|
||||||
time = resumePosition;
|
time = resumePosition;
|
||||||
sendMessage(Opcode.PLAY, FastCastPlayMessage(
|
sendMessage(Opcode.PLAY, FCastPlayMessage(
|
||||||
container = contentType,
|
container = contentType,
|
||||||
content = content,
|
content = content,
|
||||||
time = resumePosition.toInt()
|
time = resumePosition.toInt()
|
||||||
@@ -100,7 +100,7 @@ class FastCastCastingDevice : CastingDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.volume = volume
|
this.volume = volume
|
||||||
sendMessage(Opcode.SET_VOLUME, FastCastSetVolumeMessage(volume))
|
sendMessage(Opcode.SET_VOLUME, FCastSetVolumeMessage(volume))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun seekVideo(timeSeconds: Double) {
|
override fun seekVideo(timeSeconds: Double) {
|
||||||
@@ -108,7 +108,7 @@ class FastCastCastingDevice : CastingDevice {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(Opcode.SEEK, FastCastSeekMessage(
|
sendMessage(Opcode.SEEK, FCastSeekMessage(
|
||||||
time = timeSeconds.toInt()
|
time = timeSeconds.toInt()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -282,7 +282,7 @@ class FastCastCastingDevice : CastingDevice {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
val playbackUpdate = Json.decodeFromString<FastCastPlaybackUpdateMessage>(json);
|
val playbackUpdate = Json.decodeFromString<FCastPlaybackUpdateMessage>(json);
|
||||||
time = playbackUpdate.time.toDouble();
|
time = playbackUpdate.time.toDouble();
|
||||||
isPlaying = when (playbackUpdate.state) {
|
isPlaying = when (playbackUpdate.state) {
|
||||||
1 -> true
|
1 -> true
|
||||||
@@ -295,7 +295,7 @@ class FastCastCastingDevice : CastingDevice {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
val volumeUpdate = Json.decodeFromString<FastCastVolumeUpdateMessage>(json);
|
val volumeUpdate = Json.decodeFromString<FCastVolumeUpdateMessage>(json);
|
||||||
volume = volumeUpdate.volume;
|
volume = volumeUpdate.volume;
|
||||||
}
|
}
|
||||||
else -> { }
|
else -> { }
|
||||||
@@ -398,7 +398,7 @@ class FastCastCastingDevice : CastingDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getDeviceInfo(): CastingDeviceInfo {
|
override fun getDeviceInfo(): CastingDeviceInfo {
|
||||||
return CastingDeviceInfo(name!!, CastProtocolType.FASTCAST, addresses!!.filter { a -> a.hostAddress != null }.map { a -> a.hostAddress!! }.toTypedArray(), port);
|
return CastingDeviceInfo(name!!, CastProtocolType.FCAST, addresses!!.filter { a -> a.hostAddress != null }.map { a -> a.hostAddress!! }.toTypedArray(), port);
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -2,8 +2,12 @@ package com.futo.platformplayer.casting
|
|||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.util.Base64
|
||||||
import com.futo.platformplayer.*
|
import com.futo.platformplayer.*
|
||||||
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
import com.futo.platformplayer.api.http.server.ManagedHttpServer
|
import com.futo.platformplayer.api.http.server.ManagedHttpServer
|
||||||
import com.futo.platformplayer.api.http.server.handlers.*
|
import com.futo.platformplayer.api.http.server.handlers.*
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.*
|
import com.futo.platformplayer.api.media.models.streams.sources.*
|
||||||
@@ -15,6 +19,7 @@ import com.futo.platformplayer.constructs.Event2
|
|||||||
import com.futo.platformplayer.exceptions.UnsupportedCastException
|
import com.futo.platformplayer.exceptions.UnsupportedCastException
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.models.CastingDeviceInfo
|
import com.futo.platformplayer.models.CastingDeviceInfo
|
||||||
|
import com.futo.platformplayer.parsers.HLS
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
@@ -25,6 +30,9 @@ import javax.jmdns.ServiceListener
|
|||||||
import kotlin.collections.HashMap
|
import kotlin.collections.HashMap
|
||||||
import com.futo.platformplayer.stores.CastingDeviceInfoStorage
|
import com.futo.platformplayer.stores.CastingDeviceInfoStorage
|
||||||
import com.futo.platformplayer.stores.FragmentedStorage
|
import com.futo.platformplayer.stores.FragmentedStorage
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import javax.jmdns.ServiceTypeListener
|
import javax.jmdns.ServiceTypeListener
|
||||||
|
|
||||||
class StateCasting {
|
class StateCasting {
|
||||||
@@ -45,6 +53,7 @@ class StateCasting {
|
|||||||
val onActiveDevicePlayChanged = Event1<Boolean>();
|
val onActiveDevicePlayChanged = Event1<Boolean>();
|
||||||
val onActiveDeviceTimeChanged = Event1<Double>();
|
val onActiveDeviceTimeChanged = Event1<Double>();
|
||||||
var activeDevice: CastingDevice? = null;
|
var activeDevice: CastingDevice? = null;
|
||||||
|
private val _client = ManagedHttpClient();
|
||||||
|
|
||||||
val isCasting: Boolean get() = activeDevice != null;
|
val isCasting: Boolean get() = activeDevice != null;
|
||||||
|
|
||||||
@@ -144,6 +153,32 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun handleUrl(context: Context, url: String) {
|
||||||
|
val uri = Uri.parse(url)
|
||||||
|
if (uri.scheme != "fcast") {
|
||||||
|
throw Exception("Expected scheme to be FCast")
|
||||||
|
}
|
||||||
|
|
||||||
|
val type = uri.host
|
||||||
|
if (type != "r") {
|
||||||
|
throw Exception("Expected type r")
|
||||||
|
}
|
||||||
|
|
||||||
|
val connectionInfo = uri.pathSegments[0]
|
||||||
|
val json = Base64.decode(connectionInfo, Base64.URL_SAFE or Base64.NO_PADDING or Base64.NO_WRAP).toString(Charsets.UTF_8)
|
||||||
|
val networkConfig = Json.decodeFromString<FCastNetworkConfig>(json)
|
||||||
|
val tcpService = networkConfig.services.first { v -> v.type == 0 }
|
||||||
|
|
||||||
|
addRememberedDevice(CastingDeviceInfo(
|
||||||
|
name = networkConfig.name,
|
||||||
|
type = CastProtocolType.FCAST,
|
||||||
|
addresses = networkConfig.addresses.toTypedArray(),
|
||||||
|
port = tcpService.port
|
||||||
|
))
|
||||||
|
|
||||||
|
UIDialogs.toast(context,"FCast device '${networkConfig.name}' added")
|
||||||
|
}
|
||||||
|
|
||||||
fun onStop() {
|
fun onStop() {
|
||||||
val ad = activeDevice ?: return;
|
val ad = activeDevice ?: return;
|
||||||
Logger.i(TAG, "Stopping active device because of onStop.");
|
Logger.i(TAG, "Stopping active device because of onStop.");
|
||||||
@@ -331,20 +366,25 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sourceCount > 1) {
|
if (sourceCount > 1) {
|
||||||
if (ad is AirPlayCastingDevice) {
|
|
||||||
StateApp.withContext(false) { context -> UIDialogs.toast(context, "AirPlay does not support DASH. Try ChromeCast or FastCast for casting this video."); };
|
|
||||||
ad.stopCasting();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (videoSource is LocalVideoSource || audioSource is LocalAudioSource || subtitleSource is LocalSubtitleSource) {
|
if (videoSource is LocalVideoSource || audioSource is LocalAudioSource || subtitleSource is LocalSubtitleSource) {
|
||||||
castLocalDash(video, videoSource as LocalVideoSource?, audioSource as LocalAudioSource?, subtitleSource as LocalSubtitleSource?, resumePosition);
|
if (ad is AirPlayCastingDevice) {
|
||||||
|
Logger.i(TAG, "Casting as local HLS");
|
||||||
|
castLocalHls(video, videoSource as LocalVideoSource?, audioSource as LocalAudioSource?, subtitleSource as LocalSubtitleSource?, resumePosition);
|
||||||
|
} else {
|
||||||
|
Logger.i(TAG, "Casting as local DASH");
|
||||||
|
castLocalDash(video, videoSource as LocalVideoSource?, audioSource as LocalAudioSource?, subtitleSource as LocalSubtitleSource?, resumePosition);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
StateApp.instance.scope.launch(Dispatchers.IO) {
|
StateApp.instance.scope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
if (ad is FastCastCastingDevice) {
|
if (ad is FCastCastingDevice) {
|
||||||
|
Logger.i(TAG, "Casting as DASH direct");
|
||||||
castDashDirect(contentResolver, video, videoSource as IVideoUrlSource?, audioSource as IAudioUrlSource?, subtitleSource, resumePosition);
|
castDashDirect(contentResolver, video, videoSource as IVideoUrlSource?, audioSource as IAudioUrlSource?, subtitleSource, resumePosition);
|
||||||
|
} else if (ad is AirPlayCastingDevice) {
|
||||||
|
Logger.i(TAG, "Casting as HLS indirect");
|
||||||
|
castHlsIndirect(contentResolver, video, videoSource as IVideoUrlSource?, audioSource as IAudioUrlSource?, subtitleSource, resumePosition);
|
||||||
} else {
|
} else {
|
||||||
|
Logger.i(TAG, "Casting as DASH indirect");
|
||||||
castDashIndirect(contentResolver, video, videoSource as IVideoUrlSource?, audioSource as IAudioUrlSource?, subtitleSource, resumePosition);
|
castDashIndirect(contentResolver, video, videoSource as IVideoUrlSource?, audioSource as IAudioUrlSource?, subtitleSource, resumePosition);
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@@ -353,19 +393,35 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (videoSource is IVideoUrlSource)
|
if (videoSource is IVideoUrlSource) {
|
||||||
ad.loadVideo("BUFFERED", videoSource.container, videoSource.getVideoUrl(), resumePosition, video.duration.toDouble());
|
Logger.i(TAG, "Casting as singular video");
|
||||||
else if(videoSource is IHLSManifestSource)
|
ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", videoSource.container, videoSource.getVideoUrl(), resumePosition, video.duration.toDouble());
|
||||||
ad.loadVideo("BUFFERED", videoSource.container, videoSource.url, resumePosition, video.duration.toDouble());
|
} else if (audioSource is IAudioUrlSource) {
|
||||||
else if (audioSource is IAudioUrlSource)
|
Logger.i(TAG, "Casting as singular audio");
|
||||||
ad.loadVideo("BUFFERED", audioSource.container, audioSource.getAudioUrl(), resumePosition, video.duration.toDouble());
|
ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", audioSource.container, audioSource.getAudioUrl(), resumePosition, video.duration.toDouble());
|
||||||
else if(audioSource is IHLSManifestAudioSource)
|
} else if(videoSource is IHLSManifestSource) {
|
||||||
ad.loadVideo("BUFFERED", audioSource.container, audioSource.url, resumePosition, video.duration.toDouble());
|
if (ad is ChromecastCastingDevice) {
|
||||||
else if (videoSource is LocalVideoSource)
|
Logger.i(TAG, "Casting as proxied HLS");
|
||||||
|
castProxiedHls(video, videoSource.url, videoSource.codec, resumePosition);
|
||||||
|
} else {
|
||||||
|
Logger.i(TAG, "Casting as non-proxied HLS");
|
||||||
|
ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", videoSource.container, videoSource.url, resumePosition, video.duration.toDouble());
|
||||||
|
}
|
||||||
|
} else if(audioSource is IHLSManifestAudioSource) {
|
||||||
|
if (ad is ChromecastCastingDevice) {
|
||||||
|
Logger.i(TAG, "Casting as proxied audio HLS");
|
||||||
|
castProxiedHls(video, audioSource.url, audioSource.codec, resumePosition);
|
||||||
|
} else {
|
||||||
|
Logger.i(TAG, "Casting as non-proxied audio HLS");
|
||||||
|
ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", audioSource.container, audioSource.url, resumePosition, video.duration.toDouble());
|
||||||
|
}
|
||||||
|
} else if (videoSource is LocalVideoSource) {
|
||||||
|
Logger.i(TAG, "Casting as local video");
|
||||||
castLocalVideo(video, videoSource, resumePosition);
|
castLocalVideo(video, videoSource, resumePosition);
|
||||||
else if (audioSource is LocalAudioSource)
|
} else if (audioSource is LocalAudioSource) {
|
||||||
|
Logger.i(TAG, "Casting as local audio");
|
||||||
castLocalAudio(video, audioSource, resumePosition);
|
castLocalAudio(video, audioSource, resumePosition);
|
||||||
else {
|
} else {
|
||||||
var str = listOf(
|
var str = listOf(
|
||||||
if(videoSource != null) "Video: ${videoSource::class.java.simpleName}" else null,
|
if(videoSource != null) "Video: ${videoSource::class.java.simpleName}" else null,
|
||||||
if(audioSource != null) "Audio: ${audioSource::class.java.simpleName}" else null,
|
if(audioSource != null) "Audio: ${audioSource::class.java.simpleName}" else null,
|
||||||
@@ -402,15 +458,23 @@ class StateCasting {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun castVideoIndirect() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun castAudioIndirect() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun castLocalVideo(video: IPlatformVideoDetails, videoSource: LocalVideoSource, resumePosition: Double) : List<String> {
|
private fun castLocalVideo(video: IPlatformVideoDetails, videoSource: LocalVideoSource, resumePosition: Double) : List<String> {
|
||||||
val ad = activeDevice ?: return listOf();
|
val ad = activeDevice ?: return listOf();
|
||||||
|
|
||||||
val url = "http://${ad.localAddress}:${_castServer.port}";
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}";
|
||||||
val id = UUID.randomUUID();
|
val id = UUID.randomUUID();
|
||||||
val videoPath = "/video-${id}"
|
val videoPath = "/video-${id}"
|
||||||
val videoUrl = url + videoPath;
|
val videoUrl = url + videoPath;
|
||||||
|
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpFileHandler("GET", videoPath, videoSource.container, videoSource.filePath)
|
HttpFileHandler("GET", videoPath, videoSource.container, videoSource.filePath)
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
@@ -424,12 +488,12 @@ class StateCasting {
|
|||||||
private fun castLocalAudio(video: IPlatformVideoDetails, audioSource: LocalAudioSource, resumePosition: Double) : List<String> {
|
private fun castLocalAudio(video: IPlatformVideoDetails, audioSource: LocalAudioSource, resumePosition: Double) : List<String> {
|
||||||
val ad = activeDevice ?: return listOf();
|
val ad = activeDevice ?: return listOf();
|
||||||
|
|
||||||
val url = "http://${ad.localAddress}:${_castServer.port}";
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}";
|
||||||
val id = UUID.randomUUID();
|
val id = UUID.randomUUID();
|
||||||
val audioPath = "/audio-${id}"
|
val audioPath = "/audio-${id}"
|
||||||
val audioUrl = url + audioPath;
|
val audioUrl = url + audioPath;
|
||||||
|
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpFileHandler("GET", audioPath, audioSource.container, audioSource.filePath)
|
HttpFileHandler("GET", audioPath, audioSource.container, audioSource.filePath)
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
@@ -440,11 +504,106 @@ class StateCasting {
|
|||||||
return listOf(audioUrl);
|
return listOf(audioUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun castLocalHls(video: IPlatformVideoDetails, videoSource: LocalVideoSource?, audioSource: LocalAudioSource?, subtitleSource: LocalSubtitleSource?, resumePosition: Double): List<String> {
|
||||||
|
val ad = activeDevice ?: return listOf()
|
||||||
|
|
||||||
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}"
|
||||||
|
val id = UUID.randomUUID()
|
||||||
|
|
||||||
|
val hlsPath = "/hls-${id}"
|
||||||
|
val videoPath = "/video-${id}"
|
||||||
|
val audioPath = "/audio-${id}"
|
||||||
|
val subtitlePath = "/subtitle-${id}"
|
||||||
|
|
||||||
|
val hlsUrl = url + hlsPath
|
||||||
|
val videoUrl = url + videoPath
|
||||||
|
val audioUrl = url + audioPath
|
||||||
|
val subtitleUrl = url + subtitlePath
|
||||||
|
|
||||||
|
val mediaRenditions = arrayListOf<HLS.MediaRendition>()
|
||||||
|
val variantPlaylistReferences = arrayListOf<HLS.VariantPlaylistReference>()
|
||||||
|
|
||||||
|
if (videoSource != null) {
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpFileHandler("GET", videoPath, videoSource.container, videoSource.filePath)
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castLocalHls")
|
||||||
|
|
||||||
|
val duration = videoSource.duration
|
||||||
|
val videoVariantPlaylistPath = "/video-playlist-${id}"
|
||||||
|
val videoVariantPlaylistUrl = url + videoVariantPlaylistPath
|
||||||
|
val videoVariantPlaylistSegments = listOf(HLS.MediaSegment(duration.toDouble(), videoUrl))
|
||||||
|
val videoVariantPlaylist = HLS.VariantPlaylist(3, duration.toInt(), 0, 0, null, null, null, videoVariantPlaylistSegments)
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", videoVariantPlaylistPath, videoVariantPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castLocalHls")
|
||||||
|
|
||||||
|
variantPlaylistReferences.add(HLS.VariantPlaylistReference(videoVariantPlaylistUrl, HLS.StreamInfo(
|
||||||
|
videoSource.bitrate, "${videoSource.width}x${videoSource.height}", videoSource.codec, null, null, if (audioSource != null) "audio" else null, if (subtitleSource != null) "subtitles" else null, null, null)))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (audioSource != null) {
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpFileHandler("GET", audioPath, audioSource.container, audioSource.filePath)
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castLocalHls")
|
||||||
|
|
||||||
|
val duration = audioSource.duration ?: videoSource?.duration ?: throw Exception("Duration unknown")
|
||||||
|
val audioVariantPlaylistPath = "/audio-playlist-${id}"
|
||||||
|
val audioVariantPlaylistUrl = url + audioVariantPlaylistPath
|
||||||
|
val audioVariantPlaylistSegments = listOf(HLS.MediaSegment(duration.toDouble(), audioUrl))
|
||||||
|
val audioVariantPlaylist = HLS.VariantPlaylist(3, duration.toInt(), 0, 0, null, null, null, audioVariantPlaylistSegments)
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", audioVariantPlaylistPath, audioVariantPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castLocalHls")
|
||||||
|
|
||||||
|
mediaRenditions.add(HLS.MediaRendition("AUDIO", audioVariantPlaylistUrl, "audio", "en", "english", true, true, true))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subtitleSource != null) {
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpFileHandler("GET", subtitlePath, subtitleSource.format ?: "text/vtt", subtitleSource.filePath)
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castLocalHls")
|
||||||
|
|
||||||
|
val duration = videoSource?.duration ?: audioSource?.duration ?: throw Exception("Duration unknown")
|
||||||
|
val subtitleVariantPlaylistPath = "/subtitle-playlist-${id}"
|
||||||
|
val subtitleVariantPlaylistUrl = url + subtitleVariantPlaylistPath
|
||||||
|
val subtitleVariantPlaylistSegments = listOf(HLS.MediaSegment(duration.toDouble(), subtitleUrl))
|
||||||
|
val subtitleVariantPlaylist = HLS.VariantPlaylist(3, duration.toInt(), 0, 0, null, null, null, subtitleVariantPlaylistSegments)
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", subtitleVariantPlaylistPath, subtitleVariantPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castLocalHls")
|
||||||
|
|
||||||
|
mediaRenditions.add(HLS.MediaRendition("SUBTITLES", subtitleVariantPlaylistUrl, "subtitles", "en", "english", true, true, true))
|
||||||
|
}
|
||||||
|
|
||||||
|
val masterPlaylist = HLS.MasterPlaylist(variantPlaylistReferences, mediaRenditions, listOf(), true)
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", hlsPath, masterPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castLocalHls")
|
||||||
|
|
||||||
|
Logger.i(TAG, "added new castLocalHls handlers (hlsPath: $hlsPath, videoPath: $videoPath, audioPath: $audioPath, subtitlePath: $subtitlePath).")
|
||||||
|
ad.loadVideo("BUFFERED", "application/vnd.apple.mpegurl", hlsUrl, resumePosition, video.duration.toDouble())
|
||||||
|
|
||||||
|
return listOf(hlsUrl, videoUrl, audioUrl, subtitleUrl)
|
||||||
|
}
|
||||||
|
|
||||||
private fun castLocalDash(video: IPlatformVideoDetails, videoSource: LocalVideoSource?, audioSource: LocalAudioSource?, subtitleSource: LocalSubtitleSource?, resumePosition: Double) : List<String> {
|
private fun castLocalDash(video: IPlatformVideoDetails, videoSource: LocalVideoSource?, audioSource: LocalAudioSource?, subtitleSource: LocalSubtitleSource?, resumePosition: Double) : List<String> {
|
||||||
val ad = activeDevice ?: return listOf();
|
val ad = activeDevice ?: return listOf();
|
||||||
|
|
||||||
val url = "http://${ad.localAddress}:${_castServer.port}";
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}";
|
||||||
val id = UUID.randomUUID();
|
val id = UUID.randomUUID();
|
||||||
|
|
||||||
val dashPath = "/dash-${id}"
|
val dashPath = "/dash-${id}"
|
||||||
@@ -457,43 +616,28 @@ class StateCasting {
|
|||||||
val audioUrl = url + audioPath;
|
val audioUrl = url + audioPath;
|
||||||
val subtitleUrl = url + subtitlePath;
|
val subtitleUrl = url + subtitlePath;
|
||||||
|
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpConstantHandler("GET", dashPath, DashBuilder.generateOnDemandDash(videoSource, videoUrl, audioSource, audioUrl, subtitleSource, subtitleUrl),
|
HttpConstantHandler("GET", dashPath, DashBuilder.generateOnDemandDash(videoSource, videoUrl, audioSource, audioUrl, subtitleSource, subtitleUrl),
|
||||||
"application/dash+xml")
|
"application/dash+xml")
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
if (videoSource != null) {
|
if (videoSource != null) {
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpFileHandler("GET", videoPath, videoSource.container, videoSource.filePath)
|
HttpFileHandler("GET", videoPath, videoSource.container, videoSource.filePath)
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
_castServer.addHandler(
|
|
||||||
HttpOptionsAllowHandler(videoPath)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*")
|
|
||||||
.withHeader("Connection", "keep-alive"))
|
|
||||||
.withTag("cast");
|
|
||||||
}
|
}
|
||||||
if (audioSource != null) {
|
if (audioSource != null) {
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpFileHandler("GET", audioPath, audioSource.container, audioSource.filePath)
|
HttpFileHandler("GET", audioPath, audioSource.container, audioSource.filePath)
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
_castServer.addHandler(
|
|
||||||
HttpOptionsAllowHandler(audioPath)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*")
|
|
||||||
.withHeader("Connection", "keep-alive"))
|
|
||||||
.withTag("cast");
|
|
||||||
}
|
}
|
||||||
if (subtitleSource != null) {
|
if (subtitleSource != null) {
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpFileHandler("GET", subtitlePath, subtitleSource.format ?: "text/vtt", subtitleSource.filePath, true)
|
HttpFileHandler("GET", subtitlePath, subtitleSource.format ?: "text/vtt", subtitleSource.filePath)
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
_castServer.addHandler(
|
|
||||||
HttpOptionsAllowHandler(subtitlePath)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*")
|
|
||||||
.withHeader("Connection", "keep-alive"))
|
|
||||||
.withTag("cast");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.i(TAG, "added new castLocalDash handlers (dashPath: $dashPath, videoPath: $videoPath, audioPath: $audioPath, subtitlePath: $subtitlePath).");
|
Logger.i(TAG, "added new castLocalDash handlers (dashPath: $dashPath, videoPath: $videoPath, audioPath: $audioPath, subtitlePath: $subtitlePath).");
|
||||||
@@ -505,7 +649,7 @@ class StateCasting {
|
|||||||
private suspend fun castDashDirect(contentResolver: ContentResolver, video: IPlatformVideoDetails, videoSource: IVideoUrlSource?, audioSource: IAudioUrlSource?, subtitleSource: ISubtitleSource?, resumePosition: Double) : List<String> {
|
private suspend fun castDashDirect(contentResolver: ContentResolver, video: IPlatformVideoDetails, videoSource: IVideoUrlSource?, audioSource: IAudioUrlSource?, subtitleSource: ISubtitleSource?, resumePosition: Double) : List<String> {
|
||||||
val ad = activeDevice ?: return listOf();
|
val ad = activeDevice ?: return listOf();
|
||||||
|
|
||||||
val url = "http://${ad.localAddress}:${_castServer.port}";
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}";
|
||||||
val id = UUID.randomUUID();
|
val id = UUID.randomUUID();
|
||||||
val subtitlePath = "/subtitle-${id}";
|
val subtitlePath = "/subtitle-${id}";
|
||||||
|
|
||||||
@@ -527,7 +671,7 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpConstantHandler("GET", subtitlePath, content!!, subtitleSource?.format ?: "text/vtt")
|
HttpConstantHandler("GET", subtitlePath, content!!, subtitleSource?.format ?: "text/vtt")
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
@@ -547,13 +691,311 @@ class StateCasting {
|
|||||||
return listOf(videoSource?.getVideoUrl() ?: "", audioSource?.getAudioUrl() ?: "");
|
return listOf(videoSource?.getVideoUrl() ?: "", audioSource?.getAudioUrl() ?: "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun castProxiedHls(video: IPlatformVideoDetails, sourceUrl: String, codec: String?, resumePosition: Double): List<String> {
|
||||||
|
_castServer.removeAllHandlers("castProxiedHlsMaster")
|
||||||
|
|
||||||
|
val ad = activeDevice ?: return listOf();
|
||||||
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}";
|
||||||
|
|
||||||
|
val id = UUID.randomUUID();
|
||||||
|
val hlsPath = "/hls-${id}"
|
||||||
|
val hlsUrl = url + hlsPath
|
||||||
|
Logger.i(TAG, "HLS url: $hlsUrl");
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(HttpFuntionHandler("GET", hlsPath) { masterContext ->
|
||||||
|
_castServer.removeAllHandlers("castProxiedHlsVariant")
|
||||||
|
|
||||||
|
val headers = masterContext.headers.clone()
|
||||||
|
headers["Content-Type"] = "application/vnd.apple.mpegurl";
|
||||||
|
|
||||||
|
val masterPlaylistResponse = _client.get(sourceUrl)
|
||||||
|
check(masterPlaylistResponse.isOk) { "Failed to get master playlist: ${masterPlaylistResponse.code}" }
|
||||||
|
|
||||||
|
val masterPlaylistContent = masterPlaylistResponse.body?.string()
|
||||||
|
?: throw Exception("Master playlist content is empty")
|
||||||
|
|
||||||
|
val masterPlaylist: HLS.MasterPlaylist
|
||||||
|
try {
|
||||||
|
masterPlaylist = HLS.parseMasterPlaylist(masterPlaylistContent, sourceUrl)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
if (masterPlaylistContent.lines().any { it.startsWith("#EXTINF:") }) {
|
||||||
|
//This is a variant playlist, not a master playlist
|
||||||
|
Logger.i(TAG, "HLS casting as variant playlist (codec: $codec): $hlsUrl");
|
||||||
|
|
||||||
|
val vpHeaders = masterContext.headers.clone()
|
||||||
|
vpHeaders["Content-Type"] = "application/vnd.apple.mpegurl";
|
||||||
|
|
||||||
|
val variantPlaylist = HLS.parseVariantPlaylist(masterPlaylistContent, sourceUrl)
|
||||||
|
val proxiedVariantPlaylist = proxyVariantPlaylist(url, id, variantPlaylist, video.isLive)
|
||||||
|
val proxiedVariantPlaylist_m3u8 = proxiedVariantPlaylist.buildM3U8()
|
||||||
|
masterContext.respondCode(200, vpHeaders, proxiedVariantPlaylist_m3u8);
|
||||||
|
return@HttpFuntionHandler
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.i(TAG, "HLS casting as master playlist: $hlsUrl");
|
||||||
|
|
||||||
|
val newVariantPlaylistRefs = arrayListOf<HLS.VariantPlaylistReference>()
|
||||||
|
val newMediaRenditions = arrayListOf<HLS.MediaRendition>()
|
||||||
|
val newMasterPlaylist = HLS.MasterPlaylist(newVariantPlaylistRefs, newMediaRenditions, masterPlaylist.sessionDataList, masterPlaylist.independentSegments)
|
||||||
|
|
||||||
|
for (variantPlaylistRef in masterPlaylist.variantPlaylistsRefs) {
|
||||||
|
val playlistId = UUID.randomUUID();
|
||||||
|
val newPlaylistPath = "/hls-playlist-${playlistId}"
|
||||||
|
val newPlaylistUrl = url + newPlaylistPath;
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(HttpFuntionHandler("GET", newPlaylistPath) { vpContext ->
|
||||||
|
val vpHeaders = vpContext.headers.clone()
|
||||||
|
vpHeaders["Content-Type"] = "application/vnd.apple.mpegurl";
|
||||||
|
|
||||||
|
val response = _client.get(variantPlaylistRef.url)
|
||||||
|
check(response.isOk) { "Failed to get variant playlist: ${response.code}" }
|
||||||
|
|
||||||
|
val vpContent = response.body?.string()
|
||||||
|
?: throw Exception("Variant playlist content is empty")
|
||||||
|
|
||||||
|
val variantPlaylist = HLS.parseVariantPlaylist(vpContent, variantPlaylistRef.url)
|
||||||
|
val proxiedVariantPlaylist = proxyVariantPlaylist(url, playlistId, variantPlaylist, video.isLive)
|
||||||
|
val proxiedVariantPlaylist_m3u8 = proxiedVariantPlaylist.buildM3U8()
|
||||||
|
vpContext.respondCode(200, vpHeaders, proxiedVariantPlaylist_m3u8);
|
||||||
|
}.withHeader("Access-Control-Allow-Origin", "*"), true).withTag("castProxiedHlsVariant")
|
||||||
|
|
||||||
|
newVariantPlaylistRefs.add(HLS.VariantPlaylistReference(
|
||||||
|
newPlaylistUrl,
|
||||||
|
variantPlaylistRef.streamInfo
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
for (mediaRendition in masterPlaylist.mediaRenditions) {
|
||||||
|
val playlistId = UUID.randomUUID()
|
||||||
|
|
||||||
|
var newPlaylistUrl: String? = null
|
||||||
|
if (mediaRendition.uri != null) {
|
||||||
|
val newPlaylistPath = "/hls-playlist-${playlistId}"
|
||||||
|
newPlaylistUrl = url + newPlaylistPath
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(HttpFuntionHandler("GET", newPlaylistPath) { vpContext ->
|
||||||
|
val vpHeaders = vpContext.headers.clone()
|
||||||
|
vpHeaders["Content-Type"] = "application/vnd.apple.mpegurl";
|
||||||
|
|
||||||
|
val response = _client.get(mediaRendition.uri)
|
||||||
|
check(response.isOk) { "Failed to get variant playlist: ${response.code}" }
|
||||||
|
|
||||||
|
val vpContent = response.body?.string()
|
||||||
|
?: throw Exception("Variant playlist content is empty")
|
||||||
|
|
||||||
|
val variantPlaylist = HLS.parseVariantPlaylist(vpContent, mediaRendition.uri)
|
||||||
|
val proxiedVariantPlaylist = proxyVariantPlaylist(url, playlistId, variantPlaylist, video.isLive)
|
||||||
|
val proxiedVariantPlaylist_m3u8 = proxiedVariantPlaylist.buildM3U8()
|
||||||
|
vpContext.respondCode(200, vpHeaders, proxiedVariantPlaylist_m3u8);
|
||||||
|
}.withHeader("Access-Control-Allow-Origin", "*"), true).withTag("castProxiedHlsVariant")
|
||||||
|
}
|
||||||
|
|
||||||
|
newMediaRenditions.add(HLS.MediaRendition(
|
||||||
|
mediaRendition.type,
|
||||||
|
newPlaylistUrl,
|
||||||
|
mediaRendition.groupID,
|
||||||
|
mediaRendition.language,
|
||||||
|
mediaRendition.name,
|
||||||
|
mediaRendition.isDefault,
|
||||||
|
mediaRendition.isAutoSelect,
|
||||||
|
mediaRendition.isForced
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
masterContext.respondCode(200, headers, newMasterPlaylist.buildM3U8());
|
||||||
|
}.withHeader("Access-Control-Allow-Origin", "*"), true).withTag("castProxiedHlsMaster")
|
||||||
|
|
||||||
|
Logger.i(TAG, "added new castHlsIndirect handlers (hlsPath: $hlsPath).");
|
||||||
|
|
||||||
|
//ChromeCast is sometimes funky with resume position 0
|
||||||
|
val hackfixResumePosition = if (ad is ChromecastCastingDevice && !video.isLive && resumePosition == 0.0) 0.1 else resumePosition;
|
||||||
|
ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", "application/vnd.apple.mpegurl", hlsUrl, hackfixResumePosition, video.duration.toDouble());
|
||||||
|
|
||||||
|
return listOf(hlsUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun proxyVariantPlaylist(url: String, playlistId: UUID, variantPlaylist: HLS.VariantPlaylist, isLive: Boolean, proxySegments: Boolean = true): HLS.VariantPlaylist {
|
||||||
|
val newSegments = arrayListOf<HLS.Segment>()
|
||||||
|
|
||||||
|
if (proxySegments) {
|
||||||
|
variantPlaylist.segments.forEachIndexed { index, segment ->
|
||||||
|
val sequenceNumber = (variantPlaylist.mediaSequence ?: 0) + index.toLong()
|
||||||
|
newSegments.add(proxySegment(url, playlistId, segment, sequenceNumber))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newSegments.addAll(variantPlaylist.segments)
|
||||||
|
}
|
||||||
|
|
||||||
|
return HLS.VariantPlaylist(
|
||||||
|
variantPlaylist.version,
|
||||||
|
variantPlaylist.targetDuration,
|
||||||
|
variantPlaylist.mediaSequence,
|
||||||
|
variantPlaylist.discontinuitySequence,
|
||||||
|
variantPlaylist.programDateTime,
|
||||||
|
variantPlaylist.playlistType,
|
||||||
|
variantPlaylist.streamInfo,
|
||||||
|
newSegments
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun proxySegment(url: String, playlistId: UUID, segment: HLS.Segment, index: Long): HLS.Segment {
|
||||||
|
if (segment is HLS.MediaSegment) {
|
||||||
|
val newSegmentPath = "/hls-playlist-${playlistId}-segment-${index}"
|
||||||
|
val newSegmentUrl = url + newSegmentPath;
|
||||||
|
|
||||||
|
if (_castServer.getHandler("GET", newSegmentPath) == null) {
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpProxyHandler("GET", newSegmentPath, segment.uri, true)
|
||||||
|
.withInjectedHost()
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castProxiedHlsVariant")
|
||||||
|
}
|
||||||
|
|
||||||
|
return HLS.MediaSegment(
|
||||||
|
segment.duration,
|
||||||
|
newSegmentUrl
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return segment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun castHlsIndirect(contentResolver: ContentResolver, video: IPlatformVideoDetails, videoSource: IVideoUrlSource?, audioSource: IAudioUrlSource?, subtitleSource: ISubtitleSource?, resumePosition: Double) : List<String> {
|
||||||
|
val ad = activeDevice ?: return listOf();
|
||||||
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}";
|
||||||
|
val id = UUID.randomUUID();
|
||||||
|
|
||||||
|
val hlsPath = "/hls-${id}"
|
||||||
|
|
||||||
|
val hlsUrl = url + hlsPath;
|
||||||
|
Logger.i(TAG, "HLS url: $hlsUrl");
|
||||||
|
|
||||||
|
val mediaRenditions = arrayListOf<HLS.MediaRendition>()
|
||||||
|
val variantPlaylistReferences = arrayListOf<HLS.VariantPlaylistReference>()
|
||||||
|
|
||||||
|
if (audioSource != null) {
|
||||||
|
val audioPath = "/audio-${id}"
|
||||||
|
val audioUrl = url + audioPath
|
||||||
|
|
||||||
|
val duration = audioSource.duration ?: videoSource?.duration ?: throw Exception("Duration unknown")
|
||||||
|
val audioVariantPlaylistPath = "/audio-playlist-${id}"
|
||||||
|
val audioVariantPlaylistUrl = url + audioVariantPlaylistPath
|
||||||
|
val audioVariantPlaylistSegments = listOf(HLS.MediaSegment(duration.toDouble(), audioUrl))
|
||||||
|
val audioVariantPlaylist = HLS.VariantPlaylist(3, duration.toInt(), 0, 0, null, null, null, audioVariantPlaylistSegments)
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", audioVariantPlaylistPath, audioVariantPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castHlsIndirectVariant");
|
||||||
|
|
||||||
|
mediaRenditions.add(HLS.MediaRendition("AUDIO", audioVariantPlaylistUrl, "audio", "en", "english", true, true, true))
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpProxyHandler("GET", audioPath, audioSource.getAudioUrl(), true)
|
||||||
|
.withInjectedHost()
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castHlsIndirectVariant");
|
||||||
|
}
|
||||||
|
|
||||||
|
val subtitlesUri = if (subtitleSource != null) withContext(Dispatchers.IO) {
|
||||||
|
return@withContext subtitleSource.getSubtitlesURI();
|
||||||
|
} else null;
|
||||||
|
|
||||||
|
var subtitlesUrl: String? = null;
|
||||||
|
if (subtitlesUri != null) {
|
||||||
|
val subtitlePath = "/subtitles-${id}"
|
||||||
|
if(subtitlesUri.scheme == "file") {
|
||||||
|
var content: String? = null;
|
||||||
|
val inputStream = contentResolver.openInputStream(subtitlesUri);
|
||||||
|
inputStream?.use { stream ->
|
||||||
|
val reader = stream.bufferedReader();
|
||||||
|
content = reader.use { it.readText() };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content != null) {
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", subtitlePath, content!!, subtitleSource?.format ?: "text/vtt")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castHlsIndirectVariant");
|
||||||
|
}
|
||||||
|
|
||||||
|
subtitlesUrl = url + subtitlePath;
|
||||||
|
} else {
|
||||||
|
subtitlesUrl = subtitlesUri.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (subtitlesUrl != null) {
|
||||||
|
val duration = videoSource?.duration ?: audioSource?.duration ?: throw Exception("Duration unknown")
|
||||||
|
val subtitleVariantPlaylistPath = "/subtitle-playlist-${id}"
|
||||||
|
val subtitleVariantPlaylistUrl = url + subtitleVariantPlaylistPath
|
||||||
|
val subtitleVariantPlaylistSegments = listOf(HLS.MediaSegment(duration.toDouble(), subtitlesUrl))
|
||||||
|
val subtitleVariantPlaylist = HLS.VariantPlaylist(3, duration.toInt(), 0, 0, null, null, null, subtitleVariantPlaylistSegments)
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", subtitleVariantPlaylistPath, subtitleVariantPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castHlsIndirectVariant");
|
||||||
|
|
||||||
|
mediaRenditions.add(HLS.MediaRendition("SUBTITLES", subtitleVariantPlaylistUrl, "subtitles", "en", "english", true, true, true))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (videoSource != null) {
|
||||||
|
val videoPath = "/video-${id}"
|
||||||
|
val videoUrl = url + videoPath
|
||||||
|
|
||||||
|
val duration = videoSource.duration
|
||||||
|
val videoVariantPlaylistPath = "/video-playlist-${id}"
|
||||||
|
val videoVariantPlaylistUrl = url + videoVariantPlaylistPath
|
||||||
|
val videoVariantPlaylistSegments = listOf(HLS.MediaSegment(duration.toDouble(), videoUrl))
|
||||||
|
val videoVariantPlaylist = HLS.VariantPlaylist(3, duration.toInt(), 0, 0, null, null, null, videoVariantPlaylistSegments)
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", videoVariantPlaylistPath, videoVariantPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castHlsIndirectVariant");
|
||||||
|
|
||||||
|
variantPlaylistReferences.add(HLS.VariantPlaylistReference(videoVariantPlaylistUrl, HLS.StreamInfo(
|
||||||
|
videoSource.bitrate ?: 0,
|
||||||
|
"${videoSource.width}x${videoSource.height}",
|
||||||
|
videoSource.codec,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
if (audioSource != null) "audio" else null,
|
||||||
|
if (subtitleSource != null) "subtitles" else null,
|
||||||
|
null, null)))
|
||||||
|
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpProxyHandler("GET", videoPath, videoSource.getVideoUrl(), true)
|
||||||
|
.withInjectedHost()
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castHlsIndirectVariant");
|
||||||
|
}
|
||||||
|
|
||||||
|
val masterPlaylist = HLS.MasterPlaylist(variantPlaylistReferences, mediaRenditions, listOf(), true)
|
||||||
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
|
HttpConstantHandler("GET", hlsPath, masterPlaylist.buildM3U8(),
|
||||||
|
"application/vnd.apple.mpegurl")
|
||||||
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
|
).withTag("castHlsIndirectMaster")
|
||||||
|
|
||||||
|
Logger.i(TAG, "added new castHls handlers (hlsPath: $hlsPath).");
|
||||||
|
ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", "application/vnd.apple.mpegurl", hlsUrl, resumePosition, video.duration.toDouble());
|
||||||
|
|
||||||
|
return listOf(hlsUrl, videoSource?.getVideoUrl() ?: "", audioSource?.getAudioUrl() ?: "", subtitlesUri.toString());
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun castDashIndirect(contentResolver: ContentResolver, video: IPlatformVideoDetails, videoSource: IVideoUrlSource?, audioSource: IAudioUrlSource?, subtitleSource: ISubtitleSource?, resumePosition: Double) : List<String> {
|
private suspend fun castDashIndirect(contentResolver: ContentResolver, video: IPlatformVideoDetails, videoSource: IVideoUrlSource?, audioSource: IAudioUrlSource?, subtitleSource: ISubtitleSource?, resumePosition: Double) : List<String> {
|
||||||
val ad = activeDevice ?: return listOf();
|
val ad = activeDevice ?: return listOf();
|
||||||
val proxyStreams = ad !is FastCastCastingDevice;
|
val proxyStreams = ad !is FCastCastingDevice;
|
||||||
|
|
||||||
val url = "http://${ad.localAddress}:${_castServer.port}";
|
|
||||||
Logger.i(TAG, "DASH url: $url");
|
|
||||||
|
|
||||||
|
val url = "http://${ad.localAddress.toString().trim('/')}:${_castServer.port}";
|
||||||
val id = UUID.randomUUID();
|
val id = UUID.randomUUID();
|
||||||
|
|
||||||
val dashPath = "/dash-${id}"
|
val dashPath = "/dash-${id}"
|
||||||
@@ -562,6 +1004,8 @@ class StateCasting {
|
|||||||
val subtitlePath = "/subtitle-${id}"
|
val subtitlePath = "/subtitle-${id}"
|
||||||
|
|
||||||
val dashUrl = url + dashPath;
|
val dashUrl = url + dashPath;
|
||||||
|
Logger.i(TAG, "DASH url: $dashUrl");
|
||||||
|
|
||||||
val videoUrl = if(proxyStreams) url + videoPath else videoSource?.getVideoUrl();
|
val videoUrl = if(proxyStreams) url + videoPath else videoSource?.getVideoUrl();
|
||||||
val audioUrl = if(proxyStreams) url + audioPath else audioSource?.getAudioUrl();
|
val audioUrl = if(proxyStreams) url + audioPath else audioSource?.getAudioUrl();
|
||||||
|
|
||||||
@@ -583,7 +1027,7 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpConstantHandler("GET", subtitlePath, content!!, subtitleSource?.format ?: "text/vtt")
|
HttpConstantHandler("GET", subtitlePath, content!!, subtitleSource?.format ?: "text/vtt")
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
@@ -595,38 +1039,29 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpConstantHandler("GET", dashPath, DashBuilder.generateOnDemandDash(videoSource, videoUrl, audioSource, audioUrl, subtitleSource, subtitlesUrl),
|
HttpConstantHandler("GET", dashPath, DashBuilder.generateOnDemandDash(videoSource, videoUrl, audioSource, audioUrl, subtitleSource, subtitlesUrl),
|
||||||
"application/dash+xml")
|
"application/dash+xml")
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
|
|
||||||
if (videoSource != null) {
|
if (videoSource != null) {
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpProxyHandler("GET", videoPath, videoSource.getVideoUrl())
|
HttpProxyHandler("GET", videoPath, videoSource.getVideoUrl(), true)
|
||||||
.withInjectedHost()
|
.withInjectedHost()
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
_castServer.addHandler(
|
|
||||||
HttpOptionsAllowHandler(videoPath)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*")
|
|
||||||
.withHeader("Connection", "keep-alive"))
|
|
||||||
.withTag("cast");
|
|
||||||
}
|
}
|
||||||
if (audioSource != null) {
|
if (audioSource != null) {
|
||||||
_castServer.addHandler(
|
_castServer.addHandlerWithAllowAllOptions(
|
||||||
HttpProxyHandler("GET", audioPath, audioSource.getAudioUrl())
|
HttpProxyHandler("GET", audioPath, audioSource.getAudioUrl(), true)
|
||||||
.withInjectedHost()
|
.withInjectedHost()
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
.withHeader("Access-Control-Allow-Origin", "*"), true
|
||||||
).withTag("cast");
|
).withTag("cast");
|
||||||
_castServer.addHandler(
|
|
||||||
HttpOptionsAllowHandler(audioPath)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*")
|
|
||||||
.withHeader("Connection", "keep-alivcontexte"))
|
|
||||||
.withTag("cast");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.i(TAG, "added new castDash handlers (dashPath: $dashPath, videoPath: $videoPath, audioPath: $audioPath).");
|
Logger.i(TAG, "added new castDash handlers (dashPath: $dashPath, videoPath: $videoPath, audioPath: $audioPath).");
|
||||||
ad.loadVideo("BUFFERED", "application/dash+xml", dashUrl, resumePosition, video.duration.toDouble());
|
ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", "application/dash+xml", dashUrl, resumePosition, video.duration.toDouble());
|
||||||
|
|
||||||
return listOf(dashUrl, videoUrl ?: "", audioUrl ?: "", subtitlesUrl ?: "", videoSource?.getVideoUrl() ?: "", audioSource?.getAudioUrl() ?: "", subtitlesUri.toString());
|
return listOf(dashUrl, videoUrl ?: "", audioUrl ?: "", subtitlesUrl ?: "", videoSource?.getVideoUrl() ?: "", audioSource?.getAudioUrl() ?: "", subtitlesUri.toString());
|
||||||
}
|
}
|
||||||
@@ -639,8 +1074,8 @@ class StateCasting {
|
|||||||
CastProtocolType.AIRPLAY -> {
|
CastProtocolType.AIRPLAY -> {
|
||||||
AirPlayCastingDevice(deviceInfo);
|
AirPlayCastingDevice(deviceInfo);
|
||||||
}
|
}
|
||||||
CastProtocolType.FASTCAST -> {
|
CastProtocolType.FCAST -> {
|
||||||
FastCastCastingDevice(deviceInfo);
|
FCastCastingDevice(deviceInfo);
|
||||||
}
|
}
|
||||||
else -> throw Exception("${deviceInfo.type} is not a valid casting protocol")
|
else -> throw Exception("${deviceInfo.type} is not a valid casting protocol")
|
||||||
}
|
}
|
||||||
@@ -687,8 +1122,8 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addOrUpdateFastCastDevice(name: String, addresses: Array<InetAddress>, port: Int) {
|
private fun addOrUpdateFastCastDevice(name: String, addresses: Array<InetAddress>, port: Int) {
|
||||||
return addOrUpdateCastDevice<FastCastCastingDevice>(name,
|
return addOrUpdateCastDevice<FCastCastingDevice>(name,
|
||||||
deviceFactory = { FastCastCastingDevice(name, addresses, port) },
|
deviceFactory = { FCastCastingDevice(name, addresses, port) },
|
||||||
deviceUpdater = { d ->
|
deviceUpdater = { d ->
|
||||||
if (d.isReady) {
|
if (d.isReady) {
|
||||||
return@addOrUpdateCastDevice false;
|
return@addOrUpdateCastDevice false;
|
||||||
@@ -764,6 +1199,19 @@ class StateCasting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
private data class FCastNetworkConfig(
|
||||||
|
val name: String,
|
||||||
|
val addresses: List<String>,
|
||||||
|
val services: List<FCastService>
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
private data class FCastService(
|
||||||
|
val port: Int,
|
||||||
|
val type: Int
|
||||||
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val instance: StateCasting = StateCasting();
|
val instance: StateCasting = StateCasting();
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -3,7 +3,7 @@ package com.futo.platformplayer.casting.models
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@kotlinx.serialization.Serializable
|
@kotlinx.serialization.Serializable
|
||||||
data class FastCastPlayMessage(
|
data class FCastPlayMessage(
|
||||||
val container: String,
|
val container: String,
|
||||||
val url: String? = null,
|
val url: String? = null,
|
||||||
val content: String? = null,
|
val content: String? = null,
|
||||||
@@ -11,23 +11,23 @@ data class FastCastPlayMessage(
|
|||||||
) { }
|
) { }
|
||||||
|
|
||||||
@kotlinx.serialization.Serializable
|
@kotlinx.serialization.Serializable
|
||||||
data class FastCastSeekMessage(
|
data class FCastSeekMessage(
|
||||||
val time: Int
|
val time: Int
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
@kotlinx.serialization.Serializable
|
@kotlinx.serialization.Serializable
|
||||||
data class FastCastPlaybackUpdateMessage(
|
data class FCastPlaybackUpdateMessage(
|
||||||
val time: Int,
|
val time: Int,
|
||||||
val state: Int
|
val state: Int
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class FastCastVolumeUpdateMessage(
|
data class FCastVolumeUpdateMessage(
|
||||||
val volume: Double
|
val volume: Double
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class FastCastSetVolumeMessage(
|
data class FCastSetVolumeMessage(
|
||||||
val volume: Double
|
val volume: Double
|
||||||
)
|
)
|
||||||
@@ -24,6 +24,7 @@ import com.google.gson.JsonArray
|
|||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.lang.reflect.InvocationTargetException
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import kotlin.reflect.jvm.jvmErasure
|
import kotlin.reflect.jvm.jvmErasure
|
||||||
|
|
||||||
@@ -185,7 +186,11 @@ class DeveloperEndpoints(private val context: Context) {
|
|||||||
val config = context.readContentJson<SourcePluginConfig>()
|
val config = context.readContentJson<SourcePluginConfig>()
|
||||||
try {
|
try {
|
||||||
_testPluginVariables.clear();
|
_testPluginVariables.clear();
|
||||||
_testPlugin = V8Plugin(StateApp.instance.context, config);
|
|
||||||
|
val client = JSHttpClient(null, null, null, config);
|
||||||
|
val clientAuth = JSHttpClient(null, null, null, config);
|
||||||
|
_testPlugin = V8Plugin(StateApp.instance.context, config, null, client, clientAuth);
|
||||||
|
|
||||||
context.respondJson(200, testPluginOrThrow.getPackageVariables());
|
context.respondJson(200, testPluginOrThrow.getPackageVariables());
|
||||||
}
|
}
|
||||||
catch(ex: Throwable) {
|
catch(ex: Throwable) {
|
||||||
@@ -235,7 +240,7 @@ class DeveloperEndpoints(private val context: Context) {
|
|||||||
}
|
}
|
||||||
LoginActivity.showLogin(StateApp.instance.context, config) {
|
LoginActivity.showLogin(StateApp.instance.context, config) {
|
||||||
_testPluginVariables.clear();
|
_testPluginVariables.clear();
|
||||||
_testPlugin = V8Plugin(StateApp.instance.context, config, null, JSHttpClient(null), JSHttpClient(null, it));
|
_testPlugin = V8Plugin(StateApp.instance.context, config, null, JSHttpClient(null, null, null, config), JSHttpClient(null, it, null, config));
|
||||||
|
|
||||||
};
|
};
|
||||||
context.respondCode(200, "Login started");
|
context.respondCode(200, "Login started");
|
||||||
@@ -287,7 +292,6 @@ class DeveloperEndpoints(private val context: Context) {
|
|||||||
@HttpPOST("/plugin/remoteCall")
|
@HttpPOST("/plugin/remoteCall")
|
||||||
fun pluginRemoteCall(context: HttpContext) {
|
fun pluginRemoteCall(context: HttpContext) {
|
||||||
try {
|
try {
|
||||||
val parameters = context.readContentString();
|
|
||||||
val objId = context.query.get("id")
|
val objId = context.query.get("id")
|
||||||
val method = context.query.get("method")
|
val method = context.query.get("method")
|
||||||
|
|
||||||
@@ -299,16 +303,24 @@ class DeveloperEndpoints(private val context: Context) {
|
|||||||
context.respondCode(400, "Missing method");
|
context.respondCode(400, "Missing method");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(method != "isLoggedIn")
|
||||||
|
Logger.i(TAG, "Remote Call [${objId}].${method}(...)");
|
||||||
|
|
||||||
|
val parameters = context.readContentString();
|
||||||
|
|
||||||
val remoteObj = getRemoteObject(objId);
|
val remoteObj = getRemoteObject(objId);
|
||||||
val paras = JsonParser.parseString(parameters);
|
val paras = JsonParser.parseString(parameters);
|
||||||
if(!paras.isJsonArray)
|
if(!paras.isJsonArray)
|
||||||
throw IllegalArgumentException("Expected json array as body");
|
throw IllegalArgumentException("Expected json array as body");
|
||||||
if(method != "isLoggedIn")
|
|
||||||
Logger.i(TAG, "Remote Call [${objId}].${method}(...)");
|
|
||||||
val callResult = remoteObj.call(method, paras as JsonArray);
|
val callResult = remoteObj.call(method, paras as JsonArray);
|
||||||
val json = wrapRemoteResult(callResult, false);
|
val json = wrapRemoteResult(callResult, false);
|
||||||
context.respondCode(200, json, "application/json");
|
context.respondCode(200, json, "application/json");
|
||||||
}
|
}
|
||||||
|
catch(invocation: InvocationTargetException) {
|
||||||
|
val innerException = invocation.targetException;
|
||||||
|
Logger.e("DeveloperEndpoints", innerException.message, innerException);
|
||||||
|
context.respondCode(500, innerException::class.simpleName + ":" + innerException.message ?: "", "text/plain")
|
||||||
|
}
|
||||||
catch(ilEx: IllegalArgumentException) {
|
catch(ilEx: IllegalArgumentException) {
|
||||||
if(ilEx.message?.contains("does not exist") ?: false) {
|
if(ilEx.message?.contains("does not exist") ?: false) {
|
||||||
context.respondCode(400, ilEx.message ?: "", "text/plain");
|
context.respondCode(400, ilEx.message ?: "", "text/plain");
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ class AutoUpdateDialog(context: Context?) : AlertDialog(context) {
|
|||||||
_buttonUpdate.visibility = Button.GONE;
|
_buttonUpdate.visibility = Button.GONE;
|
||||||
setCancelable(false);
|
setCancelable(false);
|
||||||
setCanceledOnTouchOutside(false);
|
setCanceledOnTouchOutside(false);
|
||||||
|
|
||||||
|
Logger.i(TAG, "Keep screen on set update")
|
||||||
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
|
||||||
_text.text = context.resources.getText(R.string.downloading_update);
|
_text.text = context.resources.getText(R.string.downloading_update);
|
||||||
@@ -178,6 +180,7 @@ class AutoUpdateDialog(context: Context?) : AlertDialog(context) {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
Logger.i(TAG, "Keep screen on unset install")
|
||||||
window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ import com.futo.platformplayer.UIDialogs
|
|||||||
import com.futo.platformplayer.casting.CastProtocolType
|
import com.futo.platformplayer.casting.CastProtocolType
|
||||||
import com.futo.platformplayer.casting.StateCasting
|
import com.futo.platformplayer.casting.StateCasting
|
||||||
import com.futo.platformplayer.models.CastingDeviceInfo
|
import com.futo.platformplayer.models.CastingDeviceInfo
|
||||||
import com.futo.platformplayer.states.StateApp
|
|
||||||
import com.futo.platformplayer.toInetAddress
|
import com.futo.platformplayer.toInetAddress
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
|
|
||||||
class CastingAddDialog(context: Context?) : AlertDialog(context) {
|
class CastingAddDialog(context: Context?) : AlertDialog(context) {
|
||||||
@@ -26,6 +23,7 @@ class CastingAddDialog(context: Context?) : AlertDialog(context) {
|
|||||||
private lateinit var _textError: TextView;
|
private lateinit var _textError: TextView;
|
||||||
private lateinit var _buttonCancel: Button;
|
private lateinit var _buttonCancel: Button;
|
||||||
private lateinit var _buttonConfirm: LinearLayout;
|
private lateinit var _buttonConfirm: LinearLayout;
|
||||||
|
private lateinit var _buttonTutorial: TextView;
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -38,6 +36,7 @@ class CastingAddDialog(context: Context?) : AlertDialog(context) {
|
|||||||
_textError = findViewById(R.id.text_error);
|
_textError = findViewById(R.id.text_error);
|
||||||
_buttonCancel = findViewById(R.id.button_cancel);
|
_buttonCancel = findViewById(R.id.button_cancel);
|
||||||
_buttonConfirm = findViewById(R.id.button_confirm);
|
_buttonConfirm = findViewById(R.id.button_confirm);
|
||||||
|
_buttonTutorial = findViewById(R.id.button_tutorial)
|
||||||
|
|
||||||
ArrayAdapter.createFromResource(context, R.array.casting_device_type_array, R.layout.spinner_item_simple).also { adapter ->
|
ArrayAdapter.createFromResource(context, R.array.casting_device_type_array, R.layout.spinner_item_simple).also { adapter ->
|
||||||
adapter.setDropDownViewResource(R.layout.spinner_dropdownitem_simple);
|
adapter.setDropDownViewResource(R.layout.spinner_dropdownitem_simple);
|
||||||
@@ -62,7 +61,7 @@ class CastingAddDialog(context: Context?) : AlertDialog(context) {
|
|||||||
|
|
||||||
_buttonConfirm.setOnClickListener {
|
_buttonConfirm.setOnClickListener {
|
||||||
val castProtocolType: CastProtocolType = when (_spinnerType.selectedItemPosition) {
|
val castProtocolType: CastProtocolType = when (_spinnerType.selectedItemPosition) {
|
||||||
0 -> CastProtocolType.FASTCAST
|
0 -> CastProtocolType.FCAST
|
||||||
1 -> CastProtocolType.CHROMECAST
|
1 -> CastProtocolType.CHROMECAST
|
||||||
2 -> CastProtocolType.AIRPLAY
|
2 -> CastProtocolType.AIRPLAY
|
||||||
else -> {
|
else -> {
|
||||||
@@ -105,6 +104,11 @@ class CastingAddDialog(context: Context?) : AlertDialog(context) {
|
|||||||
StateCasting.instance.addRememberedDevice(castingDeviceInfo);
|
StateCasting.instance.addRememberedDevice(castingDeviceInfo);
|
||||||
performDismiss();
|
performDismiss();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_buttonTutorial.setOnClickListener {
|
||||||
|
UIDialogs.showCastingTutorialDialog(context)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.futo.platformplayer.dialogs
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import com.futo.platformplayer.R
|
||||||
|
import com.futo.platformplayer.UIDialogs
|
||||||
|
import com.futo.platformplayer.activities.FCastGuideActivity
|
||||||
|
import com.futo.platformplayer.activities.PolycentricWhyActivity
|
||||||
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.views.buttons.BigButton
|
||||||
|
|
||||||
|
|
||||||
|
class CastingHelpDialog(context: Context?) : AlertDialog(context) {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(LayoutInflater.from(context).inflate(R.layout.dialog_casting_help, null));
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_guide).onClick.subscribe {
|
||||||
|
context.startActivity(Intent(context, FCastGuideActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_video).onClick.subscribe {
|
||||||
|
try {
|
||||||
|
//TODO: Replace the URL with the casting video URL
|
||||||
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://fcast.org/"))
|
||||||
|
context.startActivity(browserIntent);
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to open browser.", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_website).onClick.subscribe {
|
||||||
|
try {
|
||||||
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://fcast.org/"))
|
||||||
|
context.startActivity(browserIntent);
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to open browser.", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_technical).onClick.subscribe {
|
||||||
|
try {
|
||||||
|
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://gitlab.com/futo-org/fcast/-/wikis/Protocol-version-1"))
|
||||||
|
context.startActivity(browserIntent);
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Logger.i(TAG, "Failed to open browser.", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
findViewById<BigButton>(R.id.button_close).onClick.subscribe {
|
||||||
|
dismiss()
|
||||||
|
UIDialogs.showCastingAddDialog(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TAG = "CastingTutorialDialog";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import com.futo.platformplayer.api.media.models.comments.PolycentricPlatformComm
|
|||||||
import com.futo.platformplayer.api.media.models.ratings.RatingLikeDislikes
|
import com.futo.platformplayer.api.media.models.ratings.RatingLikeDislikes
|
||||||
import com.futo.platformplayer.constructs.Event1
|
import com.futo.platformplayer.constructs.Event1
|
||||||
import com.futo.platformplayer.dp
|
import com.futo.platformplayer.dp
|
||||||
|
import com.futo.platformplayer.fullyBackfillServersAnnounceExceptions
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.selectBestImage
|
import com.futo.platformplayer.selectBestImage
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
@@ -85,6 +86,11 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol
|
|||||||
return@setOnClickListener;
|
return@setOnClickListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_editComment.text.isBlank()) {
|
||||||
|
UIDialogs.toast(context, "Comment should not be blank.");
|
||||||
|
return@setOnClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
val comment = _editComment.text.toString();
|
val comment = _editComment.text.toString();
|
||||||
val processHandle = StatePolycentric.instance.processHandle!!
|
val processHandle = StatePolycentric.instance.processHandle!!
|
||||||
val eventPointer = processHandle.post(comment, null, ref)
|
val eventPointer = processHandle.post(comment, null, ref)
|
||||||
@@ -92,7 +98,7 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol
|
|||||||
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
Logger.i(TAG, "Started backfill");
|
Logger.i(TAG, "Started backfill");
|
||||||
processHandle.fullyBackfillServers()
|
processHandle.fullyBackfillServersAnnounceExceptions()
|
||||||
Logger.i(TAG, "Finished backfill");
|
Logger.i(TAG, "Finished backfill");
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Logger.e(TAG, "Failed to backfill servers.", e);
|
Logger.e(TAG, "Failed to backfill servers.", e);
|
||||||
@@ -112,7 +118,7 @@ class CommentDialog(context: Context?, val contextUrl: String, val ref: Protocol
|
|||||||
msg = comment,
|
msg = comment,
|
||||||
rating = RatingLikeDislikes(0, 0),
|
rating = RatingLikeDislikes(0, 0),
|
||||||
date = OffsetDateTime.now(),
|
date = OffsetDateTime.now(),
|
||||||
reference = eventPointer.toReference()
|
eventPointer = eventPointer
|
||||||
));
|
));
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
|
|||||||
@@ -1,24 +1,33 @@
|
|||||||
package com.futo.platformplayer.dialogs
|
package com.futo.platformplayer.dialogs
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.drawable.Animatable
|
import android.graphics.drawable.Animatable
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.UIDialogs
|
import com.futo.platformplayer.UIDialogs
|
||||||
|
import com.futo.platformplayer.activities.AddSourceActivity
|
||||||
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
|
import com.futo.platformplayer.activities.QRCaptureActivity
|
||||||
import com.futo.platformplayer.casting.CastConnectionState
|
import com.futo.platformplayer.casting.CastConnectionState
|
||||||
import com.futo.platformplayer.casting.CastingDevice
|
import com.futo.platformplayer.casting.CastingDevice
|
||||||
import com.futo.platformplayer.casting.StateCasting
|
import com.futo.platformplayer.casting.StateCasting
|
||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.views.adapters.DeviceAdapter
|
import com.futo.platformplayer.views.adapters.DeviceAdapter
|
||||||
|
import com.google.zxing.integration.android.IntentIntegrator
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -28,6 +37,7 @@ class ConnectCastingDialog(context: Context?) : AlertDialog(context) {
|
|||||||
private lateinit var _imageLoader: ImageView;
|
private lateinit var _imageLoader: ImageView;
|
||||||
private lateinit var _buttonClose: Button;
|
private lateinit var _buttonClose: Button;
|
||||||
private lateinit var _buttonAdd: Button;
|
private lateinit var _buttonAdd: Button;
|
||||||
|
private lateinit var _buttonScanQR: Button;
|
||||||
private lateinit var _textNoDevicesFound: TextView;
|
private lateinit var _textNoDevicesFound: TextView;
|
||||||
private lateinit var _textNoDevicesRemembered: TextView;
|
private lateinit var _textNoDevicesRemembered: TextView;
|
||||||
private lateinit var _recyclerDevices: RecyclerView;
|
private lateinit var _recyclerDevices: RecyclerView;
|
||||||
@@ -44,6 +54,7 @@ class ConnectCastingDialog(context: Context?) : AlertDialog(context) {
|
|||||||
_imageLoader = findViewById(R.id.image_loader);
|
_imageLoader = findViewById(R.id.image_loader);
|
||||||
_buttonClose = findViewById(R.id.button_close);
|
_buttonClose = findViewById(R.id.button_close);
|
||||||
_buttonAdd = findViewById(R.id.button_add);
|
_buttonAdd = findViewById(R.id.button_add);
|
||||||
|
_buttonScanQR = findViewById(R.id.button_scan_qr);
|
||||||
_recyclerDevices = findViewById(R.id.recycler_devices);
|
_recyclerDevices = findViewById(R.id.recycler_devices);
|
||||||
_recyclerRememberedDevices = findViewById(R.id.recycler_remembered_devices);
|
_recyclerRememberedDevices = findViewById(R.id.recycler_remembered_devices);
|
||||||
_textNoDevicesFound = findViewById(R.id.text_no_devices_found);
|
_textNoDevicesFound = findViewById(R.id.text_no_devices_found);
|
||||||
@@ -77,6 +88,17 @@ class ConnectCastingDialog(context: Context?) : AlertDialog(context) {
|
|||||||
UIDialogs.showCastingAddDialog(context);
|
UIDialogs.showCastingAddDialog(context);
|
||||||
dismiss();
|
dismiss();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
val c = ownerActivity
|
||||||
|
if (c is MainActivity) {
|
||||||
|
_buttonScanQR.visibility = View.VISIBLE
|
||||||
|
_buttonScanQR.setOnClickListener {
|
||||||
|
c.showUrlQrCodeScanner()
|
||||||
|
dismiss()
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
_buttonScanQR.visibility = View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ import com.futo.platformplayer.casting.*
|
|||||||
import com.futo.platformplayer.states.StateApp
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.google.android.material.slider.Slider
|
import com.google.android.material.slider.Slider
|
||||||
import com.google.android.material.slider.Slider.OnChangeListener
|
import com.google.android.material.slider.Slider.OnChangeListener
|
||||||
import com.google.android.material.slider.Slider.OnSliderTouchListener
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class ConnectedCastingDialog(context: Context?) : AlertDialog(context) {
|
class ConnectedCastingDialog(context: Context?) : AlertDialog(context) {
|
||||||
@@ -105,7 +103,7 @@ class ConnectedCastingDialog(context: Context?) : AlertDialog(context) {
|
|||||||
} else if (d is AirPlayCastingDevice) {
|
} else if (d is AirPlayCastingDevice) {
|
||||||
_imageDevice.setImageResource(R.drawable.ic_airplay);
|
_imageDevice.setImageResource(R.drawable.ic_airplay);
|
||||||
_textType.text = "AirPlay";
|
_textType.text = "AirPlay";
|
||||||
} else if (d is FastCastCastingDevice) {
|
} else if (d is FCastCastingDevice) {
|
||||||
_imageDevice.setImageResource(R.drawable.ic_fc);
|
_imageDevice.setImageResource(R.drawable.ic_fc);
|
||||||
_textType.text = "FastCast";
|
_textType.text = "FastCast";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,8 @@ class ImportDialog : AlertDialog {
|
|||||||
|
|
||||||
setCancelable(false);
|
setCancelable(false);
|
||||||
setCanceledOnTouchOutside(false);
|
setCanceledOnTouchOutside(false);
|
||||||
|
|
||||||
|
Logger.i(TAG, "Keep screen on set import")
|
||||||
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
|
||||||
_updateSpinner.drawable?.assume<Animatable>()?.start();
|
_updateSpinner.drawable?.assume<Animatable>()?.start();
|
||||||
@@ -201,6 +203,7 @@ class ImportDialog : AlertDialog {
|
|||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Logger.e(TAG, "Failed to update import UI.", e)
|
Logger.e(TAG, "Failed to update import UI.", e)
|
||||||
} finally {
|
} finally {
|
||||||
|
Logger.i(TAG, "Keep screen on unset update")
|
||||||
window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package com.futo.platformplayer.dialogs
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.widget.Button
|
||||||
|
import com.futo.platformplayer.R
|
||||||
|
import com.futo.platformplayer.activities.MainActivity
|
||||||
|
import com.futo.platformplayer.readBytes
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
|
import com.futo.platformplayer.states.StateBackup
|
||||||
|
import com.futo.platformplayer.views.buttons.BigButton
|
||||||
|
|
||||||
|
class ImportOptionsDialog: AlertDialog {
|
||||||
|
private val _context: MainActivity;
|
||||||
|
|
||||||
|
private lateinit var _button_import_zip: BigButton;
|
||||||
|
private lateinit var _button_import_ezip: BigButton;
|
||||||
|
private lateinit var _button_import_txt: BigButton;
|
||||||
|
private lateinit var _button_import_newpipe_subs: BigButton;
|
||||||
|
private lateinit var _button_close: Button;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(context: MainActivity): super(context) {
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(LayoutInflater.from(context).inflate(R.layout.dialog_import_options, null));
|
||||||
|
_button_import_zip = findViewById(R.id.button_import_zip);
|
||||||
|
_button_import_ezip = findViewById(R.id.button_import_ezip);
|
||||||
|
_button_import_txt = findViewById(R.id.button_import_txt);
|
||||||
|
_button_import_newpipe_subs = findViewById(R.id.button_import_newpipe_subs);
|
||||||
|
_button_close = findViewById(R.id.button_cancel);
|
||||||
|
|
||||||
|
_button_import_zip.onClick.subscribe {
|
||||||
|
dismiss();
|
||||||
|
StateApp.instance.requestFileReadAccess(_context, null, "application/zip") {
|
||||||
|
val zipBytes = it?.readBytes(context) ?: return@requestFileReadAccess;
|
||||||
|
StateBackup.importZipBytes(_context, StateApp.instance.scope, zipBytes);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_button_import_ezip.setOnClickListener {
|
||||||
|
|
||||||
|
}
|
||||||
|
_button_import_txt.onClick.subscribe {
|
||||||
|
dismiss();
|
||||||
|
StateApp.instance.requestFileReadAccess(_context, null, "text/plain") {
|
||||||
|
val txtBytes = it?.readBytes(context) ?: return@requestFileReadAccess;
|
||||||
|
val txt = String(txtBytes);
|
||||||
|
StateBackup.importTxt(_context, txt);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
_button_import_newpipe_subs.onClick.subscribe {
|
||||||
|
dismiss();
|
||||||
|
StateApp.instance.requestFileReadAccess(_context, null, "application/json") {
|
||||||
|
val jsonBytes = it?.readBytes(context) ?: return@requestFileReadAccess;
|
||||||
|
val json = String(jsonBytes);
|
||||||
|
StateBackup.importNewPipeSubs(_context, json);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
_button_close.setOnClickListener {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dismiss() {
|
||||||
|
super.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -144,6 +144,7 @@ class MigrateDialog : AlertDialog {
|
|||||||
|
|
||||||
setCancelable(false);
|
setCancelable(false);
|
||||||
setCanceledOnTouchOutside(false);
|
setCanceledOnTouchOutside(false);
|
||||||
|
Logger.i(TAG, "Keep screen on set restore")
|
||||||
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
|
||||||
_updateSpinner.drawable?.assume<Animatable>()?.start();
|
_updateSpinner.drawable?.assume<Animatable>()?.start();
|
||||||
@@ -214,6 +215,7 @@ class MigrateDialog : AlertDialog {
|
|||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Logger.e(TAG, "Failed to update import UI.", e)
|
Logger.e(TAG, "Failed to update import UI.", e)
|
||||||
} finally {
|
} finally {
|
||||||
|
Logger.i(TAG, "Keep screen on unset restore")
|
||||||
window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
package com.futo.platformplayer.downloads
|
package com.futo.platformplayer.downloads
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
|
import com.arthenica.ffmpegkit.FFmpegKit
|
||||||
|
import com.arthenica.ffmpegkit.ReturnCode
|
||||||
|
import com.arthenica.ffmpegkit.StatisticsCallback
|
||||||
import com.futo.platformplayer.Settings
|
import com.futo.platformplayer.Settings
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.states.StateDownloads
|
import com.futo.platformplayer.states.StateDownloads
|
||||||
import com.futo.platformplayer.states.StatePlatform
|
import com.futo.platformplayer.states.StatePlatform
|
||||||
import com.futo.platformplayer.api.http.ManagedHttpClient
|
import com.futo.platformplayer.api.http.ManagedHttpClient
|
||||||
import com.futo.platformplayer.api.media.PlatformID
|
import com.futo.platformplayer.api.media.PlatformID
|
||||||
|
import com.futo.platformplayer.api.media.models.streams.VideoUnMuxedSourceDescriptor
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.*
|
import com.futo.platformplayer.api.media.models.streams.sources.*
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.other.IStreamMetaDataSource
|
import com.futo.platformplayer.api.media.models.streams.sources.other.IStreamMetaDataSource
|
||||||
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
||||||
@@ -18,22 +24,28 @@ import com.futo.platformplayer.hasAnySource
|
|||||||
import com.futo.platformplayer.helpers.FileHelper.Companion.sanitizeFileName
|
import com.futo.platformplayer.helpers.FileHelper.Companion.sanitizeFileName
|
||||||
import com.futo.platformplayer.helpers.VideoHelper
|
import com.futo.platformplayer.helpers.VideoHelper
|
||||||
import com.futo.platformplayer.isDownloadable
|
import com.futo.platformplayer.isDownloadable
|
||||||
|
import com.futo.platformplayer.parsers.HLS
|
||||||
import com.futo.platformplayer.serializers.OffsetDateTimeNullableSerializer
|
import com.futo.platformplayer.serializers.OffsetDateTimeNullableSerializer
|
||||||
import com.futo.platformplayer.serializers.OffsetDateTimeSerializer
|
|
||||||
import com.futo.platformplayer.toHumanBitrate
|
import com.futo.platformplayer.toHumanBitrate
|
||||||
import com.futo.platformplayer.toHumanBytesSpeed
|
import com.futo.platformplayer.toHumanBytesSpeed
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Deferred
|
import kotlinx.coroutines.Deferred
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
import java.util.UUID
|
||||||
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.ForkJoinPool
|
import java.util.concurrent.ForkJoinPool
|
||||||
import java.util.concurrent.ForkJoinTask
|
import java.util.concurrent.ForkJoinTask
|
||||||
import java.util.concurrent.ThreadLocalRandom
|
import java.util.concurrent.ThreadLocalRandom
|
||||||
|
import kotlin.coroutines.resumeWithException
|
||||||
|
|
||||||
@kotlinx.serialization.Serializable
|
@kotlinx.serialization.Serializable
|
||||||
class VideoDownload {
|
class VideoDownload {
|
||||||
@@ -137,7 +149,7 @@ class VideoDownload {
|
|||||||
return items.joinToString(" • ");
|
return items.joinToString(" • ");
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun prepare() {
|
suspend fun prepare(client: ManagedHttpClient) {
|
||||||
Logger.i(TAG, "VideoDownload Prepare [${name}]");
|
Logger.i(TAG, "VideoDownload Prepare [${name}]");
|
||||||
if(video == null && videoDetails == null)
|
if(video == null && videoDetails == null)
|
||||||
throw IllegalStateException("Missing information for download to complete");
|
throw IllegalStateException("Missing information for download to complete");
|
||||||
@@ -157,24 +169,65 @@ class VideoDownload {
|
|||||||
|
|
||||||
videoDetails = SerializedPlatformVideoDetails.fromVideo(original, if (subtitleSource != null) listOf(subtitleSource!!) else listOf());
|
videoDetails = SerializedPlatformVideoDetails.fromVideo(original, if (subtitleSource != null) listOf(subtitleSource!!) else listOf());
|
||||||
if(videoSource == null && targetPixelCount != null) {
|
if(videoSource == null && targetPixelCount != null) {
|
||||||
val vsource = VideoHelper.selectBestVideoSource(videoDetails!!.video, targetPixelCount!!.toInt(), arrayOf())
|
val videoSources = arrayListOf<IVideoSource>()
|
||||||
|
for (source in original.video.videoSources) {
|
||||||
|
if (source is IHLSManifestSource) {
|
||||||
|
try {
|
||||||
|
val playlistResponse = client.get(source.url)
|
||||||
|
if (playlistResponse.isOk) {
|
||||||
|
val playlistContent = playlistResponse.body?.string()
|
||||||
|
if (playlistContent != null) {
|
||||||
|
videoSources.addAll(HLS.parseAndGetVideoSources(source, playlistContent, source.url))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.i(TAG, "Failed to get HLS video sources", e)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
videoSources.add(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val vsource = VideoHelper.selectBestVideoSource(videoSources, targetPixelCount!!.toInt(), arrayOf())
|
||||||
// ?: throw IllegalStateException("Could not find a valid video source for video");
|
// ?: throw IllegalStateException("Could not find a valid video source for video");
|
||||||
if(vsource != null) {
|
if(vsource != null) {
|
||||||
if (vsource is IVideoUrlSource)
|
if (vsource is IVideoUrlSource)
|
||||||
videoSource = VideoUrlSource.fromUrlSource(vsource);
|
videoSource = VideoUrlSource.fromUrlSource(vsource)
|
||||||
else
|
else
|
||||||
throw DownloadException("Video source is not supported for downloading (yet)", false);
|
throw DownloadException("Video source is not supported for downloading (yet)", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(audioSource == null && targetBitrate != null) {
|
if(audioSource == null && targetBitrate != null) {
|
||||||
val asource = VideoHelper.selectBestAudioSource(videoDetails!!.video, arrayOf(), null, targetPixelCount)
|
val audioSources = arrayListOf<IAudioSource>()
|
||||||
|
val video = original.video
|
||||||
|
if (video is VideoUnMuxedSourceDescriptor) {
|
||||||
|
for (source in video.audioSources) {
|
||||||
|
if (source is IHLSManifestSource) {
|
||||||
|
try {
|
||||||
|
val playlistResponse = client.get(source.url)
|
||||||
|
if (playlistResponse.isOk) {
|
||||||
|
val playlistContent = playlistResponse.body?.string()
|
||||||
|
if (playlistContent != null) {
|
||||||
|
audioSources.addAll(HLS.parseAndGetAudioSources(source, playlistContent, source.url))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.i(TAG, "Failed to get HLS audio sources", e)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
audioSources.add(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val asource = VideoHelper.selectBestAudioSource(audioSources, arrayOf(), null, targetBitrate)
|
||||||
?: if(videoSource != null ) null
|
?: if(videoSource != null ) null
|
||||||
else throw DownloadException("Could not find a valid video or audio source for download")
|
else throw DownloadException("Could not find a valid video or audio source for download")
|
||||||
if(asource == null)
|
if(asource == null)
|
||||||
audioSource = null;
|
audioSource = null;
|
||||||
else if(asource is IAudioUrlSource)
|
else if(asource is IAudioUrlSource)
|
||||||
audioSource = AudioUrlSource.fromUrlSource(asource);
|
audioSource = AudioUrlSource.fromUrlSource(asource)
|
||||||
else
|
else
|
||||||
throw DownloadException("Audio source is not supported for downloading (yet)", false);
|
throw DownloadException("Audio source is not supported for downloading (yet)", false);
|
||||||
}
|
}
|
||||||
@@ -183,7 +236,8 @@ class VideoDownload {
|
|||||||
throw DownloadException("No valid sources found for video/audio");
|
throw DownloadException("No valid sources found for video/audio");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
suspend fun download(client: ManagedHttpClient, onProgress: ((Double) -> Unit)? = null) = coroutineScope {
|
|
||||||
|
suspend fun download(context: Context, client: ManagedHttpClient, onProgress: ((Double) -> Unit)? = null) = coroutineScope {
|
||||||
Logger.i(TAG, "VideoDownload Download [${name}]");
|
Logger.i(TAG, "VideoDownload Download [${name}]");
|
||||||
if(videoDetails == null || (videoSource == null && audioSource == null))
|
if(videoDetails == null || (videoSource == null && audioSource == null))
|
||||||
throw IllegalStateException("Missing information for download to complete");
|
throw IllegalStateException("Missing information for download to complete");
|
||||||
@@ -199,7 +253,7 @@ class VideoDownload {
|
|||||||
videoFilePath = File(downloadDir, videoFileName!!).absolutePath;
|
videoFilePath = File(downloadDir, videoFileName!!).absolutePath;
|
||||||
}
|
}
|
||||||
if(audioSource != null) {
|
if(audioSource != null) {
|
||||||
audioFileName = "${videoDetails!!.id.value!!} [${audioSource!!.bitrate}].${audioContainerToExtension(audioSource!!.container)}".sanitizeFileName();
|
audioFileName = "${videoDetails!!.id.value!!} [${audioSource!!.language}-${audioSource!!.bitrate}].${audioContainerToExtension(audioSource!!.container)}".sanitizeFileName();
|
||||||
audioFilePath = File(downloadDir, audioFileName!!).absolutePath;
|
audioFilePath = File(downloadDir, audioFileName!!).absolutePath;
|
||||||
}
|
}
|
||||||
if(subtitleSource != null) {
|
if(subtitleSource != null) {
|
||||||
@@ -217,7 +271,8 @@ class VideoDownload {
|
|||||||
if(videoSource != null) {
|
if(videoSource != null) {
|
||||||
sourcesToDownload.add(async {
|
sourcesToDownload.add(async {
|
||||||
Logger.i(TAG, "Started downloading video");
|
Logger.i(TAG, "Started downloading video");
|
||||||
videoFileSize = downloadSource("Video", client, videoSource!!.getVideoUrl(), File(downloadDir, videoFileName!!)) { length, totalRead, speed ->
|
|
||||||
|
val progressCallback = { length: Long, totalRead: Long, speed: Long ->
|
||||||
synchronized(progressLock) {
|
synchronized(progressLock) {
|
||||||
lastVideoLength = length;
|
lastVideoLength = length;
|
||||||
lastVideoRead = totalRead;
|
lastVideoRead = totalRead;
|
||||||
@@ -235,12 +290,18 @@ class VideoDownload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
videoFileSize = when (videoSource!!.container) {
|
||||||
|
"application/vnd.apple.mpegurl" -> downloadHlsSource(context, "Video", client, videoSource!!.getVideoUrl(), File(downloadDir, videoFileName!!), progressCallback)
|
||||||
|
else -> downloadFileSource("Video", client, videoSource!!.getVideoUrl(), File(downloadDir, videoFileName!!), progressCallback)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(audioSource != null) {
|
if(audioSource != null) {
|
||||||
sourcesToDownload.add(async {
|
sourcesToDownload.add(async {
|
||||||
Logger.i(TAG, "Started downloading audio");
|
Logger.i(TAG, "Started downloading audio");
|
||||||
audioFileSize = downloadSource("Audio", client, audioSource!!.getAudioUrl(), File(downloadDir, audioFileName!!)) { length, totalRead, speed ->
|
|
||||||
|
val progressCallback = { length: Long, totalRead: Long, speed: Long ->
|
||||||
synchronized(progressLock) {
|
synchronized(progressLock) {
|
||||||
lastAudioLength = length;
|
lastAudioLength = length;
|
||||||
lastAudioRead = totalRead;
|
lastAudioRead = totalRead;
|
||||||
@@ -258,6 +319,11 @@ class VideoDownload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
audioFileSize = when (audioSource!!.container) {
|
||||||
|
"application/vnd.apple.mpegurl" -> downloadHlsSource(context, "Audio", client, audioSource!!.getAudioUrl(), File(downloadDir, audioFileName!!), progressCallback)
|
||||||
|
else -> downloadFileSource("Audio", client, audioSource!!.getAudioUrl(), File(downloadDir, audioFileName!!), progressCallback)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (subtitleSource != null) {
|
if (subtitleSource != null) {
|
||||||
@@ -279,7 +345,105 @@ class VideoDownload {
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private fun downloadSource(name: String, client: ManagedHttpClient, videoUrl: String, targetFile: File, onProgress: (Long, Long, Long) -> Unit): Long {
|
|
||||||
|
private suspend fun downloadHlsSource(context: Context, name: String, client: ManagedHttpClient, hlsUrl: String, targetFile: File, onProgress: (Long, Long, Long) -> Unit): Long {
|
||||||
|
if(targetFile.exists())
|
||||||
|
targetFile.delete();
|
||||||
|
|
||||||
|
var downloadedTotalLength = 0L
|
||||||
|
|
||||||
|
val segmentFiles = arrayListOf<File>()
|
||||||
|
try {
|
||||||
|
val response = client.get(hlsUrl)
|
||||||
|
check(response.isOk) { "Failed to get variant playlist: ${response.code}" }
|
||||||
|
|
||||||
|
val vpContent = response.body?.string()
|
||||||
|
?: throw Exception("Variant playlist content is empty")
|
||||||
|
|
||||||
|
val variantPlaylist = HLS.parseVariantPlaylist(vpContent, hlsUrl)
|
||||||
|
variantPlaylist.segments.forEachIndexed { index, segment ->
|
||||||
|
if (segment !is HLS.MediaSegment) {
|
||||||
|
return@forEachIndexed
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.i(TAG, "Download '$name' segment $index Sequential");
|
||||||
|
val segmentFile = File(context.cacheDir, "segment-${UUID.randomUUID()}")
|
||||||
|
segmentFiles.add(segmentFile)
|
||||||
|
|
||||||
|
val segmentLength = downloadSource_Sequential(client, segmentFile.outputStream(), segment.uri) { segmentLength, totalRead, lastSpeed ->
|
||||||
|
val averageSegmentLength = if (index == 0) segmentLength else downloadedTotalLength / index
|
||||||
|
val expectedTotalLength = averageSegmentLength * (variantPlaylist.segments.size - 1) + segmentLength
|
||||||
|
onProgress(expectedTotalLength, downloadedTotalLength + totalRead, lastSpeed)
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadedTotalLength += segmentLength
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.i(TAG, "Combining segments into $targetFile");
|
||||||
|
combineSegments(context, segmentFiles, targetFile)
|
||||||
|
|
||||||
|
Logger.i(TAG, "${name} downloadSource Finished");
|
||||||
|
}
|
||||||
|
catch(ioex: IOException) {
|
||||||
|
if(targetFile.exists() ?: false)
|
||||||
|
targetFile.delete();
|
||||||
|
if(ioex.message?.contains("ENOSPC") ?: false)
|
||||||
|
throw Exception("Not enough space on device", ioex);
|
||||||
|
else
|
||||||
|
throw ioex;
|
||||||
|
}
|
||||||
|
catch(ex: Throwable) {
|
||||||
|
if(targetFile.exists() ?: false)
|
||||||
|
targetFile.delete();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
for (segmentFile in segmentFiles) {
|
||||||
|
segmentFile.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return downloadedTotalLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun combineSegments(context: Context, segmentFiles: List<File>, targetFile: File) = withContext(Dispatchers.IO) {
|
||||||
|
suspendCancellableCoroutine { continuation ->
|
||||||
|
val fileList = File(context.cacheDir, "fileList-${UUID.randomUUID()}.txt")
|
||||||
|
fileList.writeText(segmentFiles.joinToString("\n") { "file '${it.absolutePath}'" })
|
||||||
|
|
||||||
|
val cmd = "-f concat -safe 0 -i \"${fileList.absolutePath}\" -c copy \"${targetFile.absolutePath}\""
|
||||||
|
|
||||||
|
val statisticsCallback = StatisticsCallback { statistics ->
|
||||||
|
//TODO: Show progress?
|
||||||
|
}
|
||||||
|
|
||||||
|
val executorService = Executors.newSingleThreadExecutor()
|
||||||
|
val session = FFmpegKit.executeAsync(cmd,
|
||||||
|
{ session ->
|
||||||
|
if (ReturnCode.isSuccess(session.returnCode)) {
|
||||||
|
fileList.delete()
|
||||||
|
continuation.resumeWith(Result.success(Unit))
|
||||||
|
} else {
|
||||||
|
val errorMessage = if (ReturnCode.isCancel(session.returnCode)) {
|
||||||
|
"Command cancelled"
|
||||||
|
} else {
|
||||||
|
"Command failed with state '${session.state}' and return code ${session.returnCode}, stack trace ${session.failStackTrace}"
|
||||||
|
}
|
||||||
|
fileList.delete()
|
||||||
|
continuation.resumeWithException(RuntimeException(errorMessage))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ Logger.v(TAG, it.message) },
|
||||||
|
statisticsCallback,
|
||||||
|
executorService
|
||||||
|
)
|
||||||
|
|
||||||
|
continuation.invokeOnCancellation {
|
||||||
|
session.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun downloadFileSource(name: String, client: ManagedHttpClient, videoUrl: String, targetFile: File, onProgress: (Long, Long, Long) -> Unit): Long {
|
||||||
if(targetFile.exists())
|
if(targetFile.exists())
|
||||||
targetFile.delete();
|
targetFile.delete();
|
||||||
|
|
||||||
@@ -472,8 +636,10 @@ class VideoDownload {
|
|||||||
val expectedFile = File(videoFilePath!!);
|
val expectedFile = File(videoFilePath!!);
|
||||||
if(!expectedFile.exists())
|
if(!expectedFile.exists())
|
||||||
throw IllegalStateException("Video file missing after download");
|
throw IllegalStateException("Video file missing after download");
|
||||||
if(expectedFile.length() != videoFileSize)
|
if (videoSource?.container != "application/vnd.apple.mpegurl") {
|
||||||
throw IllegalStateException("Expected size [${videoFileSize}], but found ${expectedFile.length()}");
|
if (expectedFile.length() != videoFileSize)
|
||||||
|
throw IllegalStateException("Expected size [${videoFileSize}], but found ${expectedFile.length()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(audioSource != null) {
|
if(audioSource != null) {
|
||||||
if(audioFilePath == null)
|
if(audioFilePath == null)
|
||||||
@@ -481,8 +647,10 @@ class VideoDownload {
|
|||||||
val expectedFile = File(audioFilePath!!);
|
val expectedFile = File(audioFilePath!!);
|
||||||
if(!expectedFile.exists())
|
if(!expectedFile.exists())
|
||||||
throw IllegalStateException("Audio file missing after download");
|
throw IllegalStateException("Audio file missing after download");
|
||||||
if(expectedFile.length() != audioFileSize)
|
if (audioSource?.container != "application/vnd.apple.mpegurl") {
|
||||||
throw IllegalStateException("Expected size [${audioFileSize}], but found ${expectedFile.length()}");
|
if (expectedFile.length() != audioFileSize)
|
||||||
|
throw IllegalStateException("Expected size [${audioFileSize}], but found ${expectedFile.length()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(subtitleSource != null) {
|
if(subtitleSource != null) {
|
||||||
if(subtitleFilePath == null)
|
if(subtitleFilePath == null)
|
||||||
@@ -560,7 +728,7 @@ class VideoDownload {
|
|||||||
const val GROUP_PLAYLIST = "Playlist";
|
const val GROUP_PLAYLIST = "Playlist";
|
||||||
|
|
||||||
fun videoContainerToExtension(container: String): String? {
|
fun videoContainerToExtension(container: String): String? {
|
||||||
if (container.contains("video/mp4"))
|
if (container.contains("video/mp4") || container == "application/vnd.apple.mpegurl")
|
||||||
return "mp4";
|
return "mp4";
|
||||||
else if (container.contains("application/x-mpegURL"))
|
else if (container.contains("application/x-mpegURL"))
|
||||||
return "m3u8";
|
return "m3u8";
|
||||||
@@ -585,6 +753,8 @@ class VideoDownload {
|
|||||||
return "mp3";
|
return "mp3";
|
||||||
else if (container.contains("audio/webm"))
|
else if (container.contains("audio/webm"))
|
||||||
return "webma";
|
return "webma";
|
||||||
|
else if (container == "application/vnd.apple.mpegurl")
|
||||||
|
return "mp4";
|
||||||
else
|
else
|
||||||
return "audio";
|
return "audio";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
package com.futo.platformplayer.downloads
|
package com.futo.platformplayer.downloads
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import com.arthenica.ffmpegkit.*
|
import com.arthenica.ffmpegkit.*
|
||||||
import com.futo.platformplayer.api.media.models.streams.sources.*
|
import com.futo.platformplayer.api.media.models.streams.sources.*
|
||||||
import com.futo.platformplayer.constructs.Event1
|
import com.futo.platformplayer.constructs.Event1
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
|
import com.futo.platformplayer.states.StateApp
|
||||||
import com.futo.platformplayer.toHumanBitrate
|
import com.futo.platformplayer.toHumanBitrate
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
import java.util.UUID
|
||||||
import java.util.concurrent.CancellationException
|
import java.util.concurrent.CancellationException
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.coroutines.resumeWithException
|
import kotlin.coroutines.resumeWithException
|
||||||
@@ -43,7 +48,7 @@ class VideoExport {
|
|||||||
this.subtitleSource = subtitleSource;
|
this.subtitleSource = subtitleSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun export(onProgress: ((Double) -> Unit)? = null): File = coroutineScope {
|
suspend fun export(context: Context, onProgress: ((Double) -> Unit)? = null): DocumentFile = coroutineScope {
|
||||||
if(isCancelled) throw CancellationException("Export got cancelled");
|
if(isCancelled) throw CancellationException("Export got cancelled");
|
||||||
|
|
||||||
val v = videoSource;
|
val v = videoSource;
|
||||||
@@ -55,34 +60,47 @@ class VideoExport {
|
|||||||
if (a != null) sourceCount++;
|
if (a != null) sourceCount++;
|
||||||
if (s != null) sourceCount++;
|
if (s != null) sourceCount++;
|
||||||
|
|
||||||
var outputFile: File? = null;
|
val outputFile: DocumentFile?;
|
||||||
val moviesRoot = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
|
val downloadRoot = StateApp.instance.getExternalDownloadDirectory(context) ?: throw Exception("External download directory is not set");
|
||||||
val musicRoot = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
|
|
||||||
val moviesGrayjay = File(moviesRoot, "Grayjay");
|
|
||||||
val musicGrayjay = File(musicRoot, "Grayjay");
|
|
||||||
if(!moviesGrayjay.exists())
|
|
||||||
moviesGrayjay.mkdirs();
|
|
||||||
if(!musicGrayjay.exists())
|
|
||||||
musicGrayjay.mkdirs();
|
|
||||||
|
|
||||||
if (sourceCount > 1) {
|
if (sourceCount > 1) {
|
||||||
val outputFileName = toSafeFileName(videoLocal.name) + ".mp4"// + VideoDownload.videoContainerToExtension(v.container);
|
val outputFileName = toSafeFileName(videoLocal.name) + ".mp4"// + VideoDownload.videoContainerToExtension(v.container);
|
||||||
val f = File(moviesGrayjay, outputFileName);
|
val f = downloadRoot.createFile("video/mp4", outputFileName)
|
||||||
|
?: throw Exception("Failed to create file in external directory.");
|
||||||
|
|
||||||
Logger.i(TAG, "Combining video and audio through FFMPEG.");
|
Logger.i(TAG, "Combining video and audio through FFMPEG.");
|
||||||
combine(a?.filePath, v?.filePath, s?.filePath, f.absolutePath, videoLocal.duration.toDouble()) { progress -> onProgress?.invoke(progress) };
|
val tempFile = File(context.cacheDir, "${UUID.randomUUID()}.mp4");
|
||||||
|
try {
|
||||||
|
combine(a?.filePath, v?.filePath, s?.filePath, tempFile.absolutePath, videoLocal.duration.toDouble()) { progress -> onProgress?.invoke(progress) };
|
||||||
|
context.contentResolver.openOutputStream(f.uri)?.use { outputStream ->
|
||||||
|
copy(tempFile.absolutePath, outputStream) { progress -> onProgress?.invoke(progress) };
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
tempFile.delete();
|
||||||
|
}
|
||||||
outputFile = f;
|
outputFile = f;
|
||||||
} else if (v != null) {
|
} else if (v != null) {
|
||||||
val outputFileName = toSafeFileName(videoLocal.name) + "." + VideoDownload.videoContainerToExtension(v.container);
|
val outputFileName = toSafeFileName(videoLocal.name) + "." + VideoDownload.videoContainerToExtension(v.container);
|
||||||
val f = File(moviesGrayjay, outputFileName);
|
val f = downloadRoot.createFile(v.container, outputFileName)
|
||||||
|
?: throw Exception("Failed to create file in external directory.");
|
||||||
|
|
||||||
Logger.i(TAG, "Copying video.");
|
Logger.i(TAG, "Copying video.");
|
||||||
copy(v.filePath, f.absolutePath) { progress -> onProgress?.invoke(progress) };
|
|
||||||
|
context.contentResolver.openOutputStream(f.uri)?.use { outputStream ->
|
||||||
|
copy(v.filePath, outputStream) { progress -> onProgress?.invoke(progress) };
|
||||||
|
}
|
||||||
|
|
||||||
outputFile = f;
|
outputFile = f;
|
||||||
} else if (a != null) {
|
} else if (a != null) {
|
||||||
val outputFileName = toSafeFileName(videoLocal.name) + "." + VideoDownload.audioContainerToExtension(a.container);
|
val outputFileName = toSafeFileName(videoLocal.name) + "." + VideoDownload.audioContainerToExtension(a.container);
|
||||||
val f = File(musicGrayjay, outputFileName);
|
val f = downloadRoot.createFile(a.container, outputFileName)
|
||||||
|
?: throw Exception("Failed to create file in external directory.");
|
||||||
|
|
||||||
Logger.i(TAG, "Copying audio.");
|
Logger.i(TAG, "Copying audio.");
|
||||||
copy(a.filePath, f.absolutePath) { progress -> onProgress?.invoke(progress) };
|
|
||||||
|
context.contentResolver.openOutputStream(f.uri)?.use { outputStream ->
|
||||||
|
copy(a.filePath, outputStream) { progress -> onProgress?.invoke(progress) };
|
||||||
|
}
|
||||||
|
|
||||||
outputFile = f;
|
outputFile = f;
|
||||||
} else {
|
} else {
|
||||||
throw Exception("Cannot export when no audio or video source is set.");
|
throw Exception("Cannot export when no audio or video source is set.");
|
||||||
@@ -179,10 +197,9 @@ class VideoExport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun copy(fromPath: String, toPath: String, bufferSize: Int = 8192, onProgress: ((Double) -> Unit)? = null) {
|
private suspend fun copy(fromPath: String, outputStream: OutputStream, bufferSize: Int = 8192, onProgress: ((Double) -> Unit)? = null) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
var inputStream: FileInputStream? = null
|
var inputStream: FileInputStream? = null
|
||||||
var outputStream: FileOutputStream? = null
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val srcFile = File(fromPath)
|
val srcFile = File(fromPath)
|
||||||
@@ -190,17 +207,7 @@ class VideoExport {
|
|||||||
throw IOException("Source file not found.")
|
throw IOException("Source file not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
val dstFile = File(toPath)
|
|
||||||
val parentDir = dstFile.parentFile ?: throw IOException("Non existent parent dir.")
|
|
||||||
|
|
||||||
if (!parentDir.exists()) {
|
|
||||||
if (!parentDir.mkdirs()) {
|
|
||||||
throw IOException("Failed to create destination directory.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inputStream = FileInputStream(srcFile)
|
inputStream = FileInputStream(srcFile)
|
||||||
outputStream = FileOutputStream(dstFile)
|
|
||||||
|
|
||||||
val buffer = ByteArray(bufferSize)
|
val buffer = ByteArray(bufferSize)
|
||||||
val totalBytes = srcFile.length()
|
val totalBytes = srcFile.length()
|
||||||
@@ -221,7 +228,6 @@ class VideoExport {
|
|||||||
throw IOException("Error occurred while copying file: ${e.message}", e)
|
throw IOException("Error occurred while copying file: ${e.message}", e)
|
||||||
} finally {
|
} finally {
|
||||||
inputStream?.close()
|
inputStream?.close()
|
||||||
outputStream?.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.futo.platformplayer.encryption
|
||||||
|
|
||||||
|
class GEncryptionProvider {
|
||||||
|
companion object {
|
||||||
|
val instance: GEncryptionProviderV1 = GEncryptionProviderV1.instance;
|
||||||
|
val version = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-16
@@ -8,9 +8,8 @@ import java.security.KeyStore
|
|||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
import javax.crypto.KeyGenerator
|
import javax.crypto.KeyGenerator
|
||||||
import javax.crypto.spec.GCMParameterSpec
|
import javax.crypto.spec.GCMParameterSpec
|
||||||
import javax.crypto.spec.SecretKeySpec
|
|
||||||
|
|
||||||
class EncryptionProvider {
|
class GEncryptionProviderV0 {
|
||||||
private val _keyStore: KeyStore;
|
private val _keyStore: KeyStore;
|
||||||
private val secretKey: Key? get() = _keyStore.getKey(KEY_ALIAS, null);
|
private val secretKey: Key? get() = _keyStore.getKey(KEY_ALIAS, null);
|
||||||
|
|
||||||
@@ -25,45 +24,43 @@ class EncryptionProvider {
|
|||||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
||||||
.setRandomizedEncryptionRequired(false)
|
.setRandomizedEncryptionRequired(false)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
keyGenerator.generateKey();
|
keyGenerator.generateKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun encrypt(decrypted: String, password: String? = null): String {
|
fun encrypt(decrypted: String): String {
|
||||||
val encodedBytes = encrypt(decrypted.toByteArray(), password);
|
val encodedBytes = encrypt(decrypted.toByteArray());
|
||||||
val encrypted = Base64.encodeToString(encodedBytes, Base64.DEFAULT);
|
val encrypted = Base64.encodeToString(encodedBytes, Base64.DEFAULT);
|
||||||
return encrypted;
|
return encrypted;
|
||||||
}
|
}
|
||||||
fun encrypt(decrypted: ByteArray, password: String? = null): ByteArray {
|
fun encrypt(decrypted: ByteArray): ByteArray {
|
||||||
val c: Cipher = Cipher.getInstance(AES_MODE);
|
val c: Cipher = Cipher.getInstance(AES_MODE);
|
||||||
val keyToUse = if(password == null) secretKey else SecretKeySpec(password.toByteArray(), "AES");
|
c.init(Cipher.ENCRYPT_MODE, secretKey, GCMParameterSpec(TAG_LENGTH, FIXED_IV));
|
||||||
c.init(Cipher.ENCRYPT_MODE, keyToUse, GCMParameterSpec(128, FIXED_IV));
|
|
||||||
val encodedBytes: ByteArray = c.doFinal(decrypted);
|
val encodedBytes: ByteArray = c.doFinal(decrypted);
|
||||||
return encodedBytes;
|
return encodedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun decrypt(encrypted: String, password: String? = null): String {
|
fun decrypt(encrypted: String): String {
|
||||||
val c = Cipher.getInstance(AES_MODE);
|
val c = Cipher.getInstance(AES_MODE);
|
||||||
val keyToUse = if(password == null) secretKey else SecretKeySpec(password.toByteArray(), "AES");
|
c.init(Cipher.DECRYPT_MODE, secretKey, GCMParameterSpec(TAG_LENGTH, FIXED_IV));
|
||||||
c.init(Cipher.DECRYPT_MODE, keyToUse, GCMParameterSpec(128, FIXED_IV));
|
|
||||||
val decrypted = String(c.doFinal(Base64.decode(encrypted, Base64.DEFAULT)));
|
val decrypted = String(c.doFinal(Base64.decode(encrypted, Base64.DEFAULT)));
|
||||||
return decrypted;
|
return decrypted;
|
||||||
}
|
}
|
||||||
fun decrypt(encrypted: ByteArray, password: String? = null): ByteArray {
|
fun decrypt(encrypted: ByteArray): ByteArray {
|
||||||
val c = Cipher.getInstance(AES_MODE);
|
val c = Cipher.getInstance(AES_MODE);
|
||||||
val keyToUse = if(password == null) secretKey else SecretKeySpec(password.toByteArray(), "AES");
|
c.init(Cipher.DECRYPT_MODE, secretKey, GCMParameterSpec(TAG_LENGTH, FIXED_IV));
|
||||||
c.init(Cipher.DECRYPT_MODE, keyToUse, GCMParameterSpec(128, FIXED_IV));
|
|
||||||
return c.doFinal(encrypted);
|
return c.doFinal(encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val instance: EncryptionProvider = EncryptionProvider();
|
val instance: GEncryptionProviderV0 = GEncryptionProviderV0();
|
||||||
|
|
||||||
private val FIXED_IV = byteArrayOf(12, 43, 127, 2, 99, 22, 6, 78, 24, 53, 8, 101);
|
private val FIXED_IV = byteArrayOf(12, 43, 127, 2, 99, 22, 6, 78, 24, 53, 8, 101);
|
||||||
private const val AndroidKeyStore = "AndroidKeyStore";
|
private const val AndroidKeyStore = "AndroidKeyStore";
|
||||||
private const val KEY_ALIAS = "FUTOMedia_Key";
|
private const val KEY_ALIAS = "FUTOMedia_Key";
|
||||||
private const val AES_MODE = "AES/GCM/NoPadding";
|
private const val AES_MODE = "AES/GCM/NoPadding";
|
||||||
private val TAG = "EncryptionProvider";
|
private const val TAG_LENGTH = 128
|
||||||
|
private val TAG = "GEncryptionProviderV0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.futo.platformplayer.encryption
|
||||||
|
|
||||||
|
import android.security.keystore.KeyGenParameterSpec
|
||||||
|
import android.security.keystore.KeyProperties
|
||||||
|
import android.util.Base64
|
||||||
|
import java.security.Key
|
||||||
|
import java.security.KeyStore
|
||||||
|
import java.security.SecureRandom
|
||||||
|
import javax.crypto.Cipher
|
||||||
|
import javax.crypto.KeyGenerator
|
||||||
|
import javax.crypto.spec.GCMParameterSpec
|
||||||
|
|
||||||
|
class GEncryptionProviderV1 {
|
||||||
|
private val _keyStore: KeyStore;
|
||||||
|
private val secretKey: Key? get() = _keyStore.getKey(KEY_ALIAS, null);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
_keyStore = KeyStore.getInstance(AndroidKeyStore);
|
||||||
|
_keyStore.load(null);
|
||||||
|
|
||||||
|
if (!_keyStore.containsAlias(KEY_ALIAS)) {
|
||||||
|
val keyGenerator: KeyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, AndroidKeyStore)
|
||||||
|
keyGenerator.init(KeyGenParameterSpec.Builder(KEY_ALIAS, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
|
||||||
|
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
|
||||||
|
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
|
||||||
|
.setRandomizedEncryptionRequired(false)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
keyGenerator.generateKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun encrypt(decrypted: String): String {
|
||||||
|
val encrypted = encrypt(decrypted.toByteArray());
|
||||||
|
val encoded = Base64.encodeToString(encrypted, Base64.DEFAULT);
|
||||||
|
return encoded;
|
||||||
|
}
|
||||||
|
fun encrypt(decrypted: ByteArray): ByteArray {
|
||||||
|
val ivBytes = generateIv()
|
||||||
|
val c: Cipher = Cipher.getInstance(AES_MODE);
|
||||||
|
c.init(Cipher.ENCRYPT_MODE, secretKey, GCMParameterSpec(TAG_LENGTH, ivBytes));
|
||||||
|
val encodedBytes: ByteArray = c.doFinal(decrypted);
|
||||||
|
return ivBytes + encodedBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decrypt(data: String): String {
|
||||||
|
val bytes = Base64.decode(data, Base64.DEFAULT)
|
||||||
|
return String(decrypt(bytes));
|
||||||
|
}
|
||||||
|
fun decrypt(bytes: ByteArray): ByteArray {
|
||||||
|
val encrypted = bytes.sliceArray(IntRange(IV_SIZE, bytes.size - 1))
|
||||||
|
val ivBytes = bytes.sliceArray(IntRange(0, IV_SIZE - 1))
|
||||||
|
|
||||||
|
val c = Cipher.getInstance(AES_MODE);
|
||||||
|
c.init(Cipher.DECRYPT_MODE, secretKey, GCMParameterSpec(TAG_LENGTH, ivBytes));
|
||||||
|
return c.doFinal(encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateIv(): ByteArray {
|
||||||
|
val r = SecureRandom()
|
||||||
|
val ivBytes = ByteArray(IV_SIZE)
|
||||||
|
r.nextBytes(ivBytes)
|
||||||
|
return ivBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val instance: GEncryptionProviderV1 = GEncryptionProviderV1();
|
||||||
|
|
||||||
|
private const val AndroidKeyStore = "AndroidKeyStore";
|
||||||
|
private const val KEY_ALIAS = "FUTOMedia_Key";
|
||||||
|
private const val AES_MODE = "AES/GCM/NoPadding";
|
||||||
|
private const val IV_SIZE = 12;
|
||||||
|
private const val TAG_LENGTH = 128
|
||||||
|
private val TAG = "GEncryptionProviderV1";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.futo.platformplayer.encryption
|
||||||
|
|
||||||
|
class GPasswordEncryptionProvider {
|
||||||
|
companion object {
|
||||||
|
val version = 1;
|
||||||
|
val instance = GPasswordEncryptionProviderV1.instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.futo.platformplayer.encryption
|
||||||
|
|
||||||
|
import android.util.Base64
|
||||||
|
import javax.crypto.Cipher
|
||||||
|
import javax.crypto.spec.GCMParameterSpec
|
||||||
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
|
class GPasswordEncryptionProviderV0 {
|
||||||
|
private val _key: SecretKeySpec;
|
||||||
|
|
||||||
|
constructor(password: String) {
|
||||||
|
_key = SecretKeySpec(password.toByteArray(), "AES");
|
||||||
|
}
|
||||||
|
|
||||||
|
fun encrypt(decrypted: String): String {
|
||||||
|
val encodedBytes = encrypt(decrypted.toByteArray());
|
||||||
|
val encrypted = Base64.encodeToString(encodedBytes, Base64.DEFAULT);
|
||||||
|
return encrypted;
|
||||||
|
}
|
||||||
|
fun encrypt(decrypted: ByteArray): ByteArray {
|
||||||
|
val c: Cipher = Cipher.getInstance(AES_MODE);
|
||||||
|
c.init(Cipher.ENCRYPT_MODE, _key, GCMParameterSpec(TAG_LENGTH, FIXED_IV));
|
||||||
|
val encodedBytes: ByteArray = c.doFinal(decrypted);
|
||||||
|
return encodedBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decrypt(encrypted: String): String {
|
||||||
|
val c = Cipher.getInstance(AES_MODE);
|
||||||
|
c.init(Cipher.DECRYPT_MODE, _key, GCMParameterSpec(TAG_LENGTH, FIXED_IV));
|
||||||
|
val decrypted = String(c.doFinal(Base64.decode(encrypted, Base64.DEFAULT)));
|
||||||
|
return decrypted;
|
||||||
|
}
|
||||||
|
fun decrypt(encrypted: ByteArray): ByteArray {
|
||||||
|
val c = Cipher.getInstance(AES_MODE);
|
||||||
|
c.init(Cipher.DECRYPT_MODE, _key, GCMParameterSpec(TAG_LENGTH, FIXED_IV));
|
||||||
|
return c.doFinal(encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val FIXED_IV = byteArrayOf(12, 43, 127, 2, 99, 22, 6, 78, 24, 53, 8, 101);
|
||||||
|
private const val TAG_LENGTH = 128
|
||||||
|
private const val AES_MODE = "AES/GCM/NoPadding";
|
||||||
|
private val TAG = "GPasswordEncryptionProviderV0";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.futo.platformplayer.encryption
|
||||||
|
|
||||||
|
import android.util.Base64
|
||||||
|
import java.security.SecureRandom
|
||||||
|
import javax.crypto.Cipher
|
||||||
|
import javax.crypto.SecretKeyFactory
|
||||||
|
import javax.crypto.spec.GCMParameterSpec
|
||||||
|
import javax.crypto.spec.PBEKeySpec
|
||||||
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
|
class GPasswordEncryptionProviderV1 {
|
||||||
|
fun encrypt(decrypted: String, password: String): String {
|
||||||
|
val encrypted = encrypt(decrypted.toByteArray(), password);
|
||||||
|
val encoded = Base64.encodeToString(encrypted, Base64.DEFAULT);
|
||||||
|
return encoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun encrypt(decrypted: ByteArray, password: String): ByteArray {
|
||||||
|
val saltBytes = generateSalt()
|
||||||
|
val ivBytes = generateIv()
|
||||||
|
val c: Cipher = Cipher.getInstance(AES_MODE);
|
||||||
|
val key = deriveKeyFromPassword(password, saltBytes)
|
||||||
|
|
||||||
|
c.init(Cipher.ENCRYPT_MODE, key, GCMParameterSpec(TAG_LENGTH, ivBytes));
|
||||||
|
val encodedBytes: ByteArray = c.doFinal(decrypted);
|
||||||
|
return saltBytes + ivBytes + encodedBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decrypt(data: String, password: String): String {
|
||||||
|
val bytes = Base64.decode(data, Base64.DEFAULT)
|
||||||
|
return String(decrypt(bytes, password));
|
||||||
|
}
|
||||||
|
fun decrypt(bytes: ByteArray, password: String): ByteArray {
|
||||||
|
val encrypted = bytes.sliceArray(IntRange(SALT_SIZE + IV_SIZE, bytes.size - 1))
|
||||||
|
val ivBytes = bytes.sliceArray(IntRange(SALT_SIZE, SALT_SIZE + IV_SIZE - 1))
|
||||||
|
val saltBytes = bytes.sliceArray(IntRange(0, SALT_SIZE - 1))
|
||||||
|
val key = deriveKeyFromPassword(password, saltBytes)
|
||||||
|
|
||||||
|
val c = Cipher.getInstance(AES_MODE);
|
||||||
|
c.init(Cipher.DECRYPT_MODE, key, GCMParameterSpec(TAG_LENGTH, ivBytes));
|
||||||
|
return c.doFinal(encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deriveKeyFromPassword(password: String, salt: ByteArray): SecretKeySpec {
|
||||||
|
val factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256")
|
||||||
|
val spec = PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH)
|
||||||
|
val tmp = factory.generateSecret(spec)
|
||||||
|
return SecretKeySpec(tmp.encoded, "AES")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateSalt(): ByteArray {
|
||||||
|
val random = SecureRandom()
|
||||||
|
val salt = ByteArray(SALT_SIZE)
|
||||||
|
random.nextBytes(salt)
|
||||||
|
return salt
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateIv(): ByteArray {
|
||||||
|
val r = SecureRandom()
|
||||||
|
val ivBytes = ByteArray(IV_SIZE)
|
||||||
|
r.nextBytes(ivBytes)
|
||||||
|
return ivBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val instance = GPasswordEncryptionProviderV1();
|
||||||
|
private const val AES_MODE = "AES/GCM/NoPadding";
|
||||||
|
private const val IV_SIZE = 12
|
||||||
|
private const val SALT_SIZE = 16
|
||||||
|
private const val ITERATION_COUNT = 2 * 65536
|
||||||
|
private const val KEY_LENGTH = 256
|
||||||
|
private const val TAG_LENGTH = 128
|
||||||
|
private val TAG = "GPasswordEncryptionProviderV1";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import com.futo.platformplayer.engine.internal.V8BindObject
|
|||||||
import com.futo.platformplayer.getOrThrow
|
import com.futo.platformplayer.getOrThrow
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
|
import kotlin.streams.asSequence
|
||||||
import kotlin.streams.toList
|
import kotlin.streams.toList
|
||||||
|
|
||||||
class PackageHttp: V8Package {
|
class PackageHttp: V8Package {
|
||||||
@@ -171,7 +172,9 @@ class PackageHttp: V8Package {
|
|||||||
return@map it.first.requestWithBody(it.second.method, it.second.url, it.second.body!!, it.second.headers);
|
return@map it.first.requestWithBody(it.second.method, it.second.url, it.second.body!!, it.second.headers);
|
||||||
else
|
else
|
||||||
return@map it.first.request(it.second.method, it.second.url, it.second.headers);
|
return@map it.first.request(it.second.method, it.second.url, it.second.headers);
|
||||||
}.toList();
|
}
|
||||||
|
.asSequence()
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-12
@@ -4,7 +4,6 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.FrameLayout
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
@@ -12,8 +11,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import com.futo.platformplayer.states.StatePlatform
|
import com.futo.platformplayer.states.StatePlatform
|
||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
|
import com.futo.platformplayer.Settings
|
||||||
import com.futo.platformplayer.UIDialogs
|
import com.futo.platformplayer.UIDialogs
|
||||||
import com.futo.platformplayer.UISlideOverlays
|
|
||||||
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
|
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
|
||||||
import com.futo.platformplayer.api.media.models.channels.IPlatformChannel
|
import com.futo.platformplayer.api.media.models.channels.IPlatformChannel
|
||||||
import com.futo.platformplayer.api.media.models.contents.ContentType
|
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||||
@@ -25,7 +24,6 @@ import com.futo.platformplayer.api.media.structures.IPager
|
|||||||
import com.futo.platformplayer.api.media.structures.IRefreshPager
|
import com.futo.platformplayer.api.media.structures.IRefreshPager
|
||||||
import com.futo.platformplayer.api.media.structures.IReplacerPager
|
import com.futo.platformplayer.api.media.structures.IReplacerPager
|
||||||
import com.futo.platformplayer.api.media.structures.MultiPager
|
import com.futo.platformplayer.api.media.structures.MultiPager
|
||||||
import com.futo.platformplayer.cache.ChannelContentCache
|
|
||||||
import com.futo.platformplayer.constructs.Event1
|
import com.futo.platformplayer.constructs.Event1
|
||||||
import com.futo.platformplayer.constructs.Event2
|
import com.futo.platformplayer.constructs.Event2
|
||||||
import com.futo.platformplayer.constructs.TaskHandler
|
import com.futo.platformplayer.constructs.TaskHandler
|
||||||
@@ -33,10 +31,11 @@ import com.futo.platformplayer.engine.exceptions.PluginException
|
|||||||
import com.futo.platformplayer.engine.exceptions.ScriptCaptchaRequiredException
|
import com.futo.platformplayer.engine.exceptions.ScriptCaptchaRequiredException
|
||||||
import com.futo.platformplayer.fragment.mainactivity.main.FeedView
|
import com.futo.platformplayer.fragment.mainactivity.main.FeedView
|
||||||
import com.futo.platformplayer.fragment.mainactivity.main.PolycentricProfile
|
import com.futo.platformplayer.fragment.mainactivity.main.PolycentricProfile
|
||||||
|
import com.futo.platformplayer.states.StateCache
|
||||||
import com.futo.platformplayer.states.StatePolycentric
|
import com.futo.platformplayer.states.StatePolycentric
|
||||||
import com.futo.platformplayer.states.StateSubscriptions
|
import com.futo.platformplayer.states.StateSubscriptions
|
||||||
import com.futo.platformplayer.views.FeedStyle
|
import com.futo.platformplayer.views.FeedStyle
|
||||||
import com.futo.platformplayer.views.adapters.PreviewContentListAdapter
|
import com.futo.platformplayer.views.adapters.feedtypes.PreviewContentListAdapter
|
||||||
import com.futo.platformplayer.views.adapters.ContentPreviewViewHolder
|
import com.futo.platformplayer.views.adapters.ContentPreviewViewHolder
|
||||||
import com.futo.platformplayer.views.adapters.InsertedViewAdapterWithLoader
|
import com.futo.platformplayer.views.adapters.InsertedViewAdapterWithLoader
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -56,9 +55,11 @@ class ChannelContentsFragment : Fragment(), IChannelTabFragment {
|
|||||||
|
|
||||||
val onContentClicked = Event2<IPlatformContent, Long>();
|
val onContentClicked = Event2<IPlatformContent, Long>();
|
||||||
val onContentUrlClicked = Event2<String, ContentType>();
|
val onContentUrlClicked = Event2<String, ContentType>();
|
||||||
|
val onUrlClicked = Event1<String>();
|
||||||
val onChannelClicked = Event1<PlatformAuthorLink>();
|
val onChannelClicked = Event1<PlatformAuthorLink>();
|
||||||
val onAddToClicked = Event1<IPlatformContent>();
|
val onAddToClicked = Event1<IPlatformContent>();
|
||||||
val onAddToQueueClicked = Event1<IPlatformContent>();
|
val onAddToQueueClicked = Event1<IPlatformContent>();
|
||||||
|
val onLongPress = Event1<IPlatformContent>();
|
||||||
|
|
||||||
private fun getContentPager(channel: IPlatformChannel): IPager<IPlatformContent> {
|
private fun getContentPager(channel: IPlatformChannel): IPager<IPlatformContent> {
|
||||||
Logger.i(TAG, "getContentPager");
|
Logger.i(TAG, "getContentPager");
|
||||||
@@ -75,15 +76,14 @@ class ChannelContentsFragment : Fragment(), IChannelTabFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val _taskLoadVideos = TaskHandler<IPlatformChannel, IPager<IPlatformContent>>({lifecycleScope}, {
|
private val _taskLoadVideos = TaskHandler<IPlatformChannel, IPager<IPlatformContent>>({lifecycleScope}, {
|
||||||
return@TaskHandler getContentPager(it);
|
val livePager = getContentPager(it);
|
||||||
|
return@TaskHandler if(_channel?.let { StateSubscriptions.instance.isSubscribed(it) } == true)
|
||||||
|
StateCache.cachePagerResults(lifecycleScope, livePager);
|
||||||
|
else livePager;
|
||||||
}).success { livePager ->
|
}).success { livePager ->
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
val pager = if(_channel?.let { StateSubscriptions.instance.isSubscribed(it) } == true)
|
setPager(livePager);
|
||||||
ChannelContentCache.cachePagerResults(lifecycleScope, livePager);
|
|
||||||
else livePager;
|
|
||||||
|
|
||||||
setPager(pager);
|
|
||||||
}
|
}
|
||||||
.exception<ScriptCaptchaRequiredException> { }
|
.exception<ScriptCaptchaRequiredException> { }
|
||||||
.exception<Throwable> {
|
.exception<Throwable> {
|
||||||
@@ -106,7 +106,7 @@ class ChannelContentsFragment : Fragment(), IChannelTabFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val posBefore = _results.size;
|
val posBefore = _results.size;
|
||||||
val toAdd = it.filter { it is IPlatformVideo }.map { it as IPlatformVideo };
|
val toAdd = it.filter { it is IPlatformVideo }.map { it as IPlatformVideo }
|
||||||
_results.addAll(toAdd);
|
_results.addAll(toAdd);
|
||||||
_adapterResults?.let { adapterVideo -> adapterVideo.notifyItemRangeInserted(adapterVideo.childToParentPosition(posBefore), toAdd.size); };
|
_adapterResults?.let { adapterVideo -> adapterVideo.notifyItemRangeInserted(adapterVideo.childToParentPosition(posBefore), toAdd.size); };
|
||||||
}.exception<Throwable> {
|
}.exception<Throwable> {
|
||||||
@@ -153,12 +153,14 @@ class ChannelContentsFragment : Fragment(), IChannelTabFragment {
|
|||||||
|
|
||||||
_recyclerResults = view.findViewById(R.id.recycler_videos);
|
_recyclerResults = view.findViewById(R.id.recycler_videos);
|
||||||
|
|
||||||
_adapterResults = PreviewContentListAdapter(view.context, FeedStyle.THUMBNAIL, _results).apply {
|
_adapterResults = PreviewContentListAdapter(view.context, FeedStyle.THUMBNAIL, _results, null, Settings.instance.channel.progressBar).apply {
|
||||||
this.onContentUrlClicked.subscribe(this@ChannelContentsFragment.onContentUrlClicked::emit);
|
this.onContentUrlClicked.subscribe(this@ChannelContentsFragment.onContentUrlClicked::emit);
|
||||||
|
this.onUrlClicked.subscribe(this@ChannelContentsFragment.onUrlClicked::emit);
|
||||||
this.onContentClicked.subscribe(this@ChannelContentsFragment.onContentClicked::emit);
|
this.onContentClicked.subscribe(this@ChannelContentsFragment.onContentClicked::emit);
|
||||||
this.onChannelClicked.subscribe(this@ChannelContentsFragment.onChannelClicked::emit);
|
this.onChannelClicked.subscribe(this@ChannelContentsFragment.onChannelClicked::emit);
|
||||||
this.onAddToClicked.subscribe(this@ChannelContentsFragment.onAddToClicked::emit);
|
this.onAddToClicked.subscribe(this@ChannelContentsFragment.onAddToClicked::emit);
|
||||||
this.onAddToQueueClicked.subscribe(this@ChannelContentsFragment.onAddToQueueClicked::emit);
|
this.onAddToQueueClicked.subscribe(this@ChannelContentsFragment.onAddToQueueClicked::emit);
|
||||||
|
this.onLongPress.subscribe(this@ChannelContentsFragment.onLongPress::emit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_llmVideo = LinearLayoutManager(view.context);
|
_llmVideo = LinearLayoutManager(view.context);
|
||||||
|
|||||||
+20
-33
@@ -1,21 +1,20 @@
|
|||||||
package com.futo.platformplayer.fragment.channel.tab
|
package com.futo.platformplayer.fragment.channel.tab
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.futo.platformplayer.R
|
import com.futo.platformplayer.R
|
||||||
import com.futo.platformplayer.api.media.models.channels.IPlatformChannel
|
import com.futo.platformplayer.api.media.models.channels.IPlatformChannel
|
||||||
import com.futo.platformplayer.fragment.mainactivity.main.PolycentricProfile
|
import com.futo.platformplayer.fragment.mainactivity.main.PolycentricProfile
|
||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.views.SupportView
|
||||||
import com.futo.platformplayer.views.buttons.BigButton
|
|
||||||
|
|
||||||
|
|
||||||
class ChannelMonetizationFragment : Fragment, IChannelTabFragment {
|
class ChannelMonetizationFragment : Fragment, IChannelTabFragment {
|
||||||
private var _buttonStore: BigButton? = null;
|
private var _supportView: SupportView? = null
|
||||||
|
private var _textMonetization: TextView? = null
|
||||||
|
|
||||||
private var _lastChannel: IPlatformChannel? = null;
|
private var _lastChannel: IPlatformChannel? = null;
|
||||||
private var _lastPolycentricProfile: PolycentricProfile? = null;
|
private var _lastPolycentricProfile: PolycentricProfile? = null;
|
||||||
@@ -24,51 +23,39 @@ class ChannelMonetizationFragment : Fragment, IChannelTabFragment {
|
|||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
val view = inflater.inflate(R.layout.fragment_channel_monetization, container, false);
|
val view = inflater.inflate(R.layout.fragment_channel_monetization, container, false);
|
||||||
_buttonStore = view.findViewById(R.id.button_store);
|
_supportView = view.findViewById(R.id.support);
|
||||||
|
_textMonetization = view.findViewById(R.id.text_monetization);
|
||||||
_buttonStore?.onClick?.subscribe {
|
|
||||||
_lastPolycentricProfile?.systemState?.store?.let {
|
|
||||||
try {
|
|
||||||
val uri = Uri.parse(it);
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
|
||||||
intent.data = uri
|
|
||||||
startActivity(intent)
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
Logger.e(TAG, "Failed to open URI: '${it}'.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_lastChannel?.also {
|
_lastChannel?.also {
|
||||||
setChannel(it);
|
setChannel(it);
|
||||||
};
|
};
|
||||||
|
|
||||||
_lastPolycentricProfile?.also {
|
_supportView?.visibility = View.GONE;
|
||||||
setPolycentricProfile(it, animate = false);
|
_textMonetization?.visibility = View.GONE;
|
||||||
}
|
setPolycentricProfile(_lastPolycentricProfile, animate = false);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
_buttonStore = null;
|
_supportView = null;
|
||||||
|
_textMonetization = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setChannel(channel: IPlatformChannel) {
|
override fun setChannel(channel: IPlatformChannel) {
|
||||||
_lastChannel = channel;
|
_lastChannel = channel;
|
||||||
_buttonStore?.visibility = View.GONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setPolycentricProfile(polycentricProfile: PolycentricProfile?, animate: Boolean) {
|
fun setPolycentricProfile(polycentricProfile: PolycentricProfile?, animate: Boolean) {
|
||||||
_lastPolycentricProfile = polycentricProfile;
|
_lastPolycentricProfile = polycentricProfile
|
||||||
|
if (polycentricProfile != null) {
|
||||||
if (polycentricProfile == null) {
|
_supportView?.setPolycentricProfile(polycentricProfile, animate)
|
||||||
return;
|
_supportView?.visibility = View.VISIBLE
|
||||||
}
|
_textMonetization?.visibility = View.GONE
|
||||||
|
} else {
|
||||||
if (polycentricProfile.systemState.store.isNotEmpty()) {
|
_supportView?.setPolycentricProfile(null, animate)
|
||||||
_buttonStore?.visibility = View.VISIBLE;
|
_supportView?.visibility = View.GONE
|
||||||
|
_textMonetization?.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -225,7 +225,7 @@ class MenuBottomBarFragment : MainActivityFragment() {
|
|||||||
if (faqIndex != -1) {
|
if (faqIndex != -1) {
|
||||||
val button = buttons[faqIndex]
|
val button = buttons[faqIndex]
|
||||||
buttons.removeAt(faqIndex)
|
buttons.removeAt(faqIndex)
|
||||||
buttons.add(1, button)
|
buttons.add(if (buttons.size == 1) 1 else 0, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (data in buttons) {
|
for (data in buttons) {
|
||||||
@@ -252,8 +252,8 @@ class MenuBottomBarFragment : MainActivityFragment() {
|
|||||||
val defs = currentButtonDefinitions?.toMutableList() ?: return
|
val defs = currentButtonDefinitions?.toMutableList() ?: return
|
||||||
val metrics = StateApp.instance.displayMetrics ?: resources.displayMetrics;
|
val metrics = StateApp.instance.displayMetrics ?: resources.displayMetrics;
|
||||||
_buttonsVisible = floor(metrics.widthPixels.toDouble() / 65.dp(resources).toDouble()).roundToInt();
|
_buttonsVisible = floor(metrics.widthPixels.toDouble() / 65.dp(resources).toDouble()).roundToInt();
|
||||||
if (_buttonsVisible - 2 >= defs.size) {
|
if (_buttonsVisible - 1 >= defs.size) {
|
||||||
updateBottomMenuButtons(defs.slice(IntRange(0, defs.size - 1)).toMutableList(), false);
|
updateBottomMenuButtons(defs.toMutableList(), false);
|
||||||
} else {
|
} else {
|
||||||
updateBottomMenuButtons(defs.slice(IntRange(0, _buttonsVisible - 2)).toMutableList(), true);
|
updateBottomMenuButtons(defs.slice(IntRange(0, _buttonsVisible - 2)).toMutableList(), true);
|
||||||
updateMoreButtons(defs.slice(IntRange(_buttonsVisible - 1, defs.size - 1)).toMutableList());
|
updateMoreButtons(defs.slice(IntRange(_buttonsVisible - 1, defs.size - 1)).toMutableList());
|
||||||
@@ -351,6 +351,7 @@ class MenuBottomBarFragment : MainActivityFragment() {
|
|||||||
ButtonDefinition(4, R.drawable.ic_playlist, R.drawable.ic_playlist_filled, R.string.playlists, canToggle = false, { it.currentMain is PlaylistsFragment }, { it.navigate<PlaylistsFragment>() }),
|
ButtonDefinition(4, R.drawable.ic_playlist, R.drawable.ic_playlist_filled, R.string.playlists, canToggle = false, { it.currentMain is PlaylistsFragment }, { it.navigate<PlaylistsFragment>() }),
|
||||||
ButtonDefinition(5, R.drawable.ic_history, R.drawable.ic_history, R.string.history, canToggle = false, { it.currentMain is HistoryFragment }, { it.navigate<HistoryFragment>() }),
|
ButtonDefinition(5, R.drawable.ic_history, R.drawable.ic_history, R.string.history, canToggle = false, { it.currentMain is HistoryFragment }, { it.navigate<HistoryFragment>() }),
|
||||||
ButtonDefinition(6, R.drawable.ic_download, R.drawable.ic_download, R.string.downloads, canToggle = false, { it.currentMain is DownloadsFragment }, { it.navigate<DownloadsFragment>() }),
|
ButtonDefinition(6, R.drawable.ic_download, R.drawable.ic_download, R.string.downloads, canToggle = false, { it.currentMain is DownloadsFragment }, { it.navigate<DownloadsFragment>() }),
|
||||||
|
ButtonDefinition(8, R.drawable.ic_chat, R.drawable.ic_chat_filled, R.string.comments, canToggle = true, { it.currentMain is CommentsFragment }, { it.navigate<CommentsFragment>() }),
|
||||||
ButtonDefinition(7, R.drawable.ic_settings, R.drawable.ic_settings, R.string.settings, canToggle = false, { false }, {
|
ButtonDefinition(7, R.drawable.ic_settings, R.drawable.ic_settings, R.string.settings, canToggle = false, { false }, {
|
||||||
val c = it.context ?: return@ButtonDefinition;
|
val c = it.context ?: return@ButtonDefinition;
|
||||||
Logger.i(TAG, "settings preventPictureInPicture()");
|
Logger.i(TAG, "settings preventPictureInPicture()");
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ class BuyFragment : MainFragment() {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroyMainView() {
|
||||||
|
super.onDestroyMainView()
|
||||||
|
_view = null
|
||||||
|
}
|
||||||
|
|
||||||
class BuyView: LinearLayout {
|
class BuyView: LinearLayout {
|
||||||
private val _fragment: BuyFragment;
|
private val _fragment: BuyFragment;
|
||||||
|
|
||||||
@@ -91,7 +96,7 @@ class BuyFragment : MainFragment() {
|
|||||||
val price = prices[currency.id]!!;
|
val price = prices[currency.id]!!;
|
||||||
val priceDecimal = (price.toDouble() / 100);
|
val priceDecimal = (price.toDouble() / 100);
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
_buttonBuyText.text = currency.symbol + String.format("%.2f", priceDecimal);
|
_buttonBuyText.text = currency.symbol + String.format("%.2f", priceDecimal) + context.getString(R.string.plus_tax);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-8
@@ -210,6 +210,9 @@ class ChannelFragment : MainFragment() {
|
|||||||
UIDialogs.toast(context, "Queued [$name]", false);
|
UIDialogs.toast(context, "Queued [$name]", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
adapter.onUrlClicked.subscribe { url ->
|
||||||
|
fragment.navigate<BrowserFragment>(url);
|
||||||
|
}
|
||||||
adapter.onContentUrlClicked.subscribe { url, contentType ->
|
adapter.onContentUrlClicked.subscribe { url, contentType ->
|
||||||
when(contentType) {
|
when(contentType) {
|
||||||
ContentType.MEDIA -> {
|
ContentType.MEDIA -> {
|
||||||
@@ -220,6 +223,12 @@ class ChannelFragment : MainFragment() {
|
|||||||
else -> {};
|
else -> {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
adapter.onLongPress.subscribe { content ->
|
||||||
|
_overlayContainer.let {
|
||||||
|
if(content is IPlatformVideo)
|
||||||
|
_slideUpOverlay = UISlideOverlays.showVideoOptionsOverlay(content, it);
|
||||||
|
}
|
||||||
|
}
|
||||||
viewPager.adapter = adapter;
|
viewPager.adapter = adapter;
|
||||||
|
|
||||||
val tabLayoutMediator = TabLayoutMediator(tabs, viewPager) { tab, position ->
|
val tabLayoutMediator = TabLayoutMediator(tabs, viewPager) { tab, position ->
|
||||||
@@ -386,14 +395,18 @@ class ChannelFragment : MainFragment() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
val plugin = StatePlatform.instance.getChannelClientOrNull(channel.url);
|
_fragment.lifecycleScope.launch(Dispatchers.IO) {
|
||||||
if (plugin != null && plugin.capabilities.hasSearchChannelContents) {
|
val plugin = StatePlatform.instance.getChannelClientOrNull(channel.url);
|
||||||
buttons.add(Pair(R.drawable.ic_search) {
|
withContext(Dispatchers.Main) {
|
||||||
_fragment.navigate<SuggestionsFragment>(SuggestionsFragmentData("", SearchType.VIDEO, channel.url));
|
if (plugin != null && plugin.capabilities.hasSearchChannelContents) {
|
||||||
});
|
buttons.add(Pair(R.drawable.ic_search) {
|
||||||
}
|
_fragment.navigate<SuggestionsFragment>(SuggestionsFragmentData("", SearchType.VIDEO, channel.url));
|
||||||
|
});
|
||||||
|
|
||||||
_fragment.topBar?.assume<NavigationTopBarFragment>()?.setMenuItems(buttons);
|
_fragment.topBar?.assume<NavigationTopBarFragment>()?.setMenuItems(buttons);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_buttonSubscribe.setSubscribeChannel(channel);
|
_buttonSubscribe.setSubscribeChannel(channel);
|
||||||
_buttonSubscriptionSettings.visibility = if(_buttonSubscribe.isSubscribed) View.VISIBLE else View.GONE;
|
_buttonSubscriptionSettings.visibility = if(_buttonSubscribe.isSubscribed) View.VISIBLE else View.GONE;
|
||||||
@@ -424,11 +437,12 @@ class ChannelFragment : MainFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setPolycentricProfileOr(url: String, or: () -> Unit) {
|
private fun setPolycentricProfileOr(url: String, or: () -> Unit) {
|
||||||
|
setPolycentricProfile(null, animate = false);
|
||||||
|
|
||||||
val cachedProfile = channel?.let { PolycentricCache.instance.getCachedProfile(it.url) };
|
val cachedProfile = channel?.let { PolycentricCache.instance.getCachedProfile(it.url) };
|
||||||
if (cachedProfile != null) {
|
if (cachedProfile != null) {
|
||||||
setPolycentricProfile(cachedProfile, animate = false);
|
setPolycentricProfile(cachedProfile, animate = false);
|
||||||
} else {
|
} else {
|
||||||
setPolycentricProfile(null, animate = false);
|
|
||||||
or();
|
or();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user