Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Modules #10

Open
wants to merge 64 commits into
base: Arreglos-menores
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
09a0c56
Update notify_mocp.py
Tarrasquero Mar 27, 2018
ae52471
Update notify_mocp.py
Tarrasquero Mar 28, 2018
519b4e1
Update notify_mocp.py
Tarrasquero Mar 29, 2018
d77fcf7
Update notify_mocp.py
Tarrasquero Mar 30, 2018
d24e53e
Update notify_mocp.py
Tarrasquero Mar 30, 2018
9cef593
Update notify_mocp.py
Tarrasquero Mar 30, 2018
5578631
Update notify_mocp.py
Tarrasquero Mar 30, 2018
34f2543
Update notify_mocp.py
Tarrasquero Mar 30, 2018
d1bd30d
Update notify_mocp.py
Tarrasquero Mar 30, 2018
56d8d4b
Add files via upload
Tarrasquero Mar 30, 2018
c2b6216
Update README.md
Tarrasquero Mar 30, 2018
ce4d2ca
Update notify_mocp.py
Tarrasquero Mar 30, 2018
398071e
Create Licencia.txt
Tarrasquero Apr 1, 2018
ca0b9c6
Rename Licencia.txt to GPL v.3.txt
Tarrasquero Apr 1, 2018
1de8ad9
Update notify_mocp.py
Tarrasquero Apr 2, 2018
1e0b1fa
Update notify_mocp.py
Tarrasquero Apr 8, 2018
0b44e39
Update README.md
Tarrasquero Apr 9, 2018
79bcaee
Update README.md
Tarrasquero Apr 17, 2018
8b3343d
Create LICENSE
Tarrasquero Apr 21, 2018
7f1e660
Merge pull request #9 from Tarrasquero/add-license-1
Tarrasquero Apr 21, 2018
62f4dac
Delete GPL v.3.txt
Tarrasquero Apr 21, 2018
9030245
Update notify_mocp.py
Tarrasquero Apr 22, 2018
17135b6
Merge pull request #11 from Tarrasquero/Update-Modules
Tarrasquero Apr 22, 2018
59c4acf
Update notify_mocp.py
Tarrasquero Apr 22, 2018
4071248
Update notify_mocp.py
Tarrasquero Apr 23, 2018
d075f5c
Add files via upload
Tarrasquero Oct 8, 2018
94a3942
Update notify_mocp.py
Tarrasquero Oct 8, 2018
3ba9f92
Update notify_mocp.py
Tarrasquero Oct 8, 2018
efefe83
Update requeriments.txt
Tarrasquero Oct 8, 2018
d128228
Update README.md
Tarrasquero Oct 8, 2018
402702f
Update README.md
Tarrasquero Oct 8, 2018
b4eb709
Update README.md
Tarrasquero Oct 9, 2018
55ba7a4
Update README.md
Tarrasquero Oct 9, 2018
7dad5ee
Update notify_mocp.py
Tarrasquero Oct 9, 2018
3760df0
Update Mocp.py
Tarrasquero Oct 9, 2018
312658a
Update Mocp.py
Tarrasquero Oct 9, 2018
6ca42ed
Update notify_mocp.py
Tarrasquero Oct 9, 2018
1acb6bb
Update README.md
Tarrasquero Oct 9, 2018
f20c1da
Update notify_mocp.py
Tarrasquero Oct 9, 2018
7cc07be
Update README.md
Tarrasquero Oct 9, 2018
275c4af
Update README.md
Tarrasquero Oct 9, 2018
cf8cfe3
Update README.md
Tarrasquero Oct 9, 2018
35098e2
Update README.md
Tarrasquero Oct 9, 2018
6cb1414
Update README.md
Tarrasquero Oct 9, 2018
8134c0c
Update README.md
Tarrasquero Oct 9, 2018
de48e87
Update notify_mocp.py
Tarrasquero Oct 10, 2018
2156855
Update notify_mocp.py
Tarrasquero Oct 12, 2018
97dbebf
Update Mocp.py
Tarrasquero Oct 12, 2018
efe658c
Update Mocp.py
Tarrasquero Oct 18, 2018
577ab48
Update notify_mocp.py
Tarrasquero Oct 18, 2018
75c36c9
Update requeriments.txt
Tarrasquero Oct 18, 2018
fc05e23
Update README.md
Tarrasquero Oct 18, 2018
5c403c7
Update README.md
Tarrasquero Oct 18, 2018
707aa1e
Update README.md
Tarrasquero Oct 19, 2018
27eda29
Update README.md
Tarrasquero Oct 19, 2018
2771a77
Update notify_mocp.py
Tarrasquero Oct 21, 2018
6457921
Update Mocp.py
Tarrasquero Oct 21, 2018
c8033e1
Update requeriments.txt
Tarrasquero Oct 27, 2018
acf540e
Update requeriments.txt
Tarrasquero Oct 27, 2018
212607f
Update notify_mocp.py
Tarrasquero Oct 28, 2018
6946565
Update requeriments.txt
Tarrasquero Oct 28, 2018
0a408f5
Update requeriments.txt
Tarrasquero Oct 28, 2018
1bdef5a
Add files via upload
Tarrasquero Mar 30, 2019
57bc390
Update README.md
Tarrasquero Mar 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions Mocp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import os
import re
import cv2


