Skip to content

Commit

Permalink
Merge pull request #143 from caorushizi/fix/video
Browse files Browse the repository at this point in the history
Fix/video
  • Loading branch information
caorushizi authored May 14, 2024
2 parents 7cb2cd2 + a0306b3 commit aa9ea91
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=mediago
APP_ID=mediago.ziying.site
APP_COPYRIGHT=caorushizi
APP_VERSION=2.2.0-beta.0
APP_VERSION=2.2.0-beta.1

APP_SERVER_PORT=8433
1 change: 1 addition & 0 deletions packages/main/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./types
1 change: 1 addition & 0 deletions packages/main/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
types/
2 changes: 1 addition & 1 deletion packages/main/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mediago",
"version": "2.2.0-beta.0",
"version": "2.2.0-beta.1",
"description": "在线视频下载器",
"main": "main/index.js",
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/services/SniffingHelperService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
OnBeforeRequestListenerDetails,
} from "electron/main";

interface SourceParams {
export interface SourceParams {
id: number;
url: string;
filter: SourceFilter;
Expand All @@ -19,7 +19,7 @@ interface SourceParams {
type: DownloadType;
}

interface SourceFilter {
export interface SourceFilter {
matches: RegExp[];
type: DownloadType;
schema?: Record<string, string>;
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/services/WebviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class WebviewService {
try {
if (isDev && process.env.DEBUG_PLUGINS === "true") {
const content =
'const script=document.createElement("script");script.src="http://localhost:8080/src/main.ts";script.type="module";document.body.appendChild(script);';
'function addScript(src){const script=document.createElement("script");script.src=src;script.type="module";document.body.appendChild(script)}addScript("http://localhost:8080/src/main.ts");';
await this.webContents.executeJavaScript(content);
} else {
const content = readFileSync(pluginPath, "utf-8");
Expand Down
23 changes: 23 additions & 0 deletions packages/plugin/src/components/BilibiliButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@ export class BilibiliButton extends LitElement {
return html`<div class="mg-button" @click=${this.onClick}>下载</div>`;
}
}

function bilibili() {
const videoCards = document.querySelectorAll(".bili-video-card");
videoCards.forEach((card, index) => {
const imageDOM = card.querySelector(BILIBILI_DOWNLOAD_BUTTON);
if (!imageDOM) return;

const oldBtn = imageDOM.querySelectorAll("one-button");
if (oldBtn.length) return;

const isAd = $(card).find(".bili-video-card__info--ad");
if (isAd.length) return;

const downloadButton = document.createElement("bilibili-button");
downloadButton.index = index;
card.appendChild(downloadButton);
});
}

bilibili();
setInterval(() => {
bilibili();
}, 3000);
29 changes: 27 additions & 2 deletions packages/plugin/src/components/FloatButton.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/**
* 适用于 m3u8 视频下载的浮动按钮
*/
import { LitElement, html, css } from "lit";
import { customElement, property } from "lit/decorators.js";
import logo from "../assets/logo.png";
import { addIpcListener, showDownloadDialog } from "../helper";
import { addIpcListener, pluginReady, showDownloadDialog } from "../helper";
import { DownloadType } from "../../../main/types/interfaces";

interface SourceData {
id: number;
url: string;
documentURL: string;
name: string;
type: DownloadType;
}

@customElement("float-button")
export class FloatButton extends LitElement {
Expand Down Expand Up @@ -43,14 +55,17 @@ export class FloatButton extends LitElement {
}
`;

data: any = {};
data: SourceData | null = null;

@property({ type: Number })
count = 0;

onClick(e: Event) {
e.preventDefault();
e.stopPropagation();
console.log("this.data:", this.data);

if (!this.data) return;

showDownloadDialog({
name: this.data.name,
Expand Down Expand Up @@ -79,3 +94,13 @@ export class FloatButton extends LitElement {
</div>`;
}
}

function init() {
const floatButton = document.createElement("float-button");
document.body.appendChild(floatButton);

// 向主进程发送插件准备好的消息
pluginReady();
}

init();
34 changes: 0 additions & 34 deletions packages/plugin/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1 @@
import "./components";
import { BILIBILI_DOWNLOAD_BUTTON, pluginReady } from "./helper";
import $ from "jquery";

// 哔哩哔哩
function bilibili() {
const videoCards = document.querySelectorAll(".bili-video-card");
videoCards.forEach((card, index) => {
const imageDOM = card.querySelector(BILIBILI_DOWNLOAD_BUTTON);
if (!imageDOM) return;

const oldBtn = imageDOM.querySelectorAll("one-button");
if (oldBtn.length) return;

const isAd = $(card).find(".bili-video-card__info--ad");
if (isAd.length) return;

const downloadButton = document.createElement("bilibili-button");
downloadButton.index = index;
card.appendChild(downloadButton);
});
}

function sniffing() {
const floatButton = document.createElement("float-button");
document.body.appendChild(floatButton);
}

sniffing();
pluginReady();

bilibili();
setInterval(() => {
bilibili();
}, 3000);
2 changes: 1 addition & 1 deletion packages/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.33.2",
"prettier": "3.2.5",
"sass": "^1.70.0",
"stylelint": "^16.2.1",
"stylelint-config-standard": "^36.0.0",
"stylelint-config-standard-scss": "^13.0.0",
"sass": "^1.70.0",
"typescript": "~5.3.3",
"vite": "^5.0.12"
},
Expand Down

0 comments on commit aa9ea91

Please sign in to comment.