Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
artyshko committed Aug 25, 2019
1 parent d9d67b5 commit 9ee0290
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 15 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def downloadBySpotifyUri(self, uri, path):
info = self.__getSongInfoFromSpotify(uri)

if info:
notify.send(f'{info["artist"][0]} - {info["name"]}', downloaded=False)

info['uri'] = str(info['uri']).split('/')[-1]

fixed_name = f'{info["artist"][0]} - {info["name"]}'
fixed_name = fixed_name.replace('.','')
Expand All @@ -79,6 +82,8 @@ def downloadBySpotifyUri(self, uri, path):
#finding and download from YouTube and tagging
if self.__downloadMusicFromYoutube(fixed_name, info['uri'], info['duration_ms']):

print(info['uri'])

self.__editor.setTags(
data=info
)
Expand Down Expand Up @@ -201,6 +206,8 @@ def downloadBySpotifyUriPlaylistMode(self, playlist_uri, path):

print(f'Downloading {i+1} of {len(playlist)}')

notify.send(f'{info["artist"][0]} - {info["name"]}', downloaded=False)

fixed_name = f'{info["artist"][0]} - {info["name"]}'
fixed_name = fixed_name.replace('.','')
fixed_name = fixed_name.replace(',','')
Expand Down Expand Up @@ -247,6 +254,10 @@ def downloadBySpotifyUriAlbumMode(self, album_uri, path):

for info, i in zip(playlist['tracks'],range(len(playlist['tracks']))):

info['uri'] = str(info['uri']).split('/')[-1]

notify.send(f'{info["artist"][0]} - {info["name"]}', downloaded=False)

print(f'Downloading {i+1} of {len(playlist["tracks"])}')

fixed_name = f'{info["artist"][0]} - {info["name"]}'
Expand Down Expand Up @@ -306,6 +317,7 @@ def downloadByDeezerUrl(self, url, path):
#finding and download from YouTube and tagging
if self.__downloadMusicFromYoutube(fixed_name, info['uri'], info['duration_ms']):


self.__editor.setTags(
data=info
)
Expand Down Expand Up @@ -721,13 +733,13 @@ def sound(error=False):
mixer.music.play()

@staticmethod
def send(message, error=False):
def send(message, error=False, downloaded=True):
try:
ns = notify2.Notification('Spotify Music Downloader', message=message, icon=notify.image)
ns = notify2.Notification(f'{"Downloaded" if downloaded else "Start downloading"}', message=message, icon=notify.image)
# Set the urgency level
ns.set_urgency(notify2.URGENCY_NORMAL)
# Set the timeout
ns.set_timeout(1000)
ns.set_timeout(5000)
notify.sound(error)
ns.show()
except:pass
Expand Down
6 changes: 3 additions & 3 deletions youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,15 @@ def download(self, url, path='', filename='video'):
#logging.info(f"Start downloading")

ydl_opts = {
'outtmpl': f'{fullpath}/{filename}/{filename}',
'outtmpl': f'{fullpath}/{filename}/{filename}.mp4',
'format':'best'
}
with suppress_stdout():
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
with suppress_stdout():
ydl.download([url])


os.system(f'cp {fullpath}/{filename}/{filename} {fullpath}/{filename}/{filename}.mp4')


#yt.download('cache/'+ path, filename=path)

Expand All @@ -182,6 +181,7 @@ def convertVideoToMusic(self, uri):
#logging
logging.error(f"Youtube:os.makedirs(fullpath)")

print(uri)
clip = mp.VideoFileClip(f'cache/{uri}/{uri}.mp4').subclip()
clip.audio.write_audiofile(f'cache/{uri}/{uri}.mp3', bitrate='3000k', progress_bar=True)

Expand Down

0 comments on commit 9ee0290

Please sign in to comment.