Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
V1p3rOne committed Oct 20, 2024
2 parents aa024d1 + e3eec18 commit 4e82d09
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 262 deletions.
23 changes: 6 additions & 17 deletions src/onthespot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
#!/usr/bin/env python3
import os
import sys
import threading
from PyQt6.QtCore import QTranslator
from PyQt6.QtWidgets import QApplication
from .gui.mainui import MainWindow
from .gui.minidialog import MiniDialog
from .runtimedata import get_logger
from .otsconfig import config
from .parse_item import worker
import threading

from .api.spotify import spotify_login_user

def main():
logger = get_logger('__init__')
logger.info('Starting application in \n3\n2\n1')
app = QApplication(sys.argv)








thread = threading.Thread(target=worker)
thread.daemon = True # Ensure thread exits when main program does
thread.start()





# Set Application Version
version = "v0.7.1"
logger.info(f'OnTheSpot Version: {version}')
Expand Down Expand Up @@ -68,6 +52,11 @@ def main():
translator.load(path)
app.installTranslator(translator)

# Start Item Parser
thread = threading.Thread(target=worker)
thread.daemon = True
thread.start()

# Check for start url
try:
if sys.argv[1] == "-u" or sys.argv[1] == "--url":
Expand Down
9 changes: 5 additions & 4 deletions src/onthespot/accounts.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from .runtimedata import get_logger, account_pool
from .otsconfig import config

import threading

from PyQt6.QtCore import QThread, pyqtSignal
from .api.spotify import spotify_login_user, spotify_get_token
from .api.soundcloud import soundcloud_login_user, soundcloud_get_token


logger = get_logger("spotify.downloader")

class FillAccountPool(QThread):
finished = pyqtSignal()
progress = pyqtSignal(str, bool)
Expand All @@ -16,8 +17,8 @@ def __init__(self, gui=False):
super().__init__()

def run(self):
account_list = config.get('accounts')
for account in account_list:
accounts = config.get('accounts')
for account in accounts:
service = account['service']
if not account['active']:
continue
Expand Down
18 changes: 4 additions & 14 deletions src/onthespot/api/soundcloud.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import re
import os
import subprocess
import requests
import threading
from ..otsconfig import config
from ..runtimedata import get_logger, account_pool, parsing
from ..utils import sanitize_data


SOUNDCLOUD_BASE = "https://api-v2.soundcloud.com"

SOUNDCLOUD_CLIENT_ID = "AADp6RRMinJzmrc26qh92jqzJOF69SwF"
SOUNDCLOUD_APP_VERSION = "1728640498"
SOUNDCLOUD_APP_LOCALE = "en"

from ..otsconfig import config

import re
import requests
import logging
from ..runtimedata import get_logger, account_pool, parsing

from ..utils import sanitize_data

logger = get_logger("worker.utility")



