Exemple #1
0
"""Functions related to jiosaavn."""

from playx.playlist.playlistbase import (PlaylistBase, SongMetadataBase)

from bs4 import BeautifulSoup
import requests
from json import JSONDecoder
import re

from playx.logger import (Logger)

# Setup logger
logger = Logger('JioSaavn')


class SongMetadata(SongMetadataBase):
    def __init__(self, title='', subtitle=''):
        super().__init__()
        self.title = title
        self.subtitle = subtitle
        self._create_search_querry()
        self._remove_duplicates()

    def _create_search_querry(self):
        """
        Create a search querry.
        """
        self.search_querry = self.title + ' ' + self.subtitle


class JioSaavnIE(PlaylistBase):
Exemple #2
0
    For now, simple counter is used to create a "naive" baseline auto-playlist.
"""

import pathlib
import re
import random

from collections import Counter

from abc import ABC, abstractmethod

from playx.stringutils import remove_multiple_spaces, remove_punct
from playx.logger import Logger
from playx.utility import softmax

logger = Logger("autoplaylist")


class AbstractAutoPlaylist(ABC):
    def __init__(self, log_path):
        self.log_path = pathlib.Path(log_path).expanduser()
        self.data = []

    @abstractmethod
    def generate(self):
        """
            Override this method to create any arbitary playlist
        """
        pass

    def info(self):
Exemple #3
0
"""
Functions related to gaana playlist.
"""

import requests
from bs4 import BeautifulSoup
import re

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase

from playx.logger import Logger

# Setup logger
logger = Logger("Gaana")


class SongMetadata(SongMetadataBase):
    """
    title: Title of the song
    track_seokey: Seokey of the track
    album_seokey: Seokey of the album
    artist_seokey: Seokey of the artist(s).
    In case more than one artist then they will be added
    seperated by a ' ' to the artist_seokey
    """
    def __init__(
        self,
        artist_tuple=[],
        title="",
        track_seokey="",
        album_seokey="",
Exemple #4
0
#!/usr/bin/env python3
"""A utility module for misc operations."""

import os
import subprocess
from shutil import move
from playx.lyrics import search_lyricswikia
from playx.logger import Logger

# Setup logger
logger = Logger("utility")


def exe(command):
    """Execute the command externally."""
    command = command.strip()
    c = command.split()
    output, error = subprocess.Popen(c,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE).communicate()
    output = output.decode("utf-8").strip()
    error = error.decode("utf-8").strip()
    return (output, error)


def direct_to_play(url, show_lyrics, title):
    """Direct the song to be played according to the play_type."""
    if show_lyrics:
        lyric = search_lyricswikia(title)
        print("----\n{}\n----".format(lyric))
Exemple #5
0
"""Functions related to soundcloud playlists."""

import requests
import re

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase

from playx.logger import Logger

# Setup logger
logger = Logger("Soundcloud")


class SoundCloudTrack(SongMetadataBase):
    def __init__(self, title, download_url, URL):
        super().__init__()
        self.title = title
        self.download_url = download_url
        self.URL = URL

    def _create_search_querry(self):
        """
        Create a search querry.
        """
        self.search_querry = self.URL


class SoundCloudPlaylistExtractor(PlaylistBase):
    """
    Class to scrap Soundcloud playlists.
Exemple #6
0
"""Youtube music playlist related functions and classes
defined.
"""

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase
from playx.stringutils import remove_punct

from playx.logger import Logger

# Setup logger
logger = Logger("YouTubeMusic")


class YtMusicMetadata(SongMetadataBase):
    """Store data of YouTube Music songs."""

    def __init__(self, url="", title="", artist=""):
        super().__init__()
        self.URL = url
        self.title = title
        self.artist = artist
        self._create_querry()

    def _create_querry(self):
        self.search_querry = self.title + " " + self.artist


class YtMusicPlaylist(PlaylistBase):
Exemple #7
0
"""Functions to handle the caching of playlists."""

from pathlib import Path
from os import makedirs
import os
import json
import glob

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase

from playx.logger import Logger

# Get the logger
logger = Logger("PlaylistCache")


