mirror of
https://github.com/nova-r/fediplug.git
synced 2025-01-22 16:46:55 +01:00
use appdirs for cache
This commit is contained in:
parent
94f0c496d4
commit
fc98eac239
3 changed files with 11 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue