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

fix: handle YouTube URLs in any format to correctly extract video ID #77

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion next-app/app/api/streams/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function POST(req: NextRequest) {
);
}

const extractedId = data.url.split("?v=")[1];
const extractedId = data.url.split("?v=")[1].split("&")[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail for shorterned links like https://youtu.be/dQw4w9WgXcQ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @SujithThirumalaisamy ,Thanks for pointing that out.
This should now correctly handle both standard and shortened YouTube URLs. Please test it with different URL formats and let me know if there are any other issues.

const res = await youtubesearchapi.GetVideoDetails(extractedId);

// Check if the user is not the creator
Expand Down
2 changes: 1 addition & 1 deletion next-app/components/StreamView/AddSongForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function AddSongForm({
{inputLink && inputLink.match(YT_REGEX) && !loading && (
<Card className="bg-gray-900 border-gray-800">
<CardContent className="p-4">
<LiteYouTubeEmbed title="" id={inputLink.split("?v=")[1]} />
<LiteYouTubeEmbed title="" id={inputLink.split("?v=")[1].split("&")[0]} />
</CardContent>
</Card>
)}
Expand Down