mirror of
https://github.com/cooperhammond/irs.git
synced 2024-12-22 17:35:28 +00:00
Python 3 compatability
This commit is contained in:
parent
6020a18c7a
commit
224c27b96d
|
@ -1,6 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
|
||||||
sys.path.append(path.expanduser("~/.irs")) # Add config to path
|
sys.path.append(path.expanduser("~/.irs")) # Add config to path
|
||||||
|
|
||||||
import config_ # from "~/.irs/config_.py"
|
import config_ # from "~/.irs/config_.py"
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Ripper:
|
||||||
if self.args["hook-text"].get("converting") is not None:
|
if self.args["hook-text"].get("converting") is not None:
|
||||||
CONFIG["converting"] = self.args["hook-text"]["converting"]
|
CONFIG["converting"] = self.args["hook-text"]["converting"]
|
||||||
|
|
||||||
self.args = ObjManip.set_utf8_encoding(self.args)
|
print(self.args["song"])
|
||||||
|
|
||||||
self.locations = []
|
self.locations = []
|
||||||
self.type = None
|
self.type = None
|
||||||
|
@ -131,7 +131,7 @@ class Ripper:
|
||||||
def find_yt_url(self, song=None, artist=None, additional_search=None):
|
def find_yt_url(self, song=None, artist=None, additional_search=None):
|
||||||
if additional_search is None:
|
if additional_search is None:
|
||||||
additional_search = Config.parse_search_terms(self)
|
additional_search = Config.parse_search_terms(self)
|
||||||
print(self.args["hook-text"].get("youtube"))
|
print(str(self.args["hook-text"].get("youtube")))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not song:
|
if not song:
|
||||||
|
@ -142,7 +142,8 @@ class Ripper:
|
||||||
raise ValueError("Must specify song_title/artist in `args` with \
|
raise ValueError("Must specify song_title/artist in `args` with \
|
||||||
init, or in method arguments.")
|
init, or in method arguments.")
|
||||||
|
|
||||||
search_terms = song + " " + artist + " " + additional_search
|
search_terms = str(song) + " " + str(artist
|
||||||
|
) + " " + str(additional_search)
|
||||||
query_string = urlencode({"search_query": (
|
query_string = urlencode({"search_query": (
|
||||||
search_terms.encode('utf-8'))})
|
search_terms.encode('utf-8'))})
|
||||||
link = "http://www.youtube.com/results?" + query_string
|
link = "http://www.youtube.com/results?" + query_string
|
||||||
|
@ -370,7 +371,6 @@ init, or in method arguments.")
|
||||||
if data == {}:
|
if data == {}:
|
||||||
data = self.parse_song_data(song, artist)
|
data = self.parse_song_data(song, artist)
|
||||||
if data != {}:
|
if data != {}:
|
||||||
data = ObjManip.set_utf8_encoding(data)
|
|
||||||
song = data["name"]
|
song = data["name"]
|
||||||
artist = data["artist"]
|
artist = data["artist"]
|
||||||
|
|
||||||
|
@ -379,11 +379,9 @@ init, or in method arguments.")
|
||||||
|
|
||||||
video_url, video_title = self.find_yt_url(song, artist)
|
video_url, video_title = self.find_yt_url(song, artist)
|
||||||
|
|
||||||
print(self.args["hook-text"].get("song")
|
print(self.args["hook-text"].get("song").format(song, artist))
|
||||||
.encode('utf-8').format(song, artist))
|
|
||||||
|
|
||||||
file_name = str(data["file_prefix"] + ObjManip.blank(song, False) +
|
file_name = data["file_prefix"] + ObjManip.blank(song, False) + ".mp3"
|
||||||
".mp3")
|
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
|
|
27
irs/utils.py
27
irs/utils.py
|
@ -15,8 +15,11 @@ from time import sleep
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
# Config File and Flags
|
# Config File and Flags
|
||||||
import config
|
if sys.version_info[0] == 2:
|
||||||
CONFIG = config.CONFIG
|
import config
|
||||||
|
CONFIG = config.CONFIG
|
||||||
|
else:
|
||||||
|
from irs.config import CONFIG
|
||||||
|
|
||||||
|
|
||||||
# ==================
|
# ==================
|
||||||
|
@ -57,17 +60,19 @@ class YdlUtils:
|
||||||
# Object Manipulation and Checking
|
# Object Manipulation and Checking
|
||||||
# ================================
|
# ================================
|
||||||
|
|
||||||
def set_utf8_encoding(ld): # ld => a list or dictionary with strings in it
|
def set_encoding(ld, encoding): # ld => list or dictionary with strings in it
|
||||||
if type(ld) == dict:
|
if type(ld) == dict:
|
||||||
for k in ld:
|
for k in ld:
|
||||||
if type(ld[k]) == dict or type(ld[k]) == list:
|
if type(ld[k]) == dict or type(ld[k]) == list:
|
||||||
ld[k] = set_utf8_encoding(ld[k])
|
ld[k] = set_encoding(ld[k], encoding)
|
||||||
elif type(ld[k]) == str:
|
elif type(ld[k]) == str:
|
||||||
ld[k] = ld[k].encode('utf-8')
|
ld[k] = encoding(ld[k])
|
||||||
elif type(ld) == list:
|
elif type(ld) == list:
|
||||||
for index, datum in enumerate(ld):
|
for index, datum in enumerate(ld):
|
||||||
if type(datum) == str:
|
if type(datum) == str:
|
||||||
ld[index] = datum.encode('utf-8')
|
ld[index] = encoding(datum)
|
||||||
|
elif type(ld[k]) == dict or type(ld[k]) == list:
|
||||||
|
ld[k] = set_encoding(ld[k], encoding)
|
||||||
return ld
|
return ld
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,7 +97,7 @@ class ObjManip: # Object Manipulation
|
||||||
def blank(string, downcase=True):
|
def blank(string, downcase=True):
|
||||||
import re
|
import re
|
||||||
regex = re.compile('[^a-zA-Z0-9\ ]')
|
regex = re.compile('[^a-zA-Z0-9\ ]')
|
||||||
string = regex.sub('', string)
|
string = regex.sub('', str(string))
|
||||||
if downcase:
|
if downcase:
|
||||||
string = string.lower()
|
string = string.lower()
|
||||||
return ' '.join(string.split())
|
return ' '.join(string.split())
|
||||||
|
@ -133,8 +138,12 @@ class ObjManip: # Object Manipulation
|
||||||
del new_d[x]
|
del new_d[x]
|
||||||
return new_d
|
return new_d
|
||||||
|
|
||||||
def set_utf8_encoding(ld): # ld => a list or dictionary with strings in it
|
# ld => a list or dictionary with strings in it
|
||||||
return set_utf8_encoding(ld)
|
def set_utf8_encoding(ld):
|
||||||
|
return set_encoding(ld, lambda x: x.encode('utf-8'))
|
||||||
|
|
||||||
|
def set_encoding(*args):
|
||||||
|
return set_encoding(*args)
|
||||||
|
|
||||||
# ========================================
|
# ========================================
|
||||||
# Download Log Reading/Updating/Formatting
|
# Download Log Reading/Updating/Formatting
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -27,8 +27,8 @@ class PostInstallCommand(install):
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
print("\n\nDownloading Dependencies:\n")
|
print("\n\nDownloading Dependencies:\n")
|
||||||
ydl_binaries.download_ffmpeg("~/.irs/bin")
|
# ydl_binaries.download_ffmpeg("~/.irs/bin")
|
||||||
ydl_binaries.update_ydl("~/.irs/bin")
|
# ydl_binaries.update_ydl("~/.irs/bin")
|
||||||
|
|
||||||
config_file = path.expanduser("~/.irs/config_.py")
|
config_file = path.expanduser("~/.irs/config_.py")
|
||||||
if not path.isfile(config_file):
|
if not path.isfile(config_file):
|
||||||
|
|
Loading…
Reference in a new issue