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

Telegram beta #57

Open
wants to merge 148 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
22a2b11
improved by selery
artyshko Feb 15, 2019
f30672c
changed Procfile
artyshko Feb 15, 2019
a9d27bc
Heroku fix
artyshko Feb 15, 2019
a1fe54e
Heroku fix
artyshko Feb 15, 2019
48c6749
fixed heroku redis bug
artyshko Feb 16, 2019
4dc0d1f
added bash script
artyshko Feb 16, 2019
34bdb3e
fixed the mp3 names
artyshko Feb 24, 2019
1e48c7b
fixed telegram error "413 Request Entity Too Large"
artyshko Feb 24, 2019
3e795cc
Merge branch 'telegram-alpha' into telegram-beta
artyshko Feb 24, 2019
e57aa01
added new features from -alpha branch
artyshko Feb 24, 2019
d9ec6a5
updated limit
artyshko Feb 24, 2019
4afcf14
updated limit
artyshko Feb 24, 2019
d55a04b
fixed run out of memory error
artyshko Feb 24, 2019
681d69d
fix
artyshko Feb 24, 2019
b96440a
hotfix
artyshko Feb 24, 2019
43ab997
fix
artyshko Feb 24, 2019
18f63ca
fix
artyshko Feb 24, 2019
97a9381
hotfix
artyshko Feb 24, 2019
e33e27b
changed api key
artyshko Feb 24, 2019
a6ed225
added albums support
artyshko Mar 1, 2019
ab22618
added status
artyshko Mar 1, 2019
5874006
fixed image
artyshko Mar 3, 2019
ede692d
Update README.md
artyshko Mar 8, 2019
219f379
removed tokens
artyshko Mar 8, 2019
fe52fb9
Merge branch 'telegram-alpha' of https://github.com/artyshko/smd into…
artyshko Mar 8, 2019
697dfb9
Merge branch 'telegram-beta' into telegram
artyshko Mar 8, 2019
e7d3715
new hello message
artyshko Mar 9, 2019
1e2fdb3
Merge branch 'telegram' into telegram-alpha
artyshko Mar 15, 2019
8241006
fix
artyshko Mar 16, 2019
a6ec6f1
changed data
artyshko Mar 16, 2019
e02c4fb
optimized
artyshko Mar 16, 2019
f7d9325
hotfix
artyshko Mar 16, 2019
f1b1a4c
added Deezer support
artyshko Mar 16, 2019
8426be9
bug fixes
artyshko Mar 23, 2019
e847868
changed cover
artyshko Mar 26, 2019
868201c
added fonts
artyshko Mar 30, 2019
b71f14b
created image processing library
artyshko Mar 30, 2019
1a01ecd
new album art
artyshko Mar 30, 2019
1570c1c
updated requirements
artyshko Mar 30, 2019
07daafe
updated requirements
artyshko Mar 30, 2019
f67e9d6
fixed incorrect statistic
artyshko Mar 30, 2019
4060faa
blocked
artyshko Apr 24, 2019
1814987
Merge branch 'telegram-beta' into telegram-alpha
artyshko Apr 24, 2019
ae9e403
hotfix
artyshko Apr 25, 2019
8f9855b
hotfix
artyshko Apr 25, 2019
a5a7742
hotfix
artyshko Apr 25, 2019
509c79b
hotfix
artyshko Apr 25, 2019
8bb1763
hotfix
artyshko Apr 25, 2019
ae07268
updated requirements
artyshko May 14, 2019
a16bf7e
updated requirements
artyshko Jun 21, 2019
f438632
new media item'
artyshko Jun 22, 2019
57866bc
added token creator
artyshko Jun 22, 2019
cbaab2e
disabled albums support
artyshko Jun 22, 2019
1971c0c
added genius support
artyshko Jun 22, 2019
4c7d531
added lyrics
artyshko Jun 22, 2019
e5803be
optimized duno usage
artyshko Jun 22, 2019
6c41b99
updated
artyshko Jul 5, 2019
70811ac
updated
artyshko Jul 5, 2019
c7118da
Update requirements.txt
artyshko Jul 9, 2019
ecd707a
Update requirements.txt
artyshko Jul 9, 2019
6eb98e8
hotfix
artyshko Jul 10, 2019
422afc5
Merge branch 'telegram-alpha' of https://github.com/artyshko/smd into…
artyshko Jul 10, 2019
013a90c
hotfix
artyshko Jul 10, 2019
1680692
hotfix
artyshko Jul 10, 2019
da234ea
hotfix
artyshko Jul 10, 2019
a4020f3
hotfix
artyshko Jul 10, 2019
71387fd
hotfix
artyshko Jul 10, 2019
bcfee9f
Update requirements.txt
artyshko Jul 11, 2019
9fa1455
hotfix
artyshko Jul 11, 2019
a0d7c7d
Merge branch 'telegram-alpha' of https://github.com/artyshko/smd into…
artyshko Jul 11, 2019
9d35b4e
added proxy
artyshko Jul 11, 2019
15ce9d4
updated requirements
artyshko Jul 11, 2019
9985ba4
hotfix
artyshko Jul 11, 2019
088e410
hotfix
artyshko Jul 11, 2019
269181d
hotfix
artyshko Jul 11, 2019
0f51269
hotfix
artyshko Jul 11, 2019
5d8cd71
hotfix
artyshko Jul 11, 2019
7a3c06d
hotfix
artyshko Jul 11, 2019
6938b7d
hotfix
artyshko Jul 11, 2019
de4cc95
blocked
artyshko Jul 12, 2019
4cff69f
youtube fix
artyshko Jul 13, 2019
5951994
albums
artyshko Jul 13, 2019
7da21f0
youtube fix
artyshko Jul 13, 2019
26f070b
youtube fix
artyshko Jul 13, 2019
722f027
fix
artyshko Jul 13, 2019
fba300a
fix
artyshko Jul 13, 2019
0f2592a
fix
artyshko Jul 13, 2019
f8e056b
fix
artyshko Jul 13, 2019
007d0b6
fix
artyshko Jul 13, 2019
797fdb3
fix
artyshko Jul 13, 2019
8b397e4
fix
artyshko Jul 13, 2019
fa4ec65
fix
artyshko Jul 13, 2019
cf74590
fix
artyshko Jul 13, 2019
0fd672c
fix
artyshko Jul 13, 2019
667ccb2
fix
artyshko Jul 13, 2019
7865ccd
fix
artyshko Jul 13, 2019
0032016
blocked
artyshko Jul 14, 2019
80f951a
Update telegram.py
artyshko Jul 14, 2019
8d74c04
swithced to YouTube API
artyshko Jul 20, 2019
7fe209f
added dict support
artyshko Jul 20, 2019
a5a584b
removed beta
artyshko Jul 20, 2019
0dcb964
added YouTube API changing key mechanism
artyshko Jul 20, 2019
b3a5012
removed a sad message
artyshko Jul 20, 2019
0896ae5
turned safe mode on
artyshko Jul 20, 2019
82dacde
hotfix
artyshko Jul 20, 2019
1e71b83
updated youtube_dl to 7.16
artyshko Jul 20, 2019
87281b5
hotfix
artyshko Jul 21, 2019
e1ac63f
hotfix
artyshko Jul 21, 2019
3c53b5f
hotfix
artyshko Jul 21, 2019
ac23ea8
debug mode
artyshko Jul 21, 2019
6b98123
hotfix
artyshko Jul 21, 2019
4ca47eb
improved server's info message
artyshko Jul 21, 2019
9d217fe
added one more key
artyshko Jul 22, 2019
93e4eb4
added one more key
artyshko Jul 22, 2019
1d136b2
changed keys
artyshko Jul 22, 2019
4c1f9a6
updated .youtube
artyshko Jul 23, 2019
e61b844
notification about falling down
artyshko Jul 24, 2019
793feed
data was changed
artyshko Jul 24, 2019
2be1cb9
fix
artyshko Jul 24, 2019
f87fe16
added auto restart
artyshko Jul 24, 2019
9142e00
added heroku
artyshko Jul 24, 2019
650fe92
fixed
artyshko Jul 24, 2019
d5bcb4f
Delete .heroku
artyshko Jul 24, 2019
6bd2db5
updated requirements
artyshko Jul 24, 2019
8c1ecaa
hotfix
artyshko Jul 24, 2019
1223f95
fixed quota usage
artyshko Jul 25, 2019
9160947
fixed "the last message was missed"
artyshko Jul 25, 2019
92daac9
removed star artwork
artyshko Jul 25, 2019
edbcb1b
removed telegram link
artyshko Jul 25, 2019
c7cb1d9
decreased load
artyshko Jul 25, 2019
0610f71
decreased load
artyshko Jul 25, 2019
27d05b3
updated requirements
artyshko Jul 31, 2019
6dd9bdc
updated
artyshko Aug 25, 2019
075407f
added status handler
artyshko Aug 26, 2019
006f634
moved to a new module
artyshko Aug 26, 2019
d8ec527
restarting mechanism
artyshko Aug 26, 2019
422de87
fix
artyshko Aug 26, 2019
ebb333e
updated requirements
artyshko Aug 26, 2019
d35b5f9
Merge branch 'telegram-beta' into telegram-alpha
artyshko Aug 26, 2019
8434e5b
fix
artyshko Aug 26, 2019
ce4f0a0
updated
artyshko Aug 26, 2019
b34e795
changed dyno
artyshko Aug 26, 2019
d92247d
fix
artyshko Aug 26, 2019
0fdf9b5
fix
artyshko Aug 26, 2019
3d72827
fix
artyshko Aug 26, 2019
be0f59e
added auto reset
artyshko Aug 27, 2019
6d62087
hotfix
artyshko Aug 31, 2019
0e3ea25
hotfix
artyshko Aug 31, 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
Binary file added .genius
Binary file not shown.
Binary file added .heroku_data
Binary file not shown.
Binary file added .spotify
Binary file not shown.
Binary file added .status
Binary file not shown.
Binary file added .telegram
Binary file not shown.
Binary file added .youtube
Binary file not shown.
Binary file added Data/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Heavy.ttf
Binary file not shown.
Binary file added Data/Ultralight.ttf
Binary file not shown.
Binary file modified Data/header1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified Data/header3.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified Data/header5.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/logo-w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified Data/s1.webp
100644 → 100755
Empty file.
Empty file modified Data/s2.webp
100644 → 100755
Empty file.
Empty file modified Data/s3.webp
100644 → 100755
Empty file.
Empty file modified Data/s4.webp
100644 → 100755
Empty file.
Empty file modified Data/s5.webp
100644 → 100755
Empty file.
Binary file added Data/s6.webp
Binary file not shown.
Binary file modified Data/temp.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Data/temp1.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified LICENSE
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion Procfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
worker: python3 telegram.py
worker: bash worker.sh
10 changes: 5 additions & 5 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-unstable/Data/header1.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-unstable/Data/header2.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-unstable/Data/header3.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-unstable/Data/header5.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-unstable/Data/header4.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-beta/Data/header1.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-beta/Data/header2.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-beta/Data/header3.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-beta/Data/header5.png">
<img align="center" src="https://raw.githubusercontent.com/artyshko/smd/telegram-beta/Data/header4.png">
5 changes: 3 additions & 2 deletions apple.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get(self, url):

