meetDeveloper / freeDictionaryAPI

There was no free Dictionary API on the web when I wanted one for my friend, so I created one.
https://dictionaryapi.dev/
GNU General Public License v3.0
2.56k stars 259 forks source link

Is there a way to self-host this? #111

Open 1over137 opened 2 years ago

1over137 commented 2 years ago

When I run the service on my computer, it doesn't return any definitions for English (though it does work for other languages).

bordedelcielo commented 2 years ago

I am also interested in this question.

solamour commented 2 years ago

Here is something you might want to try.

  1. Open https://www.google.com/search?q=google+dictionary in your web browser.

  2. Right-click on it and select Inspect from the pop-up menu. This will open "Developer Tools" screen.

  3. Select Network tab in Developer Tools.

  4. Enter a word in the edit box that says "Search for a word", but don't press ENTER yet.

  5. Press the trash can icon (Firefox) or the "stop sign" icon (Chrome/Edge) in Developer Tools to clear the network traffic logs.

  6. Now press ENTER. You should see the browser makes a call to https://www.google.com/async/callback:5493 with a long line of parameters.

  7. Look for 1) fc, 2) fcv, and 3) async in the long line of parameters.

  8. Update modules/dictionary.js in line 140 ~ 142. Note that _fmt:prog toward the end of async seem to cause a problem, so try without it first.

Utopiah commented 2 years ago

Indeed, providing a Dockerfile would help keep AWS costs low. It's great to start, for example build a quick prototype and confirm that it works well (especially compared to the much richer but also complex Wikimedia API for Wiktionary) but once that's done I imagine advanced users would prefer to self-host.

nileblack commented 1 year ago

I follow the steps, but cannot find my browser call https://www.google.com/async/callback:5493

Open https://www.google.com/search?q=google+dictionary in your web browser.

does it need to install the "Google dictionary " chrome extention?

solamour commented 1 year ago

You don't need any extension. The following is what you need to look for.

image

nileblack commented 1 year ago

thanks. need to change google language to ENGLISH. image

solamour commented 6 months ago

Looks like Google doesn't want us to leech off of their resources. The method described here doesn't seem to work anymore.

Rigidoont commented 5 months ago

Looks like "_fmt:prog" is now required in the "async" query parameter. Without it, the response is always 400 Bad Request. But including it results in an HTML response, instead of JSON, and the CSS classes appear to be obfuscated, so it's hard to parse reliably.

Example URL:

https://www.google.com/async/callback:5493?async=term:test,corpus:en,hhdr:true,hwdgt:true,wfp:true,ttl:,tsl:,ptl:,_fmt:prog&fcv=3&fc=EswBCowBQUVzN2pOVFNkZjdMWG5vMzZVeGlMU1hBbGp1QW9nWTBOcmRTcmg4WFJCS1dKTm1HNDRySVczWDZnVHB0WEc2WmJrYWVrdlVoUUFYYzdJd09ZSmw4b0djR3hTWm13VGp0QjkwbXBmVFdJN0lTV2pocF9fdWwyTTdMYTItbFk1S0tfUkM4WmszeEJnZjMSF1dCSkJaTXlIRWZTUnhjOFAySktjZ0FnGiJBTy0wcmw2VWZJOU1ONTFaNlNyUXJ1ZnUyRGZJVll4V0R3

