0

Note: I am a completely beginner in YAML and I have not understood why and how YAML yet. So, my question may contain some irrelevant content to YAML. Excuse me and please correct them.

In a music player (MusicBee), I found a plugin which fetches the lyrics for songs. How the lyric is fetched from the lyric provider is written in a YAML file (yml). And as an example the lyrics from the AZLyrics fetched by the following yml file;

name: A-Z Lyrics Universe
url: "http://www.azlyrics.com/lyrics/{artist}/{title}.html"
extractor: '(?s)<div>\s+<!--\s+Usage.*?\s+-->(?P<lyrics>.+?)<\/div>'

headers:
- name: User-Agent
  value: 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0' # Firefox 30 Win x64 user agent

variables:
- &artist
  name: artist
  filters:
    - [lowercase]
    - [strip_nonascii]
- <<: *artist
  name: title

filters:
- [strip_html]
- [trim]
- [utf8_encode]

Here the URL of the lyric is directly given by;

http://www.azlyrics.com/lyrics/{artist}/{title}.html

But this is my problem. Instead using the above link I need to do a simple google search as

https://www.google.lk/search?q={artist}+{title}+azlyrics+lyrics

and grab the first URL from the searched result and then use it as the URL of the lyric.

Questions:

  1. Does YAML, able to do the task that I need to do?
  2. If yes, How can I do it? How to deal with google results?
  3. If no, Can you give me any suggestions, what is the path I have to go to do my task?

Note: Heres, the source code of the given plugin.

Tharindu Sathischandra
  • 1,654
  • 1
  • 15
  • 37
  • YAML is a data serialization language. Compare it to JSON, although it's a bit more powerful. It is not a programming language, and there is no YAML interpreter. It certainly can't fetch urls. – tinita Jun 15 '18 at 09:42
  • @tinita Can't we use functions in YAML? – Tharindu Sathischandra Jun 15 '18 at 12:12
  • You can have functions in YAML, but that depends on the program library used for loading the YAML document, the program language, and whether they use a "safe" load (which they should) or not. Given that anyone **distributing** programs that don't use safe loading should be thrown out of the spaceship we live on, and that it is written in C# makes it unlikely that you can do any indirect loading unless the program/plugin implements it (and reading the docs, it doesn't). – Anthon Jun 25 '18 at 16:27

2 Answers2

2

NO You can't Do that with YAML because it's just a

YAML is a human-readable data serialization language

So you have to choose a programming language to that stuff for you. which supports making HTTP requests (Most famous once does support that.)

Here you haven't mentioned which language you are familiar with so i will not go into specifics but just steps

  1. Make HTTP request to URL built for Google
  2. Parse Fetched result
  3. Read the first link available in result
  4. Use that result wherever you want.

You with each language it'll change how to perform each task. but yes it pretty much breaks Down to this.

Update:

Google provides API for querying, and for JAVA Example You can check this

Mihir Dave
  • 3,954
  • 1
  • 12
  • 28
0

YAML/YML is other alternative to .properties/.json files but is more developer/user friendly.

Usually, ".yml" files are used to specify configuration/meta data of an application.

Simply said, it is a data representation format, and does nothing by itself.

Your code has to read the contents of the YAML file and perform the operation, in this case the operation is searching google for results.

Just like there are language specific libraries for reading content from .json files, there are also libraries for reading content from .yml files.

Check the http://yaml.org/ link.

J28
  • 1,080
  • 3
  • 15
  • 25