Sayiqa commited on
Commit
fc19b4e
·
verified ·
1 Parent(s): a3f9211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -267,6 +267,13 @@ from googleapiclient.discovery import build
267
  # # Placeholder for fetching recommendations based on keywords
268
  # return f"Recommendations for: {keywords}" # Dummy return for now
269
  ######################################
 
 
 
 
 
 
 
270
  def process_youtube_video(url="", keywords=""):
271
  try:
272
  # Initialize variables
@@ -334,9 +341,44 @@ def process_youtube_video(url="", keywords=""):
334
  except Exception as e:
335
  return None, f"Error: {str(e)}", "N/A", "", ""
336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  def get_detailed_sentiment(polarity):
338
  """
339
- Returns a more detailed sentiment classification with numerical score
340
  """
341
  if polarity > 0.75:
342
  return f"Very Positive ({polarity:.2f})"
@@ -349,6 +391,22 @@ def get_detailed_sentiment(polarity):
349
  else:
350
  return f"Very Negative ({polarity:.2f})"
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  def get_recommendations(keywords, max_results=5):
353
  if not keywords:
354
  return "Please provide search keywords"
 
267
  # # Placeholder for fetching recommendations based on keywords
268
  # return f"Recommendations for: {keywords}" # Dummy return for now
269
  ######################################
270
+
271
+ from textblob import TextBlob
272
+ from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
273
+ import re
274
+ from collections import Counter
275
+ from googleapiclient.discovery import build
276
+
277
  def process_youtube_video(url="", keywords=""):
278
  try:
279
  # Initialize variables
 
341
  except Exception as e:
342
  return None, f"Error: {str(e)}", "N/A", "", ""
343
 
344
+ def extract_video_id(url):
345
+ """
346
+ Extracts the video ID from a YouTube URL.
347
+ """
348
+ match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11})", url)
349
+ return match.group(1) if match else None
350
+
351
+ def get_video_metadata(video_id):
352
+ """
353
+ Fetches video metadata such as title and description using the YouTube Data API.
354
+ """
355
+ try:
356
+ YOUTUBE_API_KEY = "YOUR_YOUTUBE_API_KEY" # Replace with your YouTube Data API key
357
+ youtube = build("youtube", "v3", developerKey=YOUTUBE_API_KEY)
358
+ request = youtube.videos().list(part="snippet", id=video_id)
359
+ response = request.execute()
360
+
361
+ if "items" in response and len(response["items"]) > 0:
362
+ snippet = response["items"][0]["snippet"]
363
+ return {
364
+ "title": snippet.get("title", "No title available"),
365
+ "description": snippet.get("description", "No description available"),
366
+ }
367
+ return {}
368
+
369
+ except Exception as e:
370
+ return {"title": "Error fetching metadata", "description": str(e)}
371
+
372
+ def clean_text_for_analysis(text):
373
+ """
374
+ Cleans the transcript text by removing extra spaces, line breaks, and non-text elements.
375
+ """
376
+ cleaned_text = " ".join(text.split())
377
+ return cleaned_text
378
+
379
  def get_detailed_sentiment(polarity):
380
  """
381
+ Returns a more detailed sentiment classification with numerical score.
382
  """
383
  if polarity > 0.75:
384
  return f"Very Positive ({polarity:.2f})"
 
391
  else:
392
  return f"Very Negative ({polarity:.2f})"
393
 
394
+ def get_recommendations(keywords):
395
+ """
396
+ Fetches related video recommendations based on the provided keywords.
397
+ """
398
+ # Placeholder for fetching recommendations based on keywords
399
+ return f"Recommendations for: {keywords}" # Dummy return for now
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
  def get_recommendations(keywords, max_results=5):
411
  if not keywords:
412
  return "Please provide search keywords"