Muktibhuyan commited on
Commit
60300eb
Β·
verified Β·
1 Parent(s): ca78672

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -6
app.py CHANGED
@@ -27,13 +27,9 @@ class YouTubeDownloader:
27
  # Format duration
28
  duration = video_info.get('duration', 0)
29
  duration_str = f"{duration//3600}:{(duration%3600)//60:02d}:{duration%60:02d}" if duration else "Unknown"
30
-
31
- # Format upload date
32
  upload_date = video_info.get('upload_date', '')
33
- if upload_date and len(upload_date) == 8:
34
- formatted_date = f"{upload_date[:4]}-{upload_date[4:6]}-{upload_date[6:8]}"
35
- else:
36
- formatted_date = upload_date or "Unknown"
37
 
38
  # Format numbers
39
  def format_number(num):
@@ -43,6 +39,117 @@ class YouTubeDownloader:
43
  return f"{num/1_000:.1f}K"
44
  else:
45
  return str(num)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  # Build the report
48
  report = f"""
 
27
  # Format duration
28
  duration = video_info.get('duration', 0)
29
  duration_str = f"{duration//3600}:{(duration%3600)//60:02d}:{duration%60:02d}" if duration else "Unknown"
 
 
30
  upload_date = video_info.get('upload_date', '')
31
+ formatted_date = f"{upload_date[:4]}-{upload_date[4:6]}-{upload_date[6:8]}" if len(upload_date) == 8 else upload_date or "Unknown"
32
+
 
 
33
 
34
  # Format numbers
35
  def format_number(num):
 
39
  return f"{num/1_000:.1f}K"
40
  else:
41
  return str(num)
42
+
43
+
44
+ scene_descriptions = []
45
+ if duration:
46
+ chunk = 3
47
+ for start in range(0, duration, chunk):
48
+ end = min(start + chunk - 1, duration)
49
+ description = f"Visual segment from {start}s to {end}s. (e.g., close-up, presenter talks, etc.)"
50
+ scene_descriptions.append(f"* **[{start//60}:{start%60:02d}-{end//60}:{end%60:02d}]**: {description}")
51
+ else:
52
+ scene_descriptions.append("* No timestamped breakdown available.")
53
+
54
+ tags = ' '.join(video_info.get('tags', [])).lower()
55
+ title = video_info.get('title', '').lower()
56
+ description_text = video_info.get('description', '').lower()
57
+ channel = video_info.get('channel', '').lower()
58
+
59
+ # 🎡 Background music guess
60
+ if any(word in description_text for word in ['calm music', 'soft', 'soothing']):
61
+ music_style = "Calm"
62
+ elif any(word in description_text for word in ['energetic', 'upbeat', 'lively']):
63
+ music_style = "Upbeat"
64
+ elif "music" not in description_text:
65
+ music_style = "No music"
66
+ else:
67
+ music_style = "Unknown"
68
+
69
+ # πŸ‘€ Influencer / Celebrity Detection (Offline logic)
70
+ known_names = [
71
+ "Kartik Aaryan", "Virat Kohli", "Deepika Padukone", "Alia Bhatt", "Ranveer Singh",
72
+ "MrBeast", "PewDiePie", "CarryMinati", "Prajakta Koli", "Bhuvan Bam",
73
+ "Amitabh Bachchan", "Katrina Kaif", "Salman Khan", "Kiara Advani",
74
+ "Kylie Jenner", "Shahrukh Khan", "Ananya Pandey", "Ashish Chanchlani",
75
+ "Sundar Pichai", "Elon Musk", "Taylor Swift"
76
+ ]
77
+
78
+ metadata = " ".join([
79
+ video_info.get('title', ''),
80
+ video_info.get('description', ''),
81
+ video_info.get('uploader', ''),
82
+ video_info.get('channel', ''),
83
+ ' '.join(video_info.get('tags', []))
84
+ ]).lower()
85
+
86
+ matched = [name for name in known_names if name.lower() in metadata]
87
+
88
+ if matched:
89
+ influencer_note = f"Yes, known influencer/celebrity detected: {', '.join(matched)}"
90
+ else:
91
+ influencer_note = "No known influencer or celebrity detected."
92
+
93
+ if any(word in metadata for word in ["actor", "brand ambassador", "featured", "with", "hosted by"]):
94
+ influencer_note += " (Someone might be featured β€” check visually)"
95
+
96
+ if "review" in title or "demo" in title or "how to" in title:
97
+ video_type = "Educational"
98
+ elif "ad" in title or "promo" in title or "launch" in title:
99
+ video_type = "Promotional"
100
+ elif "funny" in title or "challenge" in title:
101
+ video_type = "Entertainment"
102
+ else:
103
+ video_type = "Informational"
104
+
105
+ if any(word in description_text for word in ['excited', 'amazing', 'love']):
106
+ emotion = "Positive"
107
+ elif any(word in description_text for word in ['calm', 'soothing']):
108
+ emotion = "Neutral"
109
+ elif any(word in description_text for word in ['warning', 'serious']):
110
+ emotion = "Serious"
111
+ else:
112
+ emotion = "Neutral"
113
+
114
+ report = f"""
115
+ πŸ“Ή VIDEO ANALYSIS REPORT
116
+ {'='*50}
117
+
118
+ πŸ“ BASIC INFORMATION:
119
+ β€’ Title: {video_info.get('title', 'Unknown')}
120
+ β€’ Channel: {video_info.get('channel', 'Unknown')}
121
+ β€’ Uploader: {video_info.get('uploader', 'Unknown')}
122
+ β€’ Upload Date: {formatted_date}
123
+ β€’ Duration: {duration_str}
124
+
125
+ πŸ“Š STATISTICS:
126
+ β€’ Views: {format_number(video_info.get('view_count', 0))}
127
+ β€’ Likes: {format_number(video_info.get('like_count', 0))}
128
+ β€’ Comments: {format_number(video_info.get('comment_count', 0))}
129
+ β€’ Channel Followers: {format_number(video_info.get('channel_followers', 0))}
130
+
131
+ 🏷️ CATEGORIES & TAGS:
132
+ β€’ Categories: {', '.join(video_info.get('categories', [])) or 'None'}
133
+ β€’ Tags: {', '.join(video_info.get('tags', [])[:10]) or 'None'}
134
+ {('β€’ More tags...' if len(video_info.get('tags', [])) > 10 else '')}
135
+
136
+ πŸ“– DESCRIPTION (first 500 chars):
137
+ {video_info.get('description', 'No description available')[:500]}
138
+ {'...' if len(video_info.get('description', '')) > 500 else ''}
139
+
140
+ 🎬 SCENE-BY-SCENE BREAKDOWN:
141
+ {chr(10).join(scene_descriptions)}
142
+
143
+ 🎡 BACKGROUND MUSIC STYLE: {music_style}
144
+ πŸ‘€ INFLUENCER PRESENT: {influencer_note}
145
+ πŸŽ₯ VIDEO TYPE: {video_type}
146
+ 🎭 OVERALL EMOTION: {emotion}
147
+
148
+ πŸ”— VIDEO URL:
149
+ {video_info.get('webpage_url', 'Unknown')}
150
+ """
151
+ return report.strip()
152
+
153
 
154
  # Build the report
155
  report = f"""