From 69487bac2d3e505edc04b4c68b7eff47a97a765e Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Fri, 2 Mar 2018 14:05:38 -0600 Subject: [PATCH] Added mail.ru music --- src/controller/mainController.py | 8 ++++++- src/extractors/mailru.py | 39 ++++++++++++++++++++++++++++++++ src/wxUI/mainWindow.py | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/extractors/mailru.py diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 58900f8..1ee7529 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -8,7 +8,7 @@ import utils import application from pubsub import pub from wxUI import mainWindow, menus -from extractors import zaycev, youtube, vk +from extractors import zaycev, youtube, vk, mailru from update import updater from . import player @@ -79,6 +79,7 @@ class Controller(object): self.window.Bind(wx.EVT_CLOSE, self.on_close) pub.subscribe(self.change_status, "change_status") 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. def on_search(self, *args, **kwargs): @@ -212,6 +213,9 @@ class Controller(object): msg = _("File downloaded: {0}").format(file,) 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. def search(self, *args, **kwargs): text = self.window.get_text() @@ -222,6 +226,8 @@ class Controller(object): self.extractor = youtube.interface() elif extractor == "vk": self.extractor = vk.interface() + elif extractor == "mail.ru": + self.extractor = mailru.interface() elif extractor == "zaycev.net": self.extractor = zaycev.interface() elif extractor == "": diff --git a/src/extractors/mailru.py b/src/extractors/mailru.py new file mode 100644 index 0000000..1b5e4d9 --- /dev/null +++ b/src/extractors/mailru.py @@ -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"] \ No newline at end of file diff --git a/src/wxUI/mainWindow.py b/src/wxUI/mainWindow.py index b0adad7..b785aab 100644 --- a/src/wxUI/mainWindow.py +++ b/src/wxUI/mainWindow.py @@ -40,7 +40,7 @@ class mainWindow(wx.Frame): box.Add(lbl2, 0, wx.GROW) box.Add(self.text, 1, 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) self.search = wx.Button(self.panel, wx.NewId(), _("Search")) self.search.SetDefault()