|
|
@@ -34,6 +34,7 @@ import logging
|
|
|
## - Download the first X results from YoutubeSearch and pick best result
|
|
|
##
|
|
|
## - Allow interrupt to stop script (CTRL + C)
|
|
|
+##
|
|
|
|
|
|
##Vars
|
|
|
if os.path.exists('config.ini'):
|
|
|
@@ -58,6 +59,7 @@ DESTFOLDER=""
|
|
|
ALBUM=""
|
|
|
ARTIST=""
|
|
|
MASTER=True
|
|
|
+TOR=False
|
|
|
TESTFOLDER=config['DEFAULT'].getboolean('TestFolder')
|
|
|
HELP= "Takes list.txt or Discogs.com Master/Release number \n" \
|
|
|
"And downloads albums by stripping the audio from Yuotube videos. \n" \
|
|
|
@@ -66,7 +68,8 @@ HELP= "Takes list.txt or Discogs.com Master/Release number \n" \
|
|
|
" -d --discog set Discog.com Release or Master number \n" \
|
|
|
" -r --release search for Discog.com RELEASE instead of MASTER [default MASTER] \n" \
|
|
|
" -D --download override config.ini and set Download=True \n" \
|
|
|
- " -f --file Allows quick download of a single Youtube link"
|
|
|
+ " -f --file Allows quick download of a single Youtube link \n" \
|
|
|
+ " -t --tor Will perform actions over tor using torsocks\n" \
|
|
|
# " -D --download override config.ini and set Download=True"
|
|
|
JSONDATA=[]
|
|
|
|
|
|
@@ -89,7 +92,7 @@ def msg(message, level):
|
|
|
def arguments(argv):
|
|
|
msg("Starting arguments", 3)
|
|
|
try:
|
|
|
- opts, args = getopt.getopt(argv, "hvrDf:d:", ["discog", "release", "help", "download", "version", "file"])
|
|
|
+ opts, args = getopt.getopt(argv, "hvrtDf:d:", ["discog", "release", "help", "download", "version", "file", "tor"])
|
|
|
for opt, arg in opts:
|
|
|
if opt in ('-h', '--help'):
|
|
|
print(HELP)
|
|
|
@@ -112,9 +115,25 @@ def arguments(argv):
|
|
|
elif opt in ("-f", "--file"):
|
|
|
msg("call singlesong with: " + arg, 3)
|
|
|
singlesong(arg)
|
|
|
+ elif opt in ("-t", "--tor"):
|
|
|
+ msg("perform operations over tor", 1)
|
|
|
+ if not checktor():
|
|
|
+ msg("Torsocks not found! Check that torsocks is in /usr/bin/torsocks",1)
|
|
|
+ else:
|
|
|
+ TOR=True
|
|
|
+ pass
|
|
|
+
|
|
|
except getopt.GetoptError as err:
|
|
|
msg("cannot get arguments, {0}".format(err), 1)
|
|
|
|
|
|
+def checktor():
|
|
|
+ msg("Starting checktor", 3)
|
|
|
+ if not os.system('which torsocks'):
|
|
|
+ msg("Torsocks installed!", 3)
|
|
|
+ return 1
|
|
|
+ else:
|
|
|
+ return 0
|
|
|
+
|
|
|
def fetchjson(discogno, master=True, show=True):
|
|
|
msg("Starting fetchjson", 3)
|
|
|
if master:
|
|
|
@@ -250,7 +269,7 @@ def searchlinks(links, artist):
|
|
|
msg("Ending searchlinks", 3)
|
|
|
return links[0]
|
|
|
|
|
|
-def generatelink(searchterm, max_results=10, tries=5):
|
|
|
+def generatelink(searchterm, max_results=10, tries=7):
|
|
|
## This will retry the link generation routine up to *tries* times and return results
|
|
|
msg("Starting generatelink for " + searchterm, 3)
|
|
|
counter = 0
|
|
|
@@ -309,8 +328,11 @@ def parselist(musiclist):
|
|
|
def downloadsong(link, song):
|
|
|
msg("Starling Downloadsong for " + song['Title'], 3)
|
|
|
msg("Downloadsong DESTFOLDER: " + DESTFOLDER, 3)
|
|
|
- try:
|
|
|
- os.system("youtube-dl --extract-audio --audio-format best --audio-quality 0 --output '''" + DESTFOLDER + "%(title)s.%(ext)s' --ignore-errors " + link)
|
|
|
+ try:
|
|
|
+ if TOR:
|
|
|
+ os.system(".torsocks youtube-dl --extract-audio --audio-format best --audio-quality 0 --output '''" + DESTFOLDER + "%(title)s.%(ext)s' --ignore-errors " + link)
|
|
|
+ else:
|
|
|
+ os.system("youtube-dl --extract-audio --audio-format best --audio-quality 0 --output '''" + DESTFOLDER + "%(title)s.%(ext)s' --ignore-errors " + link)
|
|
|
completed.append(song['songnum'])
|
|
|
logresults.append(song['Title'] + ", " + song['Artist'] + " Audio downloaded")
|
|
|
msg(song['Title'] + " Download Complete!", 2)
|