Ejemplo n.º 1
0
 def __init__(self):
     self.client_credentials_manager = SpotifyClientCredentials(
         SPOTIFY_ID, SPOTIFY_SECRET)
     self.spotify = spotipy.Spotify(
         client_credentials_manager=self.client_credentials_manager)
     self.youtube_api = youtube.API(client_id=YOUTUBE_ID,
                                    client_secret=YOUTUBE_SECRET,
                                    api_key=YOUTUBE_KEY)
Ejemplo n.º 2
0
def searchYoutube(songName):
    api = youtube.API(client_id=APIs["youtube"]["client_id"],
                      client_secret=APIs["youtube"]["client_secret"],
                      api_key=APIs["youtube"]["api_key"])
    video = api.get('search',
                    q=songName,
                    maxResults=1,
                    type='video',
                    order='relevance')
    return ("https://www.youtube.com/watch?v=" +
            video["items"][0]["id"]["videoId"])
Ejemplo n.º 3
0
def search_track_on_youtube(config, track):
    api = youtube.API(client_id=config["youtube"]["client_id"],
                      client_secret=config["youtube"]["client_secret"],
                      api_key=config["youtube"]["api_key"])
    video = api.get('search',
                    q=track,
                    maxResults=1,
                    type='video',
                    order='relevance')
    return ("https://www.youtube.com/watch?v=" +
            video["items"][0]["id"]["videoId"])
def searchYoutube(songName):
    try:
        api = youtube.API(client_id=APIs['youtube']['client_id'],
                          client_secret=APIs['youtube']['client_secret'],
                          api_key=APIs['youtube']['api_key'])
        video = api.get('search',
                        q=songName,
                        maxResults=1,
                        type='video',
                        order='relevance')
        return 'https://www.youtube.com/watch?v=' + video['items'][0]['id'][
            'videoId']
    except youtube.exceptions.YouTubeException:
        return searchYoutubeAlternative(songName)
Ejemplo n.º 5
0
import youtube_dl
from telethon.sync import TelegramClient
from telethon.tl import types

import config

ABSOLUTE_PATH = os.path.dirname(os.path.abspath(__file__))

bot = TelegramClient(
    'bot',
    api_id=config.TELEGRAM_API_ID,
    api_hash=config.TELEGRAM_API_HASH,
).start(bot_token=config.TELEGRAM_BOT_TOKEN)
api = youtube.API(
    client_id=config.YOUTUBE_CLIENT_ID,
    client_secret=config.YOUTUBE_CLIENT_SECRET,
    api_key=config.YOUTUBE_API_KEY,
)
ydl = youtube_dl.YoutubeDL({
    'outtmpl': f'{ABSOLUTE_PATH}/tmp/tmp_file.%(ext)s',
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '140',
    }],
} if config.MODE == 'audio' else {
    'outtmpl': f'{ABSOLUTE_PATH}/tmp/tmp_file.%(ext)'
})
conn = sqlite3.connect('bot.db')
c = conn.cursor()