Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplifying installation? #65

Closed
cyphar opened this issue Aug 25, 2020 · 3 comments
Closed

simplifying installation? #65

cyphar opened this issue Aug 25, 2020 · 3 comments

Comments

@cyphar
Copy link

@cyphar cyphar commented Aug 25, 2020

Type:

  • bug
  • feature
  • enhancement
  • question

Environment:

  • OS: Linux (but it doesn't really matter)

I'm going to open a PR to resolve the issue:

  • yes
  • no

Description:

The installation instructions on the Anki add-on page indicate that we need to download and extract a file from MediaFire in order to get this add-on to work (because the file is too large to embed into the bundled data for the add-on on AnkiWeb). That's all fine and good -- but is there a reason that the add-on doesn't just download and extract this file for users? It would make installation much simpler and less error-prone.

As an aside, the file being hosted on MediaFire seems a little bit odd to me when you could just as easily host it on GitHub (as a release artefact) where it'd be much more safe IMHO to store long-term (you could even commit it to the repository in a separate branch -- which would be a more extreme solution).

I'd be happy to send a patch to fix all of this (it'd be fairly simple to do -- though we probably couldn't use requests), but I wanted to check whether this is something that you'd be interested in being fixed?

@cyphar
Copy link
Author

@cyphar cyphar commented Aug 25, 2020

For reference the patch would just be something as simple as:

commit 2c6be2df691113298d7438bda8379157ab86ae84
Author: Aleksa Sarai <cyphar@cyphar.com>
Date:   Wed Aug 26 01:16:58 2020 +1000

    main: download accentAudio on startup
    
    This avoids forcing users to go through annoying steps to download the
    accentAudio, and makes the installation experience much nicer.
    
    Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>

diff --git a/src/main.py b/src/main.py
index 5fa7f5ce3041..1a607909008f 100644
--- a/src/main.py
+++ b/src/main.py
@@ -4,8 +4,10 @@ from anki import models
 from os.path import dirname, join
 import sys, os, platform, re, subprocess, aqt.utils
 from anki.utils import stripHTML, isWin, isMac
-from . import reading 
-import re
+from . import reading
+import requests
+import tempfile
+import zipfile
 import unicodedata
 import urllib.parse
 from anki.hooks import addHook, wrap, runHook, runFilter
@@ -355,7 +357,23 @@ def fetchAudioFromDict(word, yomi, idx):
         return grabAudioForMultiReadingWord(word, yomi)
     else:
         return grabAudioForMultiPitchWord(word, yomi, idx)
-    
+
+
+def setupAccentAudio():
+    # XXX: This needs to be changed to a proper URL.
+    ACCENT_URL = "http://download31.mediafire.com/mcg2h1l0skdg/ec0i8omoayfuc75/accentAudio.zip"
+    userFiles = join(addon_path, "user_files")
+    audioDir = join(userFiles, "accentAudio")
+    # If we don't have accent audio, download it.
+    if not exists(audioDir):
+        with tempfile.TemporaryFile(mode="w+b") as tmp:
+            with requests.get(ACCENT_URL, stream=True) as req:
+                for chunk in req.iter_content(chunk_size=16*1024):
+                    tmpzip.write(chunk)
+            with zipfile.Zipfile(tmp) as tmpzip:
+                tmpzip.extractall(path=userFiles)
+
+setupAccentAudio()
 
 def clickPlayAudio(cmd):
 
@LucasMIA
Copy link
Collaborator

@LucasMIA LucasMIA commented Aug 25, 2020

The reason that audio is hosted the way it is is because it is copyrighted content. Be on the lookout because I have some things planned that will change this in the near future though.

@LucasMIA LucasMIA closed this Aug 25, 2020
@cyphar
Copy link
Author

@cyphar cyphar commented Aug 25, 2020

Ah, that makes much more sense. Thanks, and I look forward to whatever you come up with. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.