Skip to content

Commit

Permalink
Merge pull request #158 from bethropolis/main
Browse files Browse the repository at this point in the history
added piped
  • Loading branch information
OshekharO authored Jan 5, 2024
2 parents 37d5abb + 3a77b84 commit 09db563
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Miru extensions repository | [Miru App Download](https://github.com/miru-project
| Mtlnation | mtlnation.com | v0.0.2 | OshekharO | en | fikushon | [Source Code](https://github.com/miru-project/repo/blob/main/repo/mtlnation.com.js) |
| YTS.mx | mx.yts | v0.0.6 | MiaoMint | all | bangumi | [Source Code](https://github.com/miru-project/repo/blob/main/repo/mx.yts.js) |
| Nyaa | nyaa.si | v0.0.1 | appdevelpo | en | bangumi | [Source Code](https://github.com/miru-project/repo/blob/main/repo/nyaa.si.js) |
| Piped | piped.video | v0.0.1 | bethro | all | bangumi | [Source Code](https://github.com/miru-project/repo/blob/main/repo/piped.video.js) |
| rawkuma | rawkuma.com | v0.0.2 | appdevelpo | jp | manga | [Source Code](https://github.com/miru-project/repo/blob/main/repo/rawkuma.com.js) |
| ReadLN | readlightnovels | v0.0.2 | OshekharO | en | fikushon | [Source Code](https://github.com/miru-project/repo/blob/main/repo/readlightnovels.js) |
| ACG.RIP | rip.acg | v0.0.1 | MiaoMint | zh-cn | bangumi | [Source Code](https://github.com/miru-project/repo/blob/main/repo/rip.acg.js) |
Expand Down
12 changes: 12 additions & 0 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,18 @@
"version": "v0.0.1",
"webSite": "https://www.haha888.xyz"
},
{
"author": "bethro",
"icon": "https://piped.video/img/icons/android-chrome-192x192.png",
"lang": "all",
"license": "MIT",
"name": "Piped",
"package": "piped.video",
"type": "bangumi",
"url": "piped.video.js",
"version": "v0.0.1",
"webSite": "https://piped.video"
},
{
"author": "bachig26",
"icon": "https://pornenix.com/templates/pornenix/images/logo.png",
Expand Down
113 changes: 113 additions & 0 deletions repo/piped.video.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// ==MiruExtension==
// @name Piped
// @version v0.0.1
// @author bethro
// @lang all
// @license MIT
// @icon https://piped.video/img/icons/android-chrome-192x192.png
// @package piped.video
// @type bangumi
// @webSite https://piped.video
// ==/MiruExtension==

export default class extends Extension {
async req(url) {
return this.request(url, {
headers: {
"Miru-Url": await this.getSetting("piped"),
},
});
}

async load() {
this.registerSetting({
title: "PIPED INSTANCE",
key: "piped",
type: "input",
description: "url piped instance api",
defaultValue: "https://pipedapi.kavin.rocks",
});

this.registerSetting({
title: "DEFAULT QUALITY",
key: "quality",
type: "input",
description: "default video quality",
defaultValue: "480p",
});
}

async latest(page) {
const res = await this.req(`/trending?region=US`);
return res.map((item) => ({
url: item.url,
title: item.title,
cover: item.thumbnail,
}));
}

async search(kw, page) {
const res = await this.req(`/search?q=${kw}&filter=all`);
let streams = res.items.filter((item) => item.type == "stream");

return streams.map((item) => {
return {
url: item.url,
title: item.title || item.name,
cover: item.thumbnail,
};
});
}
async detail(url) {
const videoID = url.split("v=").pop();
const res = await this.req(`/streams/${videoID}`);

let preferredQuality = await this.getSetting("quality");
const sortEpisodes = (episodes) =>
episodes.sort((a, b) => {
const qualityA = a.title.toLowerCase();
const qualityB = b.title.toLowerCase();

if (qualityA === preferredQuality) return -1;
if (qualityB === preferredQuality) return 1;
return qualityA.localeCompare(qualityB);
});

let episodes = sortEpisodes(
res.videoStreams.map((item, index) => {
const audioStream = res.audioStreams[index] || res.audioStreams[0];
const combinedURL = `${item.url}|${audioStream ? audioStream.url : ''}|${videoID}`;
return {
title: item.quality,
urls: [{ name: res.title, url: combinedURL }],
};
})
);


return {
title: res.title,
cover: res.thumbnailUrl,
desc: res.description,
episodes,
};
}

async watch(url) {
const [videoUrl, audioUrl, videoID] = url.split("|");
const sub = await this.req(`/streams/${videoID}`);

const subtitles = sub.subtitles.map((item) => ({
title: item.name,
url: item.url,
language: item.code,
}));

return {
type: "hls",
url: videoUrl,
audioTrack: audioUrl,
subtitles: subtitles,
};
}
}

0 comments on commit 09db563

Please sign in to comment.