url = url + '&l=uk'


splitted = str(url).split('/')
splitted = splitted[:3]+['ua']+splitted[4:]
url = '/'.join(splitted)
Expand Down Expand Up @@ -49,4 +49,5 @@ def getName(self, url):
return None
if __name__ == "__main__":
a = AppleMusic()
a.get('https://itunes.apple.com/uk/album/simplify/1430224633?i=1430225075')
name = a.get('https://itunes.apple.com/us/album/contra-la-pared/1455082839?i=1455082850')
print(name)
73 changes: 73 additions & 0 deletions deezer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import requests

class Deezer(object):

def __init__(self):

'''
Init function
Creating deezer object
:return: None
'''

self.__url = 'http://api.deezer.com/'


def getSongInfo(self, id):

try:

response = requests.get(f'{self.__url}/track/{id}').json()

return ({
'uri' : f"D{response['id']}T",
'name' : response['title'],
'artist' : [response['artist']['name']],
'album' : response['album']['title'],
'image' : response['album']['cover_xl'],
'duration_ms' : response['duration']
})

except: return None

def getAlbum(self, id):

try:

response = requests.get(f'{self.__url}/album/{id}').json()

alb = {
'name':response['title'],
'artist':response['artist']['name'],
'copyright': None,
'image':response['cover_xl'],
}

