diff --git a/fediplay/cli.py b/fediplay/cli.py index 13c104c..75cf61b 100644 --- a/fediplay/cli.py +++ b/fediplay/cli.py @@ -117,4 +117,4 @@ def stream(instance): clientcred = ensure_clientcred(instance) usercred = ensure_usercred(instance) - mastodon.stream(instance, clientcred, usercred) + mastodon.stream(instance, clientcred, usercred, cache_dir=dirs.user_cache_dir) diff --git a/fediplay/mastodon.py b/fediplay/mastodon.py index 350c226..433bcc9 100644 --- a/fediplay/mastodon.py +++ b/fediplay/mastodon.py @@ -59,11 +59,11 @@ def login(client, grant_code, usercred): client.log_in(code=grant_code, scopes=['read'], to_file=usercred) umask(saved_umask) -def stream(instance, clientcred, usercred): +def stream(instance, clientcred, usercred, cache_dir='.'): '''Stream statuses and add them to a queue.''' client = build_client(instance, clientcred, usercred) - listener = StreamListener(Queue()) + listener = StreamListener(Queue(cache_dir)) click.echo('==> Streaming from {}'.format(instance)) client.stream_user(listener) diff --git a/fediplay/queue.py b/fediplay/queue.py index afb2c00..b709aab 100644 --- a/fediplay/queue.py +++ b/fediplay/queue.py @@ -1,11 +1,12 @@ '''The play queue.''' +from os import path import shlex from subprocess import run from threading import Thread, Lock import click -from youtube_dl import YoutubeDL +from youtube_dl import YoutubeDL, utils import fediplay.env as env @@ -15,15 +16,16 @@ class Queue(object): # pylint: disable=too-few-public-methods - def __init__(self): + def __init__(self, cache_dir): self.lock = Lock() self.playing = False self.queue = [] + self.cache_dir = cache_dir def add(self, url): '''Fetches the url and adds the resulting audio to the play queue.''' - filename = Getter().get(url) + filename = Getter(self.cache_dir).get(url) with self.lock: self.queue.append(filename) @@ -54,8 +56,9 @@ class Getter(object): # pylint: disable=too-few-public-methods - def __init__(self): + def __init__(self, cache_dir): self.filename = None + self.cache_dir = cache_dir def _progress_hook(self, progress): if progress['status'] == 'finished': @@ -67,6 +70,7 @@ class Getter(object): options = { 'format': 'mp3/mp4', 'nocheckcertificate': env.no_check_certificate(), + 'outtmpl': path.join(self.cache_dir, utils.DEFAULT_OUTTMPL), 'progress_hooks': [self._progress_hook] } with YoutubeDL(options) as downloader: