Skip to content

Commit

Permalink
refactor/ocp (#2)
Browse files Browse the repository at this point in the history
* refactor/ocp

* refactor/ocp

* refactor/ocp

* refactor/ocp

* refactor/ocp

---------

Co-authored-by: JarbasAi <[email protected]>
  • Loading branch information
NeonJarbas and JarbasAl authored Jan 8, 2024
1 parent 6943a58 commit 16d3190
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 141 deletions.
11 changes: 1 addition & 10 deletions LICENSE
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2024 Casimiro Ferreira

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -200,12 +200,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=======================================================================

Component licenses for mycroft-core:

The mycroft-core software references various Python Packages (via PIP),
each of which has a separate license. All are compatible with the
Apache 2.0 license. See the referenced packages listed in the
"requirements/requirements.txt" file for specific terms and conditions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@

## About

Extensive library of Black Metal music for mycroft
Extensive library of Black Metal music for OpenVoiceOS

![](gui.png)
![](gui.gif)
![](gui2.png)
![](gui3.png)

## Installation Notes

this requires [skill-better-playback-control](https://github.com/JarbasSkills/skill-better-playback-control), it will blacklist and replace the official mycroft skill

## Examples

Expand Down
197 changes: 93 additions & 104 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,117 +1,62 @@
import random
from os.path import join, dirname

from ovos_plugin_common_play.ocp import MediaType, PlaybackType
from ovos_utils.log import LOG
from ovos_workshop.skills.common_play import OVOSCommonPlaybackSkill, \
ocp_search, ocp_featured_media
from youtube_archivist import YoutubeMonitor
import requests
from json_database import JsonStorageXDG

from ovos_utils.ocp import MediaType, PlaybackType
from ovos_workshop.decorators.ocp import ocp_search, ocp_featured_media
from ovos_workshop.skills.common_play import OVOSCommonPlaybackSkill


class BlackMetalSkill(OVOSCommonPlaybackSkill):

def __init__(self):
super().__init__("TRVEKVLT")
def __init__(self, *args, **kwargs):
self.skill_icon = join(dirname(__file__), "ui", "trvekvlt_icon.png")
self.default_bg = join(dirname(__file__), "ui", "bg.png")
self.supported_media = [MediaType.GENERIC,
MediaType.AUDIO,
self.supported_media = [MediaType.AUDIO,
MediaType.MUSIC]
self.archive = YoutubeMonitor(db_name="TrveKvlt", logger=LOG)
self.archive = JsonStorageXDG("TrveKvlt", subfolder="OCP")
super().__init__(*args, **kwargs)

def initialize(self):
self._sync_db()
self.load_ocp_keywords()

def load_ocp_keywords(self):
albums = []
artists = []
songs = []
genre = ["Black Metal"]

for url, data in self.archive.items():
t = data["title"].split("(")[0].split("|")[0].split("[")[0].strip() \
.replace("‎-", "-")
if "-" in t:
artist, title = t.split("-")[:2]
artists.append(artist.strip())
if "album" in data["title"].lower():
albums.append(title.strip())
else:
songs.append(title.strip())

self.register_ocp_keyword(MediaType.MUSIC,
"artist_name", artists)
self.register_ocp_keyword(MediaType.MUSIC,
"album_name", albums)
self.register_ocp_keyword(MediaType.MUSIC,
"music_genre", genre)
self.register_ocp_keyword(MediaType.MUSIC,
"song_name", songs)

def _sync_db(self, message=None):
bootstrap = f"https://github.com/JarbasSkills/skill-trve-kvlt/raw/dev/bootstrap.json"
self.archive.bootstrap_from_url(bootstrap)
data = requests.get(bootstrap).json()
self.archive.merge(data)
self.schedule_event(self._sync_db, random.randint(3600, 24 * 3600))

def _sync_db(self):
urls = [
"https://www.youtube.com/watch?v=kU0pOmzj70o",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWTRkRauhAjPh0h3ddMJin0",
"https://www.youtube.com/playlist?list=PLoul9rkF5MasLz-yl4ZLXymHkYrpFz7Bs",
"https://www.youtube.com/playlist?list=PLnFvfzGgiy7_3Hk2ikc6vd4HvzSdp7ft6",
"https://www.youtube.com/user/NihiLizTikVoiD",
"https://www.youtube.com/user/Adnan3098",
"https://www.youtube.com/c/Werwolf/videos",
"https://www.youtube.com/watch?v=7njdEm4-7MU",
"https://www.youtube.com/watch?v=uNtO0_CYeaI",
"https://www.youtube.com/playlist?list=PLbkph_GtwePZmD-bruvFbuaDnmIJMBjyZ",
"https://www.youtube.com/playlist?list=PLm7wnjUQm_FC0AClRhesJXfviQ0A4IvPq",
"https://www.youtube.com/channel/UCVEf05n0AptM-N1RzeYJn-g/videos",
"https://www.youtube.com/channel/UCJs_uIwVoNCKZAQ5jDqTlkw/videos",
"https://www.youtube.com/c/NoSolace/videos",
"https://www.youtube.com/watch?v=UGOwy3fgnUE",
"https://www.youtube.com/c/AtmosphericBlackMetalAlbumsOfficial/videos",
"https://www.youtube.com/c/666unholymartyr666/videos",
"https://www.youtube.com/playlist?list=OLAK5uy_kQ_YuC4aoOYiblVOXDKOzglBELweOtfyM",
"https://www.youtube.com/playlist?list=OLAK5uy_kUM73tmSd1Ds20-R1DDHUXG1UXaGYRmBw",
"https://www.youtube.com/playlist?list=PLJmjhSfzVjAMadhqNAs_PznWhKDyxnxtd",
"https://www.youtube.com/playlist?list=PLJmjhSfzVjAPijd95sOH3x9bzMIxloz8j",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfW6kmo4Io16o9eCpsR1fe7R",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUOPubujWEeh1fMJnL9DWSi",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUZpRNS4O72txUzPW6NQCOO",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUkXyyncMaTokT27WdkyMYg",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfXXqr1QWJ_h3l4RTrPlgxAv",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfXjYUvYqzvQLVPFMSFTUabS",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVbG03H0pw72T623z4rSXmb",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfXEkgCh0X-KY62chUVAgRSH",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWHT_OQmnnkj3FnwTR5xYtk",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfW8utcSHKtDudFjqTSX82yf",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUONxfFCEGKCi4Uq676skR7",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfV18spo8YlL0Ayu9MqVrxKx",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUHYqFB5HnY5uhYSKPSYBnQ",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfXxVouOUh_GZjLJP9_Esgig",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWLSZlBqixP54DoTrrPPn_F",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVKfruimJtofLGX-tUGlhWT",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfXywfjIDudxv5Dwe_R1kHCI",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUAUmsV4qcyDbBuvE2qO57V",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVjl_ar1Jto9lQlr5zRiq21",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUJBLyMV6upmrMOVNDtBuWt",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUcCDcAKE_SqPMg5vfRjD1h",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVU2JYRqzT4fttLCqmn9h1u",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWTLQqFMFHLNdNMWXEzfCRt",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWmlKgInvh5t6QzmAMmkJQu",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWfPJCBPs6Jjj8NqgoOI-4o",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUB1RJOUUq_Za4kKeToEmsA",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVzMTtxPb1ny4L4cBdNgF2J",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfXvQGPDKyqnyuKYJu3XHYVT",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfW6E5-g9kJy1y7LKO6veU4w",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVJOEE550anPrXbl0mdRcS3",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfX1wBNu-xzWrXnIIcta2kMq",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVypjq7JW-Ep3iceVoaHfW4",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWFUqmxptBtKc9gT9bhRzRz",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUwGEasW2T_DLGPFj6E-EgZ",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVwSNl_ZYDK4Iq3MPKf2jNE",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfWzxSRA1kRmIOnqCr6k69bG",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVfdKf7bgQ-4kAQ2_N2JBSB",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUcaEY9lsaZ3meoVzY1M97O",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUkkzHxv_aSHAHCqLaGz_Mn",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfVrinRqF5sLNXOEHUIqqwf0",
"https://www.youtube.com/playlist?list=PLykNNMVjCDfUKFWDRi6mc4M7FA4eCjGaT",
"https://www.youtube.com/watch?v=rSHf81j_PQE",
"https://www.youtube.com/watch?v=ChGALXClzH4",
"https://www.youtube.com/watch?v=MiCLnDDZ4w0",
"https://www.youtube.com/watch?v=BJAnJ8b6q5M",
"https://www.youtube.com/watch?v=D50XrYiinNc",
"https://www.youtube.com/c/bmpromotion/videos",
]
for url in urls:
self.archive.parse_videos(url)
self.schedule_event(self._sync_db, random.randint(3600, 24*3600))

# matching
def match_skill(self, phrase, media_type):
score = 0
if self.voc_match(phrase, "music") or media_type == MediaType.MUSIC:
score += 10
if self.voc_match(phrase, "trve"):
score += 10
if self.voc_match(phrase, "black-metal"):
score += 90
return score

def get_playlist(self, score=50, num_entries=100, idx=1):
entries = list(self.archive.db.items())
entries = list(self.archive.items())
random.shuffle(entries)
entries = entries[:num_entries]
pl = [{
Expand All @@ -138,13 +83,50 @@ def get_playlist(self, score=50, num_entries=100, idx=1):

@ocp_search()
def search_db(self, phrase, media_type):
base_score = self.match_skill(phrase, media_type)
if base_score >= 50:
base_score = 15 if media_type == MediaType.MUSIC else 0
entities = self.ocp_voc_match(phrase)

base_score += 30 * len(entities)

candidates = list(self.archive.values())
artist = entities.get("artist_name")
album = entities.get("album_name")
song = entities.get("song_name")

if artist or song or album:
# filter valid results
if artist:
candidates = [video for video in candidates
if artist.lower() in video["title"].lower()]
elif album:
candidates = [video for video in candidates
if album.lower() in video["title"].lower()]
elif song:
candidates = [video for video in candidates
if song.lower() in video["title"].lower()]

for video in candidates:
yield {
"title": video["title"],
"author": artist or video["author"],
"album": album,
"match_confidence": min(100, base_score),
"media_type": MediaType.MUSIC,
"uri": "youtube//" + video["url"],
"playback": PlaybackType.AUDIO,
"skill_icon": self.skill_icon,
"skill_id": self.skill_id,
"image": video["thumbnail"],
"bg_image": self.default_bg
}

# black metal playlists on black metal request
if "music_genre" in entities:
for i in range(5):
yield self.get_playlist(base_score, idx=i + 1)

@ocp_featured_media()
def featured_media(self, num_entries=250):
def featured_media(self, num_entries=50):
return [
{
"match_confidence": 100,
Expand All @@ -156,9 +138,16 @@ def featured_media(self, num_entries=250):
"bg_image": self.default_bg,
"skill_icon": self.skill_icon,
"title": entry["title"]
} for entry in self.archive.sorted_entries()
} for entry in self.archive.values()
][:num_entries]


def create_skill():
return BlackMetalSkill()
if __name__ == "__main__":
from ovos_utils.messagebus import FakeBus

s = BlackMetalSkill(bus=FakeBus(), skill_id="t.fake")
for r in s.search_db("burzum", MediaType.MUSIC):
print(r)

for r in s.search_db("xasthur", MediaType.MUSIC):
print(r)
1 change: 0 additions & 1 deletion locale/en-us/black-metal.voc

This file was deleted.

5 changes: 0 additions & 5 deletions locale/en-us/home.intent

This file was deleted.

1 change: 0 additions & 1 deletion locale/en-us/intro.dialog

This file was deleted.

5 changes: 0 additions & 5 deletions locale/en-us/music.voc

This file was deleted.

2 changes: 0 additions & 2 deletions locale/en-us/play.voc

This file was deleted.

4 changes: 0 additions & 4 deletions locale/en-us/trve.voc

This file was deleted.

2 changes: 0 additions & 2 deletions locale/en-us/video.voc

This file was deleted.

7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
py_VOD>=0.4.0
json_database>=0.2.1
ovos_utils>=0.0.8a1
requests
ovos-utils >= 0.1.0a7
ovos-bus-client>=0.0.9a2
ovos-workshop>=0.0.16a3

0 comments on commit 16d3190

Please sign in to comment.