socialpulse 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- socialpulse-0.1.0/PKG-INFO +81 -0
- socialpulse-0.1.0/README.md +49 -0
- socialpulse-0.1.0/pyproject.toml +50 -0
- socialpulse-0.1.0/setup.cfg +4 -0
- socialpulse-0.1.0/socialpulse/__init__.py +39 -0
- socialpulse-0.1.0/socialpulse/channel_pulse.py +146 -0
- socialpulse-0.1.0/socialpulse/cross_publisher.py +160 -0
- socialpulse-0.1.0/socialpulse/hook_lab.py +187 -0
- socialpulse-0.1.0/socialpulse/models.py +83 -0
- socialpulse-0.1.0/socialpulse/trend_radar.py +167 -0
- socialpulse-0.1.0/socialpulse.egg-info/PKG-INFO +81 -0
- socialpulse-0.1.0/socialpulse.egg-info/SOURCES.txt +14 -0
- socialpulse-0.1.0/socialpulse.egg-info/dependency_links.txt +1 -0
- socialpulse-0.1.0/socialpulse.egg-info/requires.txt +21 -0
- socialpulse-0.1.0/socialpulse.egg-info/top_level.txt +1 -0
- socialpulse-0.1.0/tests/test_socialpulse.py +134 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: socialpulse
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Social media analytics + viral content intelligence for creators
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/teyfikoz/socialpulse
|
|
7
|
+
Project-URL: Repository, https://github.com/teyfikoz/socialpulse
|
|
8
|
+
Keywords: social media,youtube,instagram,tiktok,analytics,viral,content
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: requests>=2.31
|
|
17
|
+
Requires-Dist: python-dateutil>=2.8
|
|
18
|
+
Provides-Extra: youtube
|
|
19
|
+
Requires-Dist: google-api-python-client>=2.0; extra == "youtube"
|
|
20
|
+
Requires-Dist: google-auth-httplib2; extra == "youtube"
|
|
21
|
+
Provides-Extra: instagram
|
|
22
|
+
Requires-Dist: instaloader>=4.10; extra == "instagram"
|
|
23
|
+
Provides-Extra: tiktok
|
|
24
|
+
Requires-Dist: requests>=2.31; extra == "tiktok"
|
|
25
|
+
Provides-Extra: trends
|
|
26
|
+
Requires-Dist: pytrends>=4.9; extra == "trends"
|
|
27
|
+
Provides-Extra: full
|
|
28
|
+
Requires-Dist: google-api-python-client>=2.0; extra == "full"
|
|
29
|
+
Requires-Dist: google-auth-httplib2; extra == "full"
|
|
30
|
+
Requires-Dist: instaloader>=4.10; extra == "full"
|
|
31
|
+
Requires-Dist: pytrends>=4.9; extra == "full"
|
|
32
|
+
|
|
33
|
+
# socialpulse
|
|
34
|
+
|
|
35
|
+
Social media analytics + viral content intelligence for creators.
|
|
36
|
+
|
|
37
|
+
Unifies YouTube Analytics v3, Instagram Insights, TikTok metrics, and Google Trends into a single Python API.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install socialpulse
|
|
43
|
+
|
|
44
|
+
# Optional extras
|
|
45
|
+
pip install socialpulse[youtube] # YouTube Analytics v3
|
|
46
|
+
pip install socialpulse[instagram] # Instagram / instaloader
|
|
47
|
+
pip install socialpulse[tiktok] # TikTok metrics
|
|
48
|
+
pip install socialpulse[trends] # Google Trends via pytrends
|
|
49
|
+
pip install socialpulse[full] # All extras
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from socialpulse import ChannelPulse, TrendRadar, HookLab
|
|
56
|
+
|
|
57
|
+
# Channel analytics
|
|
58
|
+
pulse = ChannelPulse()
|
|
59
|
+
stats = pulse.weekly_summary(channels=["@yourchannel"])
|
|
60
|
+
|
|
61
|
+
# Trend discovery
|
|
62
|
+
radar = TrendRadar()
|
|
63
|
+
trends = radar.trending(niches=["ai_tools", "science"], regions=["TR", "US"])
|
|
64
|
+
|
|
65
|
+
# Viral hook generation
|
|
66
|
+
lab = HookLab()
|
|
67
|
+
hooks = lab.generate(topic="AI video tools", platform="tiktok", n=10)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Modules
|
|
71
|
+
|
|
72
|
+
| Module | Description |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `ChannelPulse` | YouTube/Instagram/TikTok channel metrics |
|
|
75
|
+
| `TrendRadar` | Cross-platform trend discovery |
|
|
76
|
+
| `HookLab` | Viral hook and title generation |
|
|
77
|
+
| `CrossPublisher` | Multi-platform post scheduling helper |
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# socialpulse
|
|
2
|
+
|
|
3
|
+
Social media analytics + viral content intelligence for creators.
|
|
4
|
+
|
|
5
|
+
Unifies YouTube Analytics v3, Instagram Insights, TikTok metrics, and Google Trends into a single Python API.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install socialpulse
|
|
11
|
+
|
|
12
|
+
# Optional extras
|
|
13
|
+
pip install socialpulse[youtube] # YouTube Analytics v3
|
|
14
|
+
pip install socialpulse[instagram] # Instagram / instaloader
|
|
15
|
+
pip install socialpulse[tiktok] # TikTok metrics
|
|
16
|
+
pip install socialpulse[trends] # Google Trends via pytrends
|
|
17
|
+
pip install socialpulse[full] # All extras
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from socialpulse import ChannelPulse, TrendRadar, HookLab
|
|
24
|
+
|
|
25
|
+
# Channel analytics
|
|
26
|
+
pulse = ChannelPulse()
|
|
27
|
+
stats = pulse.weekly_summary(channels=["@yourchannel"])
|
|
28
|
+
|
|
29
|
+
# Trend discovery
|
|
30
|
+
radar = TrendRadar()
|
|
31
|
+
trends = radar.trending(niches=["ai_tools", "science"], regions=["TR", "US"])
|
|
32
|
+
|
|
33
|
+
# Viral hook generation
|
|
34
|
+
lab = HookLab()
|
|
35
|
+
hooks = lab.generate(topic="AI video tools", platform="tiktok", n=10)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Modules
|
|
39
|
+
|
|
40
|
+
| Module | Description |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `ChannelPulse` | YouTube/Instagram/TikTok channel metrics |
|
|
43
|
+
| `TrendRadar` | Cross-platform trend discovery |
|
|
44
|
+
| `HookLab` | Viral hook and title generation |
|
|
45
|
+
| `CrossPublisher` | Multi-platform post scheduling helper |
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "socialpulse"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Social media analytics + viral content intelligence for creators"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["social media", "youtube", "instagram", "tiktok", "analytics", "viral", "content"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"requests>=2.31",
|
|
22
|
+
"python-dateutil>=2.8",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
youtube = ["google-api-python-client>=2.0", "google-auth-httplib2"]
|
|
27
|
+
instagram = ["instaloader>=4.10"]
|
|
28
|
+
tiktok = ["requests>=2.31"]
|
|
29
|
+
trends = ["pytrends>=4.9"]
|
|
30
|
+
full = [
|
|
31
|
+
"google-api-python-client>=2.0",
|
|
32
|
+
"google-auth-httplib2",
|
|
33
|
+
"instaloader>=4.10",
|
|
34
|
+
"pytrends>=4.9",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/teyfikoz/socialpulse"
|
|
39
|
+
Repository = "https://github.com/teyfikoz/socialpulse"
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
line-length = 100
|
|
43
|
+
target-version = "py310"
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint]
|
|
46
|
+
select = ["E", "F", "I", "W"]
|
|
47
|
+
ignore = ["E501"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""
|
|
2
|
+
socialpulse — Social media analytics + viral content intelligence.
|
|
3
|
+
|
|
4
|
+
Combines YouTube Analytics v3, Instagram Insights, TikTok metrics,
|
|
5
|
+
and trend analysis into a unified API for content creators.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
from socialpulse import ChannelPulse, TrendRadar, HookLab
|
|
9
|
+
|
|
10
|
+
# Channel analytics
|
|
11
|
+
pulse = ChannelPulse()
|
|
12
|
+
stats = pulse.weekly_summary(channels=["@learnlingoz", "@themrozz"])
|
|
13
|
+
|
|
14
|
+
# Trend discovery
|
|
15
|
+
radar = TrendRadar()
|
|
16
|
+
trends = radar.trending(niches=["ai_tools", "science"], regions=["TR", "US"])
|
|
17
|
+
|
|
18
|
+
# Viral hook generation
|
|
19
|
+
lab = HookLab()
|
|
20
|
+
hooks = lab.generate(topic="AI video tools", platform="tiktok", n=10)
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from .channel_pulse import ChannelPulse
|
|
24
|
+
from .trend_radar import TrendRadar
|
|
25
|
+
from .hook_lab import HookLab
|
|
26
|
+
from .cross_publisher import CrossPublisher
|
|
27
|
+
from .models import ChannelStats, TrendSignal, HookVariant, PublishResult
|
|
28
|
+
|
|
29
|
+
__version__ = "0.1.0"
|
|
30
|
+
__all__ = [
|
|
31
|
+
"ChannelPulse",
|
|
32
|
+
"TrendRadar",
|
|
33
|
+
"HookLab",
|
|
34
|
+
"CrossPublisher",
|
|
35
|
+
"ChannelStats",
|
|
36
|
+
"TrendSignal",
|
|
37
|
+
"HookVariant",
|
|
38
|
+
"PublishResult",
|
|
39
|
+
]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""ChannelPulse — Multi-platform channel analytics aggregator."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from datetime import datetime, timedelta, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .models import ChannelStats
|
|
11
|
+
|
|
12
|
+
_STATUS_PATH = Path.home() / "Projects/content/social-media/output/social_status/status.json"
|
|
13
|
+
_STALE_DAYS = 4
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ChannelPulse:
|
|
17
|
+
"""
|
|
18
|
+
Aggregate analytics from all channels using local status files.
|
|
19
|
+
|
|
20
|
+
>>> pulse = ChannelPulse()
|
|
21
|
+
>>> stats = pulse.weekly_summary()
|
|
22
|
+
>>> for s in stats:
|
|
23
|
+
... print(s.name, s.weekly_views, s.growth_score)
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, status_path: Path | str | None = None) -> None:
|
|
27
|
+
self._status_path = Path(status_path) if status_path else _STATUS_PATH
|
|
28
|
+
|
|
29
|
+
def weekly_summary(
|
|
30
|
+
self,
|
|
31
|
+
channels: list[str] | None = None,
|
|
32
|
+
platform: str | None = None,
|
|
33
|
+
) -> list[ChannelStats]:
|
|
34
|
+
"""
|
|
35
|
+
Return analytics snapshot for all channels (or a subset).
|
|
36
|
+
|
|
37
|
+
Reads from social_status/status.json written by social_status_monitor.py.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
channels: Optional list of channel names to filter
|
|
41
|
+
platform: Optional platform filter ("youtube" | "instagram" | "tiktok")
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
List of ChannelStats sorted by growth_score descending
|
|
45
|
+
"""
|
|
46
|
+
if not self._status_path.exists():
|
|
47
|
+
return []
|
|
48
|
+
|
|
49
|
+
raw = json.loads(self._status_path.read_text(encoding="utf-8"))
|
|
50
|
+
now = datetime.now(timezone.utc)
|
|
51
|
+
result: list[ChannelStats] = []
|
|
52
|
+
|
|
53
|
+
for ch in raw.get("youtube", []):
|
|
54
|
+
name = ch.get("title", "")
|
|
55
|
+
if channels and not any(c.lower() in name.lower() for c in channels):
|
|
56
|
+
continue
|
|
57
|
+
if platform and platform != "youtube":
|
|
58
|
+
continue
|
|
59
|
+
|
|
60
|
+
last_str = ch.get("latest_public_at")
|
|
61
|
+
last = None
|
|
62
|
+
if last_str:
|
|
63
|
+
try:
|
|
64
|
+
last = datetime.fromisoformat(last_str.replace("Z", "+00:00"))
|
|
65
|
+
if not last.tzinfo:
|
|
66
|
+
last = last.replace(tzinfo=timezone.utc)
|
|
67
|
+
except ValueError:
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
days_since = (now - last).days if last else None
|
|
71
|
+
stale = days_since is not None and days_since >= _STALE_DAYS
|
|
72
|
+
|
|
73
|
+
weekly_views = ch.get("weekly_views", 0)
|
|
74
|
+
subs = ch.get("subscribers", 0)
|
|
75
|
+
uploads = ch.get("weekly_upload_count", 0)
|
|
76
|
+
avg_views = weekly_views // uploads if uploads else 0
|
|
77
|
+
|
|
78
|
+
# Simple growth score (0-40)
|
|
79
|
+
score = 0.0
|
|
80
|
+
if uploads >= 5:
|
|
81
|
+
score += 10
|
|
82
|
+
elif uploads >= 3:
|
|
83
|
+
score += 7
|
|
84
|
+
elif uploads >= 1:
|
|
85
|
+
score += 3
|
|
86
|
+
if avg_views >= 10000:
|
|
87
|
+
score += 10
|
|
88
|
+
elif avg_views >= 1000:
|
|
89
|
+
score += 7
|
|
90
|
+
elif avg_views >= 100:
|
|
91
|
+
score += 3
|
|
92
|
+
if not stale:
|
|
93
|
+
score += 10
|
|
94
|
+
if subs >= 10000:
|
|
95
|
+
score += 10
|
|
96
|
+
elif subs >= 1000:
|
|
97
|
+
score += 7
|
|
98
|
+
elif subs >= 100:
|
|
99
|
+
score += 3
|
|
100
|
+
|
|
101
|
+
result.append(ChannelStats(
|
|
102
|
+
channel_id=ch.get("channel_id", ""),
|
|
103
|
+
platform="youtube",
|
|
104
|
+
name=name,
|
|
105
|
+
subscribers=subs,
|
|
106
|
+
weekly_views=weekly_views,
|
|
107
|
+
weekly_uploads=uploads,
|
|
108
|
+
avg_views_per_video=float(avg_views),
|
|
109
|
+
growth_score=score,
|
|
110
|
+
stale=stale,
|
|
111
|
+
collected_at=now,
|
|
112
|
+
))
|
|
113
|
+
|
|
114
|
+
return sorted(result, key=lambda s: s.growth_score, reverse=True)
|
|
115
|
+
|
|
116
|
+
def stale_channels(self) -> list[ChannelStats]:
|
|
117
|
+
"""Return channels that haven't uploaded in STALE_DAYS+ days."""
|
|
118
|
+
return [s for s in self.weekly_summary() if s.stale]
|
|
119
|
+
|
|
120
|
+
def top_performers(self, n: int = 3) -> list[ChannelStats]:
|
|
121
|
+
"""Return top-n channels by growth score."""
|
|
122
|
+
return self.weekly_summary()[:n]
|
|
123
|
+
|
|
124
|
+
def growth_report(self) -> str:
|
|
125
|
+
"""Return a formatted markdown growth report."""
|
|
126
|
+
all_stats = self.weekly_summary()
|
|
127
|
+
stale = [s for s in all_stats if s.stale]
|
|
128
|
+
top = all_stats[:3]
|
|
129
|
+
|
|
130
|
+
lines = [
|
|
131
|
+
f"# Growth Report — {datetime.now().strftime('%d %b %Y')}",
|
|
132
|
+
"",
|
|
133
|
+
"## 🏆 Top Performers",
|
|
134
|
+
"| Channel | Weekly Views | Score | Status |",
|
|
135
|
+
"|---------|-------------|-------|--------|",
|
|
136
|
+
]
|
|
137
|
+
for s in top:
|
|
138
|
+
status = "⚠️ STALE" if s.stale else "✅"
|
|
139
|
+
lines.append(f"| {s.name} | {s.weekly_views:,} | {s.growth_score:.0f}/40 | {status} |")
|
|
140
|
+
|
|
141
|
+
if stale:
|
|
142
|
+
lines += ["", "## ⚠️ Stale Channels (need attention)"]
|
|
143
|
+
for s in stale:
|
|
144
|
+
lines.append(f"- **{s.name}**: No upload in 4+ days")
|
|
145
|
+
|
|
146
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""CrossPublisher — Publish one video to multiple platforms."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import subprocess
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from .models import PublishResult
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CrossPublisher:
|
|
12
|
+
"""
|
|
13
|
+
Publish a video to YouTube, Instagram, and/or TikTok.
|
|
14
|
+
|
|
15
|
+
>>> publisher = CrossPublisher()
|
|
16
|
+
>>> results = publisher.publish(
|
|
17
|
+
... video_path="output/my_video.mp4",
|
|
18
|
+
... title="My viral video",
|
|
19
|
+
... platforms=["youtube", "tiktok"],
|
|
20
|
+
... youtube_token="scripts/TOKEN.json",
|
|
21
|
+
... )
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, scripts_dir: Path | str | None = None) -> None:
|
|
25
|
+
self._scripts = Path(scripts_dir) if scripts_dir else (
|
|
26
|
+
Path.home() / "Projects/content/social-media/scripts"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def publish(
|
|
30
|
+
self,
|
|
31
|
+
video_path: str | Path,
|
|
32
|
+
title: str,
|
|
33
|
+
platforms: list[str] | None = None,
|
|
34
|
+
youtube_token: str | None = None,
|
|
35
|
+
tiktok_privacy: str = "SELF_ONLY",
|
|
36
|
+
instagram_account: str = "selfixxapp",
|
|
37
|
+
description: str = "",
|
|
38
|
+
tags: list[str] | None = None,
|
|
39
|
+
auto_portrait: bool = True,
|
|
40
|
+
) -> list[PublishResult]:
|
|
41
|
+
"""
|
|
42
|
+
Publish to one or more platforms.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
video_path: Path to the video file
|
|
46
|
+
title: Video title (platform limits applied automatically)
|
|
47
|
+
platforms: ["youtube", "instagram", "tiktok"] or subset
|
|
48
|
+
youtube_token: Path to YouTube OAuth token JSON
|
|
49
|
+
tiktok_privacy: TikTok privacy ("SELF_ONLY" for testing)
|
|
50
|
+
instagram_account: IG account name for ig_autopost
|
|
51
|
+
description: Video description
|
|
52
|
+
tags: List of tags/hashtags
|
|
53
|
+
auto_portrait: Auto-convert 16:9 → 9:16 if needed
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
List of PublishResult, one per platform
|
|
57
|
+
"""
|
|
58
|
+
platforms = platforms or ["youtube"]
|
|
59
|
+
video = Path(video_path)
|
|
60
|
+
results: list[PublishResult] = []
|
|
61
|
+
|
|
62
|
+
# Auto-convert to portrait if needed
|
|
63
|
+
portrait_path = video
|
|
64
|
+
if auto_portrait:
|
|
65
|
+
portrait_path = self._ensure_portrait(video)
|
|
66
|
+
|
|
67
|
+
for platform in platforms:
|
|
68
|
+
if platform == "youtube":
|
|
69
|
+
result = self._publish_youtube(
|
|
70
|
+
portrait_path, title, description, tags or [], youtube_token
|
|
71
|
+
)
|
|
72
|
+
elif platform == "instagram":
|
|
73
|
+
result = self._publish_instagram(portrait_path, title, instagram_account)
|
|
74
|
+
elif platform == "tiktok":
|
|
75
|
+
result = self._publish_tiktok(portrait_path, title, tiktok_privacy)
|
|
76
|
+
else:
|
|
77
|
+
result = PublishResult(
|
|
78
|
+
platform=platform, success=False, error=f"Unknown platform: {platform}"
|
|
79
|
+
)
|
|
80
|
+
results.append(result)
|
|
81
|
+
|
|
82
|
+
return results
|
|
83
|
+
|
|
84
|
+
def _ensure_portrait(self, video: Path) -> Path:
|
|
85
|
+
"""Convert 16:9 to 9:16 if the video is landscape."""
|
|
86
|
+
output = video.parent / f"{video.stem}_portrait{video.suffix}"
|
|
87
|
+
if output.exists():
|
|
88
|
+
return output
|
|
89
|
+
|
|
90
|
+
# Check dimensions
|
|
91
|
+
probe = subprocess.run(
|
|
92
|
+
["ffprobe", "-v", "error", "-select_streams", "v:0",
|
|
93
|
+
"-show_entries", "stream=width,height", "-of", "csv=p=0", str(video)],
|
|
94
|
+
capture_output=True, text=True,
|
|
95
|
+
)
|
|
96
|
+
if probe.returncode == 0 and probe.stdout.strip():
|
|
97
|
+
parts = probe.stdout.strip().split(",")
|
|
98
|
+
if len(parts) == 2:
|
|
99
|
+
w, h = int(parts[0]), int(parts[1])
|
|
100
|
+
if w > h: # landscape → convert
|
|
101
|
+
subprocess.run([
|
|
102
|
+
"ffmpeg", "-i", str(video),
|
|
103
|
+
"-vf", "crop=ih*9/16:ih,scale=1080:1920",
|
|
104
|
+
"-c:v", "libx264", "-crf", "18", "-c:a", "copy",
|
|
105
|
+
str(output), "-y", "-loglevel", "error",
|
|
106
|
+
], check=True)
|
|
107
|
+
return output
|
|
108
|
+
|
|
109
|
+
return video
|
|
110
|
+
|
|
111
|
+
def _publish_youtube(
|
|
112
|
+
self, video: Path, title: str, description: str, tags: list[str], token: str | None
|
|
113
|
+
) -> PublishResult:
|
|
114
|
+
script = self._scripts.parent / "youtube/scripts/upload_video.py"
|
|
115
|
+
if not script.exists():
|
|
116
|
+
return PublishResult(platform="youtube", success=False, error="upload_video.py not found")
|
|
117
|
+
|
|
118
|
+
cmd = [
|
|
119
|
+
"python3", str(script),
|
|
120
|
+
"--file", str(video),
|
|
121
|
+
"--title", title[:100],
|
|
122
|
+
"--description", description[:5000],
|
|
123
|
+
]
|
|
124
|
+
if tags:
|
|
125
|
+
cmd += ["--tags", ",".join(tags[:30])]
|
|
126
|
+
if token:
|
|
127
|
+
cmd += ["--token", token]
|
|
128
|
+
|
|
129
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
130
|
+
if result.returncode == 0:
|
|
131
|
+
return PublishResult(platform="youtube", success=True)
|
|
132
|
+
return PublishResult(platform="youtube", success=False, error=result.stderr[:200])
|
|
133
|
+
|
|
134
|
+
def _publish_instagram(self, video: Path, caption: str, account: str) -> PublishResult:
|
|
135
|
+
script = Path.home() / "tools/ig_autopost/ig_autopost.py"
|
|
136
|
+
if not script.exists():
|
|
137
|
+
return PublishResult(platform="instagram", success=False, error="ig_autopost.py not found")
|
|
138
|
+
|
|
139
|
+
result = subprocess.run(
|
|
140
|
+
["python3", str(script), "--video", str(video), "--caption", caption, "--account", account],
|
|
141
|
+
capture_output=True, text=True,
|
|
142
|
+
)
|
|
143
|
+
if result.returncode == 0:
|
|
144
|
+
return PublishResult(platform="instagram", success=True)
|
|
145
|
+
return PublishResult(platform="instagram", success=False, error=result.stderr[:200])
|
|
146
|
+
|
|
147
|
+
def _publish_tiktok(self, video: Path, title: str, privacy: str) -> PublishResult:
|
|
148
|
+
script = self._scripts / "tiktok_direct_publisher.py"
|
|
149
|
+
if not script.exists():
|
|
150
|
+
return PublishResult(platform="tiktok", success=False, error="tiktok_direct_publisher.py not found")
|
|
151
|
+
|
|
152
|
+
result = subprocess.run(
|
|
153
|
+
["python3", str(script), "--video", str(video),
|
|
154
|
+
"--title", title[:150], "--privacy", privacy],
|
|
155
|
+
capture_output=True, text=True,
|
|
156
|
+
cwd=self._scripts.parent,
|
|
157
|
+
)
|
|
158
|
+
if result.returncode == 0:
|
|
159
|
+
return PublishResult(platform="tiktok", success=True)
|
|
160
|
+
return PublishResult(platform="tiktok", success=False, error=result.stderr[:200])
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""HookLab — Viral hook and title generation using Groq LLM."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
from .models import HookVariant
|
|
9
|
+
|
|
10
|
+
_HOOK_FORMULAS = {
|
|
11
|
+
"curiosity": [
|
|
12
|
+
"Kimse sana bunu söylemedi ama {topic} ile ilgili...",
|
|
13
|
+
"{topic}'ın gerçek sırrı nedir? ({duration}da öğren)",
|
|
14
|
+
"Bu yüzden {topic} işe yaramıyor (gerçek neden)",
|
|
15
|
+
],
|
|
16
|
+
"benefit": [
|
|
17
|
+
"{n} adımda {topic} nasıl kullanılır",
|
|
18
|
+
"Ücretsiz ama {competitor} kadar güçlü: {topic}",
|
|
19
|
+
"Bu {duration} teknikle {topic} sorunu çözüldü",
|
|
20
|
+
],
|
|
21
|
+
"number": [
|
|
22
|
+
"{n} şey {topic} hakkında bilmeniz gereken",
|
|
23
|
+
"Top {n}: {topic} için en iyi araçlar",
|
|
24
|
+
"{n} vs {m}: {topic} gerçek karşılaştırma",
|
|
25
|
+
],
|
|
26
|
+
"story": [
|
|
27
|
+
"Nasıl {topic} ile {outcome}'e geçtim",
|
|
28
|
+
"Ben de senin gibidim, ta ki {topic}'ı yapana kadar",
|
|
29
|
+
"Bu hatayı {topic}'da yaptım ve {negative_outcome}",
|
|
30
|
+
],
|
|
31
|
+
"pov": [
|
|
32
|
+
"POV: {topic} kullanmayı yeni öğrendin →",
|
|
33
|
+
"Bekliyorsun... bekle {topic} bu kadar kolay mı?",
|
|
34
|
+
"Dur, {topic}'ı görmeden gitme →",
|
|
35
|
+
],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Platform = Literal["youtube", "shorts", "reels", "tiktok"]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class HookLab:
|
|
42
|
+
"""
|
|
43
|
+
Generate viral hooks for social media content.
|
|
44
|
+
|
|
45
|
+
>>> lab = HookLab()
|
|
46
|
+
>>> hooks = lab.generate("AI video tools", platform="tiktok", n=5)
|
|
47
|
+
>>> for h in hooks:
|
|
48
|
+
... print(h.text, h.formula)
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
def __init__(self, groq_api_key: str | None = None) -> None:
|
|
52
|
+
self._api_key = groq_api_key or os.environ.get("GROQ_API_KEY", "")
|
|
53
|
+
|
|
54
|
+
def generate(
|
|
55
|
+
self,
|
|
56
|
+
topic: str,
|
|
57
|
+
platform: Platform = "shorts",
|
|
58
|
+
language: str = "tr",
|
|
59
|
+
n: int = 10,
|
|
60
|
+
formulas: list[str] | None = None,
|
|
61
|
+
) -> list[HookVariant]:
|
|
62
|
+
"""
|
|
63
|
+
Generate n hook variants for a topic.
|
|
64
|
+
|
|
65
|
+
Uses Groq LLM if API key available, otherwise falls back
|
|
66
|
+
to template-based generation.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
topic: Content topic (e.g. "AI video generation")
|
|
70
|
+
platform: Target platform
|
|
71
|
+
language: "tr" for Turkish, "en" for English
|
|
72
|
+
n: Number of variants to generate
|
|
73
|
+
formulas: Specific formula types to use
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
List of HookVariant objects, sorted by predicted score
|
|
77
|
+
"""
|
|
78
|
+
if self._api_key:
|
|
79
|
+
return self._generate_with_llm(topic, platform, language, n, formulas)
|
|
80
|
+
return self._generate_from_templates(topic, platform, language, n, formulas)
|
|
81
|
+
|
|
82
|
+
def _generate_with_llm(
|
|
83
|
+
self,
|
|
84
|
+
topic: str,
|
|
85
|
+
platform: Platform,
|
|
86
|
+
language: str,
|
|
87
|
+
n: int,
|
|
88
|
+
formulas: list[str] | None,
|
|
89
|
+
) -> list[HookVariant]:
|
|
90
|
+
try:
|
|
91
|
+
from groq import Groq # type: ignore[import-untyped]
|
|
92
|
+
except ImportError as e:
|
|
93
|
+
raise ImportError("Install groq: pip install groq") from e
|
|
94
|
+
|
|
95
|
+
platform_context = {
|
|
96
|
+
"tiktok": "9:16 dikey, 15-60 saniye, ilk 3 saniyede bağla",
|
|
97
|
+
"shorts": "9:16 dikey, max 60 saniye, ilk 5 saniyede bağla",
|
|
98
|
+
"reels": "9:16 dikey, max 90 saniye, görsel şok",
|
|
99
|
+
"youtube": "16:9, ilk 15 saniyede bağla",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
lang_instruction = "Türkçe" if language == "tr" else "İngilizce"
|
|
103
|
+
formula_instruction = (
|
|
104
|
+
f"Şu formülleri kullan: {', '.join(formulas)}" if formulas else "Farklı formüller kullan"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
prompt = f"""Sen viral içerik uzmanısın. "{topic}" için {n} farklı hook yaz.
|
|
108
|
+
|
|
109
|
+
Platform: {platform} ({platform_context.get(platform, '')})
|
|
110
|
+
Dil: {lang_instruction}
|
|
111
|
+
{formula_instruction}
|
|
112
|
+
|
|
113
|
+
Her hook için JSON objesi üret:
|
|
114
|
+
{{
|
|
115
|
+
"text": "hook metni",
|
|
116
|
+
"formula": "curiosity|benefit|number|story|pov",
|
|
117
|
+
"cta": "call-to-action önerisi",
|
|
118
|
+
"thumbnail_concept": "thumbnail konsepti (1 cümle)",
|
|
119
|
+
"score": 1-10 arasında tahmin
|
|
120
|
+
}}
|
|
121
|
+
|
|
122
|
+
Sadece JSON listesi döndür, başka açıklama yok."""
|
|
123
|
+
|
|
124
|
+
client = Groq(
|
|
125
|
+
api_key=self._api_key,
|
|
126
|
+
default_headers={"User-Agent": "OpenAI/Python 1.0.0"},
|
|
127
|
+
)
|
|
128
|
+
response = client.chat.completions.create(
|
|
129
|
+
model="llama-3.3-70b-versatile",
|
|
130
|
+
messages=[{"role": "user", "content": prompt}],
|
|
131
|
+
max_tokens=2000,
|
|
132
|
+
temperature=0.9,
|
|
133
|
+
)
|
|
134
|
+
import json
|
|
135
|
+
|
|
136
|
+
raw = response.choices[0].message.content.strip()
|
|
137
|
+
# Strip markdown code blocks if present
|
|
138
|
+
if raw.startswith("```"):
|
|
139
|
+
raw = "\n".join(raw.split("\n")[1:-1])
|
|
140
|
+
|
|
141
|
+
items = json.loads(raw)
|
|
142
|
+
variants = [
|
|
143
|
+
HookVariant(
|
|
144
|
+
text=item["text"],
|
|
145
|
+
platform=platform,
|
|
146
|
+
formula=item.get("formula", ""),
|
|
147
|
+
language=language,
|
|
148
|
+
cta=item.get("cta", ""),
|
|
149
|
+
thumbnail_concept=item.get("thumbnail_concept", ""),
|
|
150
|
+
score=float(item.get("score", 5.0)),
|
|
151
|
+
)
|
|
152
|
+
for item in items
|
|
153
|
+
]
|
|
154
|
+
return sorted(variants, key=lambda v: v.score, reverse=True)
|
|
155
|
+
|
|
156
|
+
def _generate_from_templates(
|
|
157
|
+
self,
|
|
158
|
+
topic: str,
|
|
159
|
+
platform: Platform,
|
|
160
|
+
language: str,
|
|
161
|
+
n: int,
|
|
162
|
+
formulas: list[str] | None,
|
|
163
|
+
) -> list[HookVariant]:
|
|
164
|
+
selected_formulas = formulas or list(_HOOK_FORMULAS.keys())
|
|
165
|
+
variants = []
|
|
166
|
+
for formula in selected_formulas:
|
|
167
|
+
templates = _HOOK_FORMULAS.get(formula, [])
|
|
168
|
+
for tmpl in templates[:2]: # max 2 per formula
|
|
169
|
+
text = tmpl.format(
|
|
170
|
+
topic=topic, n=5, m=3, duration="5 dakika",
|
|
171
|
+
competitor="premium araç", outcome="başarı",
|
|
172
|
+
negative_outcome="pişman oldum",
|
|
173
|
+
)
|
|
174
|
+
variants.append(
|
|
175
|
+
HookVariant(
|
|
176
|
+
text=text,
|
|
177
|
+
platform=platform,
|
|
178
|
+
formula=formula,
|
|
179
|
+
language=language,
|
|
180
|
+
score=5.0,
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
if len(variants) >= n:
|
|
184
|
+
break
|
|
185
|
+
if len(variants) >= n:
|
|
186
|
+
break
|
|
187
|
+
return variants[:n]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Data models for socialpulse."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class ChannelStats:
|
|
12
|
+
"""Analytics snapshot for a single channel."""
|
|
13
|
+
|
|
14
|
+
channel_id: str
|
|
15
|
+
platform: str # "youtube" | "instagram" | "tiktok"
|
|
16
|
+
name: str = ""
|
|
17
|
+
subscribers: int = 0
|
|
18
|
+
total_views: int = 0
|
|
19
|
+
weekly_views: int = 0
|
|
20
|
+
weekly_uploads: int = 0
|
|
21
|
+
avg_views_per_video: float = 0.0
|
|
22
|
+
engagement_rate: float = 0.0
|
|
23
|
+
estimated_rpm: float = 0.0
|
|
24
|
+
growth_score: float = 0.0 # 0-40 scale
|
|
25
|
+
stale: bool = False # True if no upload in 4+ days
|
|
26
|
+
collected_at: datetime = field(default_factory=datetime.now)
|
|
27
|
+
|
|
28
|
+
def to_dict(self) -> dict[str, Any]:
|
|
29
|
+
return {
|
|
30
|
+
"channel_id": self.channel_id,
|
|
31
|
+
"platform": self.platform,
|
|
32
|
+
"name": self.name,
|
|
33
|
+
"subscribers": self.subscribers,
|
|
34
|
+
"total_views": self.total_views,
|
|
35
|
+
"weekly_views": self.weekly_views,
|
|
36
|
+
"weekly_uploads": self.weekly_uploads,
|
|
37
|
+
"avg_views_per_video": self.avg_views_per_video,
|
|
38
|
+
"engagement_rate": self.engagement_rate,
|
|
39
|
+
"estimated_rpm": self.estimated_rpm,
|
|
40
|
+
"growth_score": self.growth_score,
|
|
41
|
+
"stale": self.stale,
|
|
42
|
+
"collected_at": self.collected_at.isoformat(),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class TrendSignal:
|
|
48
|
+
"""A trending topic or keyword signal."""
|
|
49
|
+
|
|
50
|
+
keyword: str
|
|
51
|
+
platform: str # "youtube" | "tiktok" | "instagram" | "google"
|
|
52
|
+
region: str # "TR" | "US" | "GB" | "global"
|
|
53
|
+
niche: str = ""
|
|
54
|
+
growth_rate: float = 0.0 # % growth vs prior week
|
|
55
|
+
competition: str = "medium" # "low" | "medium" | "high"
|
|
56
|
+
volume: int = 0
|
|
57
|
+
best_channel_type: str = ""
|
|
58
|
+
detected_at: datetime = field(default_factory=datetime.now)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class HookVariant:
|
|
63
|
+
"""A generated hook variant for A/B testing."""
|
|
64
|
+
|
|
65
|
+
text: str
|
|
66
|
+
platform: str
|
|
67
|
+
formula: str # "curiosity" | "benefit" | "number" | "story" | "pov"
|
|
68
|
+
language: str = "en"
|
|
69
|
+
cta: str = ""
|
|
70
|
+
thumbnail_concept: str = ""
|
|
71
|
+
score: float = 0.0 # predicted viral score 0-10
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass
|
|
75
|
+
class PublishResult:
|
|
76
|
+
"""Result of a cross-platform publish operation."""
|
|
77
|
+
|
|
78
|
+
platform: str
|
|
79
|
+
success: bool
|
|
80
|
+
video_id: str = ""
|
|
81
|
+
url: str = ""
|
|
82
|
+
error: str = ""
|
|
83
|
+
published_at: datetime = field(default_factory=datetime.now)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""TrendRadar — Multi-source trending topic discovery."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from datetime import datetime, timezone
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Literal
|
|
11
|
+
|
|
12
|
+
from .models import TrendSignal
|
|
13
|
+
|
|
14
|
+
Region = Literal["TR", "US", "GB", "DE", "FR", "global"]
|
|
15
|
+
Platform = Literal["youtube", "tiktok", "instagram", "google", "all"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TrendRadar:
|
|
19
|
+
"""
|
|
20
|
+
Discover trending topics using yt-dlp and optional pytrends.
|
|
21
|
+
|
|
22
|
+
>>> radar = TrendRadar()
|
|
23
|
+
>>> trends = radar.trending(niches=["ai_tools", "science"], regions=["TR"])
|
|
24
|
+
>>> for t in trends:
|
|
25
|
+
... print(t.keyword, t.growth_rate)
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, groq_api_key: str | None = None) -> None:
|
|
29
|
+
self._groq_key = groq_api_key or os.environ.get("GROQ_API_KEY", "")
|
|
30
|
+
self._scripts_dir = Path.home() / "Projects/content/social-media/scripts"
|
|
31
|
+
|
|
32
|
+
def trending(
|
|
33
|
+
self,
|
|
34
|
+
niches: list[str] | None = None,
|
|
35
|
+
regions: list[Region] | None = None,
|
|
36
|
+
platform: Platform = "youtube",
|
|
37
|
+
limit: int = 20,
|
|
38
|
+
) -> list[TrendSignal]:
|
|
39
|
+
"""
|
|
40
|
+
Return trending signals for given niches and regions.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
niches: Content niches to focus on (e.g. ["ai_tools", "science"])
|
|
44
|
+
regions: Geographic regions (e.g. ["TR", "US"])
|
|
45
|
+
platform: Which platform to query
|
|
46
|
+
limit: Max number of signals to return
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
List of TrendSignal objects, highest growth first
|
|
50
|
+
"""
|
|
51
|
+
niches = niches or ["technology", "science", "lifestyle"]
|
|
52
|
+
regions = regions or ["global"]
|
|
53
|
+
signals: list[TrendSignal] = []
|
|
54
|
+
|
|
55
|
+
for niche in niches:
|
|
56
|
+
for region in regions:
|
|
57
|
+
if platform in ("youtube", "all"):
|
|
58
|
+
signals.extend(self._youtube_trends(niche, region, limit=5))
|
|
59
|
+
if platform in ("tiktok", "all"):
|
|
60
|
+
signals.extend(self._tiktok_trends(niche, region, limit=5))
|
|
61
|
+
|
|
62
|
+
seen: set[str] = set()
|
|
63
|
+
unique: list[TrendSignal] = []
|
|
64
|
+
for s in signals:
|
|
65
|
+
if s.keyword not in seen:
|
|
66
|
+
seen.add(s.keyword)
|
|
67
|
+
unique.append(s)
|
|
68
|
+
|
|
69
|
+
return sorted(unique, key=lambda s: s.growth_rate, reverse=True)[:limit]
|
|
70
|
+
|
|
71
|
+
def _youtube_trends(self, niche: str, region: str, limit: int) -> list[TrendSignal]:
|
|
72
|
+
try:
|
|
73
|
+
result = subprocess.run(
|
|
74
|
+
[
|
|
75
|
+
"yt-dlp",
|
|
76
|
+
"--print", "%(title)s|%(view_count)s",
|
|
77
|
+
f"ytsearch{limit}:{niche} trending",
|
|
78
|
+
"--no-playlist", "--quiet",
|
|
79
|
+
],
|
|
80
|
+
capture_output=True, text=True, timeout=15,
|
|
81
|
+
)
|
|
82
|
+
signals = []
|
|
83
|
+
for line in result.stdout.strip().split("\n"):
|
|
84
|
+
if "|" in line:
|
|
85
|
+
title, views_str = line.rsplit("|", 1)
|
|
86
|
+
try:
|
|
87
|
+
views = int(views_str)
|
|
88
|
+
except ValueError:
|
|
89
|
+
views = 0
|
|
90
|
+
signals.append(TrendSignal(
|
|
91
|
+
keyword=title[:80],
|
|
92
|
+
platform="youtube",
|
|
93
|
+
region=region,
|
|
94
|
+
niche=niche,
|
|
95
|
+
volume=views,
|
|
96
|
+
growth_rate=min(float(views) / 100_000 * 100, 999.0),
|
|
97
|
+
competition="medium",
|
|
98
|
+
detected_at=datetime.now(timezone.utc),
|
|
99
|
+
))
|
|
100
|
+
return signals
|
|
101
|
+
except (subprocess.TimeoutExpired, FileNotFoundError):
|
|
102
|
+
return []
|
|
103
|
+
|
|
104
|
+
def _tiktok_trends(self, niche: str, region: str, limit: int) -> list[TrendSignal]:
|
|
105
|
+
# TikTok trends via yt-dlp (limited public data)
|
|
106
|
+
try:
|
|
107
|
+
result = subprocess.run(
|
|
108
|
+
[
|
|
109
|
+
"yt-dlp",
|
|
110
|
+
"--print", "%(title)s|%(view_count)s",
|
|
111
|
+
f"https://www.tiktok.com/tag/{niche.replace(' ', '')}",
|
|
112
|
+
"--no-playlist", "--playlist-items", f"1-{limit}",
|
|
113
|
+
"--quiet",
|
|
114
|
+
],
|
|
115
|
+
capture_output=True, text=True, timeout=15,
|
|
116
|
+
)
|
|
117
|
+
signals = []
|
|
118
|
+
for line in result.stdout.strip().split("\n"):
|
|
119
|
+
if "|" in line:
|
|
120
|
+
title, views_str = line.rsplit("|", 1)
|
|
121
|
+
try:
|
|
122
|
+
views = int(views_str)
|
|
123
|
+
except ValueError:
|
|
124
|
+
views = 0
|
|
125
|
+
signals.append(TrendSignal(
|
|
126
|
+
keyword=title[:80],
|
|
127
|
+
platform="tiktok",
|
|
128
|
+
region=region,
|
|
129
|
+
niche=niche,
|
|
130
|
+
volume=views,
|
|
131
|
+
growth_rate=min(float(views) / 50_000 * 100, 999.0),
|
|
132
|
+
competition="high",
|
|
133
|
+
detected_at=datetime.now(timezone.utc),
|
|
134
|
+
))
|
|
135
|
+
return signals
|
|
136
|
+
except (subprocess.TimeoutExpired, FileNotFoundError):
|
|
137
|
+
return []
|
|
138
|
+
|
|
139
|
+
def google_trends(
|
|
140
|
+
self, keywords: list[str], regions: list[Region] | None = None
|
|
141
|
+
) -> list[TrendSignal]:
|
|
142
|
+
"""
|
|
143
|
+
Use pytrends to get Google Trends data.
|
|
144
|
+
Requires: pip install socialpulse[trends]
|
|
145
|
+
"""
|
|
146
|
+
try:
|
|
147
|
+
from pytrends.request import TrendReq # type: ignore[import-untyped]
|
|
148
|
+
except ImportError as e:
|
|
149
|
+
raise ImportError("Install trends extra: pip install socialpulse[trends]") from e
|
|
150
|
+
|
|
151
|
+
pt = TrendReq(hl="tr-TR", tz=180)
|
|
152
|
+
pt.build_payload(keywords[:5], timeframe="now 7-d")
|
|
153
|
+
interest = pt.interest_over_time()
|
|
154
|
+
|
|
155
|
+
signals = []
|
|
156
|
+
for kw in keywords[:5]:
|
|
157
|
+
if kw in interest.columns:
|
|
158
|
+
avg = float(interest[kw].mean())
|
|
159
|
+
signals.append(TrendSignal(
|
|
160
|
+
keyword=kw,
|
|
161
|
+
platform="google",
|
|
162
|
+
region=regions[0] if regions else "global",
|
|
163
|
+
growth_rate=avg,
|
|
164
|
+
detected_at=datetime.now(timezone.utc),
|
|
165
|
+
))
|
|
166
|
+
|
|
167
|
+
return sorted(signals, key=lambda s: s.growth_rate, reverse=True)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: socialpulse
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Social media analytics + viral content intelligence for creators
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/teyfikoz/socialpulse
|
|
7
|
+
Project-URL: Repository, https://github.com/teyfikoz/socialpulse
|
|
8
|
+
Keywords: social media,youtube,instagram,tiktok,analytics,viral,content
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: requests>=2.31
|
|
17
|
+
Requires-Dist: python-dateutil>=2.8
|
|
18
|
+
Provides-Extra: youtube
|
|
19
|
+
Requires-Dist: google-api-python-client>=2.0; extra == "youtube"
|
|
20
|
+
Requires-Dist: google-auth-httplib2; extra == "youtube"
|
|
21
|
+
Provides-Extra: instagram
|
|
22
|
+
Requires-Dist: instaloader>=4.10; extra == "instagram"
|
|
23
|
+
Provides-Extra: tiktok
|
|
24
|
+
Requires-Dist: requests>=2.31; extra == "tiktok"
|
|
25
|
+
Provides-Extra: trends
|
|
26
|
+
Requires-Dist: pytrends>=4.9; extra == "trends"
|
|
27
|
+
Provides-Extra: full
|
|
28
|
+
Requires-Dist: google-api-python-client>=2.0; extra == "full"
|
|
29
|
+
Requires-Dist: google-auth-httplib2; extra == "full"
|
|
30
|
+
Requires-Dist: instaloader>=4.10; extra == "full"
|
|
31
|
+
Requires-Dist: pytrends>=4.9; extra == "full"
|
|
32
|
+
|
|
33
|
+
# socialpulse
|
|
34
|
+
|
|
35
|
+
Social media analytics + viral content intelligence for creators.
|
|
36
|
+
|
|
37
|
+
Unifies YouTube Analytics v3, Instagram Insights, TikTok metrics, and Google Trends into a single Python API.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install socialpulse
|
|
43
|
+
|
|
44
|
+
# Optional extras
|
|
45
|
+
pip install socialpulse[youtube] # YouTube Analytics v3
|
|
46
|
+
pip install socialpulse[instagram] # Instagram / instaloader
|
|
47
|
+
pip install socialpulse[tiktok] # TikTok metrics
|
|
48
|
+
pip install socialpulse[trends] # Google Trends via pytrends
|
|
49
|
+
pip install socialpulse[full] # All extras
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from socialpulse import ChannelPulse, TrendRadar, HookLab
|
|
56
|
+
|
|
57
|
+
# Channel analytics
|
|
58
|
+
pulse = ChannelPulse()
|
|
59
|
+
stats = pulse.weekly_summary(channels=["@yourchannel"])
|
|
60
|
+
|
|
61
|
+
# Trend discovery
|
|
62
|
+
radar = TrendRadar()
|
|
63
|
+
trends = radar.trending(niches=["ai_tools", "science"], regions=["TR", "US"])
|
|
64
|
+
|
|
65
|
+
# Viral hook generation
|
|
66
|
+
lab = HookLab()
|
|
67
|
+
hooks = lab.generate(topic="AI video tools", platform="tiktok", n=10)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Modules
|
|
71
|
+
|
|
72
|
+
| Module | Description |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `ChannelPulse` | YouTube/Instagram/TikTok channel metrics |
|
|
75
|
+
| `TrendRadar` | Cross-platform trend discovery |
|
|
76
|
+
| `HookLab` | Viral hook and title generation |
|
|
77
|
+
| `CrossPublisher` | Multi-platform post scheduling helper |
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
socialpulse/__init__.py
|
|
4
|
+
socialpulse/channel_pulse.py
|
|
5
|
+
socialpulse/cross_publisher.py
|
|
6
|
+
socialpulse/hook_lab.py
|
|
7
|
+
socialpulse/models.py
|
|
8
|
+
socialpulse/trend_radar.py
|
|
9
|
+
socialpulse.egg-info/PKG-INFO
|
|
10
|
+
socialpulse.egg-info/SOURCES.txt
|
|
11
|
+
socialpulse.egg-info/dependency_links.txt
|
|
12
|
+
socialpulse.egg-info/requires.txt
|
|
13
|
+
socialpulse.egg-info/top_level.txt
|
|
14
|
+
tests/test_socialpulse.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
requests>=2.31
|
|
2
|
+
python-dateutil>=2.8
|
|
3
|
+
|
|
4
|
+
[full]
|
|
5
|
+
google-api-python-client>=2.0
|
|
6
|
+
google-auth-httplib2
|
|
7
|
+
instaloader>=4.10
|
|
8
|
+
pytrends>=4.9
|
|
9
|
+
|
|
10
|
+
[instagram]
|
|
11
|
+
instaloader>=4.10
|
|
12
|
+
|
|
13
|
+
[tiktok]
|
|
14
|
+
requests>=2.31
|
|
15
|
+
|
|
16
|
+
[trends]
|
|
17
|
+
pytrends>=4.9
|
|
18
|
+
|
|
19
|
+
[youtube]
|
|
20
|
+
google-api-python-client>=2.0
|
|
21
|
+
google-auth-httplib2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
socialpulse
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Tests for socialpulse library."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import tempfile
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from socialpulse import ChannelPulse, HookLab, TrendRadar
|
|
12
|
+
from socialpulse.models import ChannelStats, HookVariant, TrendSignal
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestChannelPulse:
|
|
16
|
+
def test_weekly_summary_missing_file(self):
|
|
17
|
+
pulse = ChannelPulse(status_path="/nonexistent/path.json")
|
|
18
|
+
assert pulse.weekly_summary() == []
|
|
19
|
+
|
|
20
|
+
def test_weekly_summary_valid_file(self, tmp_path):
|
|
21
|
+
status = {
|
|
22
|
+
"youtube": [
|
|
23
|
+
{
|
|
24
|
+
"channel_id": "UC123",
|
|
25
|
+
"title": "TestChannel",
|
|
26
|
+
"subscribers": 1000,
|
|
27
|
+
"weekly_views": 5000,
|
|
28
|
+
"weekly_upload_count": 3,
|
|
29
|
+
"latest_public_at": "2026-11-29T10:00:00Z",
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
status_file = tmp_path / "status.json"
|
|
34
|
+
status_file.write_text(json.dumps(status))
|
|
35
|
+
|
|
36
|
+
pulse = ChannelPulse(status_path=status_file)
|
|
37
|
+
result = pulse.weekly_summary()
|
|
38
|
+
assert len(result) == 1
|
|
39
|
+
assert result[0].name == "TestChannel"
|
|
40
|
+
assert result[0].platform == "youtube"
|
|
41
|
+
assert result[0].subscribers == 1000
|
|
42
|
+
|
|
43
|
+
def test_stale_channels(self, tmp_path):
|
|
44
|
+
from datetime import datetime, timedelta, timezone
|
|
45
|
+
old_date = (datetime.now(timezone.utc) - timedelta(days=10)).isoformat()
|
|
46
|
+
status = {
|
|
47
|
+
"youtube": [
|
|
48
|
+
{
|
|
49
|
+
"channel_id": "UC456",
|
|
50
|
+
"title": "StaleChannel",
|
|
51
|
+
"subscribers": 500,
|
|
52
|
+
"weekly_views": 100,
|
|
53
|
+
"weekly_upload_count": 0,
|
|
54
|
+
"latest_public_at": old_date,
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
status_file = tmp_path / "status.json"
|
|
59
|
+
status_file.write_text(json.dumps(status))
|
|
60
|
+
|
|
61
|
+
pulse = ChannelPulse(status_path=status_file)
|
|
62
|
+
stale = pulse.stale_channels()
|
|
63
|
+
assert len(stale) == 1
|
|
64
|
+
assert stale[0].stale is True
|
|
65
|
+
|
|
66
|
+
def test_growth_report_format(self, tmp_path):
|
|
67
|
+
status = {"youtube": [{"channel_id": "UC1", "title": "Ch", "subscribers": 100,
|
|
68
|
+
"weekly_views": 500, "weekly_upload_count": 2,
|
|
69
|
+
"latest_public_at": "2026-11-29T00:00:00Z"}]}
|
|
70
|
+
status_file = tmp_path / "status.json"
|
|
71
|
+
status_file.write_text(json.dumps(status))
|
|
72
|
+
|
|
73
|
+
pulse = ChannelPulse(status_path=status_file)
|
|
74
|
+
report = pulse.growth_report()
|
|
75
|
+
assert "# Growth Report" in report
|
|
76
|
+
assert "Top Performers" in report
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class TestHookLab:
|
|
80
|
+
def test_generate_no_api_key(self):
|
|
81
|
+
lab = HookLab(groq_api_key="")
|
|
82
|
+
hooks = lab.generate("AI tools", platform="tiktok", language="tr", n=5)
|
|
83
|
+
assert len(hooks) <= 5
|
|
84
|
+
assert all(isinstance(h, HookVariant) for h in hooks)
|
|
85
|
+
assert all(h.platform == "tiktok" for h in hooks)
|
|
86
|
+
|
|
87
|
+
def test_generate_all_formulas(self):
|
|
88
|
+
lab = HookLab(groq_api_key="")
|
|
89
|
+
formulas = ["curiosity", "benefit", "number", "story", "pov"]
|
|
90
|
+
for formula in formulas:
|
|
91
|
+
hooks = lab.generate("test topic", formulas=[formula], n=2)
|
|
92
|
+
assert len(hooks) >= 1
|
|
93
|
+
|
|
94
|
+
def test_hook_has_required_fields(self):
|
|
95
|
+
lab = HookLab(groq_api_key="")
|
|
96
|
+
hooks = lab.generate("Python", n=3)
|
|
97
|
+
for h in hooks:
|
|
98
|
+
assert h.text
|
|
99
|
+
assert h.formula
|
|
100
|
+
assert h.platform
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TestTrendRadar:
|
|
104
|
+
def test_init(self):
|
|
105
|
+
radar = TrendRadar()
|
|
106
|
+
assert radar is not None
|
|
107
|
+
|
|
108
|
+
def test_trending_returns_list(self, monkeypatch):
|
|
109
|
+
def mock_run(*args, **kwargs):
|
|
110
|
+
class FakeResult:
|
|
111
|
+
returncode = 0
|
|
112
|
+
stdout = "AI tools video|50000\nMachine learning|30000\n"
|
|
113
|
+
stderr = ""
|
|
114
|
+
return FakeResult()
|
|
115
|
+
|
|
116
|
+
monkeypatch.setattr("subprocess.run", mock_run)
|
|
117
|
+
radar = TrendRadar()
|
|
118
|
+
trends = radar.trending(niches=["ai_tools"], regions=["TR"], platform="youtube", limit=5)
|
|
119
|
+
assert isinstance(trends, list)
|
|
120
|
+
assert all(isinstance(t, TrendSignal) for t in trends)
|
|
121
|
+
|
|
122
|
+
def test_trending_deduplication(self, monkeypatch):
|
|
123
|
+
def mock_run(*args, **kwargs):
|
|
124
|
+
class FakeResult:
|
|
125
|
+
returncode = 0
|
|
126
|
+
stdout = "Same video|1000\nSame video|1000\n"
|
|
127
|
+
stderr = ""
|
|
128
|
+
return FakeResult()
|
|
129
|
+
|
|
130
|
+
monkeypatch.setattr("subprocess.run", mock_run)
|
|
131
|
+
radar = TrendRadar()
|
|
132
|
+
trends = radar.trending(niches=["tech"], regions=["TR", "US"], limit=10)
|
|
133
|
+
keywords = [t.keyword for t in trends]
|
|
134
|
+
assert len(keywords) == len(set(keywords))
|