Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rename option and getFilesById #17

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Seedr.cc API
![seedr.cc](https://user-images.githubusercontent.com/17960677/97034774-0b55bf00-1583-11eb-9529-807646a216de.png)



Unofficial API wrapper for seedr.cc
## Example
Expand Down Expand Up @@ -95,6 +95,57 @@ Prints Array of Arrays with file data
]
*/
```

### Getting contents in a specific folder
To get contents (all videos, files, etc in folder), use the `getFilesById` function

```js
var Seedr = require("seedr");
var seedr = new Seedr();
await seedr.login("[email protected]","password");

await seedr.getFilesById();

/*
Prints Array of Arrays with file data


{
parentId: 167483733,
name: 'Superman.and.Lois.S01E11.1080p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv]',
folderSize: 129,
totalStorage: 2147483648,
usedStorage: 720392889,
type: 'folder',
files: [
{ id: 943600241,
type: 'file',
name: 'Newname',
size: 30
},
{
id: 943600242,
type: 'file',
name: 'RARBG_DO_NOT_MIRROR.exe',
size: 99
},
...
]
}

*/
```

### Renaming files
You can change the file name using this method
```js
var Seedr = require("seedr");
var seedr = new Seedr();
await seedr.login("[email protected]","password");

await seedr.rename("file_id", "newName");
```

### Deleting contents

To delete Folders use `deleteFolder` function and to delete files, use `deleteFiles` function
Expand Down
56 changes: 56 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,46 @@ module.exports = class Seedr {
return res;
}

async getFilesById(id = null) {
// getting the required url and requesting json data
if (id) {
var url = `https://www.seedr.cc/api/folder/${id}?access_token=${this.token}`
} else {
var url = `https://www.seedr.cc/api/folder?access_token=${this.token}`
}
var data = await axios(url);

// getting the parents if available else returning null
let parent
if (data.data.parent != -1) {
parent = data.data.parent
} else {
parent = null
}

var res = {parentId: parent, name: data.data.name, folderSize: 0, totalStorage: data.data.space_max, usedStorage: data.data.space_used, type: data.data.type, files: [], activeTorrents: data.data.torrents};
for (var folder of data.data.folders) {
res.files.push({
id: folder.id,
type: 'folder',
name: folder.name,
size: folder.size
})
if (folder.size) {res.folderSize += parseInt(folder.size)}
}
for (var file of data.data.files) {
res.files.push({
id: file.folder_file_id,
type: 'file',
name: file.name,
size: file.size
})
if (file.size) {res.folderSize += parseInt(file.size)}
}

return res;
}

async getFile(id) {
var data = new FormData();
data.append('access_token', this.token);
Expand All @@ -90,6 +130,22 @@ module.exports = class Seedr {
return res.data;
}

async rename(id, newName) {
var data = new FormData();
data.append('access_token', this.token);
data.append('func', 'rename');
data.append('rename_to', newName)
data.append('file_id', id);

var res = await axios({
method: 'post',
url: 'https://www.seedr.cc/oauth_test/resource.php',
headers: data.getHeaders(),
data: data
});
return res.data;
}

async deleteFolder(id) {
var data = new FormData();
data.append('access_token', this.token);
Expand Down