class PlaylistCache:
    """
    All functions related to playlist caching are
    defined here.

    The structure of the cached playlist is following
    -----------------------------------------
    |[Name]:[<name of the playlist>]        |
    |[URL]:[<URL of the playlist>]          |
    |[Type]:[<PlaylistType>]                |
    |[Song]:[Song name, URL of song, query]|
    |........                               |
    |........                               |
    -----------------------------------------
Exemple #8
0
import re

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from pathlib import Path
import json

from youtube_dl import YoutubeDL
from youtube_dl.utils import DownloadError

from playx.playlist.playlistbase import SongMetadataBase, PlaylistBase

from playx.logger import Logger

logger = Logger("YoutubeRelated")


class YoutubeMetadata(SongMetadataBase):
    def __init__(self, url=None):
        super().__init__()
        self.url = url
        self._create_search_query()

    def _create_search_query(self):
        """
        Update the search query using the passed URL.
        """
        self.search_query = self.url

Exemple #9
0
from bs4 import BeautifulSoup
from dataclasses import dataclass

import requests
import youtube_dl
from playx.stringutils import fix_title, is_song_url

from playx.cache import Cache

from playx.utility import exe

from playx.logger import Logger

# Setup logger
logger = Logger("youtube")

better_search_kw = [" audio", " full", " lyrics"]


@dataclass
class YoutubeMetadata:
    """A data store to store the information of a youtube video."""

    title: str = ""
    url: str = ""
    duration: str = ""

    def display(self):
        """Be informative."""
        logger.info(str(self))
Exemple #10
0
from playx.songfinder import search

from playx.logger import Logger

from playx.stringutils import is_song_url, url_type

from playx.soundcloud import get_track_info

from playx.playlist.ytrelated import get_data

from playx.playlist import playlistcache

from os.path import basename

# Setup logger
logger = Logger("player")


class URLPlayer:
    """
    Currently support for soundcloud and youtube URL's are added.
    """
    def __init__(
        self,
        URL=None,
        songObj=None,
        dont_cache_search=False,
        show_lyrics=False,
        no_cache=False,
    ):
        self.URL = URL
Exemple #11
0
import re
from bs4 import BeautifulSoup
import urllib.request, urllib.error, urllib.parse
import sys
from playx.stringutils import (
    urlencode,
    remove_punct,
    compute_jaccard,
    remove_multiple_spaces,
)

from playx.logger import Logger

# setup logger
logger = Logger("lyrics")


class ManualError(Exception):
    def __init__(self, args):
        self.args = args

    def display(self):
        print(" ".join(self.args))


def search_lyricswikia(query):
    logger.info("Searching [{}] at lyrics.wikia.com".format(query))
    query = remove_multiple_spaces(query).lower()
    tokens1 = query.split()
    query = urlencode(query.lower())
Exemple #12
0
import urllib.request

from json.decoder import JSONDecodeError

from playx.stringutils import (
    remove_multiple_spaces,
    remove_punct,
    compute_jaccard,
    remove_stopwords,
    check_keywords,
    fix_title,
)
from playx.logger import Logger

# Setup logger
logger = Logger("cache")


class Cache:
    """Class to cache the song to a dir for quick acces."""
    def __init__(self, directory="~/.playx/songs"):
        """
            Init the stuff.
            directory: the directory where songs lie

            Note:
                The reason for choosing `playx/songs` is that I have allocated
                other tree structure for misc activities like `playx/logs` and
                `playx/playxlist`
        """
        self.dir = os.path.expanduser(directory)
Exemple #13
0
"""Simple API to access Billboard charts."""


import requests
from bs4 import BeautifulSoup
import re
import os

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase

from playx.logger import Logger

# Setup logger
logger = Logger("Billboard")


"""
__author__ = Deepjyoti Barman
__github__ = github.com/deepjyoti30

"""


class Song(SongMetadataBase):
    """Class to store song details."""

    def __init__(self, title="", artist="", rank=0):
        super().__init__()
        self.title = title
        self.artist = artist
        self.rank = 0
Exemple #14
0
"""Functions related to jiosaavn."""

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase

from bs4 import BeautifulSoup
import requests
from json import JSONDecoder
import re

from playx.logger import Logger

# Setup logger
logger = Logger("JioSaavn")


class SongMetadata(SongMetadataBase):
    def __init__(self, title="", subtitle=""):
        super().__init__()
        self.title = title
        self.subtitle = subtitle
        self._create_search_querry()
        self._remove_duplicates()

    def _create_search_querry(self):
        """
        Create a search querry.
        """
        self.search_querry = self.title + " " + self.subtitle


class JioSaavnIE(PlaylistBase):
Exemple #15
0
"""

