Added mail.ru music

This commit is contained in:
Manuel Cortez 2018-03-02 14:05:38 -06:00
parent a2074d2b49
commit 69487bac2d
3 changed files with 47 additions and 2 deletions

View File

@ -8,7 +8,7 @@ import utils
import application import application
from pubsub import pub from pubsub import pub
from wxUI import mainWindow, menus from wxUI import mainWindow, menus
from extractors import zaycev, youtube, vk from extractors import zaycev, youtube, vk, mailru
from update import updater from update import updater
from . import player from . import player
@ -79,6 +79,7 @@ class Controller(object):
self.window.Bind(wx.EVT_CLOSE, self.on_close) self.window.Bind(wx.EVT_CLOSE, self.on_close)
pub.subscribe(self.change_status, "change_status") pub.subscribe(self.change_status, "change_status")
pub.subscribe(self.on_download_finished, "download_finished") pub.subscribe(self.on_download_finished, "download_finished")
pub.subscribe(self.on_notify, "notify")
# Event functions. These functions will call other functions in a thread and are bound to widget events. # Event functions. These functions will call other functions in a thread and are bound to widget events.
def on_search(self, *args, **kwargs): def on_search(self, *args, **kwargs):
@ -212,6 +213,9 @@ class Controller(object):
msg = _("File downloaded: {0}").format(file,) msg = _("File downloaded: {0}").format(file,)
self.window.notify(title, msg) self.window.notify(title, msg)
def on_notify(self, title, message):
self.window.notify(title, message)
# real functions. These functions really are doing the work. # real functions. These functions really are doing the work.
def search(self, *args, **kwargs): def search(self, *args, **kwargs):
text = self.window.get_text() text = self.window.get_text()
@ -222,6 +226,8 @@ class Controller(object):
self.extractor = youtube.interface() self.extractor = youtube.interface()
elif extractor == "vk": elif extractor == "vk":
self.extractor = vk.interface() self.extractor = vk.interface()
elif extractor == "mail.ru":
self.extractor = mailru.interface()
elif extractor == "zaycev.net": elif extractor == "zaycev.net":
self.extractor = zaycev.interface() self.extractor = zaycev.interface()
elif extractor == "": elif extractor == "":

39
src/extractors/mailru.py Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import urllib.parse
import requests
import youtube_dl
from bs4 import BeautifulSoup
from . import baseFile
class interface(object):
def __init__(self):
self.results = []
self.name = "mailru"
self.needs_transcode = False
def search(self, text, page=1):
site = 'https://my.mail.ru/music/search/%s' % (text)
r = requests.get(site)
soup = BeautifulSoup(r.text, 'html.parser')
search_results = soup.find_all("div", {"class": "songs-table__row__col songs-table__row__col--title title songs-table__row__col--title-hq-similar resize"})
self.results = []
for search in search_results:
data = search.find_all("a")
s = baseFile.song(self)
s.title = data[0].text.replace("\n", "").replace("\t", "")
# s.artist = data[1].text.replace("\n", "").replace("\t", "")
# print(data)
s.url = u"https://my.mail.ru"+urllib.parse.quote(data[0].__dict__["attrs"]["href"])
self.results.append(s)
def get_download_url(self, url):
ydl = youtube_dl.YoutubeDL({'quiet': True, 'format': 'bestaudio/best', 'outtmpl': u'%(id)s%(ext)s'})
with ydl:
result = ydl.extract_info(url, download=False)
if 'entries' in result:
video = result['entries'][0]
else:
video = result
return video["url"]

View File

@ -40,7 +40,7 @@ class mainWindow(wx.Frame):
box.Add(lbl2, 0, wx.GROW) box.Add(lbl2, 0, wx.GROW)
box.Add(self.text, 1, wx.GROW) box.Add(self.text, 1, wx.GROW)
box.Add(wx.StaticText(self.panel, wx.NewId(), _("Search in")), 0, wx.GROW) box.Add(wx.StaticText(self.panel, wx.NewId(), _("Search in")), 0, wx.GROW)
self.extractor = wx.ComboBox(self.panel, wx.NewId(), choices=["youtube", "vk", "zaycev.net"], value="youtube", style=wx.CB_READONLY) self.extractor = wx.ComboBox(self.panel, wx.NewId(), choices=["youtube", "vk", "mail.ru", "zaycev.net"], value="youtube", style=wx.CB_READONLY)
box.Add(self.extractor, 1, wx.GROW) box.Add(self.extractor, 1, wx.GROW)
self.search = wx.Button(self.panel, wx.NewId(), _("Search")) self.search = wx.Button(self.panel, wx.NewId(), _("Search"))
self.search.SetDefault() self.search.SetDefault()