Skip to content

Commit

Permalink
style: lint code
Browse files Browse the repository at this point in the history
Also, remove “strict” rule in favor of typescript (#93, #97)
  • Loading branch information
LuanRT committed Jul 13, 2022
1 parent 7ded405 commit 1ce2feb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ rules:
prefer-template: error

keyword-spacing: ["error", { "before": true } ]
strict: ["error", "global"]
array-bracket-spacing: ["error", "always"]
arrow-parens: ["error", "always"]
comma-dangle: ["error", "never"]
Expand Down
52 changes: 26 additions & 26 deletions lib/core/PlaylistManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class PlaylistManager {
title,
videoIds: video_ids
};

const response = await this.#actions.execute('/playlist/create', { ...payload, parse: false });

return {
playlist_id: response.data.playlistId,
data: response.data
Expand Down Expand Up @@ -62,14 +62,14 @@ class PlaylistManager {
playlistId: playlist_id,
actions: []
};

payload.actions = video_ids.map((id) => ({
action: 'ACTION_ADD_VIDEO',
addedVideoId: id
}));

const response = await this.#actions.execute('/browse/edit_playlist', { ...payload, parse: false });

return {
playlist_id,
action_result: response.data.actions // TODO: implement actions in the parser
Expand All @@ -87,44 +87,44 @@ class PlaylistManager {

const info = await this.#actions.execute('/browse', { browseId: `VL${playlist_id}`, parse: true });
const playlist = new Playlist(this.#actions, info, true);

if (!playlist.info.is_editable)
throw new InnertubeError('This playlist cannot be edited.', playlist_id);

const payload = {
playlistId: playlist_id,
actions: []
};

const getSetVideoIds = async (pl) => {
const videos = pl.videos.filter((video) => video_ids.includes(video.id));
videos.forEach((video) =>

videos.forEach((video) =>
payload.actions.push({
action: 'ACTION_REMOVE_VIDEO',
setVideoId: video.set_video_id
})
);

if (payload.actions.length < video_ids.length) {
const next = await pl.getContinuation();
return getSetVideoIds(next);
}
}
};

await getSetVideoIds(playlist);

if (!payload.actions.length)
throw new InnertubeError('Given video ids were not found in this playlist.', video_ids);

const response = await this.#actions.execute('/browse/edit_playlist', { ...payload, parse: false });

return {
playlist_id,
action_result: response.data.actions // TODO: implement actions in the parser
};
}

/**
* Moves a video to a new position within a given playlist.
* @param {string} playlist_id
Expand All @@ -136,40 +136,40 @@ class PlaylistManager {

const info = await this.#actions.execute('/browse', { browseId: `VL${playlist_id}`, parse: true });
const playlist = new Playlist(this.#actions, info, true);

if (!playlist.info.is_editable)
throw new InnertubeError('This playlist cannot be edited.', playlist_id);

const payload = {
playlistId: playlist_id,
actions: []
};

let set_video_id_0, set_video_id_1;

const getSetVideoIds = async (pl) => {
const video_0 = pl.videos.find((video) => moved_video_id === video.id);
const video_1 = pl.videos.find((video) => predecessor_video_id === video.id);

set_video_id_0 = set_video_id_0 || video_0?.set_video_id;
set_video_id_1 = set_video_id_1 || video_1?.set_video_id;

if (!set_video_id_0 || !set_video_id_1) {
const next = await pl.getContinuation();
return getSetVideoIds(next);
}
}
};

await getSetVideoIds(playlist);

payload.actions.push({
action: 'ACTION_MOVE_VIDEO_AFTER',
setVideoId: set_video_id_0,
movedSetVideoIdPredecessor: set_video_id_1
});

const response = await this.#actions.execute('/browse/edit_playlist', { ...payload, parse: false });

return {
playlist_id,
action_result: response.data.actions // TODO: implement actions in the parser
Expand Down

0 comments on commit 1ce2feb

Please sign in to comment.