Skip to content

Commit

Permalink
Added m4a extension file and extract tags from file
Browse files Browse the repository at this point in the history
  • Loading branch information
son-link committed Dec 24, 2023
1 parent b879701 commit 26e10fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions PQMusic/player.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from urllib.parse import urlparse
from os import path, access, R_OK, mkdir, environ, listdir
from pathlib import Path

from PyQt5.QtMultimedia import (
QMediaPlayer,
QMediaPlaylist,
Expand All @@ -7,10 +11,8 @@
from PyQt5.QtCore import QUrl, QCoreApplication, QSize, Qt
from PyQt5.QtGui import QIcon, QPixmap, QStandardItem
from PyQt5 import QtWidgets
from pathlib import Path
from .utils import getMetaData, openM3U, saveM3U, getTrackerTitle, notify
from urllib.parse import urlparse
from os import path, access, R_OK, mkdir, environ, listdir

from .covers import searchTrackInfo, downCover

import magic
Expand Down Expand Up @@ -121,7 +123,7 @@ def changePos(self, pos):
self.player.play()

def checkValidFile(self, file):
""" Check if the file is a valid audio file.
""" Check if the file is a valid audio file or m4a.
Args:
file : str
Path to the file
Expand All @@ -130,8 +132,12 @@ def checkValidFile(self, file):
"""
if access(file, R_OK):
f = magic.Magic(mime=True)

if f.from_file(file).startswith('audio'):
mimetype = f.from_file(file)
_, extension = path.splitext(file)
if (
mimetype.startswith('audio') or
(mimetype == 'video/mp4' and extension == '.m4a')
):
return True

return False
Expand Down Expand Up @@ -320,7 +326,6 @@ def __getcover(data):
timeout=3000
)


def openPlaylist(self, file=None):
""" Opens the dialog to select files to add """
if not file:
Expand Down
3 changes: 3 additions & 0 deletions PQMusic/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mutagen import File
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3
from mutagen.easymp4 import EasyMP4
from pathlib import Path
from os import (
access,
Expand Down Expand Up @@ -75,6 +76,8 @@ def getMetaData(filename):
return tags
elif ext == 'mp3':
info = MP3(filename, ID3=EasyID3)
elif ext == 'm4a':
info = EasyMP4(filename)
else:
info = File(filename)

Expand Down

0 comments on commit 26e10fb

Please sign in to comment.