tracks = []

for item in response['tracks']['data']:

tracks.append({
'uri' : f"D{item['id']}T",
'name' : item['title'],
'artist' : [item['artist']['name']],
'album' : alb['name'],
'image' : alb['image'],
'preview_url' : item['preview'],
'duration_ms' : item['duration']
})

alb.setdefault(
'tracks', tracks
)

return alb

except: return None

if __name__ == '__main__':

deezer = Deezer()
data = deezer.getSongInfo('636758392')

print(data)
30 changes: 25 additions & 5 deletions editor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/python3
import re, os
import shutil
import genius
#used for mp3 ID3 tagging
from mutagen.id3._frames import TIT2, TALB, TPE1
from mutagen.id3._frames import TIT2, TALB, TPE1, USLT
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error

#used for web scraping
import urllib.request

Expand All @@ -20,15 +22,21 @@ class TagEditor(object):

@staticmethod
def getImageFromSpotify(url, name):
if len(url):
urllib.request.urlretrieve(url, name)
else:

try:
if len(url):
urllib.request.urlretrieve(url, name)
else:

cachepath = os.getcwd() + '/cache'
datapath = os.getcwd() + '/Data'
os.system(f'cp {datapath}/temp.png {name}')

except:
cachepath = os.getcwd() + '/cache'
datapath = os.getcwd() + '/Data'
os.system(f'cp {datapath}/temp.png {name}')


