Skip to content

Commit

Permalink
Merge pull request #3 from lachhebo/dev
Browse files Browse the repository at this point in the history
MusicBrainz Feature
  • Loading branch information
lachhebo authored Jun 2, 2019
2 parents 12e42ee + 59528ca commit ca1d700
Show file tree
Hide file tree
Showing 12 changed files with 699 additions and 83 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <img width="30" src="data/icons/hicolor/scalable/apps/com.github.lachhebo.Gabtag.svg"/> Marker GabTag [![Build Status](https://travis-ci.com/lachhebo/GabTag.svg?branch=master)](https://travis-ci.com/lachhebo/GabTag)
# <img width="30" src="data/icons/hicolor/scalable/apps/com.github.lachhebo.Gabtag.svg"/> GabTag [![Build Status](https://travis-ci.com/lachhebo/GabTag.svg?branch=master)](https://travis-ci.com/lachhebo/GabTag)


## Description :
Expand All @@ -15,13 +15,13 @@ It uses Mutagen to handle tags. I hope to make it available on Flathub as soon a
- [x] MP3 File handled
- [ ] Flac File handled
- [ ] bold font on modified tags and files
- [ ] Automatic completion of tags (from web data)
- [x] Automatic completion of tags (from web data)
- [ ] Multi-folder modification


## Screenshots:

![ScreenShot](https://raw.githubusercontent.com/lachhebo/GabTag/screenshots/Image3.png)
![ScreenShot](https://raw.githubusercontent.com/lachhebo/GabTag/screenshots/GabTag_V1_1.png)


## Installation :
Expand Down
41 changes: 28 additions & 13 deletions com.github.lachhebo.Gabtag.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"command": "gabtag",
"finish-args": [
"--filesystem=home",
"--share=network",
"--share=ipc",
"--socket=x11",
"--socket=wayland",
Expand Down Expand Up @@ -41,18 +42,32 @@
]
},
{
"name": "python3-Pillow",
"buildsystem": "simple",
"build-commands": [
"pip3 install --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} Pillow"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/81/1a/6b2971adc1bca55b9a53ed1efa372acff7e8b9913982a396f3fa046efaf8/Pillow-6.0.0.tar.gz",
"sha256": "809c0a2ce9032cbcd7b5313f71af4bdc5c8c771cb86eb7559afd954cab82ebb5"
}
]
"name": "python3-musicbrainzngs",
"buildsystem": "simple",
"build-commands": [
"pip3 install --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} musicbrainzngs"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/63/cc/67ad422295750e2b9ee57c27370dc85d5b85af2454afe7077df6b93d5938/musicbrainzngs-0.6.tar.gz",
"sha256": "28ef261a421dffde0a25281dab1ab214e1b407eec568cd05a53e73256f56adb5"
}
]
},
{
"name": "python3-Pillow",
"buildsystem": "simple",
"build-commands": [
"pip3 install --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} Pillow"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/81/1a/6b2971adc1bca55b9a53ed1efa372acff7e8b9913982a396f3fa046efaf8/Pillow-6.0.0.tar.gz",
"sha256": "809c0a2ce9032cbcd7b5313f71af4bdc5c8c771cb86eb7559afd954cab82ebb5"
}
]
},
{
"name": "gabtag",
Expand All @@ -62,7 +77,7 @@
"sources": [
{
"type": "git",
"tag": "v1.0.5",
"tag": "v1.1.0",
"url": "https://github.com/lachhebo/GabTag"
}
]
Expand Down
15 changes: 7 additions & 8 deletions data/com.github.lachhebo.Gabtag.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-3.0-or-later</project_license>
<releases>
<release date="2019-05-28" version="1.0.5"/>
<release date="2019-06-02" version="1.1.0"/>
</releases>
<version>1.0.5</version>
<version>1.1.0</version>
​<categories>
<category>Audio</category>
</categories>
Expand All @@ -19,17 +19,16 @@
and efficiency.
</p>
<p>
It consists of two main components, a file tree and a grid box. It allow
users to select several file and modify their tags. Actually it is possible
to set the title, album, artist, cover, track release and track number.
It allow users to select several file and modify their tags, It is also possible to directly let GabTag automatically
find tags for the audio files using online data.
</p>
<p>
GabTag is written in Python 3 and uses Mutagen API to handle audio tags.
GabTag is written in Python 3, uses Mutagen to handle audio tags and MusicBrainz database to find audio tags online.
</p>
</description>
<screenshots>
<screenshot type="default" height="647" width="800">
<image>https://raw.githubusercontent.com/lachhebo/GabTag/screenshots/Image3.png</image>
<screenshot type="default" height="647" width="847">
<image>https://raw.githubusercontent.com/lachhebo/GabTag/screenshots/GabTag_V1_1.png</image>
<caption/>
</screenshot>
</screenshots>
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mutagen==1.42.0
pycairo>=1.11.1
musicbrainzngs
pygobject
Pillow
44 changes: 35 additions & 9 deletions src/MP3Handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __init__(self,path_file):
self.id3 = self.audio.tags


def getextensiontype(self):
return ".mp3"

def get_one_tag(self,id3_nametag,data_type):
'''
A function to return the first tag of an id3 label
Expand All @@ -34,6 +37,14 @@ def get_one_tag(self,id3_nametag,data_type):
return ""


def get_tag_research(self):
return [
self.get_one_tag('TIT2',"text"),
self.get_one_tag('TPE1',"text"),
self.get_one_tag('TALB',"text")
]


def getTag(self,tag_key):
'''
We handle tag using a switch, it is working well because it is basically the structure.
Expand Down Expand Up @@ -97,19 +108,34 @@ def check_tag_existence(self,key):
def setTag(self,tag_key,tag_value):

if tag_key == "cover":
extension_image = self.get_extension_image(tag_value)

self.id3.delall('APIC')

self.id3.add(
APIC(
encoding = 3, # UTF-8
mime= extension_image, # '/image/png'
type= 3, # 3 is for album art
desc='Cover',
data= open(tag_value, 'rb').read()
if tag_value == "" :
pass
elif type(tag_value) == bytes :
self.id3.add(
APIC(
encoding = 3, # UTF-8
mime= "/image/png", # '/image/png'
type= 3, # 3 is for album art
desc='Cover',
data= tag_value
)
)
)
else :
extension_image = self.get_extension_image(tag_value)
print("type of tag_value : ",type(tag_value))
self.id3.add(
APIC(
encoding = 3, # UTF-8
mime= extension_image, # '/image/png'
type= 3, # 3 is for album art
desc='Cover',
data= open(tag_value, 'rb').read()
)
)

elif tag_key == "title":
self.id3.delall("TIT2")
self.id3.add(TIT2(encoding=3, text=tag_value))
Expand Down
159 changes: 159 additions & 0 deletions src/data_scrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import musicbrainzngs as mb
from os import walk
from .moteur import Moteur
import threading
from .view import View
from gi.repository import Gtk

class Data_Scrapper :


class __Data_Scrapper :


def __init__(self):
mb.set_useragent("GabTag", version = "1.0.5", contact = "[email protected]")
self.tag_finder = {}
self.view = View.getInstance()


def scrap_one_tag(self,namefile, directory):
if Moteur().check_extension(namefile) :
audio = Moteur().getFile(namefile,directory)

tags = audio.get_tag_research()

if tags[0] == "" and tags[1] == "" :
## Either filename if no_tags
mzquery = self.remove_extension(namefile)
self.tag_finder[namefile] = self.reorder_data(mb.search_recordings(query = mzquery,limit=1))
else :
## Using tags title artist and album if they are present
if tags[0] != "" and tags[1] != 0 :
self.tag_finder[namefile] = self.reorder_data(mb.search_recordings(recording = tags[0], artistname = tags[1],limit=1))
elif tags[1] == "" :
self.tag_finder[namefile] = self.reorder_data(mb.search_recordings(recording = tags[0], release = tags[2],limit=1))
elif tags[0] == "" :
self.tag_finder[namefile] = self.reorder_data(mb.search_recordings(query = self.remove_extension(namefile), artistname = tags[1],limit=1))
else :
print("BIG ISSUE")


def update_tag_finder(self,modifications, directory,store):
for namefile in modifications :
self.scrap_one_tag(namefile,directory)


def scrap_tags(self,directory,store):
self.tag_finder = {}

filelist = []
for (dirpath, dirnames, filenames) in walk(directory):
filelist.extend(filenames)
break

i = 0
for namefile in filelist:
if Moteur().check_extension(namefile) :
self.scrap_one_tag(namefile,directory)
path = Gtk.TreePath(i)
listiter = store.get_iter(path)
store.set_value(listiter,1,"Yes")
i = i+1

def get_tags(self,model,listiter, multiline_selected):

namefile = model[listiter][0]
if namefile in self.tag_finder :
alpha = self.tag_finder[namefile]
else :
return { "title":"", "artist":"", "album":"", "track":"", "year":"", "genre":"", "cover":""}


if multiline_selected == 1 :
for i in range(1,len(listiter)):
beta = model[listiter[i]][0]
if beta in self.tag_finder :
for tagi in ["artist","album","year","genre","cover"] :
if alpha[tagi] != self.tag_finder[beta][tagi] :
alpha[tagi] = ""
alpha["title"] = ""
alpha["track"] = ""


return alpha

def reorder_data(self,mzdata):
'''
take a bunch of data from mz and make it in the form { title = , ...}
'''

dictionnary = {
"title":"",
"artist": "",
"genre":"",
"cover":"",
"album":"",
"track":"",
"year":""}

if len(mzdata['recording-list']) >= 1 :
dictionnary["title"] = mzdata['recording-list'][0]['title']
dictionnary["artist"] = mzdata['recording-list'][0]['artist-credit'][0]["artist"]["name"]

if 'disambiguation' in mzdata['recording-list'][0]['artist-credit'][0]["artist"]:
dictionnary["genre"] = mzdata['recording-list'][0]['artist-credit'][0]["artist"]["disambiguation"]
else :
dictionnary["genre"] = ""


if 'release-list' in mzdata['recording-list'][0] :
try :
dictionnary["cover"] = mb.get_image(mbid = mzdata['recording-list'][0]["release-list"][0]["id"],coverid = "front", size = 250)
except :
dictionnary["cover"] = ""

dictionnary["album"] = mzdata['recording-list'][0]['release-list'][0]["release-group"]["title"] #album
dictionnary["track"] = mzdata['recording-list'][0]['release-list'][0]["medium-list"][0]['track-list'][0]["number"]
if 'date' in mzdata['recording-list'][0]['release-list'][0] :
dictionnary["year"] = mzdata['recording-list'][0]['release-list'][0]["date"].split("-")[0]
else :
dictionnary["year"] = ""
else :
dictionnary["album"] = ""
dictionnary["track"] = ""
dictionnary["year"] = ""
dictionnary["cover"] = ""

return dictionnary




def remove_extension(self, filename):
'''
return the filename without the extension
'''
namelist = filename.split('.')
#print(namelist)
return namelist[0:-1]




__instance = None

def __init__(self):
""" Virtually private constructor. """
if Data_Scrapper.__instance != None:
raise Exception("This class is a singleton!")
else:
Data_Scrapper.__instance = Data_Scrapper.__Data_Scrapper()


@staticmethod
def getInstance():
""" Static access method. """
if Data_Scrapper.__instance == None:
Data_Scrapper()
return Data_Scrapper.__instance
4 changes: 3 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ gabtag_sources = [
'window.py',
'moteur.py',
'audiobasics.py',
'MP3Handler.py'
'MP3Handler.py',
'data_scrapper.py'

]

install_data(gabtag_sources, install_dir: moduledir)
Loading

0 comments on commit ca1d700

Please sign in to comment.