ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.71k stars 2.24k forks source link

wrong voice file is downloading when using advance editor and pronunciation option #4789

Closed Abbas-509 closed 6 years ago

Abbas-509 commented 6 years ago
Research

Enter an [ x ] character to confirm the points below:

[ x ] I have read the support page and am reporting a bug or enhancement request specific to AnkiDroid

[ x ] I have checked the manual and the FAQ and could not find a solution to my issue

[ x ] I have searched for similar existing issues here and on the user forum

Reproduction Steps
Expected Result

correct voice media file for pronunciation

Actual Result

a html file like this format:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://dict.tu-chemnitz.de/speak-en/4/6/DTfvxijDRBw.mp3">here</a>.</p>
<hr>
<address>Apache/2.2.34 (Scientific Linux) Server at <a href="mailto:beolingus@tu-chemnitz.de">dict.tu-chemnitz.de</a> Port 80</address>
</body></html>

Debug info

Refer to the support page if you are unsure where to get the "debug info".

mikehardy commented 6 years ago

Hello! Apologies for the late reply on this. From the look of this, AnkiDroid doesn't follow HTTP 301 Redirects. I'm not sure if it should or not (or if it is even possible to make it do so or not), but I can see how a failure to follow a 301 redirected link would break remote media.

Can I ask for the original link in the card before the redirect? Or an Anki deck (.apkg file) with just one or two cards containing links that are redirected and don't work?

Also, as a workaround, on AnkiDesktop there is a media internalizer plugin that you can use to take external links (which are admittedly not supported well) and download them as local media files while updating the card to then create local media references. After running that and syncing your deck from desktop to the cloud then from the cloud to AnkiDroid you should find these things work.

timrae commented 6 years ago

It sounds like the URLs were generated by AnkiDroid from here: https://github.com/ankidroid/Anki-Android/blob/master/AnkiDroid/src/main/java/com/ichi2/anki/multimediacard/beolingus/parsing/BeolingusParser.java

Unfortunately nobody has been maintaining that code for years now, I just tried it and doesn't appear to work anymore. I guess the "API" has changed, and old URLs need to be updated as well.

mikehardy commented 6 years ago

Ah, I didn't pay enough attention to the title of the bug report, I didn't realize Anki could auto-lookup/download pronunciation for words. I see the Beolingus stuff now and I'm able to reproduce this as well. It looks really close to functioning, I'll see if I can either get to to follow redirects (one possibility, if they just are enforcing referrer from same source or something), or fix up the the URL.

@timrae - one question, for functionality like this that depends on an external integration, a unit test (that some would call an integration test) that pulls a live page seems more useful than the current unit test for this functionality that just uses a canned string. Does the project have any sort of philosophy with regards to automated tests like "tests shall not access the internet" or similar? I'd imagine tests like this might be best in a separate or sub-folder marked as integration so people developing offline (if there are any) aren't shocked by failures, but other than that, is it okay to alter the test to fetch the Beolingus stuff live during the test?

timrae commented 6 years ago

I'm ok with accessing the internet from a unit test, as long as it works on Travis and prints a clear message about lack of Internet connectivity when that's the reason it fails