mike %!s(int64=5) %!d(string=hai) anos
pai
achega
5e81fd3d97
Modificáronse 2 ficheiros con 4 adicións e 109 borrados
  1. 0 3
      config.ini
  2. 4 106
      ytsearch

+ 0 - 3
config.ini

@@ -4,11 +4,8 @@ DefaultStoragePath = $HOME/Music
 Retries = 3
 Download = True
 Key = AdmufSbEgfzbRjaxHBMvyvdKqBxhNYvCzvXHXWQK
-<<<<<<< HEAD
 ## creates unique folder name for each download attempt to test various search queries for best results.  Normall False
 TestFolder = False
-=======
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 
 #Set Verbosity level [0-3]
 #0 - Quiet <- Lowest number of messages

+ 4 - 106
ytsearch

@@ -5,10 +5,7 @@ import os
 import configparser
 import sys, getopt
 import requests, json
-<<<<<<< HEAD
 import random, string
-=======
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 
 ##Import list of songs, artists from list.txt
 ##parse this file into a list of dictionaries
@@ -28,13 +25,10 @@ import random, string
 ##    - YoutubeSearch
 ##
 ## - Differentiate between releases and masters when calling api
-<<<<<<< HEAD
 ##
 ## - check for dependencies on start
 ##   - youtube-dl
 ##   - tor (if used)
-=======
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 
 ##Vars
 if os.path.exists('config.ini'):
@@ -45,10 +39,7 @@ else:
 	print("Exiting...")
 	exit(1)
 
-<<<<<<< HEAD
 VERSION="0.0.2"
-=======
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 DOWNLOAD=config['DEFAULT'].getboolean('Download')	#Download True/False
 MUSICFILE=config['DEFAULT']['Musicfile']		#location of text file containing songs
 RETRIES=config['DEFAULT'].getint('Retries')		#Number of retries to search for songs
@@ -56,24 +47,18 @@ ITERATOR=0						#Number or current tries
 VERBOSITY=config['DEFAULT'].getint('Verbosity')
 KEY=config['DEFAULT']['Key']
 DISCOG=""
-<<<<<<< HEAD
 DESTFOLDER=""
 ALBUM=""
 ARTIST=""
 TESTFOLDER=config['DEFAULT'].getboolean('TestFolder')
-=======
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 HELP=	"Takes list.txt or Discogs.com Master/Release number \n" \
 	"And downloads albums by stripping the audio from Yuotube videos. \n" \
 	"USAGE: ytsearch [-flag] [Discog Num] \n" \
 	"	-h 		This help file \n" \
 	"	-d --discog	set Discog.com Release or Master number \n" \
-<<<<<<< HEAD
 	"	-D --download	override config.ini and set Download=True \n" \
 	"	-f --file	Allows quick download of a single Youtube link"
-=======
-	"	-D --download	override config.ini and set Download=True"
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
+#	"	-D --download	override config.ini and set Download=True"
 JSONDATA=[]
 
 music=[]	# list to hold dictionaries of songnum, Title, Artist
@@ -93,15 +78,9 @@ def msg(message, level):
 def arguments(argv):
 	msg("Starting arguments", 3)
 	try:
-<<<<<<< HEAD
 		opts, args = getopt.getopt(argv, "hvDf:d:", ["discog", "help", "download", "version", "file"])
 		for opt, arg in opts:
 			if opt in ('-h', '--help'):
-=======
-		opts, args = getopt.getopt(argv, "hDd:", ["discogno="])
-		for opt, arg in opts:
-			if opt == '-h':
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 				print(HELP)
 				sys.exit()
 			elif opt in ("-d", "--discog"):
@@ -110,7 +89,6 @@ def arguments(argv):
 				msg("Discog number:" + DISCOG, 3)
 			elif opt in ("-D", "--download"):
 				global DOWNLOAD
-<<<<<<< HEAD
 				DOWNLOAD = arg
 				msg("Override DOWNLOAD from agrs", 2)
 			elif opt in ("-v", "--version"):
@@ -119,10 +97,6 @@ def arguments(argv):
 			elif opt in ("-f", "--file"):
 				msg("call singlesong with: " + arg, 3)
 				singlesong(arg)
-=======
-				DOWNLOAD = True
-				msg("Override DOWNLOAD from agrs", 2)
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 	except getopt.GetoptError as err:
 		msg("cannot get arguments, {0}".format(err), 1)
 
@@ -133,11 +107,7 @@ def fetchjson(discogno, master=True, show=True):
 	else:
 		url = 'https://api.discogs.com/releases/'
 	url = url + discogno
-<<<<<<< HEAD
 	msg("Downloading " + url, 1)
-=======
-	msg("Downloading " + url, 3)
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 	r = requests.get(url)
 	global JSONDATA
 #	JSONDATA = r.json()
@@ -162,18 +132,14 @@ def buildlist(jsondata, write=False):
 	if Artist.find( '(' ) != -1:	## Discovered a Artist 'Tool (2)' (Discogs 1181).  This removes ()
 		Artist = Artist[:Artist.find( '(' )-1]
 		msg("Correcting Artist name to " + Artist, 2)
-<<<<<<< HEAD
-
 	global ALBUM
 	try:
 		ALBUM = Album
 		msg("Set ALBUM var to: " + ALBUM, 3)
 	except Exception as e:
 		msg("Could not set ALBUM var." + e, 2)
-=======
 	else:
 		print(Artist)
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 
 	tracks = gettracks(jsondata['tracklist'])
 
