|
|
@@ -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
|