Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into prod
Browse files Browse the repository at this point in the history
  • Loading branch information
ayyubibrahimi committed May 3, 2024
2 parents ea7ac37 + ffefbfb commit fb4bae0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/googlecloud/functions/getanswer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def update_citations(citations, card_id, processing_time_ms):
"source_publish_date": cit["Published"],
"source_url": cit["URL"],
"source_page_number": cit["Page Number"],
"source_timestamp": cit["Video timestamp"], # Add this line
}
for cit in citations
]
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Card/BetaCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const BetaCard = ({ card }: { card: ICard }) => {
{isYouTubeURL(thumbnail?.source_url) && (
<iframe
id="ytplayer"
src={getYouTubeEmbedUrl(thumbnail?.source_url)}
src={getYouTubeEmbedUrl(thumbnail?.source_url, thumbnail?.source_timestamp)}
frameBorder="0"
className="h-64 w-full lg:h-96"
></iframe>
Expand Down
18 changes: 6 additions & 12 deletions packages/web/components/Card/Citation.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
getYouTubeEmbedUrl,
getYouTubeThumbnail,
isYouTubeURL,
} from "@/lib/utils";
import { getYouTubeEmbedUrl, getYouTubeThumbnail, isYouTubeURL } from "@/lib/utils";
import moment from "moment";
import "./Citation.css";

Expand All @@ -22,12 +18,12 @@ const Citation = ({
source_url,
source_page_number: pageNumber,
source_publish_date: publishedAt,
source_timestamp: timestamp,
score: ignore,
...otherMetadata
} = originalCitation;

const isYoutube =
source_url && isYouTubeURL(source_url) && getYouTubeThumbnail(source_url);
const isYoutube = source_url && isYouTubeURL(source_url) && getYouTubeThumbnail(source_url);
const isUrlAvailable = source_url && source_url !== "url not available";

return (
Expand All @@ -37,9 +33,7 @@ const Citation = ({
}`}
>
<div>
<p className="font-bold lg:text-lg">
#{index + 1}: {title}
</p>
<p className="font-bold lg:text-lg">#{index + 1}: {title}</p>
<p className="text-black">{moment(publishedAt).fromNow()}</p>
</div>

Expand All @@ -48,7 +42,7 @@ const Citation = ({
{isYoutube ? (
<iframe
id="ytplayer"
src={getYouTubeEmbedUrl(source_url)}
src={getYouTubeEmbedUrl(source_url, timestamp)}
frameBorder="0"
className="h-64 w-full lg:h-96"
></iframe>
Expand Down Expand Up @@ -81,4 +75,4 @@ const Citation = ({
);
};

export default Citation;
export default Citation;
2 changes: 1 addition & 1 deletion packages/web/components/HomeResults/QueryResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function QueryResult({ card }: { card: ICard }) {
{isYouTubeURL(thumbnail?.source_url) && (
<iframe
id="ytplayer"
src={getYouTubeEmbedUrl(thumbnail?.source_url)}
src={getYouTubeEmbedUrl(thumbnail?.source_url, thumbnail?.source_timestamp)}
frameBorder="0"
className="h-64 w-full lg:h-96"
></iframe>
Expand Down
20 changes: 12 additions & 8 deletions packages/web/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ export function getYouTubeThumbnail(url: string): string | undefined {
}

export function getYouTubeEmbedUrl(
url: string | undefined
url: string | undefined,
timestamp: string | undefined
): string | undefined {
if (!url) return undefined;

const videoId = url.split("v=")[1]?.split("&")[0];
const tParts = url.split("t=");
let t = "";
if (tParts.length > 1) {
t = tParts[1].split("s")[0];
}
if (!videoId) return undefined;
return `https://www.youtube.com/embed/${videoId}?autoplay=0&start=${t}`;
}

let startTime = 0;
if (timestamp) {
const [minutes, seconds] = timestamp.split(":").map(Number);
startTime = minutes * 60 + seconds;
}

return `https://www.youtube.com/embed/${videoId}?autoplay=0&start=${startTime}`;
}

0 comments on commit fb4bae0

Please sign in to comment.