Skip to content

Commit

Permalink
Merge pull request #6711 from Bnyro/master
Browse files Browse the repository at this point in the history
fix: work around that some livestreams are not declared as such by NPE
  • Loading branch information
Bnyro authored Nov 9, 2024
2 parents 5d49eba + 65758e6 commit 9c418f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/github/libretube/api/obj/Streams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ data class Streams(
val uploaderSubscriberCount: Long = 0,
val previewFrames: List<PreviewFrames> = emptyList()
) {
val isLive = livestream || duration <= 0

fun toDownloadItems(downloadData: DownloadData): List<DownloadItem> {
val (id, name, videoFormat, videoQuality, audioFormat, audioQuality, audioTrackLocale, subCode) = downloadData
val items = mutableListOf<DownloadItem>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
binding.relPlayerDownload.setOnClickListener {
if (!this::streams.isInitialized) return@setOnClickListener

if (streams.duration <= 0) {
Toast.makeText(context, R.string.cannotDownload, Toast.LENGTH_SHORT).show()
} else {
DownloadHelper.startDownloadDialog(requireContext(), childFragmentManager, videoId)
}
DownloadHelper.startDownloadDialog(requireContext(), childFragmentManager, videoId)
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Expand Down Expand Up @@ -1135,8 +1131,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
R.string.subscribers,
streams.uploaderSubscriberCount.formatShort()
)
player.isLive = streams.livestream
relPlayerDownload.isVisible = !streams.livestream
player.isLive = streams.isLive
relPlayerDownload.isVisible = !streams.isLive
}
playerBinding.exoTitle.text = streams.title

Expand Down Expand Up @@ -1295,7 +1291,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
viewModel.player.seekTo(timeStamp * 1000)
// delete the time stamp because it already got consumed
timeStamp = 0L
} else if (!streams.livestream) {
} else if (!streams.isLive) {
// seek to the saved watch position
PlayerHelper.getStoredWatchPosition(videoId, streams.duration)?.let {
viewModel.player.seekTo(it)
Expand Down Expand Up @@ -1346,7 +1342,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
!PlayerHelper.useHlsOverDash && streams.videoStreams.isNotEmpty() -> {
// only use the dash manifest generated by YT if either it's a livestream or no other source is available
val dashUri =
if (streams.livestream && streams.dash != null) {
if (streams.isLive && streams.dash != null) {
ProxyHelper.unwrapStreamUrl(
streams.dash!!
).toUri()
Expand Down

0 comments on commit 9c418f9

Please sign in to comment.