aparat-api v1.0.0
Aparat Video Platform NodeJs Api
This is a Node.js library for interacting with the Aparat video platform API. You can use it to manage user profiles, search videos, upload videos, fetch video details, and more.
Features π
- β Login to the Aparat platform
- β Fetch user profiles and categories
- β Search for users and videos
- β Upload videos
- β Fetch video details
- β Fetch comments and tags associated with videos
Installation π§
Install the package using npm:
npm install aparat-api
Usage π
Import and Initialization
Start by importing the Aparat
class from the library and creating an instance of it:
const Aparat = require('aparat-api');
const aparat = new Aparat();
Login to Aparat π
You must log in before accessing most of the platformβs features. Hereβs how you can log in:
(async () => {
try {
const profile = await aparat.login('your_username', 'your_password');
if (profile) {
console.log(`Logged in as ${profile.username}`);
} else {
console.log('Login failed.');
}
} catch (error) {
console.error('An error occurred during login:', error);
}
})();
Fetch User Profile π€
You can retrieve a user's profile using their username:
(async () => {
try {
const userProfile = await aparat.profile('some_username');
if (userProfile) {
console.log(`Profile of ${userProfile.username}:`, userProfile);
} else {
console.log('User not found.');
}
} catch (error) {
console.error('An error occurred while fetching the profile:', error);
}
})();
Search Users π
You can search for users by a keyword:
(async () => {
try {
const users = await aparat.userBySearch('search_term', 5);
if (users.length > 0) {
console.log('Users found:', users);
} else {
console.log('No users found.');
}
} catch (error) {
console.error('An error occurred while searching for users:', error);
}
})();
Fetch Video Details πΉ
Retrieve video details using a video hash:
(async () => {
try {
const video = await aparat.video('video_hash_here');
if (video) {
console.log('Video details:', video);
} else {
console.log('Video not found.');
}
} catch (error) {
console.error('An error occurred while fetching the video details:', error);
}
})();
Upload a Video π€
To upload a video, first fetch the upload form, and then send the video file with the form:
(async () => {
try {
// Login first
const profile = await aparat.login('your_username', 'your_password');
if (!profile) {
console.log('Login failed. Please check your credentials.');
return;
}
// Fetch the upload form
const uploadForm = await aparat.uploadForm(profile.username, profile.ltokem);
if (!uploadForm) {
console.log('Failed to retrieve the upload form.');
return;
}
// Upload the video
const uploadedVideo = await aparat.uploadPost(
'path/to/your/video.mp4', // Path to video file
'My Awesome Video', // Video title
1, // Category ID
uploadForm, // Upload form object
{
tags: ['example', 'tags'], // Optional tags
allow_comment: true, // Allow comments
description: 'This is a test video.', // Video description
video_pass: false // Optional: Password protection
}
);
console.log('Video uploaded successfully:', uploadedVideo);
} catch (error) {
console.error('An error occurred while uploading the video:', error);
}
})();
Fetch Videos by User π½οΈ
You can fetch the list of videos uploaded by a specific user:
(async () => {
try {
const videos = await aparat.videoByUser('some_username', 10);
if (videos.length > 0) {
console.log('Videos by user:', videos);
} else {
console.log('No videos found.');
}
} catch (error) {
console.error('An error occurred while fetching videos by user:', error);
}
})();
Contributing
Contributions are welcome! Here's how you can contribute to this project:
Fork the repository. Create a new branch (git checkout -b feature-branch). Make your changes. Commit your changes (git commit -am 'Add new feature'). Push to the branch (git push origin feature-branch). Submit a pull request. Please ensure your pull request adheres to the following guidelines:
Describe clearly what problem you're solving with this PR. Keep the PR focused on a single feature or bug fix.
Repository Stats π
License π
This library is provided under the MIT License.
10 months ago