# task-355.1: 유튜브 크롤링 + 업계동향 토픽 테스트 + 업로드

## 목표
유튜브 크롤러로 실제 영상 데이터를 수집하고, 업계동향 카테고리로 콘텐츠 생성 → Threads 업로드

## 실행 절차

### Step 1: 유튜브 캐시 갱신
```bash
cd /home/jay/projects/ThreadAuto
python3 -c "
from crawler.youtube_crawler import update_cache
videos = update_cache()
print(f'수집 영상: {len(videos)}건')
for v in videos[:3]:
    print(f'  {v.get(\"title\", \"?\")[:60]}')
"
```

### Step 2: 업계동향 토픽 1개 선택
```python
from content.topic_selector import select_single_topic
topic = select_single_topic(category="업계동향")
```
- `select_single_topic`은 이제 1개만 used_count 갱신함
- 유튜브 캐시가 있으면 `select_trend_topic()`이 캐시에서 가져옴

### Step 3: 콘텐츠 생성
- `ContentGeneratorV2().generate(topic, context)` 호출
- context에 유튜브 자막/요약 포함

### Step 4: 카드뉴스 렌더링 + Threads 업로드

### 주의사항
- `select_single_topic(category="업계동향")`을 직접 호출하되,
  업계동향은 `select_trend_topic()`을 내부적으로 사용하지 않음 (select_from_pool 직접 호출)
- 그러므로 **유튜브 캐시가 채워진 상태에서** topic_selector의 `select_trend_topic()`을 직접 호출하여 유튜브 소스 토픽을 가져와야 함
- 아래 코드 참고:

```python
import sys
sys.path.insert(0, "/home/jay/projects/ThreadAuto")

# Step 1: 유튜브 캐시 갱신
from crawler.youtube_crawler import update_cache
videos = update_cache()
print(f"유튜브 수집: {len(videos)}건")

# Step 2: 업계동향 토픽 (유튜브 소스)
from content.topic_selector import load_topics, select_trend_topic, save_topics
topics = load_topics()
trend_topic = select_trend_topic(topics)
save_topics(topics)
print(f"선택 토픽: {trend_topic.get('title', '?')}")
print(f"소스: {trend_topic.get('_source', 'evergreen')}")

# Step 3: 콘텐츠 생성 (컨텍스트 주입)
from content.pipeline import _build_trend_context
from content.content_generator_v2 import ContentGeneratorV2

context = _build_trend_context(trend_topic)
generator = ContentGeneratorV2()
content = generator.generate(topic=trend_topic, context=context)

# Step 4: 렌더링
from renderer.cardnews import CardNewsRenderer
from renderer.themes import get_theme
theme = get_theme("NavyGold")
renderer = CardNewsRenderer()
image_paths = [str(p) for p in renderer.render_from_slides(content["slides"], theme=theme)]

# Step 5: 업로드
from publisher.threads_publisher import ThreadsPublisher
publisher = ThreadsPublisher()
result = publisher.publish_cardnews(
    title=content.get("slides", [{}])[0].get("title", ""),
    items=[],
    theme_name="NavyGold",
    content=content,
)
```

## 검증 포인트
1. **유튜브 캐시 정상 수집**: youtube_cache.json에 영상 데이터 저장
2. **업계동향 토픽 소스**: `_source`가 "youtube"인지 확인
3. **컨텍스트 주입**: 자막/요약이 콘텐츠 생성에 반영됐는지
4. **캡션 줄바꿈 스타일**: 새 줄바꿈 가이드 반영
5. **해시태그 0개**: 해시태그 없음 확인
6. **랜딩페이지 URL**: CTA에 URL 있으면 캡션에 삽입

## 결과물
1. 생성된 이미지 6장을 아누에게 sendfile로 전송
2. Threads Post ID 보고
3. 캡션 전문 보고
4. 유튜브 소스 토픽 정보 보고 (title, _source, transcript 유무)

## 완료 후
- `memory/events/task-355.1.done` 파일 생성
- 보고서: `memory/reports/task-355.1.md`
