mike 5 سال پیش
والد
کامیت
379ea10ccb
4فایلهای تغییر یافته به همراه227 افزوده شده و 0 حذف شده
  1. 3 0
      CHANGELOG
  2. 3 0
      config.ini
  3. 96 0
      ytsearch
  4. 125 0
      ytsearch.save

+ 3 - 0
CHANGELOG

@@ -9,5 +9,8 @@ Version 0.0.2 - 5/12/2020
     - Command line arguments will override config.ini for download=true
     - will take -d and number to download jsons from Discogs.com API
   - Added first implementation of Verbosity (needs teaking)
+<<<<<<< HEAD
   - Builds Folder Structure for downloads
 	- NOTE- only creates album name folder if it queries Discogs.com
+=======
+>>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335

+ 3 - 0
config.ini

@@ -4,8 +4,11 @@ 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

+ 96 - 0
ytsearch

@@ -5,7 +5,10 @@ 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
@@ -25,10 +28,13 @@ 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'):
@@ -39,7 +45,10 @@ 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
@@ -47,17 +56,24 @@ 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
 JSONDATA=[]
 
 music=[]	# list to hold dictionaries of songnum, Title, Artist
@@ -77,9 +93,15 @@ 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"):
@@ -88,6 +110,7 @@ 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"):
@@ -96,6 +119,10 @@ 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)
 
@@ -106,7 +133,11 @@ 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()
@@ -131,6 +162,7 @@ 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:
@@ -138,6 +170,10 @@ def buildlist(jsondata, write=False):
 		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'])
 
@@ -163,6 +199,7 @@ def gettracks(tracks):
 
 	return goodtracks
 
+<<<<<<< HEAD
 def randomizer(length=8):
 	#Creates a Random directory name
 	randoms = string.ascii_letters + string.digits
@@ -192,6 +229,14 @@ def readlist(file):
 	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:
@@ -204,12 +249,16 @@ 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
@@ -220,22 +269,37 @@ def parselist(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:
@@ -244,12 +308,19 @@ def downloadsong(link, song, path=""):
        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)
+       try: 
+         os.system("youtube-dl --extract-audio --audio-format best --audio-quality 0 --output '%(title)s.%(ext)s' --ignore-errors " + link)
+>>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335
          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:
@@ -275,6 +346,27 @@ 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")
@@ -299,4 +391,8 @@ if __name__ == "__main__":
 	readlist(MUSICFILE)
 	parselist(music)
 
+<<<<<<< HEAD
 	print("ytsearch complete, exiting")
+=======
+	msg("ytsearch complete, exiting", -1)
+>>>>>>> dbddaab0c7c86b535f7b59e3940c9623537ef335

+ 125 - 0
ytsearch.save

@@ -0,0 +1,125 @@
+#!/usr/bin/python3
+
+from youtube_search import YoutubeSearch
+import os
+
+##Import list of songs, artists from list.txt
+##parse this file into a list of dictionaries
+##for each dictionary pair, search youtube and output formatted links in file
+##
+## FUTURE
+## -Config File
+##    -Default Musicfile
+##    -Defualt retrys
+##    -Default save-to location
+##    -Default verbosity and logging location
+##
+## - Download over tor
+##   - Check if Tor installed
+##   - Warn user if NOT using tor
+##
+## - Multi-thread conversion mp3
+##
+## - Retry up to X times the link-generation routine
+##
+## - Allow discogs reference number as argument
+##   - ytsearch will parse discogs website with BeautifulSoup
+##   - Find the Artist, Album Track Titles
+##   - Create folder structure locally and create list.txt
+##   - Begin processing...
+##
+## - Logging and Verbosit levels
+##
+## - Check for dependencies
+##    - Tor?
+##    - Write Permissions in log files?
+##    - YoutubeSearch
+
+##Vars
+
+DOWNLOAD=True
+MUSICFILE="list.txt"
+
+##
+
+
+music=[]	# list to hold dictionaries of songnum, Title, Artist
+logresults=[]	# list to hold results of link creation attempts, and download attempts
+linkresults=[]	#
+completed=[]	# list to hold song numbers of completed downloads so they can be removed from MUSICFILE
+
+##Open list.txt, read into music[]
+def readlist(file):
+	songnum = 0
+	with open(file) as f:
+	  for line in f:
+	    song={}
+	    (key, val) = line.split(", ")
+	    songnum += 1
+	    song['songnum'] = songnum
+	    song['Title'] = key
+	    song['Artist'] = val.rstrip()
+#	    song['raw'] = line
+	    music.append(song)
+	f.close()
+	return music
+
+def parselist(musiclist):
+	for song in musiclist:
+	  searchterm = song['Title'] + " " + song['Artist'] + ' lyrics'
+	  dictlink={}
+	  try:
+	    ytresult = YoutubeSearch(searchterm, max_results=1).to_dict() ##increase timeout!!
+	    link = 'https://youtube.com' + ytresult[0]['link']
+cherokee2
+
+cherokee2
+	    logresults.append(song['Title'] + ", " + song['Artist'] + " Link Created")
+	    if DOWNLOAD:
+              print("Attempting to download", song['Title'])
+              downloadsong(link, song)
+	    else:
+	      print("ERROR: Not Downloading for some reason")
+	  except:
+	    logresults.append(song['Title'] + ", " + song['Artist'] + " COULD NOT CREATE LINK")
+	cleanup(MUSICFILE)
+
+def downloadsong(link, song):
+       try: 
+         os.system("youtube-dl --extract-audio --audio-format mp3 --audio-quality 0 --output '%(title)s.%(ext)s' --ignore-errors " + link)
+         completed.append(song['songnum'])
+         logresults.append(song['Title'] + ", " + song['Artist'] + " Audio downloaded")
+         print("Download Complete!")
+       except e as youtubedlexception:
+         logresults.append(song['Title'] + ", " + song['Artist'] + " FAILED TO DOWNLOAD SONG (youtube-dl)")
+         print(youtubedlexception)
+	
+
+def cleanup(file):
+	print("Cleaning completed files from list")
+	print("Completed Downloads:", completed)
+
+	linenum=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)
+
+	f.close()
+
+
+if __name__ == "__main__":
+	readlist(MUSICFILE)
+	parselist(music)
+
+
+print("------------")
+for r in logresults:
+  print(r)
+
+
+#print(completed)
+