def descargar_img(cantante, disco, directorio):
os.chdir(directorio)
cantante = cantante.title()
disco = disco.title()
cantante = cantante.replace(' ', '_')
cantante = cantante.replace('.', '_')
disco = disco.replace(' ', '_')
disco = disco.replace('...', '_')
disco = disco.replace('.', '_')
disco = disco.replace('?', '_')
disco = disco.replace('[Ep]', '(Ep)')
disco = disco.replace('_#', '_')
disco = disco.replace(': ', '_')
disco = disco.replace("_(Disc_1)", "")
disco = disco.replace("_(Disc_2)", "")
disco = re.sub(r"_(Cd[\d*])", "", disco)
disco = re.sub(r"_(19[\d**])", "", disco)
disco = re.sub(r"_(20[\d**])", "", disco)
print(cantante, disco)
link = ("http://images.coveralia.com/audio/%s/" +
cantante + "-" + disco +
"-Frontal.jpg") % cantante.lower()[0]
#link = (url + cantante + "-" + disco + "-Frontal.jpg")
try:
imagen = requests.get(link).content
nombreli = (directorio + cantante + "-" + disco + "-Frontal.jpg")
print(link)
with open(nombreli, 'wb') as handler:
handler.write(imagen)
path = os.walk(directorio)
try:
for root, dirs, files in path:
for fichero in files:
(nombreFichero, extension) = os.path.splitext(fichero)
if (extension == ".jpg"):
img = cv2.imread(nombreFichero + extension)
cv2.imwrite(nombreFichero +
".png", img,
[int(cv2.IMWRITE_PNG_COMPRESSION), 9])
os.remove(nombreFichero + ".jpg")
if os.stat(nombreFichero + ".png").st_size < 345:
os.remove(nombreFichero + ".png")
if (extension == ".jpeg"):
img = cv2.imread(nombreFichero + extension)
cv2.imwrite(nombreFichero +
".png", img,
[int(cv2.IMWRITE_PNG_COMPRESSION), 9])
os.remove(nombreFichero + ".jpeg")
else:
pass
except OSError:
pass
except requests.exceptions.ConnectionError:
pass
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@
[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/x6CiPKTay8o/0.jpg)](https://www.youtube.com/watch?v=x6CiPKTay8o)


[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/Pg2lRTem2O4/0.jpg)](https://www.youtube.com/watch?v=Pg2lRTem2O4)




## Dependencias:
- python-notify2
- Instale dependencias: `sudo pip install --upgrade -r requeriments.txt`


## Novedades:
- Paquete instalable `Debian`
- Conversion a formato `PNG` compatible con `Dunst`.
- Agregado `modulo de descarga para carátulas` last.fm.
- `Reemplazo` de la notificación.
- `Redimensionado` de imagenes a 100x100 a copia en miniatura.

## Configuración para notificación de mocp:
- Extraer `/usr/share/doc/moc/example/config.example.gz` en `~/.moc` con el nombre `config`.
- Mover script: `notify_mocp.py` a `~/.moc/scripts`:
`mkdir $HOME/.moc/scripts ; mv notify_mocp.py $HOME/.moc/scripts`
- Extraer `/usr/share/doc/moc/examples/config.example.gz` en `~/.moc` con el nombre `config`.
- Mover script: `notify_mocp.py` con modulo `Mocp.py` y `icon-moc.png` a `~/.moc/scripts`:
`mkdir $HOME/.moc/scripts ; mv notify_mocp.py icon-moc.png Mocp.py $HOME/.moc/scripts`
- Otorgar permisos de ejecución: `chmod +x notify_mocp.py`
- Buscar la linea: `#OnSongChange=` que debería quedar parecida a esta: `OnSongChange= "$HOME/.moc/scripts/notify_mocp.py %a %t %r %f"`
- Busque la linea `imge = '/home/user/.moc/scripts/icon-moc.png'` en `notify_mocp.py` y reemplace `user` por el usuario con sesion iniciada.
## Bugs:
- ~~El directorio del album debería contener `al menos una imagen y solo una para mostrar en la notificacion`.~~
- En el archibo `config` buscar la linea: `#OnSongChange=` que debería quedar parecida a esta: `OnSongChange= "$HOME/.moc/scripts/notify_mocp.py %a %t %r %f"`
- Si usas Dunst, busca la linea `allow_markup = yes` en `~/.config/dunst/dunstrc`, de esta forma activarás el formateo `html`de la notificación, o no.

## En el supuesto que escojas instalar el paquete:
- `sudo dpkg -i notify-moc-1.0.deb;sudo apt-get install -f`
- Ya solo bastaría con editar la línea `OnSongChange= "/usr/bin/moc-notify %a %t %r %f"`
Binary file added notify-moc-1.0.deb
Binary file not shown.
209 changes: 111 additions & 98 deletions notify_mocp.py
Original file line number Diff line number Diff line change
@@ -1,107 +1,120 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# import string
# import dowload_img
# -*- coding: utf-8 -*-
import notify2
import sys
import os
import commands
import Image
import cgi
import re
from cPickle import dump, load
from PIL import Image
from commands import getoutput
from sys import argv, exit
from re import sub
from cgi import escape
from cPickle import dump
from cPickle import load
import Mocp

notify2.init("mocp")
__autor__ = "Jorge"


class Cuerpo():
def Load(self):
self.file_dump = '/tmp/pymocp.id'
self.n = None
try:
self.n = load(open(self.file_dump, mode="rb"))
except IOError:
self.n = notify2.Notification('')

def notify():
file_dump = '/tmp/pymocp.id'
try:
artista = sys.argv[1]
cancion = sys.argv[2]
album = sys.argv[3]
fil = sys.argv[4]
except IndexError:
artista = commands.getoutput('mocp -Q %artist')
cancion = commands.getoutput('mocp -Q %song')
album = commands.getoutput('mocp -Q %album')
fil = commands.getoutput('mocp -Q %file')
imge = '/home/jorge/.moc/scripts/icon-moc.png'
def Dump(self):
objeto = os.path.abspath(os.path.join(
__file__, os.pardir, 'icon-moc.png'))
try:
self.n.update(self.sumario, self.filename, self.imagen_t)
self.n.show()
self.n = dump(self.n, open(self.file_dump, mode='wb'))
exit(0)
except AttributeError:
self.n.update(self.sumario, self.filename, objeto)
self.n.show()
self.n = dump(self.n, open(self.file_dump, mode='wb'))
exit(0)

filename = ("<b>Artista: </b>" + "<b>%s</b>" %
cgi.escape(artista) + '\n' + "<b>Cancion: </b>" + "<i>%s</i>" %
cgi.escape(cancion) + '\n' + "<b>Album: </b>" + "<i>%s</i>" %
cgi.escape(album))
sumario = ('')
if not (artista and cancion):
filename = os.path.splitext(fil)[0]
filename = os.path.basename(filename)

n = None
try:
n = load(open(file_dump, mode="rb"))
except:
n = notify2.Notification('')

width = 100
height = 100
class Notify(Cuerpo):
def Imagen(self):
play = getoutput('mocp -Q %state')
if (play != 'PLAY'):
self.datos = "Mocp no está funcionando"
self.sumario = "STOP"
MiNotify.Dump()
try:
self.artista = argv[1]
self.cancion = argv[2]
self.album = argv[3]
self.fil = argv[4]
except IndexError:
self.artista = getoutput('mocp -Q %artist')
self.cancion = getoutput('mocp -Q %song')
self.album = getoutput('mocp -Q %album')
self.fil = getoutput('mocp -Q %file')
if not self.cancion:
filename = os.path.splitext(self.fil)[0]
filename = os.path.basename(filename)
f = filename.split('-')
self.artista = f[0]
self.cancion = f[1]
al = self.fil.split('/')
self.album = al[4]
self.sumario = ''
self.width = 100
self.height = 100
self.filename = ("<b>Artista: </b>" + "<b>%s</b>" %
escape(self.artista) + '\n' +
"<b>Cancion: </b>" + "<i>%s</i>" %
escape(self.cancion) + '\n' +
"<b>Album: </b>" + "<i>%s</i>" %
escape(self.album))
_path = self.fil.rfind('/')
if _path != -1:
_path = self.fil[:_path + 1]
_path = sub(r"CD[\d*]/", "", _path)
_path = sub(r"CD [\d*]/", "", _path)
_path = sub(r"Disc [\d*]/", "", _path)
_path = sub(r"Disc[\d*]/", "", _path)
Mocp.descargar_img(self.artista, self.album, _path)
lstDir = os.walk(_path)
for root, dirs, files in lstDir:
for fichero in files:
(nombreFichero, extension) = os.path.splitext(fichero)
try:
if (extension == ".png"):
self.imagen = '{0}{1}{2}'.format(
_path, nombreFichero, extension)
self.img = Image.open(self.imagen)
if (self.img.size == (100, 100)):
self.imagen_t = '{0}{1}{2}'.format(
_path, nombreFichero, extension)
MiNotify.Dump()
exit(0)
elif (self.img.size > (100, 100)):
self.imagen = '{0}{1}{2}'.format(
_path, nombreFichero, extension)
self.img = Image.open(self.imagen)
nombreFichero = (nombreFichero + '.Thumbnail')
self.img = self.img.resize((
self.width, self.height), Image.ANTIALIAS)
self.img.save(_path + nombreFichero + extension)
self.imagen_t = (_path + nombreFichero + extension)
MiNotify.Dump()
exit(0)
except IOError:
self.imagen_t = os.path.abspath(os.path.join(
__file__, os.pardir, 'icon-moc.png'))
MiNotify.Dump()
exit(0)

path = fil.rfind('/')
if path != -1:
path = fil[:path+1]
path = path.replace("CD1/", "")
path = path.replace("CD2/", "")
path = path.replace("CD3/", "")
path = path.replace("CD4/", "")
path = path.replace("CD5/", "")
path = path.replace("CD 1/", "")
path = path.replace("CD 2/", "")
path = path.replace("CD 3/", "")
path = path.replace("CD 4/", "")
path = path.replace("CD 5/", "")
lstDir = os.walk(path)
for root, dirs, files in lstDir:
for fichero in files:
(nombreFichero, extension) = os.path.splitext(fichero)
if (extension == ".jpeg" or extension == ".png" or extension == ".jpg"):
_imagen = '{0}{1}{2}'.format(path, nombreFichero, extension)
_I = Image.open(_imagen)
if (_I.size != (100, 100)):
img = _I.resize((width, height), Image.ANTIALIAS)
nombreFichero = (nombreFichero + '.Thumbnail')
img.save(path + nombreFichero + extension)
_imagen = '{0}{1}{2}'.format(path, nombreFichero, extension)
n.update(sumario, filename, _imagen)
n.show()
n = dump(n, open(file_dump, mode='wb'))
sys.exit(0)

def noimagen():
file_dump = '/tmp/pymocp.id'
n = None
try:
n = load(open(file_dump, mode="rb"))
except:
n = notify2.Notification('')
try:
artista = sys.argv[1]
cancion = sys.argv[2]
album = sys.argv[3]
fil = sys.argv[4]
except IndexError:
artista = commands.getoutput('mocp -Q %artist')
cancion = commands.getoutput('mocp -Q %song')
album = commands.getoutput('mocp -Q %album')
fil = commands.getoutput('mocp -Q %file')
imge = '/home/jorge/.moc/scripts/icon-moc.png'
filename = ("<b>Artista: </b>" + "<b>%s</b>" % cgi.escape(artista) + '\n' + "<b>Cancion: </b>" + "<i>%s</i>" %
cgi.escape(cancion) + '\n' + "<b>Album: </b>" + "<i>%s</i>" % cgi.escape(album))
sumario = ('')
if not (artista and album):
filename = os.path.splitext(fil)[0]
filename = os.path.basename(filename)
n.update(sumario, filename, imge)
n.show()
n = dump(n, open(file_dump, mode='wb'))
sys.exit(0)

notify()
noimagen()
if __name__ == "__main__":
MiNotify = Notify()
MiNotify.Load()
MiNotify.Imagen()
MiNotify.Dump()
5 changes: 5 additions & 0 deletions requeriments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pillow
cgi-tools
notify2
requests
opencv-python