open youtube links in app

This commit is contained in:
rimthekid 2022-03-14 14:28:44 -04:00
parent 8092759199
commit 72f12b1af4
3 changed files with 56 additions and 5 deletions

View File

@ -40,9 +40,6 @@
<!-- youtube -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
@ -55,7 +52,7 @@
<data android:pathPrefix="/v/" />
<data android:pathPrefix="/embed/" />
<data android:pathPrefix="/watch" />
<data android:pathPrefix="/attribution_link" />
<!--<data android:pathPrefix="/attribution_link" />-->
<data android:pathPrefix="/shorts/" />
<!-- channel prefix -->
<data android:pathPrefix="/channel/" />
@ -98,7 +95,6 @@
<data android:host="tube.connect.cafe" />
<data android:host="invidious.kavin.rocks" />
<data android:host="invidious-us.kavin.rocks" />
<data android:host="piped.kavin.rocks" />
<data android:host="invidious.site" />
<data android:host="vid.mint.lgbt" />
<data android:host="invidiou.site" />
@ -118,6 +114,7 @@
<data android:host="y.com.cm" />
<data android:pathPrefix="/" />
</intent-filter>
<!-- Piped filter -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />

View File

@ -14,6 +14,7 @@ import android.widget.LinearLayout
import androidx.appcompat.widget.Toolbar
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.view.ViewCompat
import androidx.core.view.ViewCompat.getWindowInsetsController
@ -101,9 +102,61 @@ class MainActivity : AppCompatActivity() {
if (data != null) {
Log.d("dafaq",data.host+" ${data.path} ")
if(data.host != null){
if(data.host!!.contains("youtube.com",true)){
if(data.path != null){
//channel
if(data.path!!.contains("/channel/") || data.path!!.contains("/c/") || data.path!!.contains("/user/")){
var channel = data.path
channel = channel!!.replace("/c/","")
channel = channel!!.replace("/user/","")
val bundle = bundleOf("channel_id" to channel)
navController.navigate(R.id.channel,bundle)
}else if(data.path!!.contains("/playlist")){
var playlist = data.query
playlist = playlist!!.replace("list=","")
val bundle = bundleOf("playlist_id" to playlist)
navController.navigate(R.id.playlistFragment,bundle)
}else if(data.path!!.contains("/shorts/") || data.path!!.contains("/embed/") || data.path!!.contains("/v/")){
var watch = data.path!!.replace("/shorts/","").replace("/v/","").replace("/embed/","")
var bundle = Bundle()
bundle.putString("videoId",watch)
var frag = PlayerFragment()
frag.arguments = bundle
supportFragmentManager.beginTransaction()
.remove(PlayerFragment())
.commit()
supportFragmentManager.beginTransaction()
.replace(R.id.container, frag)
.commitNow()
}else if(data.path!!.contains("/watch") && data.query != null){
Log.d("dafaq",data.query!!)
var watch = data.query!!
var watches = watch.split("&")
if (watches.size >1){
for (v in watches){
if (v.contains("v=")){
var bundle = Bundle()
bundle.putString("videoId",v.replace("v=",""))
var frag = PlayerFragment()
frag.arguments = bundle
supportFragmentManager.beginTransaction()
.remove(PlayerFragment())
.commit()
supportFragmentManager.beginTransaction()
.replace(R.id.container, frag)
.commitNow()
break
}
}
}
}
}
}
}
}
}
override fun onBackPressed() {

View File

@ -95,6 +95,7 @@ class PlayerFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
videoId = videoId!!.replace("/watch?v=","")
relDownloadVideo = view.findViewById(R.id.relPlayer_download)
val mainActivity = activity as MainActivity
mainActivity.findViewById<FrameLayout>(R.id.container).visibility=View.VISIBLE