-
Notifications
You must be signed in to change notification settings - Fork 5
/
wantyougone.py
87 lines (74 loc) · 2.28 KB
/
wantyougone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# this script preserves extra spaces
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import sys
import time
import pygame
def type_with_wpm(text, wpm):
words = text.split(" ") # Split by space to preserve extra spaces
skip_next = False
for word in words:
if skip_next:
skip_next = False
continue
if '/f' in word:
wpm *= 2
word = word.replace('/f', '')
elif '/s' in word:
wpm /= 1.5
word = word.replace('/s', '')
elif '/rs' in word:
wpm /= 2
word = word.replace('/rs', '')
elif '/ns' in word:
wpm = original_wpm
word = word.replace('/ns', '')
elif '/i' in word:
wpm *= 9999999999
word = word.replace('/i', '')
elif '/nl' in word:
print()
continue
elif word.startswith('/d'):
split_word = word.split("/d")
if len(split_word) > 1 and split_word[1].strip():
delay = float(split_word[1])
else:
delay = 0
time.sleep(delay)
skip_next = True
continue
delay = 60 / wpm
for i, char in enumerate(word):
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(delay)
if word != words[-1]:
sys.stdout.write(' ')
sys.stdout.flush()
time.sleep(delay)
sys.stdout.flush()
lyrics_file = './lyrics.txt'
if not os.path.exists(lyrics_file):
print("Unable to find the file 'lyrics.txt'.")
sys.exit()
with open(lyrics_file, 'r') as file:
lyrics = file.read()
bg_music_file = "wyg.mp3"
if not os.path.exists(bg_music_file):
print("Unable to find the file 'wyg.mp3'. Background music will not play.")
pygame.init()
if os.path.exists(bg_music_file):
pygame.mixer.music.load(bg_music_file)
pygame.mixer.music.play()
original_wpm = 800
wpm = original_wpm
for line in lyrics.split("\n"):
if '/c' in line:
os.system('cls' if os.name == 'nt' else 'clear')
elif line.strip() and '/nl' not in line:
type_with_wpm(line, wpm)
print()
elif line.strip():
type_with_wpm(line, wpm)
pygame.mixer.music.stop()