Closed 1varunvc closed 17 hours ago
From the YouTube Search API response, extract the following fields for each video:
videoId
title
publishedAt
(to derive videoYear
)thumbnails
(include default
, medium
, high
)channelId
channelTitle
description
Classify each video as 'Audio' or 'Video' using the following criteria:
Normalize Text:
title
and description
to lowercase.Audio Criteria:
description
starts with 'provided to youtube by'
.'official audio'
, 'audio'
, 'lyric video'
, 'lyrics'
in the title
.channelId
to determine if the channel is an Official Artist Channel.channelTitle
with Artist Name:
title
and compare it with the channelTitle
.productionHouses.js
to check if the channelTitle
matches any known production house.description
starts with 'provided to youtube by'
, classify as 'Audio'.title
contains the specified keywords.
a
is false: Classify as 'Video'.a
is true: b
:
b
is true: Classify as 'Audio'.b
is false: c
:
c
is true: Classify as 'Audio'.c
is false: Classify as 'Video'.Video Criteria:
Organize the extracted data into two arrays within youtube.tracks
:
audios
: Contains all items classified as 'Audio'.videos
: Contains all items classified as 'Video'.Validate Data Fields:
videoId
or title
are missing, skip the item and log a warning.Assign Default Values:
'Unknown Title'
, 'No Description Available'
).Error Handling:
Maintain a consistent JSON structure for both YouTube and future integrations like Spotify:
{
"youtube": {
"tracks": {
"audios": [
{
"videoId": "",
"title": "",
"videoYear": "",
"thumbnails": {
"default": "",
"medium": "",
"high": ""
},
"channelTitle": "",
"description": ""
}
// ... more audio items
],
"videos": [
{
"videoId": "",
"title": "",
"videoYear": "",
"thumbnails": {
"default": "",
"medium": "",
"high": ""
},
"channelTitle": "",
"description": ""
}
// ... more video items
]
},
"artists": [],
"albums": [],
"playlists": []
},
"spotify": {
"tracks": {
"audios": [],
"videos": []
},
"artists": [],
"albums": [],
"playlists": []
}
}
Future Integration Placeholders:
artists
, albums
, and playlists
under both youtube
and spotify
to facilitate future integration without significant restructuring.Consistent Schema:
Create a new API endpoint (e.g., /api/youtube/details
) that accepts a videoId
and fetches additional details when a user clicks on a search result.
Use the YouTube Videos API to retrieve:
Use the [Return YouTube Dislike API](https://returnyoutubedislikeapi.com/) to get:
viewCount
likes
dislikes
Note: Ensure to handle these external API calls efficiently to manage quota usage.
Since YouTube provides rectangular thumbnails:
Server-Side Cropping:
Lazy Processing:
Implement logic to format numerical counts (viewCount
, likes
, dislikes
) based on the user's region:
Region Detection:
'IN'
for India or 'US'
for the United States) picked from the request object.Formatting Rules:
Formatting Utility:
Implement Region Detection Middleware:
regionMiddleware.js
to extract the region from the request headers and set a default value if not provided.Rename youtubeService
to youtubeAPI.js
:
youtubeAPI.js
is more descriptive.Similarly Rename Other Services:
spotifyService
to spotifyAPI.js
.authService
to authAPI.js
(if applicable).searchService
to searchAPI.js
(if applicable).Create youtubeDataProcessor.js
:
Benefits:
Skip In-Memory Caching:
Plan for Redis Integration:
Cache Invalidation Strategies:
Sanitize User Inputs:
Handle Sensitive Data Carefully:
Logging Practices:
Structured Logging:
Error Handling:
youtubeAPI.js
returnyoutubedislikeapi.com
for view counts, likes, and dislikes.youtubeController.js
audios
and videos
.youtubeRoutes.js
/api/youtube/details
).searchController.js
(if applicable)
youtubeDataProcessor.js
Utility Modules:
formatter.js
imageProcessor.js
regionDetector.js
cache.js
Configuration Files:
productionHouses.js
Middleware:
regionMiddleware.js
Logging Enhancements:
By integrating these refinements into your approach, you will:
Enhance Classification Accuracy:
Optimize API Usage:
Improve User Experience:
Prepare for Future Growth:
Ensure Security and Compliance:
Maintainability:
Implement the Updated Data Processing Logic:
Develop Utility Modules and Middleware:
regionMiddleware.js
to handle region extraction from request headers.Plan for Redis Integration:
Test Thoroughly:
Enhance Error Handling and Logging:
Rename Services Appropriately:
youtubeService
to youtubeAPI.js
and similarly for other services to reflect their purpose better.Create Separate Data Processing Module:
youtubeDataProcessor.js
to handle data processing separately from API interactions.TODO: Consider implementing backend/utils/imageProcessor.js
in the front-end instead.