Esempio n. 1
0
due to all those crawling shit
"""
from bs4 import BeautifulSoup
import requests
from layx.stringutils import (fix_title, is_song_url)

import re

from layx.cache import Cache

from layx.utility import exe

from layx.logger import Logger

# Setup logger
logger = Logger('youtube')

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


class YoutubeMetadata:
    """A data store to store the information of a youtube video."""
    def __init__self(self):
        self.title = ""
        self.url = ""
        self.duration = ""

    def display(self):
        """Be informative."""
        logger.info("Title: {}".format(self.title))
        logger.info("Duration: {}".format(self.duration))
Esempio n. 2
0
#!/usr/bin/env python3
import re
from bs4 import BeautifulSoup
import urllib.request, urllib.error, urllib.parse
import sys
from layx.stringutils import (urlencode, remove_punct, compute_jaccard,
                              remove_multiple_spaces)

from layx.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())
    url = "http://lyrics.wikia.com/wiki/Special:Search?query={}".format(query)
    response = urllib.request.urlopen(url)
    extractor = BeautifulSoup(response.read(), "html.parser")
    divs = extractor.find_all("li", {'class': 'result'})
Esempio n. 3
0
"""
    This module is intended to use Markov Chains for generating playlist automatically.
    For now, simple counter is used to create a "naive" baseline auto-playlist.
"""

import pathlib
import re

from collections import Counter

from abc import (ABC, abstractmethod)

from layx.stringutils import (remove_multiple_spaces, remove_punct)
from layx.logger import Logger

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):
Esempio n. 4
0
#!/usr/bin/env python3
"""A utility module for misc operations."""
import os
import subprocess
from shutil import move
from layx.lyrics import search_lyricswikia
from layx.logger import Logger
import threading

# Setup logger
logger = Logger('utility')


class MPVThread(threading.Thread):
    def __init__(self, URL, title=None):
        threading.Thread.__init__(self)
        self.songURL = URL
        self.title = title

    def run(self):
        logger.info("Playing [{}]".format(self.title))
        #player = MPV(ytdl=True)
        #player.play(self.songURL)
        #player.wait_for_playback()
        pass


def exe(command):
    """Execute the command externally."""
    command = command.strip()
    c = command.split()
Esempio n. 5
0
"""Functions related to soundcloud playlists."""

import requests
import re

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

from layx.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.
    We need to get the set(playlist) id by scraping
Esempio n. 6
0
"""Functions related to layxlist."""

import os

from layx.playlist.playlistbase import (
    PlaylistBase
)

from layx.logger import (
    Logger
)

# Setup logger
logger = Logger("layxlist")


class layxlist(PlaylistBase):
    """Class to store layx list data."""

    def __init__(self, content, pl_start=None, pl_end=None):
        """
            Initialize with either filepath or content.
            Content represent either filepath or list of song names
        """
        super().__init__(pl_start, pl_end)
        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
Esempio n. 7
0
"""Definitions related to caching the song."""
import os
import threading
import glob
import sys
import json
import urllib.request
from json.decoder import JSONDecodeError
from layx.stringutils import (
    remove_multiple_spaces, remove_punct, compute_jaccard, remove_stopwords,
    check_keywords, fix_title
)
from layx.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='~/.layx/songs'):
        """
            Init the stuff.
            directory: the directory where songs lie
            Note:
                The reason for choosing `layx/songs` is that I have allocated
                other tree structure for misc activities like `layx/logs` and
                `layx/layxlist`
        """
        self.dir = os.path.expanduser(directory)
Esempio n. 8
0
'''Scrap Youtube to get the related list from youtube'''

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

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

from layx.logger import Logger

logger = Logger('YoutubeRelated')


class YoutubeMetadata(SongMetadataBase):
    """
    Class to hold contents of the playlist.
    """
    def __init__(self, title):
        super().__init__()
        self.title = title
        self._create_search_querry()

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


class YoutubeRelatedIE(PlaylistBase):
    """Youtube Related songs extractor."""
Esempio n. 9
0
"""Functions to handle the caching of playlists."""

from pathlib import Path
from os import makedirs

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

from layx.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, querry]|
    |........                               |
    |........                               |
    -----------------------------------------
    The playlist is saved by <NameOfPlaylist-Type>.playlist
    """
    def __init__(self, entity):
        self.entity = entity  # Entity can be either a name or an URL
        self.dir_path = Path('~/.layx/playlist').expanduser()
