Skip to content

Commit

Permalink
Fix problems introduced by trying to fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Douile committed Sep 10, 2023
1 parent 048def6 commit 2b8616d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
16 changes: 8 additions & 8 deletions friends_queue/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
from mpv import MPV


def __pause(player):
def _pause(player):
player.pause = True


def __resume(player):
def _resume(player):
player.pause = False


def __volume_up(player):
def _volume_up(player):
player.volume = floor(min(player.volume + 5, 100))


def __volume_down(player):
def _volume_down(player):
player.volume = floor(max(player.volume - 5, 0))


Expand All @@ -27,9 +27,9 @@ def __volume_down(player):
"seek_forward": lambda player: player.seek("10", "relative+keyframes"),
"prev": lambda player: player.playlist_prev("force"),
"skip": lambda player: player.playlist_next("force"),
"pause": __pause,
"resume": __resume,
"volume_up": __volume_up,
"volume_down": __volume_down,
"pause": _pause,
"resume": _resume,
"volume_up": _volume_up,
"volume_down": _volume_down,
"quit": lambda player: player.quit(0),
}
6 changes: 3 additions & 3 deletions friends_queue/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __del__(self):
rmtree(self.base)


def __make_cache_dir(base: str, name: str) -> str:
def _make_cache_dir(base: str, name: str) -> str:
directory = os.path.join(base, name)
mkdir(directory)
return directory
Expand All @@ -33,6 +33,6 @@ def make_cache_dirs(base_dir: str = None):
base_dir = os.path.abspath(base_dir)
return CacheDirs(
base_dir,
__make_cache_dir(base_dir, "thumbnails"),
__make_cache_dir(base_dir, "ytdl"),
_make_cache_dir(base_dir, "thumbnails"),
_make_cache_dir(base_dir, "ytdl"),
)
4 changes: 2 additions & 2 deletions friends_queue/friends_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def do_GET(self):
if state.redirect:
self.send_response(302)
path = self.path[:i]
if len(state.extra) > 1:
path += state.extra
if len(state.location_extra) > 1:
path += state.location_extra
self.send_header("Location", path)
self.end_headers()
return
Expand Down
15 changes: 9 additions & 6 deletions friends_queue/video_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def append(self, item: VideoQueueItem):

def append_url(self, url: str):
"""Fetch video URL and asyncronously append to queue"""
__fetch_video(self._ytdl, self._thumbs, self, url)
_fetch_video(self._ytdl, self._thumbs, self, url)

def move(self, item_index: int, new_index: int):
"""Move queue items"""
Expand All @@ -72,7 +72,7 @@ def move(self, item_index: int, new_index: int):
self._player.playlist_move(item_index, new_index)


def __choose_thumbnail(thumbnails):
def _choose_thumbnail(thumbnails):
if thumbnails is None:
return None
for thumb in thumbnails:
Expand All @@ -82,7 +82,7 @@ def __choose_thumbnail(thumbnails):
return None


def __get_stream_urls(info):
def _get_stream_urls(info):
video = None
audio = None

Expand Down Expand Up @@ -117,6 +117,9 @@ def run(self):
# Fetch video info
info = self._ytdl.extract_info(self._item.url, download=False)

if info is None:
return # TODO: handle error

if info.get("_type") == "playlist":
info = info.get("entries")[0]

Expand All @@ -125,7 +128,7 @@ def run(self):
self._item.duration = info.get("duration")
self._item.duration_str = info.get("duration_string")

video, audio = __get_stream_urls(info)
video, audio = _get_stream_urls(info)
self._item.video_url = video.get("url")
self._item.audio_url = audio.get("url")
# TODO: Add other metadata added by ytdl_hook e.g. subtitles, chapters, bitrate
Expand All @@ -135,12 +138,12 @@ def run(self):
self._queue.append(self._item)

# Fetch video thumbnail (as base64)
thumbnail = __choose_thumbnail(info.get("thumbnails"))
thumbnail = _choose_thumbnail(info.get("thumbnails"))
if thumbnail is not None:
self._item.thumbnail = self._thumbs.cache_thumbnail(thumbnail)


def __fetch_video(
def _fetch_video(
ytdl: yt_dlp.YoutubeDL, thumbnails: ThumbnailCache, queue: VideoQueue, url: str
) -> VideoQueueItem:
item = VideoQueueItem(url)
Expand Down

0 comments on commit 2b8616d

Please sign in to comment.