It almost works
This commit is contained in:
parent
0407a6f53c
commit
2cff3fdc53
41
badwitch.py
41
badwitch.py
@ -15,6 +15,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
|
import youtube_dl
|
||||||
|
|
||||||
class Library:
|
class Library:
|
||||||
# A thing full of albums
|
# A thing full of albums
|
||||||
@ -48,18 +49,35 @@ class Library:
|
|||||||
raise Exception('Library not valid')
|
raise Exception('Library not valid')
|
||||||
|
|
||||||
# Download library
|
# Download library
|
||||||
def download(self, album=None):
|
def download(self, targetalbum=None):
|
||||||
if album is not None:
|
if targetalbum is not None:
|
||||||
print('Downloading album: ' + album)
|
print('Downloading album: ' + album)
|
||||||
else:
|
else:
|
||||||
print('Downloading entire library')
|
print('Downloading entire library')
|
||||||
for album, albumcontent in self.albums.items():
|
for album, albumcontent in self.albums.items():
|
||||||
|
# Skip albums that don't match our criterea
|
||||||
|
if targetalbum is not None and not album == targetalbum:
|
||||||
|
logging.debug('Skipping album ' + album)
|
||||||
|
continue
|
||||||
# God have mercy on my soul
|
# God have mercy on my soul
|
||||||
artist = (next(iter(next(iter(albumcontent.values())).values())))
|
artist = next(iter(albumcontent.values()))['artist']
|
||||||
print(artist)
|
destpath = (Path.home() / 'Music' / artist / album)
|
||||||
Path(Path.home() / 'Music' / artist / album).mkdir(parents=True, exist_ok=True)
|
Path(destpath).mkdir(parents=True, exist_ok=True)
|
||||||
for song, songcontent in albumcontent.items():
|
for song, songcontent in albumcontent.items():
|
||||||
logging.info('Downloaded song: ' + song + ' by ' + songcontent['artist'])
|
# See if we already have it
|
||||||
|
matches = sorted(Path(destpath).glob(song + '.*'))
|
||||||
|
if not matches == []:
|
||||||
|
logging.debug('Using cached song: ' + song)
|
||||||
|
continue
|
||||||
|
# Download the song
|
||||||
|
ytdl_opts = {
|
||||||
|
'audio-format': 'best',
|
||||||
|
'x'
|
||||||
|
'playlist-items': 1
|
||||||
|
}
|
||||||
|
with youtube_dl.YoutubeDL(ytdl_opts) as ydl:
|
||||||
|
ydl.download([songcontent['source']])
|
||||||
|
logging.info('Downloaded song: ' + song)
|
||||||
|
|
||||||
class BadWitch:
|
class BadWitch:
|
||||||
# Our program
|
# Our program
|
||||||
@ -99,32 +117,41 @@ class BadWitch:
|
|||||||
elif self.args.action == 'list':
|
elif self.args.action == 'list':
|
||||||
for album, albumcontent in lib.albums.items():
|
for album, albumcontent in lib.albums.items():
|
||||||
for song, songcontent in albumcontent.items():
|
for song, songcontent in albumcontent.items():
|
||||||
print(album + ' - ' + song + ' by ' + songcontent['artist'])
|
print(album
|
||||||
|
+ ' - ' + str(songcontent['track'])
|
||||||
|
+ ' - ' + song
|
||||||
|
+ ' by ' + songcontent['artist'])
|
||||||
return
|
return
|
||||||
elif self.args.action == 'test':
|
elif self.args.action == 'test':
|
||||||
# Set up a test album
|
# Set up a test album
|
||||||
lib.albums['Bad Witch'] = {
|
lib.albums['Bad Witch'] = {
|
||||||
'Shit Mirror': {
|
'Shit Mirror': {
|
||||||
|
'track': 1,
|
||||||
'artist': 'Nine Inch Nails',
|
'artist': 'Nine Inch Nails',
|
||||||
'source': 'https://www.youtube.com/watch?v=yeqjz5mXrLQ'
|
'source': 'https://www.youtube.com/watch?v=yeqjz5mXrLQ'
|
||||||
},
|
},
|
||||||
'Ahead of Ourselves': {
|
'Ahead of Ourselves': {
|
||||||
|
'track': 2,
|
||||||
'artist': 'Nine Inch Nails',
|
'artist': 'Nine Inch Nails',
|
||||||
'source': 'https://www.youtube.com/watch?v=4Ab1O-i4ep4'
|
'source': 'https://www.youtube.com/watch?v=4Ab1O-i4ep4'
|
||||||
},
|
},
|
||||||
'Play the Goddamned Part': {
|
'Play the Goddamned Part': {
|
||||||
|
'track': 3,
|
||||||
'artist': 'Nine Inch Nails',
|
'artist': 'Nine Inch Nails',
|
||||||
'source': 'https://www.youtube.com/watch?v=85UgvBkMfr8'
|
'source': 'https://www.youtube.com/watch?v=85UgvBkMfr8'
|
||||||
},
|
},
|
||||||
'God Break Down the Door': {
|
'God Break Down the Door': {
|
||||||
|
'track': 4,
|
||||||
'artist': 'Nine Inch Nails',
|
'artist': 'Nine Inch Nails',
|
||||||
'source': 'https://www.youtube.com/watch?v=eeJ_DzRJUI4'
|
'source': 'https://www.youtube.com/watch?v=eeJ_DzRJUI4'
|
||||||
},
|
},
|
||||||
'I\'m Not From This World': {
|
'I\'m Not From This World': {
|
||||||
|
'track': 5,
|
||||||
'artist': 'Nine Inch Nails',
|
'artist': 'Nine Inch Nails',
|
||||||
'source': 'https://www.youtube.com/watch?v=9fjbcSUSt9w'
|
'source': 'https://www.youtube.com/watch?v=9fjbcSUSt9w'
|
||||||
},
|
},
|
||||||
'Over and Out': {
|
'Over and Out': {
|
||||||
|
'track': 6,
|
||||||
'artist': 'Nine Inch Nails',
|
'artist': 'Nine Inch Nails',
|
||||||
'source': 'https://www.youtube.com/watch?v=h-XlN3N2fis'
|
'source': 'https://www.youtube.com/watch?v=h-XlN3N2fis'
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
appdirs>=1.4.3
|
appdirs>=1.4.3
|
||||||
|
youtube-dl
|
||||||
|
Loading…
Reference in New Issue
Block a user