Response:

)]}'
22;["ZNf5ZeC4N4OpwPAP4c6EmA0","1974"]3;[2]1189;<style>.nGphre{float:right;padding-left:16px}.UykT9d{border-radius:8px;display:block}.nYT7Qb{clear:both}.Gx5Zad{background-color:#fff;margin-bottom:30px;box-shadow:0 0 0 1px #dfe1e5;border-radius:8px}.pkphOe{font-size:14px;line-height:22px;}.EtOod>*:first-child{border-top-left-radius:8px;border-top-right-radius:8px}.EtOod>*:last-child{border-bottom-left-radius:8px;border-bottom-right-radius:8px}.EtOod.avPKgf>*:last-child{border-bottom-left-radius:4px}.EtOod>.qxDOhb>*:first-child{border-top-left-radius:8px;border-top-right-radius:8px}.EtOod>.qxDOhb>*:last-child{border-bottom-left-radius:8px;border-bottom-right-radius:8px}.kCrYT{padding:12px 16px 12px}.l97dzf{font-weight:400}.zBAuLc{line-height:normal;margin:0;padding:0}.BNeawe{white-space:pre-line;word-wrap:break-word}.deIvCb{font-size:16px;line-height:20px;font-weight:400}.deIvCb.HrGdeb{color:#fff}.deIvCb.AP7Wnd{color:#202124}.RJI4s{vertical-align:middle}.tAd8D{font-size:14px;line-height:20px}.tAd8D.HrGdeb{color:rgba(255,255,255,.70)}.tAd8D.AP7Wnd{color:#70757a}.skVgpb{display:table;table-layout:fixed;width:100%}.VGHMXd{display:table-cell;vertical-align:middle;height:52px;text-align:center}.LpaDrb{margin:0 auto 8px;display:block}.vbShOe{padding-top:0}.x54gtf{height:1px;background-color:#dadce0;margin:0 16px}.Q0HXG{height:1px;background-color:#dadce0}.Ap5OSd{padding-bottom:12px}.s3v9rd{font-size:14px;line-height:22px}.s3v9rd.HrGdeb{color:#fff}.s3v9rd.AP7Wnd{color:#202124}.r0bn4c.tr0dw{color:rgba(255,255,255,.70)}.r0bn4c.rQMQod{color:#70757a}.mSx1Ee{padding-left:48px;margin:0}.v9i61e{padding-bottom:8px}.v7pIac{padding-right:16px}</style><div><div class="Gx5Zad xpd EtOod pkphOe"><div class="kCrYT"><span><h3 class="zBAuLc l97dzf"><div class="BNeawe deIvCb AP7Wnd"><img style="vertical-align:top;width:20px;height:20px;max-width:20px;max-height:20px" id="flex_text_audio_icon_chunk" alt="            " role="button" tabindex="0" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-deferred="1"><audio src="https://ssl.gstatic.com/dictionary/static/sounds/20220808/test--_gb_1.mp3"></audio> test</div></h3></span><span><div class="BNeawe tAd8D AP7Wnd">/t st/</div></span></div><div class="Q0HXG"></div><div class="kCrYT"><div><div class="BNeawe s3v9rd AP7Wnd"><div class="Ap5OSd"><div class="BNeawe s3v9rd AP7Wnd"><span class="r0bn4c rQMQod">noun
</span></div></div><div class="Ap5OSd"><ol class="mSx1Ee v7pIac"><li class="v9i61e"><div class="v9i61e"><div class="BNeawe s3v9rd AP7Wnd">a procedure intended to establish the quality, performance, or reliability of something, especially before it is taken into widespread use.</div></div><div class="v9i61e"><div class="BNeawe s3v9rd AP7Wnd"><span class="r0bn4c rQMQod">"both countries carried out nuclear tests in May"</span></div></div><div><div class="BNeawe s3v9rd AP7Wnd"><span class="r0bn4c rQMQod">        : trial, experiment, pilot study, try-out, check, examination, assessment, evaluation, appraisal, investigation, inspection, analysis, scrutiny, scrutinization, study, probe, exploration, screening, audition, screen test, assay</span></div></div></li><li class="v9i61e"><div class="v9i61e"><div class="BNeawe s3v9rd AP7Wnd">short for Test match.</div></div><div><div class="BNeawe s3v9rd AP7Wnd"><span class="r0bn4c rQMQod">"the first Test against New Zealand"</span></div></div></li><li><div><div class="BNeawe s3v9rd AP7Wnd">a movable hearth in a reverberating furnace, used for separating gold or silver from lead.</div></div></li></ol></div><div class="Ap5OSd"><div class="BNeawe s3v9rd AP7Wnd"><br></div></div><div class="Ap5OSd"><div class="BNeawe s3v9rd AP7Wnd"><span class="r0bn4c rQMQod">verb
</span></div></div><div class="Ap5OSd"><div><div class="v9i61e"><div class="BNeawe s3v9rd AP7Wnd">take measures to check the quality, performance, or reliability of (something), especially before putting it into widespread use or practice.</div></div><div class="v9i61e"><div class="BNeawe s3v9rd AP7Wnd"><span class="r0bn4c rQMQod">"this range has not been tested on animals"</span></div></div><div><div class="BNeawe s3v9rd AP7Wnd"><span class="r0bn4c rQMQod">        : try out, trial, carry out trials on, put to the test, put through its paces, experiment with, pilot, check, examine, assess, evaluate, appraise, investigate, analyse, scrutinize, study, probe, explore, sample, screen, assay</span></div></div></div></div><div><div class="BNeawe s3v9rd AP7Wnd"><br></div></div></div></div></div></div></div>3;[9]0;3;[4]692;(function(){var f="undefined"!==typeof navigator&&!/Opera/.test(navigator.userAgent)&&/WebKit/.test(navigator.userAgent),g={A:1,INPUT:1,TEXTAREA:1,SELECT:1,BUTTON:1},h={Enter:13," ":32},k={A:13,BUTTON:0,CHECKBOX:32,COMBOBOX:13,FILE:0,GRIDCELL:13,LINK:13,LISTBOX:13,MENU:0,MENUBAR:0,MENUITEM:0,MENUITEMCHECKBOX:0,MENUITEMRADIO:0,OPTION:0,RADIO:32,RADIOGROUP:32,RESET:0,SUBMIT:0,SWITCH:32,TAB:0,TREE:13,TREEITEM:13},l={CHECKBOX:!0,FILE:!0,OPTION:!0,RADIO:!0},m={COLOR:!0,DATE:!0,DATETIME:!0,"DATETIME-LOCAL":!0,EMAIL:!0,MONTH:!0,NUMBER:!0,PASSWORD:!0,RANGE:!0,SEARCH:!0,TEL:!0,TEXT:!0,TEXTAREA:!0,TIME:!0,URL:!0,WEEK:!0};document.addEventListener("DOMContentLoaded",function(){var e=document.getElementById("flex_text_audio_icon_chunk");e&&(e.onclick=function(){e.parentElement.querySelector("audio").play()},e.onkeydown=function(d){var c=d.which||d.keyCode;!c&&d.key&&(c=h[d.key]);f&&3===c&&(c=13);if(13!==c&&32!==c)c=!1;else{var a=d.target;!a.getAttribute&&a.parentNode&&(a=a.parentNode);var b;if(!(b="keydown"!==d.type)){if(b="getAttribute"in a)b=!((a.getAttribute("type")||a.tagName).toUpperCase()in m);b=!(b&&!("BUTTON"===
a.tagName.toUpperCase()||a.type&&"FILE"===a.type.toUpperCase())&&!a.isContentEditable)}(b=b||d.ctrlKey||d.shiftKey||d.altKey||d.metaKey||(a.getAttribute("type")||a.tagName).toUpperCase()in l&&32===c)||((b=a.tagName in g)||(b=a.getAttributeNode("tabindex"),b=null!=b&&b.specified),b=!(b&&!a.disabled));if(b)c=!1;else{b=(a.getAttribute("role")||a.type||a.tagName).toUpperCase();var n=!(b in k)&&13===c;a="INPUT"!==a.tagName.toUpperCase()||!!a.type;c=(0===k[b]%c||n)&&a}}c&&(d.preventDefault(),e.parentElement.querySelector("audio").play())})});}).call(this);20;[3,"flex_text_audio_icon_chunk"]19a;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAA6ElEQVR4Ae2UvQ7BYBSGW4uFxlVICLsYDA0D14NEunRxHSJ+BkYG9ibiHtgkuvpZWOod3uFESqpOF/ElT/q958h5OtQx/iexY/evY9ACJjBewUtkXHEPyBYUNQQuCETuggNrF2DHF3A4kfUMmLB+BoUYAg4nIX0TTNnbfCjg8HDBGuR4z4Ij+813giAC8rcrkXusjdQEpMpcYt5rCzrMaea7tqD9JLhpCyrMZeadpmApssPaUOszXQALGHz67De0/2gpMGPP014VFpizfgJ5zWXnAF8MryW1rj3x5l8LJANQF1lZQH5f8AAWpNcUs6HAEAAAAABJRU5ErkJggg==

@solamour have you managed to find a solution? I'm not sure what to do now.

solamour commented 5 months ago

I noticed the same thing as well; I get 400 if _fmt:prog is missing, and un-parsable if present. If anyone figured it out, please share your experience.

An alternative is Oxford Languages (https://languages.oup.com/products/api/), which is where Google is getting its dictionary from (with heavy formatting, of course). Oxford doesn't seem to give out the API keys for personal uses, though.