clear playlist mass operations and retry functionality
This commit is contained in:
@@ -24,4 +24,9 @@ export class PlaylistController {
|
||||
remove(@Param('id') id: number): Promise<void> {
|
||||
return this.service.remove(id);
|
||||
}
|
||||
|
||||
@Get('retry/:id')
|
||||
retryFailedOfPlaylist(@Param('id') id: number): Promise<void> {
|
||||
return this.service.retryFailedOfPlaylist(id);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import {Injectable} from '@nestjs/common';
|
||||
import {InjectRepository} from '@nestjs/typeorm';
|
||||
import {Repository} from 'typeorm';
|
||||
import {PlaylistEntity} from "./playlist.entity";
|
||||
import {TrackService} from "../track/track.service";
|
||||
import {WebSocketGateway, WebSocketServer} from "@nestjs/websockets";
|
||||
import {Server} from "socket.io";
|
||||
import {TrackStatusEnum} from "../track/track.model";
|
||||
|
||||
const fetch = require('isomorphic-unfetch');
|
||||
const { getData, getPreview, getTracks, getDetails } = require('spotify-url-info')(fetch);
|
||||
|
||||
@@ -57,4 +59,13 @@ export class PlaylistService {
|
||||
await this.repository.update(id, playlist);
|
||||
this.io.emit('trackPlaylist', playlist);
|
||||
}
|
||||
|
||||
async retryFailedOfPlaylist(id: number): Promise<void> {
|
||||
const tracks = await this.trackService.getAllByPlaylist(id);
|
||||
for(let track of tracks) {
|
||||
if (track.status === TrackStatusEnum.Error) {
|
||||
await this.trackService.retry(track.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,9 @@ export class TrackController {
|
||||
remove(@Param('id') id: number): Promise<void> {
|
||||
return this.service.remove(id);
|
||||
}
|
||||
|
||||
@Get('retry/:id')
|
||||
retry(@Param('id') id: number): Promise<void> {
|
||||
return this.service.retry(id);
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,13 @@ import {PlaylistEntity} from "../playlist/playlist.entity";
|
||||
import {Interval} from "@nestjs/schedule";
|
||||
import {TrackStatusEnum} from "./track.model";
|
||||
import * as yts from 'yt-search';
|
||||
import {SearchResult} from 'yt-search';
|
||||
import * as ytdl from '@distube/ytdl-core';
|
||||
import * as fs from 'fs';
|
||||
import {ConfigService} from "@nestjs/config";
|
||||
import {resolve} from "path";
|
||||
import {WebSocketGateway, WebSocketServer} from "@nestjs/websockets";
|
||||
import {Server} from "socket.io";
|
||||
import {SearchResult} from "yt-search";
|
||||
|
||||
@WebSocketGateway()
|
||||
@Injectable()
|
||||
@@ -53,6 +53,11 @@ export class TrackService {
|
||||
this.io.emit('trackUpdate', track);
|
||||
}
|
||||
|
||||
async retry(id: number): Promise<void> {
|
||||
const track = await this.findOne(id);
|
||||
await this.update(id, {...track, status: TrackStatusEnum.New});
|
||||
}
|
||||
|
||||
@Interval(1000)
|
||||
async findOnYoutube() {
|
||||
const newTracks = await this.findAll({status: TrackStatusEnum.New});
|
||||
@@ -66,6 +71,7 @@ export class TrackService {
|
||||
youtubeResult = await yts(`${track.artist} - ${track.song}`);
|
||||
updatedTrack = {...track, youtubeUrl: youtubeResult.videos[0].url, status: TrackStatusEnum.Queued};
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
updatedTrack = {...track, error: String(err), status: TrackStatusEnum.Error};
|
||||
}
|
||||
await this.update(track.id, updatedTrack);
|
||||
|
||||
Reference in New Issue
Block a user