@@ -199,7 +165,6 @@ def gettracks(tracks):
 
 	return goodtracks
 
-<<<<<<< HEAD
 def randomizer(length=8):
 	#Creates a Random directory name
 	randoms = string.ascii_letters + string.digits
@@ -214,7 +179,6 @@ def buildfolders(artist, album=""):
 		album = ALBUM
 #	msg("buildfolders local album is set to: " + album, 3)
 	global DESTFOLDER
-#	DESTFOLDER = randomizer() + "/" + artist + "/" + album
 	DESTFOLDER = artist + "/" + album + "/"
 	if TESTFOLDER:
 		DESTFOLDER = randomizer() + "/" + DESTFOLDER
@@ -226,18 +190,10 @@ def buildfolders(artist, album=""):
 
 def readlist(file):
 	msg("Starting readlist", 3)
+	##Open list.txt, read into music[]
 	if not os.path.exists(MUSICFILE):
 		msg("List.txt file not found.  Exiting", 1)
 		sys.exit()
-=======
-def buildfolders(jsondata, parent_directory):
-	## Takes raw json data and creates foldes in parent_directory for Artist/Album
-	pass
-
-def readlist(file):
-	msg("Starting readlist", 3)
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
-	##Open list.txt, read into music[]
 	songnum = 0
 	with open(file) as f:
 	  for line in f:
@@ -249,78 +205,45 @@ def readlist(file):
 	    song['Artist'] = val.rstrip()
 	    music.append(song)
 	f.close()
-<<<<<<< HEAD
-	
-=======
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 	return music
 
 def parselist(musiclist):
 	msg("Starting parselist", 3)
 	global ITERATOR
-<<<<<<< HEAD
 	if ITERATOR == 0 and DOWNLOAD:
 		buildfolders(musiclist[0]['Artist'])
 	## Build File Structure using buildfolders
 	## Somehow have downloads save to this folder without knowing the file name?
 	## Perhaps with a flag in youtube-dl
-	ITERATOR+=1
-	print(musiclist)
-	for song in musiclist:
-	  searchterm = song['Title'] + " " + song['Artist'] + ' lyrics HD'
-#	  searchterm = song['Title'] + " " + song['Artist']
-=======
 	ITERATOR+=1
 	for song in musiclist:
 #	  searchterm = song['Title'] + " " + song['Artist'] + ' lyrics HD'
 	  searchterm = song['Title'] + " " + song['Artist']
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 	  dictlink={}
 	  try:
 	    ytresult = YoutubeSearch(searchterm, max_results=1).to_dict() ##increase timeout!!
 	    link = 'https://youtube.com' + ytresult[0]['link']
 	    logresults.append(song['Title'] + ", " + song['Artist'] + " Link Created")
 	    if DOWNLOAD:
-<<<<<<< HEAD
               msg("Attempting to download " + song['Title'], 2)
               downloadsong(link, song)
 	    else:
 	      print("Not downloading " + song['Title'] + ".  Change this in config.ini")
 	  except Exception as ex:
 	    print(ex)
-=======
-              print("Attempting to download", song['Title'])
-              downloadsong(link, song)
-	    else:
-	      print("Not downloading.  Change this in config.ini")
-	  except:
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
-	    logresults.append(song['Title'] + ", " + song['Artist'] + " COULD NOT CREATE LINK")
 	if DOWNLOAD:
 		cleanup(MUSICFILE)
 
-<<<<<<< HEAD
-def downloadsong(link, song, path=""):
-       msg("Starting Downloadsong", 3)
-       if len(DESTFOLDER) > 1:
-         path=DESTFOLDER
-       msg("DESTFOLDER var = " + DESTFOLDER, 3)
-       msg("local path var = " + path, 3)
-       try: 
-         os.system("youtube-dl --extract-audio --audio-format best --audio-quality 0 --output '''" + path + "%(title)s.%(ext)s' --ignore-errors " + link)
-=======
 def downloadsong(link, song):
-       msg("Starling Downloadsong for" + song['Title'], 3)
+       msg("Starling Downloadsong for " + song['Title'], 3)
        try: 
-         os.system("youtube-dl --extract-audio --audio-format best --audio-quality 0 --output '%(title)s.%(ext)s' --ignore-errors " + link)
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
+         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)
        except e as youtubedlexception:
          logresults.append(song['Title'] + ", " + song['Artist'] + " FAILED TO DOWNLOAD SONG (youtube-dl)")
          print(youtubedlexception)
-<<<<<<< HEAD
 
 def singlesong(link):
 	try:
@@ -346,27 +269,6 @@ def cleanup(file):
 
 	f.close()
 
-=======
-	
-
-def cleanup(file):
-	print("Cleaning completed files from list")
-	print("Completed Downloads:", completed)
-
-	linenum=0
-	count=0
-	with open(file, "r") as f:
-	  lines = f.readlines()
-	with open(file, "w") as f:
-	  for line in lines:
-	    linenum += 1
-	    if linenum not in completed:
-	     f.write(line)
-	     count += 1
-
-	f.close()
-
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
 	if count >=1:
 		print(count, "TRACKS REMAIN")
 		print(RETRIES - ITERATOR, "tries remaining")
@@ -391,8 +293,4 @@ if __name__ == "__main__":
 	readlist(MUSICFILE)
 	parselist(music)
 
-<<<<<<< HEAD
 	print("ytsearch complete, exiting")
-=======
-	msg("ytsearch complete, exiting", -1)
->>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335