Add song.link and change loading link to a better vid
This commit is contained in:
parent
8a29f6f96d
commit
12118c5dd3
25
music.py
25
music.py
@ -111,7 +111,7 @@ def inlinequery(update, context: CallbackContext):
|
||||
|
||||
def button(update, context: CallbackContext):
|
||||
query = update.callback_query
|
||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Loading links, please wait", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Loading links, please wait", url='https://www.youtube.com/watch?v=rTga41r3a4s')]])
|
||||
query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
|
||||
query_id = re.search('(?<=query_id:\<).*(?=\>result)', f"{query.data}") # matches everything between query_id:< and >result
|
||||
@ -130,25 +130,19 @@ def button(update, context: CallbackContext):
|
||||
with open(f"./queries/{query_id}.json", encoding='utf-8') as data_file:
|
||||
sp_info = json.loads(data_file.read())
|
||||
|
||||
# reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Loaded search results", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
# query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
|
||||
sp_link = dpath.util.get(sp_info, f"/tracks/items/[{result_chosen}]/external_urls/spotify")
|
||||
sp_title = dpath.util.get(sp_info, f"/tracks/items/[{result_chosen}]/name")
|
||||
sp_artist = dpath.util.get(sp_info, f"/tracks/items/[{result_chosen}]/artists/[0]/name")
|
||||
sp_albname = dpath.util.get(sp_info, f"/tracks/items/[{result_chosen}]/album/name")
|
||||
sp_art = dpath.util.get(sp_info, f"/tracks/items/[{result_chosen}]/album/images/[2]/url")
|
||||
|
||||
# reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Imported results to variables", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
# query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
songlink = "https://song.link/{0}".format(sp_link)
|
||||
|
||||
|
||||
gpm = ask_for_credentials()
|
||||
if not gpm.is_authenticated():
|
||||
print("\n\nGPM fucked up somewhere\n\n")
|
||||
|
||||
# reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Searching GPM", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
# query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
|
||||
gpm = Mobileclient(debug_logging=False)
|
||||
gpm.oauth_login(Mobileclient.FROM_MAC_ADDRESS, oauth_credentials=u'./gpmlogin.json')
|
||||
gpm_results = gpm.search(f"{sp_title} by {sp_artist} on {sp_albname}", max_results=1)
|
||||
@ -162,34 +156,25 @@ def button(update, context: CallbackContext):
|
||||
else:
|
||||
gpm_link = dpath.util.get(gpm_results, '/song_hits/[0]/track/nid')
|
||||
gpm_link = f"https://play.google.com/music/m/T{gpm_link}"
|
||||
# reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Finding GPM link", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
# query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
try:
|
||||
dpath.util.get(gpm_results, '/video_hits/[0]/youtube_video/id')
|
||||
except KeyError:
|
||||
yt_link = False
|
||||
else:
|
||||
# reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Found YouTube link", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
# query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
yt_link = dpath.util.get(gpm_results, '/video_hits/[0]/youtube_video/id')
|
||||
yt_link = f"https://www.youtube.com/watch?v={yt_link}"
|
||||
|
||||
if not yt_link:
|
||||
# reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Searching for YouTube link", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
# query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
query_string = urllib.parse.urlencode({"search_query" : f"{sp_title} {sp_artist}"})
|
||||
html_content = urllib.request.urlopen(f"http://www.youtube.com/results?{query_string}")
|
||||
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
|
||||
yt_link = f"http://www.youtube.com/watch?v={search_results[0]}"
|
||||
|
||||
# reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Formatting links", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ')]])
|
||||
# query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
|
||||
if gpm_link:
|
||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Spotify", url = sp_link), InlineKeyboardButton("GPM", url = gpm_link), InlineKeyboardButton("YouTube", url = yt_link)]])
|
||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Spotify", url = sp_link), InlineKeyboardButton("GPM", url = gpm_link), InlineKeyboardButton("YouTube", url = yt_link), InlineKeyboardButton("More", url = songlink)]])
|
||||
|
||||
if not gpm_link:
|
||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Spotify", url = sp_link), InlineKeyboardButton("YouTube", url = yt_link)]])
|
||||
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Spotify", url = sp_link), InlineKeyboardButton("YouTube", url = yt_link), InlineKeyboardButton("More", url = songlink)]])
|
||||
|
||||
query.edit_message_reply_markup(reply_markup=reply_markup)
|
||||
|
||||
|
@ -7,8 +7,8 @@ Group=david
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
Type=default
|
||||
WorkingDirectory=/home/david/tmusic
|
||||
ExecStart=/home/david/.local/share/virtualenvs/tmusic-l3mWxOyb/bin/python3 music.py
|
||||
WorkingDirectory=/path/to/working/dir
|
||||
ExecStart=/path/to/pipenv/virtualenv/python3 music.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
Loading…
Reference in New Issue
Block a user