import json
import requests
from bs4 import BeautifulSoup
import re

from playx.utility import exe

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase
from playx.stringutils import remove_punct

from playx.logger import Logger

# Setup logger
logger = Logger("YoutubePlaylist")


class YoutubeMetadata(SongMetadataBase):
    def __init__(self, url="", title=""):
        super().__init__(title, url, "")
        self._create_search_query()

    def _create_search_query(self):
        """
        Create a search querry.
        """
        self.search_query = self.URL

    def display(self):
        """Be informative."""
Exemple #16
0
    spotify,
    youtube,
    billboard,
    soundcloud,
    jiosaavn,
    gaana,
    playlistcache,
    ytmusic,
)

import re
from random import shuffle
from playx.logger import Logger

# Get the logger
logger = Logger("Playlist")
"""
__author__ = Deepjyoti Barman
__github__ = github.com/deepjyoti30
"""


class Playlist:
    """Class for every kind of playlist supported."""
    def __init__(self, URL, pl_start, pl_end, is_shuffle=False):
        """
        URL: Passed URL
        pl_start: Playlist start index.
        pl_end: Playlist end index.
        """
        self.URL = URL
Exemple #17
0
"""Functions related to playxlist."""

import os
import random

from playx.playlist.playlistbase import PlaylistBase

from playx.logger import Logger

# Setup logger
logger = Logger("Playxlist")


class Playxlist(PlaylistBase):
    """Class to store playx list data."""

    def __init__(self, content, pl_start=None, pl_end=None, shuffle=False):
        """
            Initialize with either filepath or content.
            Content represent either filepath or list of song names
        """
        super().__init__(pl_start, pl_end, shuffle=shuffle)
        if type(content) is list:
            self.file_path = None
            self.list_content_tuple = content
        if type(content) is str:
            self.list_content_tuple = []
            self.file_path = content

    def is_playx_list(self):
        """Check if the passed filepath is a playx playlist."""
Exemple #18
0
"""File to modify the playlists."""

from playx.logger import Logger

from playx.stringutils import remove_duplicates

# Setup logger
logger = Logger("PlaylistBase")


class SongMetadataBase:
    """
    Base class to store song metadata.
    """
    def __init__(self, title=None, url=None, query=None):
        self.title = title
        self.search_query = query
        self.URL = url
        self.better_search_kw = [
            # ' audio',
            # ' lyrics',
            # ' full'
        ]

    def _add_better_search_words(self):
        """
        Add the keywords in better_search_kw list to get a better result.
        """
        for kw in self.better_search_kw:
            self.search_query += kw
Exemple #19
0
from requests import get
from bs4 import BeautifulSoup
import re

from playx.playlist.playlistbase import PlaylistBase, SongMetadataBase

from playx.logger import Logger

# Setup logger
logger = Logger("Spotify")


class SpotifySong(SongMetadataBase):
    """Spotify songs container."""
    def __init__(self, title="", artist="", album=""):
        super().__init__()
        self.title = title
        self.artist = artist
        self.album = album
        self._create_search_querry()
        self._remove_duplicates()

    def _create_search_querry(self):
        """
        Create a search querry.
        """
        self.search_querry = self.title + " " + self.artist


class SpotifyIE(PlaylistBase):
    """Spotify playlist data extractor."""
Exemple #20
0
from .version import __version__
from playx.logger import Logger

from playx.cache import Cache, clean_url_cache
from playx.utility import run_mpv_dir
from playx.youtube import grab_link
from playx.playlist.playlist import Playlist
from playx.playlist.playxlist import Playxlist
from playx.player import Player
from playx.songfinder import search
from playx.playlist.autoplaylist import MarkovBasedAutoPlaylist
from playx.playlist.playlistcache import list_all

# Get the logger
logger = Logger("main")


def parse():
    """Parse the arguments."""
    parser = argparse.ArgumentParser(description="playx - Search and play\
                                     any song that comes to your mind.\n\
                                     If you have any issues, raise an issue in\
                                     the github\
                                     (https://github.com/NISH1001/playx) page")
    parser.add_argument("--version", action="version", version=__version__)
    parser.add_argument(
        "song",
        help="Name or youtube link of song to download",
        default=None,
        type=str,