-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetem.py
executable file
·95 lines (82 loc) · 3.26 KB
/
getem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
import os
import os.path
import json
import slugify #pip awesome-slugify, pipreqs did not detect?
import easyargs
from distutils.spawn import find_executable
import findsource
import download
import songlist
import playlists
def processSong(songdesc, path):
descstr = str(songdesc)
songs = findsource.songSource(descstr)
top = next(iter(songs.items()))
print('***** Selected = {}'.format(top))
ytcode = top[0]
info = top[1]
download.getInfo(ytcode, info)
#include rank with leading zeros so they easily are sorted by mp3 player
prettyname = '{:03d}_{}_{}'.format(songdesc.rank, songdesc, ytcode)
fname = path + slugify.slugify(prettyname)
j = json.dumps(info)
#view json file with: cat info.json | python -m json.tool | less
with open(fname+'.json', 'w') as f:
f.write(j)
download.getAudio(ytcode, fname+'.ogg')
def processPlaylists(charts):
for chart in charts:
sl = songlist.getSongs(chart)
if len(sl) < 1:
print('no playlist found with title: {}'.format(chart))
else:
if os.path.exists(chart):
if not os.path.isdir(chart):
print('file in the way of new dir: {}'.format(chart))
exit(13)
else:
os.mkdir(chart)
path = chart + '/' #todo: os ind sep
print('{} songs to download'.format(len(sl)))
for s in sl:
songdesc = s #'sometitle someartist'
processSong(songdesc, path)
@easyargs
def main(src='billboard', showplaylists=False, pl=None, plfile=None):
"""
GetEm - get electronic music\n
download songs and info within the playlist - e.g. billboard charts\n
for now in ogg - since android was not working well with mp3\n
1. getem.py --showplaylists > list.m3u #create playlists file then uncomment playlists for downloading\n
2. getem.py --plfile list.m3u #download all the uncommented playlists\n
\n
:param src: source for the playlist - for now only 1 src supported
:param showplaylists: the available playlists, direct it to a file, to send with plfile option
:param pl: one or more comma separated playlists
:param plfile: a playlist to get
"""
if not src == 'billboard':
print('Unsupported source: {}'.format(src))
exit(10)
if not (find_executable("ffmpeg") or (find_executable("avconv"))):
print("ffmpeg or avconv needed")
exit(11)
if showplaylists:
lists = playlists.getPlaylists()
print('\n'.join(lists))
elif pl:
charts = pl.split(',') #'dance-electronic-albums' #'dance-electronic-songs'
processPlaylists(charts)
elif plfile:
if not os.path.isfile(plfile):
print('{} not found'.format(plfile))
exit(12)
charts = [ ]
with open(plfile, 'r') as f:
charts = [line.rstrip() for line in f if not line.startswith('#')]
processPlaylists(charts)
else:
print('-h for help, follow the 2 steps model of use')
if __name__ == '__main__':
main()