diff --git a/command.py b/command.py
index 9799884..725f0c8 100644
--- a/command.py
+++ b/command.py
@@ -1,6 +1,5 @@
# coding=utf-8
import logging
-import os.path
import pymumble.pymumble_py3 as pymumble
import re
@@ -10,12 +9,9 @@ import util
import variables as var
from librb import radiobrowser
from database import SettingsDatabase, MusicDatabase
-from media.item import item_builders, item_loaders, item_id_generators, dict_to_item, dicts_to_items
+from media.item import item_id_generators, dict_to_item, dicts_to_items
from media.cache import get_cached_wrapper_from_scrap, get_cached_wrapper_by_id, get_cached_wrappers_by_tags
-from media.file import FileItem
-from media.url_from_playlist import PlaylistURLItem, get_playlist_info
-from media.url import URLItem
-from media.radio import RadioItem
+from media.url_from_playlist import get_playlist_info
log = logging.getLogger("bot")
@@ -281,7 +277,6 @@ def cmd_play_file(bot, user, text, command, parameter, do_not_refresh_cache=Fals
def cmd_play_file_match(bot, user, text, command, parameter, do_not_refresh_cache=False):
global log
- music_folder = var.music_folder
if parameter:
files = var.cache.files
msgs = [constants.strings('multiple_file_added') + "
"]
@@ -701,12 +696,10 @@ def cmd_remove(bot, user, text, command, parameter):
global log
# Allow to remove specific music into the queue with a number
- if parameter and parameter.isdigit() and int(parameter) > 0 \
- and int(parameter) <= len(var.playlist):
+ if parameter and parameter.isdigit() and 0 < int(parameter) <= len(var.playlist):
index = int(parameter) - 1
- removed = None
if index == var.playlist.current_index:
removed = var.playlist.remove(index)
@@ -766,7 +759,6 @@ def cmd_queue(bot, user, text, command, parameter):
else:
msgs = [constants.strings('queue_contents')]
for i, music in enumerate(var.playlist):
- newline = ''
tags = ''
if len(music.item().tags) > 0:
tags = "{}".format(", ".join(music.item().tags))
@@ -854,8 +846,6 @@ def cmd_add_tag(bot, user, text, command, parameter):
global log
params = parameter.split()
- index = ""
- tags = []
if len(params) == 2:
index = params[0]
tags = list(map(lambda t: t.strip(), params[1].split(",")))
@@ -892,8 +882,6 @@ def cmd_remove_tag(bot, user, text, command, parameter):
params = parameter.split()
- index = ""
- tags = []
if len(params) == 2:
index = params[0]
tags = list(map(lambda t: t.strip(), params[1].split(",")))
@@ -1007,7 +995,6 @@ def cmd_search_library(bot, user, text, command, parameter):
def cmd_shortlist(bot, user, text, command, parameter):
global song_shortlist, log
- indexes = []
try:
indexes = [int(i) for i in parameter.split(" ")]
except ValueError:
@@ -1047,7 +1034,6 @@ def cmd_shortlist(bot, user, text, command, parameter):
def cmd_delete_from_library(bot, user, text, command, parameter):
global song_shortlist, log
- indexes = []
try:
indexes = [int(i) for i in parameter.split(" ")]
except ValueError:
diff --git a/constants.py b/constants.py
index ed56eff..355112d 100644
--- a/constants.py
+++ b/constants.py
@@ -2,33 +2,31 @@ import variables as var
def strings(option, *argv, **kwargs):
- string = ""
try:
string = var.config.get("strings", option)
- except KeyError as e:
- raise KeyError("Missed strings in configuration file: '{string}'. ".format(string=option) +
- "Please restore you configuration file back to default if necessary.")
+ except KeyError:
+ raise KeyError("Missed strings in configuration file: '{string}'. ".format(string=option)
+ + "Please restore you configuration file back to default if necessary.")
if argv or kwargs:
try:
formatted = string.format(*argv, **kwargs)
return formatted
except KeyError as e:
raise KeyError(
- "Missed/Unexpected placeholder {{{placeholder}}} in string '{string}'. ".format(placeholder=str(e).strip("'"), string=option) +
- "Please restore you configuration file back to default if necessary.")
- except TypeError as e:
+ "Missed/Unexpected placeholder {{{placeholder}}} in string '{string}'. ".format(placeholder=str(e).strip("'"), string=option)
+ + "Please restore you configuration file back to default if necessary.")
+ except TypeError:
raise KeyError(
- "Missed placeholder in string '{string}'. ".format(string=option) +
- "Please restore you configuration file back to default if necessary.")
+ "Missed placeholder in string '{string}'. ".format(string=option)
+ + "Please restore you configuration file back to default if necessary.")
else:
return string
def commands(command):
- string = ""
try:
string = var.config.get("commands", command)
return string
- except KeyError as e:
- raise KeyError("Missed command in configuration file: '{string}'. ".format(string=command) +
- "Please restore you configuration file back to default if necessary.")
+ except KeyError:
+ raise KeyError("Missed command in configuration file: '{string}'. ".format(string=command)
+ + "Please restore you configuration file back to default if necessary.")
diff --git a/database.py b/database.py
index 4ba493f..c4815a1 100644
--- a/database.py
+++ b/database.py
@@ -15,7 +15,6 @@ class SettingsDatabase:
# connect
conn = sqlite3.connect(self.db_path)
- cursor = conn.cursor()
self.db_version_check_and_create()
diff --git a/interface.py b/interface.py
index fcef7d7..6022072 100644
--- a/interface.py
+++ b/interface.py
@@ -16,7 +16,7 @@ import time
class ReverseProxied(object):
- '''Wrap the application in this middleware and configure the
+ """Wrap the application in this middleware and configure the
front-end server to add these headers, to let you quietly bind
this to a URL other than / and to an HTTP scheme that is
different than what is used locally.
@@ -31,7 +31,7 @@ class ReverseProxied(object):
}
:param app: the WSGI application
- '''
+ """
def __init__(self, app):
self.app = app
diff --git a/librb/rbRadios.py b/librb/rbRadios.py
index 2350baa..09baf1a 100644
--- a/librb/rbRadios.py
+++ b/librb/rbRadios.py
@@ -1,8 +1,5 @@
import requests
-from xml.etree import ElementTree
-from urllib.parse import urljoin
-
from librb.rbConstants import endpoints, BASE_URL
diff --git a/media/cache.py b/media/cache.py
index b4ca274..1373258 100644
--- a/media/cache.py
+++ b/media/cache.py
@@ -1,11 +1,10 @@
import logging
import os
-from database import MusicDatabase
import json
import threading
-from media.item import item_builders, item_loaders, item_id_generators, dict_to_item, dicts_to_items
+from media.item import item_builders, item_id_generators, dict_to_item
from database import MusicDatabase
import variables as var
import util
@@ -18,6 +17,7 @@ class MusicCache(dict):
self.log = logging.getLogger("bot")
self.dir = None
self.files = []
+ self.file_id_lookup = {}
self.dir_lock = threading.Lock()
def get_item_by_id(self, bot, id): # Why all these functions need a bot? Because it need the bot to send message!
@@ -111,7 +111,6 @@ class MusicCache(dict):
self.dir_lock.acquire()
self.log.info("library: rebuild directory cache")
self.files = []
- self.file_id_lookup = {}
files = util.get_recursive_file_list_sorted(var.music_folder)
self.dir = util.Dir(var.music_folder)
for file in files:
diff --git a/media/file.py b/media/file.py
index 6b18981..4718ea3 100644
--- a/media/file.py
+++ b/media/file.py
@@ -1,4 +1,3 @@
-import logging
import os
import re
from io import BytesIO
@@ -6,9 +5,7 @@ import base64
import hashlib
import mutagen
from PIL import Image
-import json
-import util
import variables as var
from media.item import BaseItem, item_builders, item_loaders, item_id_generators
import constants
@@ -83,7 +80,7 @@ class FileItem(BaseItem):
return True
def _get_info_from_tag(self):
- match = re.search("(.+)\.(.+)", self.uri())
+ match = re.search(r"(.+)\.(.+)", self.uri())
assert match is not None
file_no_ext = match[1]
diff --git a/media/item.py b/media/item.py
index 4f28f4f..bd09a81 100644
--- a/media/item.py
+++ b/media/item.py
@@ -1,15 +1,4 @@
import logging
-import threading
-import os
-import re
-from io import BytesIO
-import base64
-import hashlib
-import mutagen
-from PIL import Image
-
-import util
-import variables as var
item_builders = {}
item_loaders = {}
@@ -117,5 +106,3 @@ class BaseItem:
def to_dict(self):
return {"type": self.type, "id": self.id, "ready": self.ready, "path": self.path, "tags": self.tags}
-
-
diff --git a/media/playlist.py b/media/playlist.py
index 152906b..d078fa3 100644
--- a/media/playlist.py
+++ b/media/playlist.py
@@ -359,4 +359,3 @@ class AutoPlaylist(OneshotPlaylist):
if len(self) == 0:
self.refresh()
return super().next()
-
diff --git a/media/radio.py b/media/radio.py
index 54e445a..65b1c59 100644
--- a/media/radio.py
+++ b/media/radio.py
@@ -16,12 +16,11 @@ def get_radio_server_description(url):
global log
log.debug("radio: fetching radio server description")
- p = re.compile('(https?\:\/\/[^\/]*)', re.IGNORECASE)
+ p = re.compile('(https?://[^/]*)', re.IGNORECASE)
res = re.search(p, url)
base_url = res.group(1)
url_icecast = base_url + '/status-json.xsl'
url_shoutcast = base_url + '/stats?json=1'
- title_server = None
try:
r = requests.get(url_shoutcast, timeout=10)
data = r.json()
@@ -31,7 +30,7 @@ def get_radio_server_description(url):
except (requests.exceptions.ConnectionError,
requests.exceptions.HTTPError,
requests.exceptions.ReadTimeout,
- requests.exceptions.Timeout) as e:
+ requests.exceptions.Timeout):
error_traceback = traceback.format_exc()
error = error_traceback.rstrip().split("\n")[-1]
log.debug("radio: unsuccessful attempts on fetching radio description (shoutcast): " + error)
@@ -52,7 +51,7 @@ def get_radio_server_description(url):
except (requests.exceptions.ConnectionError,
requests.exceptions.HTTPError,
requests.exceptions.ReadTimeout,
- requests.exceptions.Timeout) as e:
+ requests.exceptions.Timeout):
error_traceback = traceback.format_exc()
error = error_traceback.rstrip().split("\n")[-1]
log.debug("radio: unsuccessful attempts on fetching radio description (icecast): " + error)
@@ -82,7 +81,7 @@ def get_radio_title(url):
requests.exceptions.HTTPError,
requests.exceptions.ReadTimeout,
requests.exceptions.Timeout,
- KeyError) as e:
+ KeyError):
log.debug("radio: unsuccessful attempts on fetching radio title (icy)")
return url
@@ -163,6 +162,3 @@ class RadioItem(BaseItem):
def display_type(self):
return constants.strings("radio")
-
-
-
diff --git a/media/url.py b/media/url.py
index 2d342f2..f5f4163 100644
--- a/media/url.py
+++ b/media/url.py
@@ -149,8 +149,6 @@ class URLItem(BaseItem):
self.ready = "preparing"
self.log.info("bot: downloading url (%s) %s " % (self.title, self.url))
- ydl_opts = ""
-
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': save_path,
@@ -170,7 +168,7 @@ class URLItem(BaseItem):
for i in range(attempts):
self.log.info("bot: download attempts %d / %d" % (i+1, attempts))
try:
- info = ydl.extract_info(self.url)
+ ydl.extract_info(self.url)
download_succeed = True
break
except:
diff --git a/media/url_from_playlist.py b/media/url_from_playlist.py
index 8559743..99b6007 100644
--- a/media/url_from_playlist.py
+++ b/media/url_from_playlist.py
@@ -1,8 +1,6 @@
import youtube_dl
import constants
-import media
import variables as var
-import hashlib
from media.item import item_builders, item_loaders, item_id_generators
from media.url import URLItem, url_item_id_generator
diff --git a/mumbleBot.py b/mumbleBot.py
index c9f0102..ec63bb4 100644
--- a/mumbleBot.py
+++ b/mumbleBot.py
@@ -14,8 +14,6 @@ import os
import os.path
import pymumble.pymumble_py3 as pymumble
import variables as var
-import hashlib
-import youtube_dl
import logging
import logging.handlers
import traceback
@@ -25,9 +23,6 @@ import util
import command
import constants
from database import SettingsDatabase, MusicDatabase
-import media.url
-import media.file
-import media.radio
import media.system
from media.playlist import BasePlaylist
from media.cache import MusicCache
@@ -585,7 +580,6 @@ def start_web_interface(addr, port):
# setup logger
werkzeug_logger = logging.getLogger('werkzeug')
logfile = util.solve_filepath(var.config.get('webinterface', 'web_logfile'))
- handler = None
if logfile:
handler = logging.handlers.RotatingFileHandler(logfile, mode='a', maxBytes=10240) # Rotate after 10KB
else:
diff --git a/util.py b/util.py
index 56d699e..af763d6 100644
--- a/util.py
+++ b/util.py
@@ -6,23 +6,16 @@ import magic
import os
import sys
import variables as var
-import constants
import zipfile
import requests
-import mutagen
import re
import subprocess as sp
import logging
import youtube_dl
from importlib import reload
-from PIL import Image
-from io import BytesIO
from sys import platform
import traceback
import urllib.request
-import base64
-import media
-import media.radio
from packaging import version
log = logging.getLogger("bot")
@@ -173,7 +166,7 @@ def url_unban(url):
def pipe_no_wait(pipefd):
- ''' Used to fetch the STDERR of ffmpeg. pipefd is the file descriptor returned from os.pipe()'''
+ """ Used to fetch the STDERR of ffmpeg. pipefd is the file descriptor returned from os.pipe()"""
if platform == "linux" or platform == "linux2" or platform == "darwin":
import fcntl
import os
@@ -316,13 +309,13 @@ def youtube_search(query):
try:
r = requests.get("https://www.youtube.com/results", params={'search_query': query}, timeout=5)
- results = re.findall("watch\?v=(.*?)\".*?title=\"(.*?)\".*?"
+ results = re.findall(r"watch\?v=(.*?)\".*?title=\"(.*?)\".*?"
"(?:user|channel).*?>(.*?)<", r.text) # (id, title, uploader)
if len(results) > 0:
return results
- except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout) as e:
+ except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout):
error_traceback = traceback.format_exc().split("During")[0]
log.error("util: youtube query failed with error:\n %s" % error_traceback)
return False