Skip to content

Commit

Permalink
change: moved kamyroll subtitle change stuff from exoplayer
Browse files Browse the repository at this point in the history
 to PlayerSettingsActivity.kt
  • Loading branch information
Adolar0042 committed Oct 17, 2022
1 parent 4bded6d commit 3ce5b90
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 31 deletions.
55 changes: 26 additions & 29 deletions app/src/main/java/ani/saikou/anime/ExoplayerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener {
}

// Subtitle View Margin fix for Kamyroll
if(model.watchSources!!.names[media.selected!!.source] == "Kamyroll" && settings.kamySubType == 0){
if(model.watchSources!!.names[media.selected!!.source] == "Kamyroll" && (settings.kamySubType == 0 || settings.kamySubType == 2)) {
val marginInt = -19 // This gets rounded to -18dp
val margin = (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, marginInt.toFloat(), getResources().getDisplayMetrics())).roundToInt()
exoSubtitleView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
Expand Down Expand Up @@ -882,6 +882,7 @@ class ExoplayerView : AppCompatActivity(), Player.Listener {
saveData("${media.id}_${media.anime!!.selectedEpisode}", exoPlayer.currentPosition, this)
val intent = Intent(this, PlayerSettingsActivity::class.java).apply {
putExtra("media", media)
putExtra("subtitle", subtitle)
}
finish()
startActivity(intent)
Expand Down Expand Up @@ -1031,38 +1032,34 @@ class ExoplayerView : AppCompatActivity(), Player.Listener {
subClick()
}

var kamySubUrl = ""
if(subtitle != null){
// Change Kamyroll Subtitle Type
if (model.watchSources!!.names[media.selected!!.source] == "Kamyroll") {
if (settings.kamySubType == 0) kamySubUrl =
subtitle!!.url.url.replace("&out=vtt", "&out=ass").replace("&out=srt", "&out=ass")
if (settings.kamySubType == 1) kamySubUrl =
subtitle!!.url.url.replace("&out=ass", "&out=vtt").replace("&out=srt", "&out=vtt")
if (settings.kamySubType == 2) kamySubUrl =
subtitle!!.url.url.replace("&out=ass", "&out=srt").replace("&out=vtt", "&out=srt")
}
val newSub: Subtitle? = intent.getSerializableExtra("subtitle") as Subtitle?
var sub: MediaItem.SubtitleConfiguration? = null
if(newSub == null && subtitle != null) {
sub = MediaItem.SubtitleConfiguration
.Builder(Uri.parse(subtitle!!.url.url))
.setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setMimeType(
when (subtitle?.type) {
SubtitleType.VTT -> MimeTypes.TEXT_VTT
SubtitleType.ASS -> MimeTypes.TEXT_SSA
SubtitleType.SRT -> MimeTypes.APPLICATION_SUBRIP
else -> MimeTypes.TEXT_UNKNOWN
}
)
.build()
}

val sub = if (subtitle != null)
MediaItem.SubtitleConfiguration
.Builder(Uri.parse(if(kamySubUrl != "") kamySubUrl else subtitle!!.url.url))
.setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setMimeType(
if(kamySubUrl != "") when(settings.kamySubType){
0 -> MimeTypes.TEXT_SSA
1 -> MimeTypes.TEXT_VTT
2 -> MimeTypes.APPLICATION_SUBRIP
else -> MimeTypes.TEXT_UNKNOWN
} else when (subtitle?.type) {
if(newSub != null){
sub = MediaItem.SubtitleConfiguration
.Builder(Uri.parse(newSub.url.url))
.setSelectionFlags(C.SELECTION_FLAG_FORCED)
.setMimeType(when (newSub.type) {
SubtitleType.VTT -> MimeTypes.TEXT_VTT
SubtitleType.ASS -> MimeTypes.TEXT_SSA
SubtitleType.SRT -> MimeTypes.APPLICATION_SUBRIP
else -> MimeTypes.TEXT_UNKNOWN
}
)
.build()
else null
}
)
.build()
}

lifecycleScope.launch(Dispatchers.IO) {
ext.onVideoPlayed(video)
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/ani/saikou/settings/PlayerSettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.AlertDialog
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
Expand All @@ -14,6 +15,7 @@ import ani.saikou.*
import ani.saikou.anime.ExoplayerView
import ani.saikou.databinding.ActivityPlayerSettingsBinding
import ani.saikou.media.Media
import ani.saikou.parsers.*
import com.google.android.material.snackbar.Snackbar
import kotlin.math.roundToInt

Expand All @@ -23,10 +25,36 @@ class PlayerSettingsActivity : AppCompatActivity() {
private val player = "player_settings"

var media:Media?=null
var subtitle:Subtitle?=null
override fun onBackPressed() {
val settings = loadData<PlayerSettings>(player, toast = false) ?: PlayerSettings().apply { saveData(player, this) }
if(media!=null) {
var newSubtitle: Subtitle? = null
if(subtitle != null){
// Change Kamyroll Subtitle Type
var newUrl: FileUrl? = null
var newType: SubtitleType? = null
val newLanguage: String
Log.d("Subtitle","SOURCE URL: ${subtitle!!.url.url}")
if (subtitle!!.url.url.contains("api.kamyroll.tech", true)) {
if (settings.kamySubType == 0) {
newUrl = FileUrl[subtitle!!.url.url.replace("&out=vtt", "&out=ass").replace("&out=srt", "&out=ass")]!!
newType = SubtitleType.ASS
}
if (settings.kamySubType == 1) {
newUrl = FileUrl[subtitle!!.url.url.replace("&out=ass", "&out=vtt").replace("&out=srt", "&out=vtt")]!!
newType = SubtitleType.VTT
}
if (settings.kamySubType == 2) {
newUrl = FileUrl[subtitle!!.url.url.replace("&out=ass", "&out=srt").replace("&out=vtt", "&out=srt")]!!
newType = SubtitleType.SRT
}
newLanguage = subtitle!!.language
newSubtitle = Subtitle(newLanguage, newUrl!!, newType!!) }
}
val intent = Intent(this, ExoplayerView::class.java).apply {
putExtra("media", media)
if(newSubtitle != null) putExtra("subtitle", newSubtitle)
}
finish()
startActivity(intent)
Expand All @@ -45,6 +73,7 @@ class PlayerSettingsActivity : AppCompatActivity() {

try {
media = intent.getSerializableExtra("media") as? Media
subtitle = intent.getSerializableExtra("subtitle") as? Subtitle
} catch (e: Exception) {
toast(e.toString())
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_player_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@
android:fontFamily="@font/poppins_family"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/subtitle_language_info"
android:text="@string/kamyroll_language_info"
android:textSize="14sp" />

</LinearLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
<string name="sub_font_select">Subtitle Font</string>
<string name="subtitle_font_size">Subtitle Size</string>
<string name="kamyroll_language_button">Kamyroll Language</string>
<string name="subtitle_language_info"><b>Note:</b> This changes the episode title and description language. <b>New Episodes won\'t be available with translated titles for up to 2 hours and will not be shown in the episode list. To view them as they release please switch to english.</b> For changes to take effect the app needs to restart. <b>Some languages might not work!</b></string>
<string name="kamyroll_language_info"><b>Note:</b> This changes the episode title and description language. <b>New Episodes won\'t be available with translated titles for up to 2 hours and will not be shown in the episode list. To view them as they release please switch to english.</b> For changes to take effect the app needs to restart. <b>Some languages might not work!</b></string>

<string name="auto">Auto</string>
<string name="auto_play_next_episode">Autoplay Next Episode</string>
Expand Down

0 comments on commit 3ce5b90

Please sign in to comment.