Browse Source

finish 0.0.4. Final commit

mike 5 years ago
parent
commit
bc817526e6
3 changed files with 28 additions and 7 deletions
  1. 1 0
      CHANGELOG
  2. 0 0
      list.txt
  3. 27 7
      ytsearch

+ 1 - 0
CHANGELOG

@@ -30,6 +30,7 @@ Version 0.0.4
      - This is a fork of youtube_search with custom attributes
      - This is a fork of youtube_search with custom attributes
      - ytsearch imports this library 
      - ytsearch imports this library 
   - Removed old/ folder with backup archives of previous versions
   - Removed old/ folder with backup archives of previous versions
+  - Added ability to download over tor
 
 
 Version 0.0.5
 Version 0.0.5
   - Test
   - Test

+ 0 - 0
list.txt


+ 27 - 7
ytsearch

@@ -35,7 +35,6 @@ import logging
 ##
 ##
 ## - Allow interrupt to stop script (CTRL + C)
 ## - Allow interrupt to stop script (CTRL + C)
 ##
 ##
-## - Test for Git
 
 
 ##Vars
 ##Vars
 if os.path.exists('config.ini'):
 if os.path.exists('config.ini'):
@@ -46,7 +45,7 @@ else:
 	print("Exiting...")
 	print("Exiting...")
 	exit(1)
 	exit(1)
 
 
-VERSION="0.0.5"
+VERSION="0.0.4"
 DOWNLOAD=config['DEFAULT'].getboolean('Download')	#Download True/False
 DOWNLOAD=config['DEFAULT'].getboolean('Download')	#Download True/False
 MUSICFILE=config['DEFAULT']['Musicfile']		#location of text file containing songs
 MUSICFILE=config['DEFAULT']['Musicfile']		#location of text file containing songs
 RETRIES=config['DEFAULT'].getint('Retries')		#Number of retries to search for songs
 RETRIES=config['DEFAULT'].getint('Retries')		#Number of retries to search for songs
@@ -60,6 +59,7 @@ DESTFOLDER=""
 ALBUM=""
 ALBUM=""
 ARTIST=""
 ARTIST=""
 MASTER=True
 MASTER=True
+TOR=False
 TESTFOLDER=config['DEFAULT'].getboolean('TestFolder')
 TESTFOLDER=config['DEFAULT'].getboolean('TestFolder')
 HELP=	"Takes list.txt or Discogs.com Master/Release number \n" \
 HELP=	"Takes list.txt or Discogs.com Master/Release number \n" \
 	"And downloads albums by stripping the audio from Yuotube videos. \n" \
 	"And downloads albums by stripping the audio from Yuotube videos. \n" \
@@ -68,7 +68,8 @@ HELP=	"Takes list.txt or Discogs.com Master/Release number \n" \
 	"	-d --discog	set Discog.com Release or Master 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" \
 	"	-r --release	search for Discog.com RELEASE instead of MASTER [default MASTER] \n" \
 	"	-D --download	override config.ini and set Download=True \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"
 #	"	-D --download	override config.ini and set Download=True"
 JSONDATA=[]
 JSONDATA=[]
 
 
@@ -91,7 +92,7 @@ def msg(message, level):
 def arguments(argv):
 def arguments(argv):
 	msg("Starting arguments", 3)
 	msg("Starting arguments", 3)
 	try:
 	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:
 		for opt, arg in opts:
 			if opt in ('-h', '--help'):
 			if opt in ('-h', '--help'):
 				print(HELP)
 				print(HELP)
@@ -114,9 +115,25 @@ def arguments(argv):
 			elif opt in ("-f", "--file"):
 			elif opt in ("-f", "--file"):
 				msg("call singlesong with: " + arg, 3)
 				msg("call singlesong with: " + arg, 3)
 				singlesong(arg)
 				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:
 	except getopt.GetoptError as err:
 		msg("cannot get arguments, {0}".format(err), 1)
 		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):
 def fetchjson(discogno, master=True, show=True):
 	msg("Starting fetchjson", 3)
 	msg("Starting fetchjson", 3)
 	if master:
 	if master:
@@ -252,7 +269,7 @@ def searchlinks(links, artist):
 	msg("Ending searchlinks", 3)
 	msg("Ending searchlinks", 3)
 	return links[0]
 	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
 	## This will retry the link generation routine up to *tries* times and return results
 	msg("Starting generatelink for " + searchterm, 3)
 	msg("Starting generatelink for " + searchterm, 3)
 	counter = 0
 	counter = 0
@@ -311,8 +328,11 @@ def parselist(musiclist):
 def downloadsong(link, song):
 def downloadsong(link, song):
        msg("Starling Downloadsong for " + song['Title'], 3)
        msg("Starling Downloadsong for " + song['Title'], 3)
        msg("Downloadsong DESTFOLDER: " + DESTFOLDER, 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'])
          completed.append(song['songnum'])
          logresults.append(song['Title'] + ", " + song['Artist'] + " Audio downloaded")
          logresults.append(song['Title'] + ", " + song['Artist'] + " Audio downloaded")
          msg(song['Title'] + " Download Complete!", 2)
          msg(song['Title'] + " Download Complete!", 2)