Skip to content

Commit

Permalink
metadata/Music: adjust our lyrics *.py to use CU LRC unmodified
Browse files Browse the repository at this point in the history
by moving our CLI from *.py to common/culrcwrap.py which uses tiny
Kodistubs to let the few xbmc calls work.  See README for simple
upgrade procedure for any future CU LRC upgrades.
  • Loading branch information
twitham1 committed Jan 25, 2024
1 parent f17a18b commit c7ed5e9
Show file tree
Hide file tree
Showing 28 changed files with 807 additions and 2,888 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This is a tiny portion of Kodistubs to translate CU LRC to MythTV.

If CU LRC ever refers to other functions, simply copy them in here
from original Kodistubs and update as needed.

-twitham@sbcglobal.net, 2024/01 for v34

source: https://github.com/romanvm/Kodistubs
10 changes: 10 additions & 0 deletions mythtv/programs/scripts/metadata/Music/lyrics/Kodistubs/xbmc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tiny portion of Kodistubs to translate CU LRC to MythTV. If CU LRC
# ever refers to other functions, simply copy them in here from
# original Kodistubs and update where needed like below.

import sys

LOGDEBUG = 0

def log(msg: str, level: int = LOGDEBUG) -> None:
print(msg, file=sys.stderr)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Tiny portion of Kodistubs to translate CU LRC to MythTV. If CU LRC
# ever refers to other functions, simply copy them in here from
# original Kodistubs and update where needed like below.

from typing import Optional

class Addon:

def __init__(self, id: Optional[str] = None) -> None:
pass

def getLocalizedString(self, id: int) -> str:
# only testall.py / scrapertest.py needs only 1 message from
# resources/language/resource.language.en_us/strings.po
if (id == 32163):
return "Testing: %s"
return "(%s)" % id

def getSettingBool(self, id: str) -> bool:
return True

def getSettingInt(self, id: str) -> int:
return 0

def getSettingString(self, id: str) -> str:
return ""

def getAddonInfo(self, id: str) -> str:
return ""
38 changes: 38 additions & 0 deletions mythtv/programs/scripts/metadata/Music/lyrics/Kodistubs/xbmcgui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Tiny portion of Kodistubs to translate CU LRC to MythTV. If CU LRC
# ever refers to other functions, simply copy them in here from
# original Kodistubs and update where needed like below.

# show "dialog" on stderr for testall.py / scrapertest.py
import sys

class Dialog:

def __init__(self) -> None:
pass

def ok(self, heading: str, message: str) -> bool:
return True

class DialogProgress:

def __init__(self) -> None:
pass

def create(self, heading: str, message: str = "") -> None:
print("\tDIALOG created: ", heading, " : ", message, file=sys.stderr)
pass

def update(self, percent: int, message: str = "") -> None:
print("\tDIALOG updated %s: " % percent, message, file=sys.stderr)
pass

def close(self) -> None:
pass

def iscanceled(self) -> bool:
# not cancelled is needed to continue the testall.py / scrapertest.py
return False

class Window:
def __init__(self, existingWindowId: int = -1) -> None:
pass
56 changes: 56 additions & 0 deletions mythtv/programs/scripts/metadata/Music/lyrics/Kodistubs/xbmcvfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Tiny portion of Kodistubs to translate CU LRC to MythTV. If CU LRC
# ever refers to other functions, simply copy them in here from
# original Kodistubs and update where needed like below.

from typing import Union, Optional
import os.path

# embedlrc.py and musixmatchlrc.py need some File access

class File:

def __init__(self, filepath: str, mode: Optional[str] = None) -> None:
self.filename = filepath
if mode:
self.fh = open(filepath, mode)
else:
self.fh = open(filepath, "rb")

def __enter__(self) -> 'File': # Required for context manager
return self

def __exit__(self, exc_type, exc_val, exc_tb): # Required for context manager
pass

def read(self, numBytes: int = 0) -> str:
if numBytes:
return self.fh.read(numBytes)
return self.fh.read()