Esempio n. 10
0
"""
Functions related to gaana playlist.
"""

import requests
from bs4 import BeautifulSoup
import re

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

from layx.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='',
Esempio n. 11
0
"""File to modify the playlists."""

from layx.logger import (Logger)

from layx.stringutils import remove_duplicates

# Setup logger
logger = Logger('PlaylistBase')


class SongMetadataBase:
    """
    Base class to store song metadata.
    """
    def __init__(self):
        self.title = ''
        self.search_querry = ''
        self.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_querry += kw
Esempio n. 12
0
defined.
"""

import requests
from bs4 import BeautifulSoup
import re

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

from layx.logger import Logger


# Setup logger
logger = Logger('YoutubePlaylist')


class YoutubeMetadata(SongMetadataBase):

    def __init__(self, url='', title=''):
        super().__init__()
        self.URL = url
        self.title = title
        self._create_search_querry()

    def _create_search_querry(self):
        """
        Create a search querry.
        """
        self.search_querry = self.URL
Esempio n. 13
0
"""File to handle all other playlists"""
from layx.playlist.billboard import (get_chart_names, get_chart_names_online,
                                     dump_to_file)

from layx.playlist import (spotify, youtube, billboard, soundcloud, jiosaavn,
                           gaana, playlistcache)

import re
from layx.logger import Logger

# Get the logger
logger = Logger('Playlist')
"""
__author__ = Roshan Lamichhane
__github__ = github.com/roshancode
"""


class Playlist:
    """Class for every kind of playlist supported."""
    def __init__(self, URL, pl_start, pl_end):
        """
        URL: Passed URL
        pl_start: Playlist start index.
        pl_end: Playlist end index.
        """
        self.URL = URL
        self.file_path = None  # Used for cached playlists
        self.temp_type = None  # Used for cached playlists
        self.pl_start = pl_start
        self.pl_end = pl_end
Esempio n. 14
0
File: main.py Progetto: Grayul/layx
)

from layx.player import (
    Player
)

from layx.logger import Logger
from layx.songfinder import search

from layx.playlist.autoplaylist import (
    CountBasedAutoPlaylist
)


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


def parse():
    """Parse the arguments."""
    parser = argparse.ArgumentParser(description="Layx - 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/roshancode/layx) page")
    parser.add_argument('song',
                        help="Name or youtube link of song to download",
                        default=None, type=str, nargs="*")
    parser.add_argument('-p', '--play-cache',
                        action='store_true',
                        help="Play all songs from the cache.\
Esempio n. 15
0
from layx.youtube import (grab_link, dw, get_youtube_title)

from layx.songfinder import (search)

from layx.logger import (Logger)

from layx.stringutils import (is_song_url, url_type)

from layx.soundcloud import (get_track_info)

from layx.playlist.ytrelated import (get_data)

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
        self.stream_url = ''
        self.title = ''
Esempio n. 16
0
from requests import get
from bs4 import BeautifulSoup
import re

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

from layx.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.
        """
Esempio n. 17
0
"""Simple API to access Billboard charts."""
import requests
from bs4 import BeautifulSoup
import re
import os

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

from layx.logger import (Logger)

# Setup logger
logger = Logger('Billboard')
"""
__author__ = Roshan Lamichhane
__github__ = github.com/roshancode
"""


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
        self._create_search_querry()
        self._remove_duplicates()

    def _create_search_querry(self):
        """
        Create a search querry using the title and the artist name.