I made an intro quiz by myself because I can't play outside

I'm a sound gamer. I usually play with CHUNITHM at arcades. But I can't play because I have declared an emergency. Am free. That's why I decided to take an intro quiz with the Soundtrack that I bought for the time being. But you can't do an intro quiz without a questioner. It's also a matter of asking my parents to play the role of the questioner, so I decided to have Python do it for the time being.

Gist is here.

environment

Python: 3.8.2 python-vlc: 3.0.7110 VLC Media Player: 3.0.8 Vetinari

How to use

For steps 1 and 2, see this article. (0. Install Python 3.8.2.)

  1. Install VLC Media Player.
  2. Do pip install python -vlc. (For those who are familiar with it: If you do not want to pollute the global environment, set venv in the directory shown in step 3.)
  3. Copy and paste ʻintro_quiz.py` from Gist, save it, and put it in the folder (directory) where the music is placed.
  4. Double-click it and it will probably start, so enjoy it.

specification

--The song will play for 10 seconds from the beginning. --Unless the song title is less than 3 characters, it will not respond if it is less than 3 characters. It is useless to try to deceive by inserting only 1-2 characters. --You can give up by typing give up. ――If it is a partial match, it will be judged as "correct", and if it is an exact match, it will be judged as "perfect". ――I feel that bitrate related errors sometimes occur ~~, so there is no problem ~~.

Play image

SnapCrab_NoName_2020-4-8_0-12-8_No-00.png Songs such as Arcaea are also mixed in the folder.

Caution

I made it properly so I don't know if it's a bug. But if you tell me, I may or may not fix it.


From here on, it's for people who are interested in the contents.

code

It's dirty because I rubbed my sleepy eyes in the middle of the night and wrote it properly.

intro_quiz.py



#After installing VLC media player, pip install python-Please vlc.

import glob
import os
import random
import time

import vlc

player = vlc.MediaPlayer()

print("Intro quiz!")
print("Please enter part of the song title! I will judge by partial match!")
print("The song plays for 10 seconds!")
print("If you really don't understand, enter "give up"!")
print("Unless the song title is 2 characters or less, it will not respond if the number of characters entered is 2 characters or less!")

music_count = 1

musics = glob.glob("*")

while True:
    #File selection / playback
    if musics == []:
        break
    else:
        while True:
            filename = random.choice(musics)
            if filename.endswith(".py") or filename.endswith(".txt") or filename.startswith("AlbumArt_") or "Folder" in filename:
                musics.pop(musics.index(filename))
            else:
                musics.pop(musics.index(filename))
                break
        music_name = os.path.splitext(os.path.basename(filename))[0]
        player.set_mrl(filename)
        player.play()
        print(f"{music_count}Playing the song ...")
        time.sleep(10)
        player.stop()
        print("Now enter the song title!")
        while True:
            answer = input(">> ")
            if len(answer) >= min(3, len(filename)):
                if answer == music_name:
                    print("Perfect! amazing!")
                    break
                elif answer in music_name:
                    print("Correct answer! Congrats!")
                    break
                elif answer == "giveup":
                    print("Nice try!")
                    break
                else:
                    print("Sorry! Incorrect answer!")
            else:
                print(f"{min(3, len(filename))}Let's enter more than characters!")
        print(f"The correct answer is "{music_name}"was!")
        music_count += 1
print("All songs are over! Cheers for good work!")

Explanation

Glob collects all the files in the same hierarchy. However, at that time, there were a lot of album arts in the same directory just because they were not displayed, so I play them properly. Other than that, I play Python files and txt files that are mixed in with something. You can add conditions to play with or, so it's a good idea to run print (glob.glob ("*")) to see if there are any strange files. I think it's better to play extensions such as .jpg and .png.

Promotion

Let's all do CHUNITHM! I tried to say, but I can't play now, so let's do Arcaea instead.

Recommended Posts

I made an intro quiz by myself because I can't play outside
I made an Ansible-installer
I made an Xubuntu server.
I made an Anpanman painter discriminator
I made an Angular starter kit