def readBytes(self, numBytes: int = 0) -> bytearray:
if numBytes:
return bytearray(self.fh.read(numBytes))
return bytearray(self.fh.read())

def write(self, buffer: Union[str, bytes, bytearray]) -> bool:
return self.fh.write(buffer)

def size(self) -> int:
return 0

def seek(self, seekBytes: int, iWhence: int = 0) -> int:
return self.fh.seek(seekBytes, iWhence);

def tell(self) -> int:
return self.fh.tell()

def close(self) -> None:
self.fh.close()
pass

def exists(path: str) -> bool:
# for musixmatchlrc.py the test must work or return False
return os.path.isfile(path)

def translatePath(path: str) -> str:
return ""
93 changes: 73 additions & 20 deletions mythtv/programs/scripts/metadata/Music/lyrics/README
Original file line number Diff line number Diff line change
@@ -1,10 +1,80 @@
Lyrics Grabbers
===============
Lyrics Grabbers for MythMusic of MythTV
=======================================

You can add your own grabbers to this directory and MythMusic will
automatically use them so long as they comply with the other grabbers.

The grabber should support these command line options :-
The included grabbers are sourced from the CU LRC Kodi addon:

https://gitlab.com/ronie/script.cu.lrclyrics


Copyright / LICENSE
===================

CU LRC and therefore this directory are licensed under the terms of
the GNU GPL version 2, see ./LICENSE.txt for details.


Grabbers as/of 2024/01, Their Priority And Whether Synchronized
===============================================================

EmbeddedLyrics 50 Yes/No
FileLyrics 90 Yes/No
musixmatchlrc 100 Yes NEW in v34
lrclib 110 Yes NEW in v34
lyricsify 130 Yes NEW in v34
genius 200 No
musixmatch 210 No NEW in v34
lyricsmode 220 No
azlyrics 230 No NEW in v34
lyricscom 240 No
supermusic 250 No NEW in v34
darklyrics 260 No
megalobiz 400 Yes (too slow to be earlier, was 140)
music163 500 Yes (sometimes returns author only, was 120)


To Upgrade to latest CU LRC
===========================

Simply overwrite lib/ with the latest from the source:

https://gitlab.com/ronie/script.cu.lrclyrics

* remove any ./*.py that has been removed from lib/culrcscrapers

* add a new ./*.py for any new scraper in lib/culrcscrapers

* adjust the fields of info{} as needed

* overwrite ./changelog.txt from the source, compare its head to line
2 of addon.xml in the source and update the latest version number
into the header of ./common/culrcwrap.py

* ./testlyrics -k -t

That's all!

As of v34 in 2024/01 this is how we use CU LRC unmodified:

Only a small boilerplate bootstrap file of a few lines of information
is needed in this directory. These files import only the
LyricsFetcher from ./lib/culrcscrapers or from ./common for any
additional grabbers like filelyrics.py. Finally they run main from
./common/culrcwrap.py which implements the below CLI translation to
MythTV via a very tiny and simple ./Kodistubs.

Custom grabbers can similarly use ./common/culrcwrap.py for the CLI
and simply put their LyricsFetcher in ./common, like filelyrics did.


Required command line options for all grabbers
==============================================

(automatically done by ./common/culrcwrap.py)

All grabbers should support these command line options:

Options:
-h, --help show this help message and exit
Expand Down Expand Up @@ -87,20 +157,3 @@ Options:



Current Grabbers, Their Priority And Whether Synchronized
=========================================================

EmbeddedLyrics 50 Yes/No
FileLyrics 90 Yes/No
musixmatchlrc 100 Yes NEW in v34
lrclib 110 Yes NEW in v34
lyricsify 130 Yes NEW in v34
genius 200 No
musixmatch 210 No NEW in v34
lyricsmode 220 No
azlyrics 230 No NEW in v34
lyricscom 240 No
supermusic 250 No NEW in v34
darklyrics 260 No
megalobiz 400 Yes (too slow to be earlier, was 140)
music163 500 Yes (returns incomplete results, was 120)
Loading

0 comments on commit c7ed5e9

Please sign in to comment.