@staticmethod
def getTags():
pass
Expand Down Expand Up @@ -63,6 +71,10 @@ def setTags(data):
'''
if data:

if data['image'] == 'https://lastfm-img2.akamaized.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png':

data['image'] = None

#download image
TagEditor.getImageFromSpotify(data['image'], f"cache/{data['uri']}/{data['uri']}.png")

Expand Down Expand Up @@ -106,6 +118,14 @@ def setTags(data):
text=(data['artist'][0]))
)

#add song artist
audio.tags.add(USLT(
encoding=3,
lang=u'eng',
desc=u'desc',
text=genius.getLyrics(data['artist'][0],data['name']))
)

#save result
audio.save()
ID3(f"cache/{data['uri']}/{data['uri']}.mp3").save(v2_version=3)
Expand Down
31 changes: 31 additions & 0 deletions genius.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import lyricsgenius
import pickle


def getLyrics(artist, song):

def function():

try:

with open('.genius', 'rb') as f:
data = pickle.load(f)

return data['token']

except:

return None

try:

genius = lyricsgenius.Genius(function())
genius.verbose, genius.remove_section_headers = False, True
song = genius.search_song(song, artist)

return song.lyrics

except:return None

if __name__ == '__main__':
print(getLyrics('Cage The Elephant', 'Ready To Let Go'))
37 changes: 37 additions & 0 deletions heroku.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import heroku3
import pickle


def restart():

def getData():

try:

with open('.heroku_data', 'rb') as f:
data = pickle.load(f)

return data['token']

except:

sys.exit()

try:

heroku_conn = heroku3.from_key(getData())
app = heroku_conn.apps()['smd-bot']
dyno = app.dynos()[0]

print('RESTARTING_DYNO:DONE')

dyno.restart()

except:

print('RESTARTING_DYNO:ERROR')


if __name__ == '__main__':

restart()
90 changes: 90 additions & 0 deletions image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from PIL import Image, ImageFilter, ImageDraw, ImageFont, ImageEnhance

class Effects():

@staticmethod
def rounded(im, rad=5, width=None, height=None, _scale=1):
im = Image.open(im)

if width is None and height is None: width, height = im.size[0], im.size[1]
im = im.resize((int(width / _scale), int(height / _scale)), Image.ANTIALIAS)

circle = Image.new('L', (rad * 2, rad * 2), 0)

draw = ImageDraw.Draw(circle)
draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)

alpha = Image.new('L', im.size, 255)
w, h = im.size

alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))

im.putalpha(alpha)

return im

@staticmethod
def text(image, name='Name', artist='Artist'):
draw = ImageDraw.Draw(image)

f1, s1, l1, c1 = 528, 40, 0, 0
f2, s2, l2, c2 = 535, 40, 0, 0

font = ImageFont.truetype("Data/Ultralight.ttf", s1)
font1 = ImageFont.truetype("Data/Heavy.ttf", s2)
font2 = ImageFont.truetype("Data/Heavy.ttf", 20)

font_size = font.getsize(name)
font_size1 = font1.getsize(artist)

if font_size[0] > f1:
temp = s1
while font_size[0] > f1:
font = ImageFont.truetype("Data/Ultralight.ttf", temp)
font_size = font.getsize(name)
temp, l1 = temp - 1, l1 + 1

if font_size1[0] > f2:
temp = s2
while font_size1[0] > f2:
font1 = ImageFont.truetype("Data/Heavy.ttf", temp)
font_size1 = font1.getsize(artist)
temp, l2 = temp - 1, l2 + 1

c1, c2 = (f1 - font_size[0]) / 2, (f2 - font_size1[0]) / 2

draw.text((520 + c1, 150 + l1 * 2), name, (255,255,255), font=font)
draw.text((520 + c2, 250), artist, (255,255,255), font=font1)
draw.text((665, 365), 'Spotify Music Downloader', (255,255,255), font=font2)

return image

@staticmethod
def createPoster(image, name='Name', artist='Artist', file='image.png'):
original = Image.open(image)
logo = Image.open('Data/logo-w.png')
logo = logo.resize((20, 20), Image.ANTIALIAS)

rounded = Effects.rounded(image, rad=30)
rounded = rounded.resize((440, 440), Image.ANTIALIAS)

image = Image.open(image)
image = image.resize((1080, 1080), Image.ANTIALIAS)
width, height = image.size

left, right, top, bottom = 0, width, height/4, 3 * height/4
cropped = image.crop((left, top, right, bottom))
blurred = cropped.filter(ImageFilter.GaussianBlur(radius=40))
enhancer = ImageEnhance.Brightness(blurred)
enhanced_im = enhancer.enhance(.6)
enhanced_im.paste(rounded, (50, 50), rounded)
enhanced_im.paste(logo, (635, 368), logo)
enhanced_im = Effects.text(enhanced_im, name, artist)
enhanced_im.save(file)


if __name__ == "__main__":
Effects.createPoster('image.jpg', name='Hard EP', artist='The Neighbourhood', file='Downloads/image.png')
Empty file modified lastfm.py
100644 → 100755
Empty file.
Loading