|
@@ -1,6 +1,6 @@
|
|
|
#!/usr/bin/python3
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
-from youtube_search import YoutubeSearch
|
|
|
|
|
|
|
+from tg_youtube_search import YoutubeSearch
|
|
|
import os
|
|
import os
|
|
|
import configparser
|
|
import configparser
|
|
|
import sys, getopt
|
|
import sys, getopt
|
|
@@ -44,7 +44,7 @@ else:
|
|
|
print("Exiting...")
|
|
print("Exiting...")
|
|
|
exit(1)
|
|
exit(1)
|
|
|
|
|
|
|
|
-VERSION="0.0.3"
|
|
|
|
|
|
|
+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
|
|
@@ -223,33 +223,32 @@ def readlist(file):
|
|
|
f.close()
|
|
f.close()
|
|
|
return music
|
|
return music
|
|
|
|
|
|
|
|
-#def searchlinks(links, artist):
|
|
|
|
|
-# ## Takes a list of dictionaries and parses the results
|
|
|
|
|
-# ## Discards bad choices
|
|
|
|
|
-# ## Returns a dictionary of one entry (best result)
|
|
|
|
|
-# ## Good results include published by artist,
|
|
|
|
|
-# ## bad results include words live "live" or "Video"
|
|
|
|
|
-# msg("Starting searchlinks", 3)
|
|
|
|
|
-# list_badterms = ["live", "video", "sexy"]
|
|
|
|
|
-#
|
|
|
|
|
-# ### FIX RANKINGS! ##
|
|
|
|
|
-#
|
|
|
|
|
-# for link in links:
|
|
|
|
|
-# rating = 0
|
|
|
|
|
-# for term in list_badterms:
|
|
|
|
|
-# if term.lower() in link['title'].lower():
|
|
|
|
|
-## print("Contains Term!")
|
|
|
|
|
-# rating -= 1
|
|
|
|
|
-# print(rating)
|
|
|
|
|
-# if artist != "":
|
|
|
|
|
-# if artist.lower() == link['publisher'].lower():
|
|
|
|
|
-## print("Published by Artist!")
|
|
|
|
|
-# rating += 10
|
|
|
|
|
-# link["rating"] = rating
|
|
|
|
|
-#
|
|
|
|
|
-# links.sort(reverse=True, key = lambda i: i['rating']) ## Sort links based on rating
|
|
|
|
|
-# msg("Ending serachlinks", 3)
|
|
|
|
|
-# return links[0]
|
|
|
|
|
|
|
+def searchlinks(links, artist):
|
|
|
|
|
+ ## Takes a list of dictionaries and parses the results
|
|
|
|
|
+ ## Discards bad choices
|
|
|
|
|
+ ## Returns a dictionary of one entry (best result)
|
|
|
|
|
+ ## Good results include published by artist,
|
|
|
|
|
+ ## bad results include words live "live" or "Video"
|
|
|
|
|
+ msg("Starting searchlinks", 3)
|
|
|
|
|
+ list_badterms = ["live", "video", "sexy"]
|
|
|
|
|
+
|
|
|
|
|
+ ### FIX RANKINGS! ##
|
|
|
|
|
+
|
|
|
|
|
+ for link in links:
|
|
|
|
|
+ rating = 0
|
|
|
|
|
+ for term in list_badterms:
|
|
|
|
|
+ if term.lower() in link['title'].lower():
|
|
|
|
|
+# print("Contains Term!")
|
|
|
|
|
+ rating -= 1
|
|
|
|
|
+ if artist != "":
|
|
|
|
|
+ if artist.lower() == link['publisher'].lower():
|
|
|
|
|
+# print("Published by Artist!")
|
|
|
|
|
+ rating += 10
|
|
|
|
|
+ link["rating"] = rating
|
|
|
|
|
+
|
|
|
|
|
+ links.sort(reverse=True, key = lambda i: i['rating']) ## Sort links based on rating
|
|
|
|
|
+ msg("Ending searchlinks", 3)
|
|
|
|
|
+ return links[0]
|
|
|
|
|
|
|
|
def generatelink(searchterm, max_results=10, tries=5):
|
|
def generatelink(searchterm, max_results=10, tries=5):
|
|
|
## 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
|
|
@@ -288,11 +287,11 @@ def parselist(musiclist):
|
|
|
dictlink={}
|
|
dictlink={}
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
-## ytresult = generatelink(searchterm)
|
|
|
|
|
-## bestlink = searchlinks(ytresult, song['Artist'])
|
|
|
|
|
ytresult = generatelink(searchterm)
|
|
ytresult = generatelink(searchterm)
|
|
|
- link = 'https://youtube.com' + ytresult[0]['link']
|
|
|
|
|
-# link = 'https://youtube.com' + bestlink['link']
|
|
|
|
|
|
|
+ bestlink = searchlinks(ytresult, song['Artist'])
|
|
|
|
|
+# ytresult = generatelink(searchterm)
|
|
|
|
|
+# link = 'https://youtube.com' + ytresult[0]['link']
|
|
|
|
|
+ link = 'https://youtube.com' + bestlink['link']
|
|
|
logresults.append(song['Title'] + ", " + song['Artist'] + " Link Created")
|
|
logresults.append(song['Title'] + ", " + song['Artist'] + " Link Created")
|
|
|
if DOWNLOAD:
|
|
if DOWNLOAD:
|
|
|
msg("Attempting to download " + song['Title'], 2)
|
|
msg("Attempting to download " + song['Title'], 2)
|