Created
May 24, 2022 09:59
-
-
Save Prince-of-sea/3b93a2320a6670a86c9943cd522bcdd3 to your computer and use it in GitHub Desktop.
SpotiFlyerでぶっこ抜いた音楽を自動リネームするやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from mutagen.easyid3 import EasyID3 | |
| import subprocess | |
| import psutil | |
| import glob | |
| import time | |
| import os | |
| import re | |
| # ---------------------------------------- | |
| ############################ | |
| ### この辺いじって使ってね ### | |
| ############################ | |
| # SpotiFlyer側で設定した音楽の保存先のパス | |
| SpotiFlyer_dir = os.environ['USERPROFILE'] | |
| # 実際の保存先のパス | |
| Music_dir = os.path.join(os.environ['USERPROFILE'],'Music','_SpotiFlyer') | |
| # exe本体のパス | |
| SF_exe = r'C:/Program Files/SpotiFlyer/SpotiFlyer.exe' | |
| # ---------------------------------------- | |
| def SF_check(): | |
| c = False | |
| for proc in psutil.process_iter(): | |
| try: | |
| if SF_exe.replace('\\', r'/').lower() == proc.exe().replace('\\', r'/').lower(): | |
| c = True | |
| except psutil.AccessDenied: | |
| pass | |
| return(c) | |
| def MP3_move(): | |
| for f in glob.glob( os.path.join(SpotiFlyer_dir, 'SpotiFlyer', 'Albums', '**', '*') ): | |
| if (not 'temp' in os.path.basename(f)) and (not 'tagged' in os.path.basename(f)): | |
| try: | |
| tags = EasyID3(f) | |
| tag_album = str(tags.get('album')[0]) | |
| tag_title = str(tags.get('title')[0]) | |
| tag_tracknumber = str(tags.get('tracknumber')[0]) | |
| except: | |
| pass | |
| else: | |
| album = str( re.sub(r'[\\/:*?"<>|]+', '_', tag_album.replace('\\ufeff', '')) ) | |
| title = str( re.sub(r'[\\/:*?"<>|]+', '_', tag_title) ) | |
| tracknumber = tag_tracknumber.zfill(3) | |
| result_d = os.path.join(Music_dir, album) | |
| result_f = os.path.join(result_d, tracknumber + '_' + title + '.mp3') | |
| os.makedirs(result_d, exist_ok=True) | |
| os.rename(f, result_f) | |
| print(os.path.basename(result_f)) | |
| # ---------------------------------------- | |
| subprocess.Popen(SF_exe, stdout=subprocess.PIPE, shell=True) | |
| while (not SF_check()):#↑が起動するまで一旦待ち | |
| time.sleep(0.5) | |
| while (SF_check()):#本処理 | |
| MP3_move() | |
| time.sleep(1) | |
| #Python 3.7.7及び3.7.9で動作確認 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[作者より]SpotiFlyer自体が"同一(と思われる)音源をYoutubeから取ってきているだけ"のツールだということを今更知ったので(情弱)、
本ツールの利用はおすすめしません
おとなしく普通にyt-dlpとか使おうね