Skip to content

Commit

Permalink
Merge pull request #24 from chytanka/develop
Browse files Browse the repository at this point in the history
feat: pixiv
  • Loading branch information
rodzyk authored Aug 24, 2024
2 parents 23b2574 + 00c8027 commit dc0be90
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function urlMatcher(segments: UrlSegment[], group: UrlSegmentGroup, route

if (segments.length > 1) {
const url = segments.map(segment => segment.path).join('/');

return {
consumed: segments,
posParams: { url: new UrlSegment(url, {}) }
Expand All @@ -25,6 +25,7 @@ export const ZENKO_PATH = `zenko`;
export const NHENTAI_PATH = `nhentai`;
export const COMICK_PATH = `comick`;
export const YANDERE_PATH = `yandere`;
export const PIXIV_PATH = 'pixiv';

const routes: Routes = [
{
Expand Down Expand Up @@ -71,6 +72,10 @@ const routes: Routes = [
path: YANDERE_PATH,
loadChildren: () => import('./yandere/yandere.module').then(m => m.YandereModule)
},
{
path: PIXIV_PATH,
loadChildren: () => import('./pixiv/pixiv.module').then(m => m.PixivModule)
},
{
matcher: urlMatcher,
loadChildren: () => import('./link-parser/link-parser.module').then(m => m.LinkParserModule)
Expand Down
4 changes: 3 additions & 1 deletion src/app/link-parser/link-parser/link-parser.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Signal, ViewChild, WritableSignal, computed, effect, inject, signal } from '@angular/core';
import { LinkParserService } from '../data-access/link-parser.service';
import {ZenkoLinkParser, ImgurLinkParser, JsonLinkParser, MangadexLinkParser, RedditLinkParser, TelegraphLinkParser, NhentaiLinkParser, YandereParser } from '../utils';
import {ZenkoLinkParser, ImgurLinkParser, JsonLinkParser, MangadexLinkParser, RedditLinkParser, TelegraphLinkParser, NhentaiLinkParser, YandereParser, PixivLinkParser } from '../utils';
import { ActivatedRoute, Router } from '@angular/router';
import { LangService } from '../../shared/data-access/lang.service';
import { Base64 } from '../../shared/utils';
Expand Down Expand Up @@ -50,6 +50,7 @@ export class LinkParserComponent {
this.parser.parsers.push(new NhentaiLinkParser)
this.parser.parsers.push(new ComickLinkParser)
this.parser.parsers.push(new YandereParser)
this.parser.parsers.push(new PixivLinkParser)
this.parser.parsers.push(new JsonLinkParser)
}

Expand Down Expand Up @@ -123,6 +124,7 @@ export class LinkParserComponent {
nhentai: '//nhentai.net/favicon.ico',
comick: '//comick.io/favicon.ico',
yandere: '//yande.re/favicon.ico',
pixiv: '//pixiv.net/favicon.ico',
read: 'data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🗯️</text></svg>'
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/link-parser/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * from './telegraph-link-parser';
export * from './reddit-link-parser';
export * from './zenko-link-parser';
export * from './nhentai-link-parser'
export * from './yandere-link-parser'
export * from './yandere-link-parser'
export * from './pixiv-link-parser'
6 changes: 6 additions & 0 deletions src/app/link-parser/utils/pixiv-link-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LinkParser } from "./link-parser";

export class PixivLinkParser extends LinkParser {
override regex = /pixiv\.net\/(?:en\/)?artworks\/(\d+)/;
override site = 'pixiv';
};
3 changes: 2 additions & 1 deletion src/app/list/list-shell/list-shell.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, EffectCleanupRegisterFn, WritableSignal, computed, effect, inject, signal } from '@angular/core';
import { LinkParserService } from '../../link-parser/data-access/link-parser.service';
import { ImgurLinkParser, JsonLinkParser, LinkParser, MangadexLinkParser, NhentaiLinkParser, RedditLinkParser, TelegraphLinkParser, YandereParser, ZenkoLinkParser } from '../../link-parser/utils';
import { ImgurLinkParser, JsonLinkParser, LinkParser, MangadexLinkParser, NhentaiLinkParser, PixivLinkParser, RedditLinkParser, TelegraphLinkParser, YandereParser, ZenkoLinkParser } from '../../link-parser/utils';
import { DomManipulationService } from '../../shared/data-access';
import { LangService } from '../../shared/data-access/lang.service';
import { ComickLinkParser } from '../../link-parser/utils/comick-link-parser';
Expand Down Expand Up @@ -90,6 +90,7 @@ export class ListShellComponent {
this.parser.parsers.push(new NhentaiLinkParser)
this.parser.parsers.push(new ComickLinkParser)
this.parser.parsers.push(new YandereParser)
this.parser.parsers.push(new PixivLinkParser)
this.parser.parsers.push(new JsonLinkParser)
}

Expand Down
59 changes: 59 additions & 0 deletions src/app/pixiv/data-access/pixiv.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { environment } from '../../../environments/environment';
import { CompositionEpisode, CompositionPublisher } from '../../common/common-read';
import { Base64 } from '../../shared/utils';

@Injectable({
providedIn: 'root'
})
export class PixivService {
http: HttpClient = inject(HttpClient)

getComposition(id: string): Observable<CompositionEpisode> {
return this.http.get<any>(environment.proxy + Base64.toBase64(environment.pixivHost + id))
.pipe(map((data) => { return this.map(data.body) }))
}

map(data: any): CompositionEpisode {

const mappedResponse = {
title: data.illust_details.title,
nsfw: data.illust_details.tags.includes('R-18'),
publisher: {
id: data.author_details.user_id as string,
site: `https://pixiv.net/en/users/` + data.author_details.user_id as string,
name: data.author_details.user_name as string,
avatar: environment.proxy + Base64.toBase64(data.author_details.profile_img.main) + '&ref=https://www.pixiv.net' as string,
description: '',
links: []
} as unknown as CompositionPublisher,

images: (data.illust_details.manga_a ? data.illust_details.manga_a.map((item: any, index: number) => {
return {
src: item.url,
width: data.illust_details.illust_images[index].illust_image_width,
height: data.illust_details.illust_images[index].illust_image_height
};
}) : [
{
src: data.illust_details.url,
width: data.illust_details.illust_images[0].illust_image_width,
height: data.illust_details.illust_images[0].illust_image_height
}
])

.filter((i: any) => i.src).map((img: any) => {
return {
src: environment.proxy + Base64.toBase64(img.src) + '&ref=https://www.pixiv.net',
width: img.width,
height: img.height
}
})

};
// ugoira_meta.frames for animation
return mappedResponse;
}
}
17 changes: 17 additions & 0 deletions src/app/pixiv/pixiv-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { PixivShellComponent } from './pixiv-shell/pixiv-shell.component';

const routes: Routes = [
{ path: '', redirectTo: '/', pathMatch: 'full' },
{
path: ':id',
component: PixivShellComponent
}
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class PixivRoutingModule { }
8 changes: 8 additions & 0 deletions src/app/pixiv/pixiv-shell/pixiv-shell.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<app-common-read [episode$]="episode$" [error$]="error$" [loading$]="loading$" (refreshData)="refreshData()"
[playlist]="playlistService.playlist()" [playlistLink]="playlistLink()" [currentPlaylistItem]="currentPlItem()">

<p>{{lang.ph().imagesVia}}<a href="https://pixiv.net" target="_blank" rel="noopener noreferrer">Pixiv</a>
API.
{{lang.ph().thanks}}<br>{{lang.ph().detalisCopy}}</p>

</app-common-read>
Empty file.
39 changes: 39 additions & 0 deletions src/app/pixiv/pixiv-shell/pixiv-shell.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Component, inject, OnDestroy } from '@angular/core';
import { PixivService } from '../data-access/pixiv.service';
import { PIXIV_PATH } from '../../app-routing.module';
import { switchMap, of } from 'rxjs';
import { ReadBaseComponent } from '../../common/common-read';
import { Base64 } from '../../shared/utils';

@Component({
selector: 'app-pixiv-shell',
templateUrl: './pixiv-shell.component.html',
styleUrl: './pixiv-shell.component.scss'
})
export class PixivShellComponent extends ReadBaseComponent implements OnDestroy {
pixiv = inject(PixivService)

override episode$ = this.combineParamMapAndRefresh()
.pipe(this.tapStartLoading(),
switchMap(([params]) => {
const pathParam = params?.get('id');

if (!pathParam) return of(null);

const path = (Base64.isBase64(pathParam)) ? Base64.fromBase64(pathParam) : pathParam;

return (this.pixiv.getComposition(path)).pipe(this.catchError(), this.tapSetTitle(),
this.tapSaveToHistory(PIXIV_PATH, path),
this.tapSaveToCurrentPlaylistItem(PIXIV_PATH, path),
this.finalizeLoading());
})
);

constructor() {
super()
}

ngOnDestroy(): void {
this.plObserv?.unsubscribe();
}
}
19 changes: 19 additions & 0 deletions src/app/pixiv/pixiv.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { PixivRoutingModule } from './pixiv-routing.module';
import { CommonReadModule } from '../common/common-read';
import { PixivShellComponent } from './pixiv-shell/pixiv-shell.component';


@NgModule({
declarations: [
PixivShellComponent
],
imports: [
CommonModule,
PixivRoutingModule,
CommonReadModule
]
})
export class PixivModule { }
2 changes: 1 addition & 1 deletion src/app/shared/ui/viewer/viewer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<div>
<p style="text-align: center;">Кінець епізоду</p>
@if(episode?.publisher?.id) {
<p>Переклад від {{episode?.publisher?.name}}</p>
<p>Робота від <a [href]="episode?.publisher?.site" target="_blank" rel="noopener noreferrer">{{episode?.publisher?.name}}</a></p>
<div style="display: flex; justify-content: center; flex-wrap: wrap; gap: 1ch; font-size: x-small;">
@for (l of episode?.publisher?.links; track $index) {
<a [href]="l.link" target="_blank" rel="noopener noreferrer">{{l.title}}</a>
Expand Down
8 changes: 4 additions & 4 deletions src/app/telegraph/data-access/telegraph.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
import { CompositionEpisode } from '../../common/common-read';
import { environment } from '../../../environments/environment';
import { Base64 } from '../../shared/utils';

@Injectable({
providedIn: 'root'
Expand All @@ -25,12 +26,11 @@ export class TelegraphService {
return {
src: item.children.find((child: any) => child.tag === "img")?.attrs.src
};
})).filter((i: any) => i.src).map((img: any)=> {return {src: 'https://telegra.ph'+ img.src}})
})).filter((i: any) => i.src).map((img: any)=> {return {src:
environment.proxy + Base64.toBase64('https://telegra.ph'+ img.src)
}})
};




return mappedResponse;
}
}
3 changes: 2 additions & 1 deletion src/environments/environment.development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export const environment = {
zenkoHost: `https://zenko-api.onrender.com/chapters/`,
nhentaiHost: `https://nhentai.net/api/gallery/`,
comickHost: `https://api.comick.fun/chapter/`,
yanderePoolsHost: `https://yande.re/pool/show.json/`
yanderePoolsHost: `https://yande.re/pool/show.json/`,
pixivHost: `https://www.pixiv.net/touch/ajax/illust/details?illust_id=`
};
3 changes: 2 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const environment = {
zenkoHost: `https://zenko-api.onrender.com/chapters/`,
nhentaiHost: `https://nhentai.net/api/gallery/`,
comickHost: `https://api.comick.fun/chapter/`,
yanderePoolsHost: `https://yande.re/pool/show.json/`
yanderePoolsHost: `https://yande.re/pool/show.json/`,
pixivHost: `https://www.pixiv.net/touch/ajax/illust/details?illust_id=`
};

0 comments on commit dc0be90

Please sign in to comment.