Skip to content

Commit

Permalink
use official google api instead of ytlemnoslife
Browse files Browse the repository at this point in the history
  • Loading branch information
zaanposni committed Oct 27, 2024
1 parent 782801a commit 42ffe73
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ INSTAGRAM_2FA_SECRET=
TWITTER_USERNAME=
TWITTER_PASSWORD=
TWITTER_LIST_ID=

YOUTUBE_API_KEY=
1 change: 1 addition & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ services:
- TWITTER_USERNAME=${TWITTER_USERNAME}
- TWITTER_PASSWORD=${TWITTER_PASSWORD}
- TWITTER_LIST_ID=${TWITTER_LIST_ID}
- YOUTUBE_API_KEY=${YOUTUBE_API_KEY}
volumes:
- shared-data:/app/cdn
- config:/app/config
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ services:
- TWITTER_USERNAME=${TWITTER_USERNAME}
- TWITTER_PASSWORD=${TWITTER_PASSWORD}
- TWITTER_LIST_ID=${TWITTER_LIST_ID}
- YOUTUBE_API_KEY=${YOUTUBE_API_KEY}
volumes:
- shared-data:/app/cdn
- config:/app/config
Expand Down
2 changes: 2 additions & 0 deletions src/dataimport/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ INSTAGRAM_2FA_SECRET=
TWITTER_USERNAME=
TWITTER_PASSWORD=
TWITTER_LIST_ID=

YOUTUBE_API_KEY=
16 changes: 9 additions & 7 deletions src/dataimport/youtube_video_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

console = Console()

server_base_url = (
os.getenv("YT_SERVER_BASE_URL")
if os.getenv("YT_SERVER_BASE_URL")
else "http://localhost:8080"
)
youtube_key = os.getenv("YOUTUBE_API_KEY")

if not youtube_key:
raise Exception("YOUTUBE_API_KEY not set")

channel_ids = [
"UCqwGaUvq_l0RKszeHhZ5leA", # PietSmiet
"UC3wla9xMoxDu7MIZImad1kQ", # PietSmietTV
"UCYCQdW5rvpLA5Jd1nM6YxxA", # PietSmietLive
"UC5yPQPrd8h6r3mGpbbbWVFg", # Best of PietSmiet
]
collection_url = "https://yt.lemnoslife.com/noKey/search?part=snippet&order=date&maxResults=50&channelId={}&type=video"
collection_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&order=date&maxResults=50&channelId={}&type=video&key={}"
youtube_url_template = "https://youtu.be/{}"

UPDATE_STATEMENT = "UPDATE ContentPiece SET description = :description, secondaryHref = :secondaryHref WHERE id = :id"
Expand Down Expand Up @@ -54,7 +54,9 @@ async def youtube():
console.log("Fetching yt data...")
for channel in channel_ids:
console.log(f"Fetching yt data for {channel}")
yt_data = requests.get(collection_url.format(channel)).json()["items"]
yt_data = requests.get(collection_url.format(channel, youtube_key)).json()[
"items"
]

for video in yt_data:
console.log(f"Processing youtube video '{video['snippet']['title']}'")
Expand Down

0 comments on commit 42ffe73

Please sign in to comment.