Python 3 compatability

This commit is contained in:
Kepoor Hampond 2017-06-10 17:37:16 -07:00
parent 6020a18c7a
commit 224c27b96d
4 changed files with 27 additions and 19 deletions

View file

@ -1,6 +1,7 @@
import sys
from os import path
sys.path.append(path.expanduser("~/.irs")) # Add config to path
import config_ # from "~/.irs/config_.py"

View file

@ -47,7 +47,7 @@ class Ripper:
if self.args["hook-text"].get("converting") is not None:
CONFIG["converting"] = self.args["hook-text"]["converting"]
self.args = ObjManip.set_utf8_encoding(self.args)
print(self.args["song"])
self.locations = []
self.type = None
@ -131,7 +131,7 @@ class Ripper:
def find_yt_url(self, song=None, artist=None, additional_search=None):
if additional_search is None:
additional_search = Config.parse_search_terms(self)
print(self.args["hook-text"].get("youtube"))
print(str(self.args["hook-text"].get("youtube")))
try:
if not song:
@ -142,7 +142,8 @@ class Ripper:
raise ValueError("Must specify song_title/artist in `args` with \
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": (
search_terms.encode('utf-8'))})
link = "http://www.youtube.com/results?" + query_string
@ -370,7 +371,6 @@ init, or in method arguments.")
if data == {}:
data = self.parse_song_data(song, artist)
if data != {}:
data = ObjManip.set_utf8_encoding(data)
song = data["name"]
artist = data["artist"]
@ -379,11 +379,9 @@ init, or in method arguments.")
video_url, video_title = self.find_yt_url(song, artist)
print(self.args["hook-text"].get("song")
.encode('utf-8').format(song, artist))
print(self.args["hook-text"].get("song").format(song, artist))
file_name = str(data["file_prefix"] + ObjManip.blank(song, False) +
".mp3")
file_name = data["file_prefix"] + ObjManip.blank(song, False) + ".mp3"
ydl_opts = {
'format': 'bestaudio/best',

View file

@ -15,8 +15,11 @@ from time import sleep
import pkg_resources
# Config File and Flags
import config
CONFIG = config.CONFIG
if sys.version_info[0] == 2:
import config
CONFIG = config.CONFIG
else:
from irs.config import CONFIG
# ==================
@ -57,17 +60,19 @@ class YdlUtils:
# 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:
for k in ld:
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:
ld[k] = ld[k].encode('utf-8')
ld[k] = encoding(ld[k])
elif type(ld) == list:
for index, datum in enumerate(ld):
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
@ -92,7 +97,7 @@ class ObjManip: # Object Manipulation
def blank(string, downcase=True):
import re
regex = re.compile('[^a-zA-Z0-9\ ]')
string = regex.sub('', string)
string = regex.sub('', str(string))
if downcase:
string = string.lower()
return ' '.join(string.split())
@ -133,8 +138,12 @@ class ObjManip: # Object Manipulation
del new_d[x]
return new_d
def set_utf8_encoding(ld): # ld => a list or dictionary with strings in it
return set_utf8_encoding(ld)
# ld => a list or dictionary with strings in it
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

View file

@ -27,8 +27,8 @@ class PostInstallCommand(install):
from shutil import copyfile
print("\n\nDownloading Dependencies:\n")
ydl_binaries.download_ffmpeg("~/.irs/bin")
ydl_binaries.update_ydl("~/.irs/bin")
# ydl_binaries.download_ffmpeg("~/.irs/bin")
# ydl_binaries.update_ydl("~/.irs/bin")
config_file = path.expanduser("~/.irs/config_.py")
if not path.isfile(config_file):