make conversion & meta-tags optional

This commit is contained in:
Ritiek Malhotra
2017-02-02 09:54:02 +05:30
committed by GitHub
parent 99ca0590c8
commit 981235455e

View File

@@ -8,6 +8,7 @@ import pafy
import shutil import shutil
import os import os
import sys import sys
import argparse
#import spotipy.util as util #import spotipy.util as util
os.chdir(sys.path[0]) os.chdir(sys.path[0])
@@ -18,6 +19,13 @@ open('list.txt', 'a').close()
spotify = spotipy.Spotify() spotify = spotipy.Spotify()
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--no-convert", help="skip the conversion process and meta-tags",
action="store_true")
args = parser.parse_args()
if args.no_convert:
print("-n, --no-convert skip the conversion process and meta-tags")
def searchYT(number): def searchYT(number):
items = (requests.request(method='GET', url=URL)).text items = (requests.request(method='GET', url=URL)).text
items_parse = BeautifulSoup(items, "html.parser") items_parse = BeautifulSoup(items, "html.parser")
@@ -43,27 +51,33 @@ def searchYT(number):
def checkExists(islist): def checkExists(islist):
if os.path.exists("Music/" + title + ".m4a.temp"): if os.path.exists("Music/" + title + ".m4a.temp"):
os.remove("Music/" + title + ".m4a.temp") os.remove("Music/" + title + ".m4a.temp")
if os.path.exists("Music/" + title + ".mp3"): if args.no_convert:
audiofile = eyed3.load("Music/" + title + '.mp3') extension = '.m4a'
if isSpotify() and not audiofile.tag.title == content['name']: else:
os.remove("Music/" + title + '.mp3') extension = '.mp3'
if os.path.exists("Music/" + title + extension):
if extension == '.mp3':
audiofile = eyed3.load("Music/" + title + extension)
if isSpotify() and not audiofile.tag.title == content['name']:
os.remove("Music/" + title + extension)
return False
elif islist: elif islist:
trimSong() trimSong()
return True return True
else: else:
prompt = raw_input('Song with same name has already been downloaded. Re-download? (y/n/play): ') prompt = raw_input('Song with same name has already been downloaded. Re-download? (y/n/play): ')
if prompt == "y": if prompt == "y":
os.remove("Music/" + title + ".mp3") os.remove("Music/" + title + extension)
return False
elif prompt =="play": elif prompt =="play":
if not os.name == 'nt': if not os.name == 'nt':
os.system('mplayer "' + 'Music/' + title + '.mp3"') os.system('mplayer "' + 'Music/' + title + extension)
else: else:
print('Playing ' + title + '.mp3') print('Playing ' + title + extension)
os.system('start ' + 'Music/' + title + '.mp3') os.system('start ' + 'Music/' + title + extension)
return True return True
else: else:
return True return True
return False
def getLyrics(): def getLyrics():
if not title == '': if not title == '':
@@ -152,7 +166,7 @@ while True:
y = 0 y = 0
try: try:
for m in os.listdir('Music/'): for m in os.listdir('Music/'):
if m.endswith('.temp') or m.endswith('.m4a'): if m.endswith('.m4a.temp'):
os.remove('Music/' + m) os.remove('Music/' + m)
print('') print('')
print('') print('')
@@ -183,9 +197,10 @@ while True:
if not checkExists(islist=True): if not checkExists(islist=True):
downloadSong() downloadSong()
print('') print('')
convertSong() if not args.no_convert:
if isSpotify(): convertSong()
fixSong() if isSpotify():
fixSong()
trimSong() trimSong()
else: else:
trimSong() trimSong()
@@ -204,9 +219,10 @@ while True:
if not checkExists(islist=False): if not checkExists(islist=False):
downloadSong() downloadSong()
print('') print('')
convertSong() if not args.no_convert:
if isSpotify(): convertSong()
fixSong() if isSpotify():
fixSong()
except KeyboardInterrupt: except KeyboardInterrupt:
graceQuit() graceQuit()
except KeyboardInterrupt: except KeyboardInterrupt: