Skip to content

Commit

Permalink
Refactored util functions, started argparse support
Browse files Browse the repository at this point in the history
  • Loading branch information
hajin-park committed Mar 20, 2024
1 parent 5fb4598 commit 4b38d1f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 449 deletions.
31 changes: 0 additions & 31 deletions src/spotify_translator/main.py

This file was deleted.

64 changes: 64 additions & 0 deletions src/spotify_translator/spotify_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import argparse
import time
import json
import os
import sys
from logging import DEBUG, ERROR
from pathlib import Path, PurePath
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials


def spotify_translator():
parser = argparse.ArgumentParser(
prog="spotify_translator", description="Translate Spotify songs."
)
parser.add_argument(
"-l",
"--url",
action="store",
help="Spotify Playlist link URL",
type=str,
nargs="+",
required=False, # this has to be set to false to prevent useless prompt for url when all user wants is the script version
)
parser.add_argument(
"-o",
"--output",
type=str,
action="store",
help="Specify download directory for transcriptions, translations, and mp3.",
required=False,
)
parser.add_argument(
"-d",
"--download",
action="store_true",
help="Download mp3 using youtube-dl",
required=False,
default=False,
)

# url = input("Enter track/playlist/album URL: ")
# songs = []

# try:
# if url.find("track") != -1:
# songs = spotify_track(url)
# if url.find("playlist") != -1:
# songs = spotify_playlist(url)
# if url.find("album") != -1:
# songs = spotify_album(url)
# except ValueError:
# raise ValueError("Invalid URL")

# for song in songs:
# download_one(song)
# print(f"\nTranslating track: {song['name']}\n")
# results = translate(song["name"], "Korean")
# print(f"Transcription:\n{results[0]}\n")
# print(f"Translation:\n{results[1]}\n")


if __name__ == "__main__":
spotify_translator()
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
"""
Handle translation and transcription of audio files
"""

from spotify_dl.spotify import (
fetch_tracks,
parse_spotify_url,
get_item_name,
validate_spotify_urls,
)
from spotify_dl.scaffold import get_tokens
from spotify_dl import youtube as yt
from spotipy.oauth2 import SpotifyClientCredentials
from pathlib import Path
import os
import sys
import whisper
import spotipy


def translate(file, from_lang):
Expand All @@ -24,3 +33,18 @@ def translate(file, from_lang):
f.write(f"Transcription:\n{transcription}\n\nTranslation:\n{translation}")

return transcription, translation


def spotify_auth():
# test client ids, b64 for just to deter.
tokens = get_tokens()
if tokens is None:
sys.exit(1)
client_id, client_secret = tokens

sp = spotipy.Spotify(
auth_manager=SpotifyClientCredentials(
client_id=client_id, client_secret=client_secret
)
)
return sp
51 changes: 0 additions & 51 deletions src/spotify_translator/utils/download_youtube.py

This file was deleted.

Loading

0 comments on commit 4b38d1f

Please sign in to comment.