Skip to content

Commit

Permalink
Add DailymotionProvider (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna712 authored Sep 11, 2024
1 parent 03c032f commit bf168de
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 4 deletions.
24 changes: 24 additions & 0 deletions DailymotionProvider/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// use an integer for version numbers
version = 1

cloudstream {
// All of these properties are optional, you can safely remove them

description = "Watch content from Dailymotion"
authors = listOf("Luna712")

/**
* Status int as the following:
* 0: Down
* 1: Ok
* 2: Slow
* 3: Beta only
* */
status = 1 // will be 3 if unspecified

// List of video source types. Users are able to filter for extensions in a given category.
// You can find a list of available types here:
// https://recloudstream.github.io/cloudstream/html/app/com.lagradost.cloudstream3/-tv-type/index.html
tvTypes = listOf("Others")
iconUrl = "https://www.google.com/s2/favicons?domain=www.dailymotion.com&sz=%size%"
}
2 changes: 2 additions & 0 deletions DailymotionProvider/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package recloudstream

import android.content.Context
import com.lagradost.cloudstream3.plugins.CloudstreamPlugin
import com.lagradost.cloudstream3.plugins.Plugin

@CloudstreamPlugin
class DailymotionPlugin: Plugin() {
override fun load(context: Context) {
// All providers should be added in this manner. Please don't edit the providers list directly.
registerMainAPI(DailymotionProvider())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package recloudstream

import com.lagradost.cloudstream3.HomePageList
import com.lagradost.cloudstream3.HomePageResponse
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.MainAPI
import com.lagradost.cloudstream3.MainPageRequest
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.SubtitleFile
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.newHomePageResponse
import com.lagradost.cloudstream3.newMovieLoadResponse
import com.lagradost.cloudstream3.newMovieSearchResponse
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.loadExtractor
import java.net.URLEncoder

class DailymotionProvider : MainAPI() {

data class VideoSearchResponse(
val list: List<VideoItem>
)

data class VideoItem(
val id: String,
val title: String,
val thumbnail_360_url: String
)

data class VideoDetailResponse(
val id: String,
val title: String,
val description: String,
val thumbnail_720_url: String
)

override var mainUrl = "https://api.dailymotion.com"
override var name = "Dailymotion"
override val supportedTypes = setOf(TvType.Others)

override var lang = "en"

override val hasMainPage = true

override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
val response = app.get("$mainUrl/videos?fields=id,title,thumbnail_360_url&limit=26").text
val popular = tryParseJson<VideoSearchResponse>(response)?.list ?: emptyList()

return newHomePageResponse(
listOf(
HomePageList(
"Popular",
popular.map { it.toSearchResponse(this) },
true
),
),
false
)
}

override suspend fun search(query: String): List<SearchResponse> {
val response = app.get("$mainUrl/videos?fields=id,title,thumbnail_360_url&limit=10&search=${query.encodeUri()}").text
val searchResults = tryParseJson<VideoSearchResponse>(response)?.list ?: return emptyList()
return searchResults.map { it.toSearchResponse(this) }
}

override suspend fun load(url: String): LoadResponse? {
val videoId = Regex("dailymotion.com/video/([a-zA-Z0-9]+)").find(url)?.groups?.get(1)?.value
val response = app.get("$mainUrl/video/$videoId?fields=id,title,description,thumbnail_720_url").text
val videoDetail = tryParseJson<VideoDetailResponse>(response) ?: return null
return videoDetail.toLoadResponse(this)
}

private fun VideoItem.toSearchResponse(provider: DailymotionProvider): SearchResponse {
return provider.newMovieSearchResponse(
this.title,
"https://www.dailymotion.com/video/${this.id}",
TvType.Movie
) {
this.posterUrl = thumbnail_360_url
}
}

private suspend fun VideoDetailResponse.toLoadResponse(provider: DailymotionProvider): LoadResponse {
return provider.newMovieLoadResponse(
this.title,
"https://www.dailymotion.com/video/${this.id}",
TvType.Movie,
this.id
) {
plot = description
posterUrl = thumbnail_720_url
}
}

override suspend fun loadLinks(
data: String,
isCasting: Boolean,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
): Boolean {
loadExtractor(
"https://www.dailymotion.com/embed/video/$data",
subtitleCallback,
callback
)
return true
}

companion object {
fun String.encodeUri(): String = URLEncoder.encode(this, "utf8")
}
}
4 changes: 2 additions & 2 deletions InvidiousProvider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ cloudstream {
status = 1 // will be 3 if unspecified

// List of video source types. Users are able to filter for extensions in a given category.
// You can find a list of avaliable types here:
// You can find a list of available types here:
// https://recloudstream.github.io/cloudstream/html/app/com.lagradost.cloudstream3/-tv-type/index.html
tvTypes = listOf("Others")
iconUrl = "https://www.google.com/s2/favicons?domain=invidious.io&sz=%size%"
}
}
4 changes: 2 additions & 2 deletions TwitchProvider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ cloudstream {
status = 1 // will be 3 if unspecified

// List of video source types. Users are able to filter for extensions in a given category.
// You can find a list of avaliable types here:
// You can find a list of available types here:
// https://recloudstream.github.io/dokka/-cloudstream/com.lagradost.cloudstream3/-tv-type/index.html
tvTypes = listOf("Live")
iconUrl = "https://www.google.com/s2/favicons?domain=twitch.tv&sz=%size%"
}
}

0 comments on commit bf168de

Please sign in to comment.