Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Android build

on:
push:
branches: ["main"]
pull_request:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
cache: gradle

- name: Build debug APK
run: ./gradlew assembleDebug
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Paste a link → Play → Close your phone → keeps playing
- **Pagination** — infinite scroll through a channel/playlist feed, or **Load all** to cache every page
- **Audio-only mode** — plays just the audio stream (no video) to save bandwidth and battery. Default on.
- **Background playback** — a Media3 foreground service keeps playing with the screen off, with a media notification (play / pause / stop) and lock-screen media controls
- **Video downloads** — save the currently playing or pasted YouTube video to the device's Downloads folder using Android's system download manager
- **Auto-play next** — optional toggle to keep playing through a channel/playlist queue
- **Never AI-dubbed** — when a video has multi-language AI dubbing, only the original language audio track is played
- **Live streams** — plays YouTube live streams, with periodic refresh so the URL doesn't expire
Expand All @@ -26,7 +27,7 @@ Paste a link → Play → Close your phone → keeps playing

Download the latest `app-release.apk` from the [Releases page](https://github.com/20plays/LiveTube/releases), allow "Install unknown apps" for your browser/download manager, and open the APK.

On first launch, grant the notification permission so the playback notification shows up.
On first launch, grant the notification permission so the playback notification shows up. Android 8 and 9 also ask for legacy storage permission the first time you save a video to Downloads.

## Build from source

Expand All @@ -53,15 +54,23 @@ The signed release APK is produced at `app/build/outputs/apk/release/app-release

- **Library tab** — tap `+`, paste a channel or playlist URL, it's validated and saved. Tap an item to open its feed; tap a video to play it.
- **Player tab** — paste any YouTube link (or a direct media URL) and press **Play**. Toggle **Audio only** to strip video, and **Auto-play next** to keep a list playing.
- **Download** — while a YouTube video is playing, or after pasting its URL, press **Download**. LiveTube resolves the best single-file stream containing both video and audio and hands it to Android's download manager. The file appears in Downloads and Android shows system download progress.

### Download quality

YouTube often serves higher resolutions as separate video-only and audio-only streams. LiveTube intentionally does not merge those tracks yet; downloads use the highest-quality stream that already contains both video and audio. This keeps downloads reliable and avoids bundling a media transcoder.

Live streams cannot be downloaded yet.

## Privacy

- No accounts, no telemetry, no ads. Everything is stored on-device (Room database).
- Requires network access to YouTube to fetch feeds and streams.
- Downloads are handled by Android's built-in download manager.

## Disclaimer

This app plays YouTube content through unofficial extraction of stream URLs and isn't endorsed by YouTube/Google. Background playback and audio-only streaming of YouTube content may not be permitted by YouTube's Terms of Service and generally require YouTube Premium via the official app — use responsibly, for personal, legal content. The extraction technique can break if YouTube changes its internals.
This app plays and downloads YouTube content through unofficial extraction of stream URLs and isn't endorsed by YouTube/Google. Background playback, audio-only streaming, and downloading YouTube content may not be permitted by YouTube's Terms of Service and may also be restricted by copyright — only download content you have the right to save. The extraction technique can break if YouTube changes its internals.

## License

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
applicationId = "com.livetube.player"
minSdk = 26
targetSdk = 36
versionCode = 1
versionName = "1.0"
versionCode = 2
versionName = "1.1"
}

signingConfigs {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<application
android:name=".App"
Expand Down
56 changes: 47 additions & 9 deletions app/src/main/java/com/livetube/player/extractor/Yt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ object Yt {

data class StreamPlay(val url: String, val live: Boolean, val title: String)

data class DownloadStream(
val url: String,
val title: String,
val mimeType: String,
val extension: String,
)

val service: StreamingService get() = ServiceList.YouTube

fun identify(raw: String): String {
Expand All @@ -104,8 +111,6 @@ object Yt {
} catch (e: java.io.IOException) {
throw UserMessageException("Couldn't reach YouTube. Check your connection.")
} catch (e: RuntimeException) {
// Guard against YouTube layout changes that make the parser throw (e.g. NPE while
// reading the channel header). Log for diagnosis, show a clean message.
android.util.Log.e("LT", "resolveNew failed", e)
throw UserMessageException("Couldn't add that link. Try again in a moment.")
}
Expand All @@ -114,8 +119,6 @@ object Yt {
private fun resolveChannel(raw: String): NewItem {
val ce = service.getChannelExtractor(raw)
ce.fetchPage()
// YouTube's channel header layout is A/B tested, so header parsing can throw for some
// accounts/regions. Keep the add resilient: degrade missing fields, never crash on them.
val id = headerSafe { ce.id } ?: raw
val name = headerSafe { ce.name } ?: fallbackName(raw)
val thumbnail = headerSafe { firstImageUrl(ce.avatars) }
Expand All @@ -127,14 +130,11 @@ object Yt {
?: throw ParsingException("No video tab found for this channel.")
tabUrl = absoluteUrl(videosTab.url)
val extractor = service.getChannelTabExtractor(videosTab)
// Preloaded ("ready") tabs already carry their page data; plain tabs need a fetch.
if (videosTab !is ReadyChannelTabListLinkHandler) {
extractor.fetchPage()
}
extractor
} catch (e: Exception) {
// Tabs/header couldn't be parsed (newer channel layout): fall back to the videos
// tab URL directly, which only parses the tab content and skips the header.
tabUrl = tabUrlFor(raw)
val extractor =
service.getChannelTabExtractor(service.getChannelTabLHFactory().fromUrl(tabUrl))
Expand Down Expand Up @@ -273,8 +273,6 @@ object Yt {
return@withContext StreamPlay(liveUrl, true, info.name)
}
if (audioOnly) {
// Always play the original language audio — never an AI dub or secondary
// track. Track type is null for videos without explicit audio tracks.
val original = info.audioStreams.filter {
it.audioTrackType == null || it.audioTrackType == AudioTrackType.ORIGINAL
}
Expand Down Expand Up @@ -305,6 +303,46 @@ object Yt {
throw UserMessageException(e.message ?: "Couldn't prepare playback.")
} catch (e: java.io.IOException) {
throw UserMessageException("Couldn't reach YouTube. Check your connection.")
} catch (e: RuntimeException) {
android.util.Log.e("LT", "resolveStream failed", e)
throw UserMessageException("Couldn't prepare playback. YouTube may have changed.")
}
}

suspend fun resolveDownload(videoUrl: String): DownloadStream =
withContext(Dispatchers.IO) {
try {
val info = StreamInfo.getInfo(service.getStreamExtractor(videoUrl))
if (isLiveType(info.streamType)) {
throw UserMessageException("Live streams can't be downloaded yet.")
}

val best = info.videoStreams
.asSequence()
.filter { !it.isVideoOnly && !it.url.isNullOrBlank() }
.maxByOrNull { parseResolution(it.resolution) }
?: throw UserMessageException(
"No single-file video stream is available for this video.",
)

val resolvedUrl = best.url
?: throw UserMessageException("The selected video stream has no download URL.")
val format = best.format
DownloadStream(
url = resolvedUrl,
title = info.name,
mimeType = format?.mimeType ?: "video/mp4",
extension = format?.suffix ?: "mp4",
)
} catch (e: UserMessageException) {
throw e
} catch (e: ExtractionException) {
throw UserMessageException(e.message ?: "Couldn't prepare the download.")
} catch (e: java.io.IOException) {
throw UserMessageException("Couldn't reach YouTube. Check your connection.")
} catch (e: RuntimeException) {
android.util.Log.e("LT", "resolveDownload failed", e)
throw UserMessageException("Couldn't prepare the download. YouTube may have changed.")
}
}

Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/com/livetube/player/ui/AddItemDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class AddItemDialog : DialogFragment() {

private val vm: LibraryViewModel by activityViewModels()

private lateinit var binding: DialogAddBinding
private var _binding: DialogAddBinding? = null
private val binding get() = _binding!!
private var alert: androidx.appcompat.app.AlertDialog? = null

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
binding = DialogAddBinding.inflate(layoutInflater)
_binding = DialogAddBinding.inflate(layoutInflater)
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.add_library_item)
.setView(binding.root)
Expand All @@ -39,14 +40,20 @@ class AddItemDialog : DialogFragment() {
val dlg = alert ?: return
val addButton = dlg.getButton(Dialog.BUTTON_POSITIVE)
addButton.isEnabled = false
vm.addUrl(raw) { error ->
vm.addUrl(raw) callback@{ error ->
val currentBinding = _binding ?: return@callback
if (error == null) {
dlg.dismiss()
} else {
binding.error.text = error
binding.error.isVisible = true
currentBinding.error.text = error
currentBinding.error.isVisible = true
addButton.isEnabled = true
}
}
}
}
override fun onDestroyView() {
alert = null
_binding = null
super.onDestroyView()
}
}
19 changes: 14 additions & 5 deletions app/src/main/java/com/livetube/player/ui/DetailFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ import kotlinx.coroutines.launch

class DetailFragment : Fragment(R.layout.fragment_detail) {

private lateinit var binding: FragmentDetailBinding
private var _binding: FragmentDetailBinding? = null
private val binding get() = _binding!!

private val itemId: String by lazy { requireArguments().getString("itemId").orEmpty() }
private val vm: DetailViewModel
by viewModels { DetailViewModel.factory(itemId) }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentDetailBinding.bind(view)
_binding = FragmentDetailBinding.bind(view)

binding.toolbar.setNavigationOnClickListener {
findNavController().navigateUp()
Expand Down Expand Up @@ -134,7 +135,8 @@ class DetailFragment : Fragment(R.layout.fragment_detail) {
} else {
emptyList()
}
val snackbar = Snackbar.make(binding.root, R.string.preparing, Snackbar.LENGTH_LONG)
val root = _binding?.root ?: return
val snackbar = Snackbar.make(root, R.string.preparing, Snackbar.LENGTH_LONG)
snackbar.show()
viewLifecycleOwner.lifecycleScope.launch {
val result = if (stream.videoUrl.contains("youtube.com") || stream.videoUrl.contains("youtu.be")) {
Expand All @@ -148,9 +150,16 @@ class DetailFragment : Fragment(R.layout.fragment_detail) {
Playback.play(stream.videoUrl, play.url, play.title, play.live, queue)
},
onFailure = { e ->
Snackbar.make(binding.root, e.message ?: "Failed to play", Snackbar.LENGTH_LONG).show()
_binding?.root?.let { rootView ->
Snackbar.make(rootView, e.message ?: "Failed to play", Snackbar.LENGTH_LONG).show()
}
},
)
}
}
}
override fun onDestroyView() {
binding.rv.adapter = null
_binding = null
super.onDestroyView()
}
}
12 changes: 9 additions & 3 deletions app/src/main/java/com/livetube/player/ui/LibraryFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import kotlinx.coroutines.launch

class LibraryFragment : Fragment(R.layout.fragment_library) {

private lateinit var binding: FragmentLibraryBinding
private var _binding: FragmentLibraryBinding? = null
private val binding get() = _binding!!

private val vm: LibraryViewModel by activityViewModels()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentLibraryBinding.bind(view)
_binding = FragmentLibraryBinding.bind(view)

binding.toolbar.setOnMenuItemClickListener {
if (it.itemId == R.id.menu_refresh) {
Expand Down Expand Up @@ -69,4 +70,9 @@ class LibraryFragment : Fragment(R.layout.fragment_library) {
}
}
}
}
override fun onDestroyView() {
binding.rv.adapter = null
_binding = null
super.onDestroyView()
}
}
Loading
Loading