-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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%" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"/> |
13 changes: 13 additions & 0 deletions
13
DailymotionProvider/src/main/kotlin/recloudstream/DailymotionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
DailymotionProvider/src/main/kotlin/recloudstream/DailymotionProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters