Skip to content

Commit

Permalink
Improve JPop => RED search
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Dec 17, 2023
1 parent 897f1d2 commit cc1ac67
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 41 deletions.
36 changes: 26 additions & 10 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@
var common_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/dom/index.mjs");
const parseYear = element => {
const text = element.children[3].textContent.trim();
const match = text.match(/(\d{4})\.\d{2}\.\d{2}/);
const match = text.match(/\[(\d{4})(\.\d{2}\.\d{2})?]/);
return match ? parseInt(match[1]) : null;
};
const parseType = element => {
Expand Down Expand Up @@ -1284,6 +1284,20 @@
}));
}
};
const parseArtist = element => {
const artists = new Set;
artists.add(element.textContent?.trim());
const title = element.getAttribute("title").split(" (View Artist)");
if (2 == title.length) artists.add(title[0].trim());
return Array.from(artists);
};
const parseAlbum = element => {
const titles = new Set;
titles.add(element.textContent?.trim());
const title = element.getAttribute("title").split(" (View Torrent)");
if (2 == title.length) titles.add(title[0].trim());
return Array.from(titles);
};
class JPop {
canBeUsedAsSource() {
return true;
Expand All @@ -1300,16 +1314,16 @@
total: elements.length
};
for (const element of elements) {
const artist = element.querySelector('a[title*="View Artist"]')?.textContent?.trim();
const title = element.querySelector('a[title*="View Torrent"]')?.textContent?.trim();
const artists = parseArtist(element.querySelector('a[title*="View Artist"]'));
const titles = parseAlbum(element.querySelector('a[title*="View Torrent"]'));
const year = parseYear(element);
const type = parseType(element);
const torrents = parseTorrents(element);
const request = {
torrents,
dom: [ element ],
title,
artist,
titles,
artists,
type,
year,
category: _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MUSIC
Expand Down Expand Up @@ -1996,11 +2010,13 @@
if (request.category != _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MUSIC) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_ALLOWED;
const musicRequest = request;
if (musicRequest.type != _tracker__WEBPACK_IMPORTED_MODULE_0__.MusicReleaseType.ALBUM && musicRequest.type != _tracker__WEBPACK_IMPORTED_MODULE_0__.MusicReleaseType.SINGLE) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_ALLOWED;
if (!musicRequest.artist || !musicRequest.title || !musicRequest.year) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_CHECKED;
const queryUrl = `https://redacted.ch/torrents.php?artistname=${encodeURIComponent(musicRequest.artist)}&groupname=${encodeURIComponent(musicRequest.title)}&year=${musicRequest.year}&order_by=time&order_way=desc&group_results=1&filter_cat%5B1%5D=1&action=advanced&searchsubmit=1`;
const result = await (0, common_http__WEBPACK_IMPORTED_MODULE_1__.fetchAndParseHtml)(queryUrl);
if (result.textContent?.includes("Your search did not match anything.")) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_EXIST;
return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.EXIST;
if (!musicRequest.artists || !musicRequest.titles || !musicRequest.year) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_CHECKED;
for (let artist of musicRequest.artists) for (let title of musicRequest.titles) {
const queryUrl = `https://redacted.ch/torrents.php?artistname=${encodeURIComponent(artist)}&groupname=${encodeURIComponent(title)}&year=${musicRequest.year}&order_by=time&order_way=desc&group_results=1&filter_cat%5B1%5D=1&action=advanced&searchsubmit=1`;
const result = await (0, common_http__WEBPACK_IMPORTED_MODULE_1__.fetchAndParseHtml)(queryUrl);
if (!result.textContent?.includes("Your search did not match anything.")) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.EXIST;
}
return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_EXIST;
}
insertTrackersSelect(select) {}
}
Expand Down
51 changes: 32 additions & 19 deletions Find Unique Titles/src/trackers/JPop.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { parseSize } from "../utils/utils";
import {
Category,
MetaData,
MusicReleaseType,
MusicRequest,
Request,
SearchResult,
Torrent,
tracker,
} from "./tracker";
import { Category, MetaData, MusicReleaseType, MusicRequest, Request, SearchResult, Torrent, tracker } from "./tracker";
import { insertBefore } from "common/dom";


const parseYear = (element: HTMLElement) => {
const text = element.children[3]!!.textContent!!.trim();
const match = text.match(/(\d{4})\.\d{2}\.\d{2}/);
const match = text.match(/\[(\d{4})(\.\d{2}\.\d{2})?]/);
return match ? parseInt(match[1]) : null;
};
const parseType = (element: HTMLElement) => {
Expand Down Expand Up @@ -82,6 +74,27 @@ const parseTorrents = (element: HTMLElement): Array<Torrent> => {
);
}
};
const parseArtist = (element: Element): string[] => {
const artists = new Set<string>();
artists.add(element.textContent?.trim()!!);
const title = element.getAttribute("title")!!.split(" (View Artist)");
if (title.length == 2) {
artists.add(title[0].trim());
}

return Array.from(artists);
};

const parseAlbum = (element: Element): string[] => {
const titles = new Set<string>();
titles.add(element.textContent?.trim()!!);
const title = element.getAttribute("title")!!.split(" (View Torrent)");
if (title.length == 2) {
titles.add(title[0].trim());
}

return Array.from(titles);
};
export default class JPop implements tracker {
canBeUsedAsSource(): boolean {
return true;
Expand All @@ -103,21 +116,21 @@ export default class JPop implements tracker {
total: elements.length,
};
for (const element of elements) {
const artist = element
.querySelector('a[title*="View Artist"]')
?.textContent?.trim();
const title = element
.querySelector('a[title*="View Torrent"]')
?.textContent?.trim();
const artists = parseArtist(
element.querySelector('a[title*="View Artist"]')!!
);
const titles = parseAlbum(
element.querySelector('a[title*="View Torrent"]')!!
);
const year = parseYear(element);
const type = parseType(element);
const torrents = parseTorrents(element);

const request: MusicRequest = {
torrents,
dom: [element],
title,
artist,
titles,
artists,
type,
year,
category: Category.MUSIC,
Expand Down
26 changes: 16 additions & 10 deletions Find Unique Titles/src/trackers/RED.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ export default class RED implements tracker {
musicRequest.type != MusicReleaseType.SINGLE
)
return SearchResult.NOT_ALLOWED;
if (!musicRequest.artist || !musicRequest.title || !musicRequest.year)
if (!musicRequest.artists || !musicRequest.titles || !musicRequest.year)
return SearchResult.NOT_CHECKED;
const queryUrl = `https://redacted.ch/torrents.php?artistname=${encodeURIComponent(
musicRequest.artist
)}&groupname=${encodeURIComponent(musicRequest.title)}&year=${
musicRequest.year
}&order_by=time&order_way=desc&group_results=1&filter_cat%5B1%5D=1&action=advanced&searchsubmit=1`;

const result = await fetchAndParseHtml(queryUrl);
if (result.textContent?.includes("Your search did not match anything."))
return SearchResult.NOT_EXIST;
for (let artist of musicRequest.artists) {
for (let title of musicRequest.titles) {
const queryUrl = `https://redacted.ch/torrents.php?artistname=${encodeURIComponent(
artist
)}&groupname=${encodeURIComponent(title)}&year=${
musicRequest.year
}&order_by=time&order_way=desc&group_results=1&filter_cat%5B1%5D=1&action=advanced&searchsubmit=1`;
const result = await fetchAndParseHtml(queryUrl);
if (
!result.textContent?.includes("Your search did not match anything.")
)
return SearchResult.EXIST;
}
}
return SearchResult.NOT_EXIST;

return SearchResult.EXIST;
}
Expand Down
4 changes: 2 additions & 2 deletions Find Unique Titles/src/trackers/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export interface TVRequest extends Request<Category.TV> {
}

export interface MusicRequest extends Request<Category.MUSIC> {
title?: string;
artist?: string;
titles?: string[];
artists?: string[];
type?: MusicReleaseType;
}

Expand Down

0 comments on commit cc1ac67

Please sign in to comment.