def soundcloud_parse_url(url):
headers = {}
headers["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
Expand Down
51 changes: 11 additions & 40 deletions src/onthespot/api/spotify.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
import base64
import os
import re
import string
import subprocess
import requests.adapters
from ..otsconfig import config, cache_dir
from ..post_download import conv_list_format
import requests
import time
import uuid
import json
from hashlib import md5
import requests
import requests.adapters
from librespot.audio.decoders import AudioQuality
from librespot.core import Session
from librespot.zeroconf import ZeroconfServer
from mutagen import File
from mutagen.easyid3 import EasyID3, ID3
from mutagen.flac import Picture, FLAC
from mutagen.id3 import APIC, TXXX, USLT, WOAS
from mutagen.mp4 import MP4, MP4Cover
from mutagen.oggvorbis import OggVorbis
from pathlib import Path
from PIL import Image
from io import BytesIO
from hashlib import md5
from ..runtimedata import get_logger, session_pool, account_pool
from librespot.audio.decoders import AudioQuality

from ..otsconfig import config, cache_dir
from ..post_download import conv_list_format
from ..runtimedata import get_logger, account_pool
from ..post_download import set_audio_tags

from librespot.core import Session

from ..utils import sanitize_data

import os
import pathlib
import sys
import time
import uuid
from librespot.zeroconf import ZeroconfServer
from ..otsconfig import cache_dir, config
from ..runtimedata import get_logger
import json


logger = get_logger("spotify.api")
Expand Down Expand Up @@ -703,21 +689,6 @@ def spotify_get_show_episodes(session, show_id_str):

return episodes


def get_thumbnail(image_dict, preferred_size=22500):
images = {}
for image in image_dict:
try:
images[image['height'] * image['width']] = image['url']
except TypeError:
# Some playlist and media item do not have cover images
pass
available_sizes = sorted(images)
for size in available_sizes:
if size >= preferred_size:
return images[size]
return images[available_sizes[-1]] if len(available_sizes) > 0 else ""

def make_call(url, token, params=None, headers=None, skip_cache=False):
if params is None:
params = {}
Expand Down
24 changes: 5 additions & 19 deletions src/onthespot/downloader.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import os
import traceback
import time
import subprocess
from PyQt6.QtCore import QThread, pyqtSignal
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality
from librespot.metadata import TrackId, EpisodeId
#from .spotify.api import get_item_metadata, get_episode_info, get_track_lyrics, check_premium
#from .utils.utils import re_init_session, fetch_account_uuid, sanitize_data
from .runtimedata import get_logger, download_queue, download_queue_gui, downloads_status, downloaded_data, failed_downloads, cancel_list, \
session_pool, thread_pool
from .runtimedata import get_logger, download_queue
from .otsconfig import config
from .post_download import convert_audio_format, set_audio_tags, set_music_thumbnail
import traceback
from PyQt6.QtCore import QThread, pyqtSignal
from .api.spotify import spotify_get_token, spotify_get_track_metadata, spotify_get_episode_metadata, spotify_format_track_path, spotify_format_episode_path, spotify_get_lyrics
from .api.soundcloud import soundcloud_get_token, soundcloud_get_track_metadata, soundcloud_format_track_path
#, soundcloud_download_track
import time
import requests

from .accounts import get_account_token

import re
import os
import subprocess
import requests
import threading

from .runtimedata import parsing, download_queue, pending, failed, completed, cancelled


logger = get_logger("spotify.downloader")


Expand Down
5 changes: 1 addition & 4 deletions src/onthespot/gui/dl_progressbtn.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import platform
import os
import subprocess
import pyperclip
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QHBoxLayout, QWidget
from ..otsconfig import config
from ..runtimedata import downloaded_data, cancel_list, failed_downloads, downloads_status, download_queue, session_pool, get_logger
from ..runtimedata import download_queue, get_logger
from ..utils import open_item
from ..api.spotify import check_if_media_in_library, save_media_to_library, remove_media_from_library, queue_media, play_media

from ..runtimedata import download_queue_gui

logger = get_logger("worker.utility")

Expand Down
33 changes: 9 additions & 24 deletions src/onthespot/gui/mainui.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
import os
import queue
import time
import threading
import uuid
from PyQt6 import uic, QtNetwork, QtGui
from PyQt6.QtCore import QThread, QDir, Qt
from urllib3.exceptions import MaxRetryError, NewConnectionError
from PyQt6 import uic, QtGui
from PyQt6.QtCore import QThread, QDir, Qt, pyqtSignal, QObject, QTimer
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QMainWindow, QHeaderView, QLabel, QPushButton, QProgressBar, QTableWidgetItem, QFileDialog, QRadioButton
from ..api.spotify import get_thumbnail
from ..utils import name_by_from_sdata, remove_user, re_init_session, latest_release, open_item

from ..utils import re_init_session, latest_release, open_item
from .dl_progressbtn import DownloadActionsButtons
from .settings import load_config, save_config
from .minidialog import MiniDialog
from ..otsconfig import config_dir, config
from ..parse_item import parse_url
from ..runtimedata import get_logger, downloads_status, downloaded_data, failed_downloads, cancel_list, \
session_pool, thread_pool
from ..otsconfig import config
from ..runtimedata import get_logger, parsing, pending, download_queue, account_pool
from .thumb_listitem import LabelWithThumb
from urllib3.exceptions import MaxRetryError, NewConnectionError

from ..runtimedata import parsing, pending, failed, completed, cancelled, download_queue, account_pool

from PyQt6.QtCore import QThread, pyqtSignal, QObject, QTimer

from ..api.spotify import spotify_get_token, spotify_get_track_metadata, spotify_get_episode_metadata, spotify_new_session
from ..post_download import conv_list_format

from ..accounts import get_account_token

from ..api.soundcloud import soundcloud_get_token, soundcloud_get_track_metadata
from ..post_download import conv_list_format
from ..accounts import get_account_token, FillAccountPool
from ..search import get_search_results
import time
from ..downloader import DownloadWorker
from ..accounts import FillAccountPool

logger = get_logger('gui.main_ui')


Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/gui/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from PyQt6.QtGui import QIcon
from ..otsconfig import config_dir, config
from ..otsconfig import config


def load_config(self):
Expand Down
31 changes: 12 additions & 19 deletions src/onthespot/parse_item.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
import re
import time
#from .parse_url import parse_url
import queue
from .otsconfig import config

from .api.spotify import spotify_get_token, spotify_get_album_tracks, spotify_get_playlist_data, spotify_get_playlist_items, spotify_get_artist_albums, spotify_get_show_episodes


from .api.soundcloud import soundcloud_parse_url, soundcloud_get_set_items


from .runtimedata import get_logger, download_queue, downloads_status, downloaded_data, failed_downloads, cancel_list, \
session_pool, thread_pool

from .runtimedata import parsing, download_queue, pending, failed, completed, cancelled
from .runtimedata import get_logger, parsing, download_queue, pending
from .accounts import get_account_token
import re


logger = get_logger('gui.main_ui')

SOUNDCLOUD_URL_REGEX = re.compile(r"https://soundcloud.com/[-\w:/]+")
SPOTIFY_URL_REGEX = re.compile(r"^(https?://)?open\.spotify\.com/(?P<Type>track|album|artist|playlist|episode|show)/(?P<ID>[0-9a-zA-Z]{22})(\?si=.+?)?$")
SPOTIFY_INTERNATIONAL_URL_REGEX = re.compile(r"^(https?://)?open\.spotify\.com/intl-([a-zA-Z]+)/(?P<Type>track|album|artist|playlist|episode|show)/(?P<ID>[0-9a-zA-Z]{22})(\?si=.+?)?$")
SPOTIFY_URL_REGEX = re.compile(r"^(https?://)?open\.spotify\.com/(intl-([a-zA-Z]+)/|)(?P<Type>track|album|artist|playlist|episode|show)/(?P<ID>[0-9a-zA-Z]{22})(\?si=.+?)?$")
#QOBUZ_INTERPRETER_URL_REGEX = re.compile(r"https?://www\.qobuz\.com/\w\w-\w\w/interpreter/[-\w]+/([-\w]+)")
#YOUTUBE_URL_REGEX = re.compile(r"https://www\.youtube\.com/watch\?v=[-\w]")




def parse_url(url):
if re.match(SOUNDCLOUD_URL_REGEX, url):
accounts = config.get('accounts')
account_service = accounts[config.get('parsing_acc_sn') - 1]['service']
print(account_service)
if account_service == 'soundcloud' and re.match(SOUNDCLOUD_URL_REGEX, url):
item_type, item_id = soundcloud_parse_url(url)
item_service = "soundcloud"
elif re.match(SPOTIFY_URL_REGEX, url) or re.match(SPOTIFY_INTERNATIONAL_URL_REGEX, url):
elif account_service == 'spotify' and re.match(SPOTIFY_URL_REGEX, url):
match = re.search(SPOTIFY_URL_REGEX, url)
item_id = match.group("ID")
item_type = match.group("Type")
item_service = "spotify"
else:
logger.info('Invalid Url')
return
parsing[item_id] = {
'item_url': url,
'item_service': item_service,
Expand Down
20 changes: 1 addition & 19 deletions src/onthespot/runtimedata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from queue import Empty, Queue
from .otsconfig import config
import sys
import os
import logging
from logging.handlers import RotatingFileHandler

from .otsconfig import config

log_formatter = logging.Formatter(
'[%(asctime)s :: %(name)s :: %(pathname)s -> %(lineno)s:%(funcName)20s() :: %(levelname)s] -> %(message)s'
Expand All @@ -18,28 +16,12 @@
stdout_handler = logging.StreamHandler(sys.stdout)
log_handler.setFormatter(log_formatter)
stdout_handler.setFormatter(log_formatter)
download_queue = Queue()
thread_pool = {}
session_pool = {}

parsing = {}
pending = {}
download_queue = {}
account_pool = []


download_queue_gui = []
failed = []
completed = []
cancelled = []

failed_downloads = {}
cancel_list = {}
downloads_status = {}
playlist_m3u_queue = {}
downloaded_data = {}
unavailable = set()

loglevel = int(os.environ.get("LOG_LEVEL", 20))


Expand Down
Loading

0 comments on commit 4e82d09

Please sign in to comment.