Skip to content

Instantly share code, notes, and snippets.

@michimani
Last active July 9, 2019 06:57
Show Gist options
  • Save michimani/797f44f75fe52b9ecb7ef20389fed6a8 to your computer and use it in GitHub Desktop.
Save michimani/797f44f75fe52b9ecb7ef20389fed6a8 to your computer and use it in GitHub Desktop.
Convert share string that generated by Amazon Music share button to NoyPlaying string with hashtag #nowplaying .

Share playing music on Amazon Music as NowPlaying

Convert share string that generated by Amazon Music "Embed" share button to NoyPlaying string with hashtag #nowplaying .

Usage

Runtime: Python 3.x

$ pip3 install -r requirements.txt
$ python3 share-amazon-music-as-nowplay.py "<iframe id='AmazonMusicEmbedB07RSQMSDM' src='https://music.amazon.co.jp/embed/B07RSQMSDM/?id=WR4QXS0ND8&marketplaceId=A1VC38T7YXB528&musicTerritory=JP' width='100%' height='290px' style='border:1px solid rgba(0, 0, 0, 0.12);max-width:500px'></iframe>"
4番目の光/乃木坂46 - Sing Out! (Special Edition) #nowplaying

If you want to convet and copy the result to clip board,

$ python3 share-amazon-music-as-nowplay.py "<iframe id='AmazonMusicEmbedB07RSQMSDM' src='https://music.amazon.co.jp/embed/B07RSQMSDM/?id=WR4QXS0ND8&marketplaceId=A1VC38T7YXB528&musicTerritory=JP' width='100%' height='290px' style='border:1px solid rgba(0, 0, 0, 0.12);max-width:500px'></iframe>" | pbcopy
from bs4 import BeautifulSoup
from urllib import request
import re
import sys
import traceback
if __name__ == "__main__":
args = sys.argv
if len(args) < 2:
print('At least one argument is required.')
else:
embed_src = re.sub(r".+src='(.+)' width.+", r'\1', args[1])
if embed_src is not '':
try:
src = request.urlopen(embed_src).read()
soup = BeautifulSoup(src.decode('utf-8'), 'html.parser')
title = soup.select(
'.trackTitle a')[0].string.strip()
artist = soup.select(
'.trackArtist a')[0].string.strip()
album = soup.select(
'.trackAlbum a')[0].string.strip()
print('{}/{} - {} #nowplaying'.format(title, artist, album))
except Exception:
print(traceback.format_exc())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment