From 59689dcbf678a95ac6e3e44ba3eab5934d59b51c Mon Sep 17 00:00:00 2001 From: nmemmert Date: Mon, 17 Nov 2025 12:18:25 -0500 Subject: [PATCH] windows --- amazon_buy_list.txt | 11 +++--- main.py | 79 ++++++++++++++++++++++++++++++++++---------- playlist_history.db | Bin 0 -> 8192 bytes 3 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 playlist_history.db diff --git a/amazon_buy_list.txt b/amazon_buy_list.txt index a5cb9e6..81b2a4b 100644 --- a/amazon_buy_list.txt +++ b/amazon_buy_list.txt @@ -3,21 +3,18 @@ Songs not in your library - Amazon search links: Danny Gokey - I Got You https://www.amazon.com/s?k=Danny%20Gokey%20I%20Got%20You&i=digital-music -Danny Gokey - I Got You -https://www.amazon.com/s?k=Danny%20%20Gokey%20I%20%20Got%20%20You&i=digital-music - -Have For You Colton Dixon - The Love I +Have For You Colton Dixon - The Love I https://www.amazon.com/s?k=Have%20%20For%20%20You%20Colton%20%20Dixon%20The%20%20Love%20%20I%20&i=digital-music -Done Tasha Layton - Look What You've +Done Tasha Layton - Look What You've https://www.amazon.com/s?k=Done%20Tasha%20%20Layton%20Look%20%20What%20%20You%27ve%20&i=digital-music Cochren & Co. - Who Can https://www.amazon.com/s?k=Cochren%20%26%20%20Co.%20Who%20%20Can&i=digital-music -Have For You Colton Dixon - The Love I +Have For You Colton Dixon - The Love I https://www.amazon.com/s?k=Have%20%20For%20%20You%20Colton%20%20Dixon%20The%20%20Love%20%20I%20&i=digital-music -Done Tasha Layton - Look What You've +Done Tasha Layton - Look What You've https://www.amazon.com/s?k=Done%20Tasha%20%20Layton%20Look%20%20What%20%20You%27ve%20&i=digital-music diff --git a/main.py b/main.py index 855c47e..bd899fb 100644 --- a/main.py +++ b/main.py @@ -32,6 +32,8 @@ PLAYLIST_NAME = 'Journey FM Recently Played' def scrape_recently_played(): """Scrape recently played songs from multiple stations using Selenium""" + import platform + urls = [ ('https://www.myjourneyfm.com/recently-played/', 'Journey FM'), ('https://spiritfm.com/spiritfm-recently-played/', 'Spirit FM') @@ -47,10 +49,20 @@ def scrape_recently_played(): options.add_argument("--disable-dev-shm-usage") options.add_argument("--disable-gpu") options.add_argument("--remote-debugging-port=9222") - options.add_argument("--user-data-dir=/tmp/chromium") options.add_argument("--no-first-run") options.add_argument("--disable-extensions") - options.binary_location = "/usr/bin/chromium-browser" + + # Set binary location based on OS + if platform.system() == 'Windows': + options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe" + options.add_argument("--user-data-dir=C:\\temp\\chromium") + elif platform.system() == 'Darwin': # macOS + options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + options.add_argument("--user-data-dir=/tmp/chromium") + else: # Linux + options.binary_location = "/usr/bin/chromium-browser" + options.add_argument("--user-data-dir=/tmp/chromium") + service = Service() driver = webdriver.Chrome(service=service, options=options) @@ -76,14 +88,46 @@ def scrape_recently_played(): # Find elements (div, li) that contain time in their text song_elements = soup.find_all(lambda tag: tag.name in ['div', 'li', 'p'] and re.search(r'\d+:\d+ [AP]M', tag.get_text())) for element in song_elements: - spans = element.find_all('span') - if len(spans) >= 3: - title = spans[0].get_text().strip() - artist = spans[1].get_text().strip() - # Ignore time - songs.append({'artist': artist, 'title': title, 'source': source}) + if source == 'Journey FM': + # Journey FM uses for title + strong = element.find('strong') + if strong: + title = strong.get_text().strip() + full_text = element.get_text().strip() + # Remove the title and time + match = re.search(r'(\d+:\d+ [AP]M)', full_text) + if match: + time_part = match.group(1) + before_time = full_text.split(time_part)[0].strip() + artist = before_time.replace(title, '').strip() + else: + artist = full_text.replace(title, '').strip() + artist = artist.strip() + else: + # Fallback + full_text = element.get_text().strip() + match = re.search(r'(\d+:\d+ [AP]M)', full_text) + if match: + play_time = match.group(1) + before = full_text.split(play_time)[0].strip() + if ' by ' in before: + title, artist = before.split(' by ', 1) + title = title.strip() + artist = artist.strip() + elif ' - ' in before: + title, artist = before.split(' - ', 1) + title = title.strip() + artist = artist.strip() + else: + parts = re.findall(r'[A-Z][^A-Z]*', before) + if len(parts) >= 4: + title = ' '.join(parts[:2]) + artist = ' '.join(parts[2:]) + else: + title = ' '.join(parts[:len(parts)//2]) + artist = ' '.join(parts[len(parts)//2:]) else: - # Fallback to text parsing + # Spirit FM uses text with - full_text = element.get_text().strip() match = re.search(r'(\d+:\d+ [AP]M)', full_text) if match: @@ -93,19 +137,20 @@ def scrape_recently_played(): title, artist = before.split(' by ', 1) title = title.strip() artist = artist.strip() + elif ' - ' in before: + title, artist = before.split(' - ', 1) + title = title.strip() + artist = artist.strip() else: - # Split on capital letters parts = re.findall(r'[A-Z][^A-Z]*', before) - if len(parts) == 4: + if len(parts) >= 4: title = ' '.join(parts[:2]) artist = ' '.join(parts[2:]) else: - title = ' '.join(parts[:3]) - artist = ' '.join(parts[3:]) - if title and artist: - songs.append({'artist': artist, 'title': title, 'source': source}) - - # Add to all_songs, avoiding duplicates + title = ' '.join(parts[:len(parts)//2]) + artist = ' '.join(parts[len(parts)//2:]) + if title and artist: + songs.append({'artist': artist, 'title': title, 'source': source}) # Add to all_songs, avoiding duplicates for song in songs: key = (song['title'].lower(), song['artist'].lower()) if key not in seen: diff --git a/playlist_history.db b/playlist_history.db new file mode 100644 index 0000000000000000000000000000000000000000..d45d0574c6d5f3a298a1c25dc9b7a724c3c561f5 GIT binary patch literal 8192 zcmeI1-*1yp6vts}by1t?gYjW6CpF+@j2q$BSxp~S z_02!eKgdgexI(%}wwRcBPD;3(bI+H{=brO$)5F(ok2>(4gr^pTGIy8bdG09y$8mXf zt+8uiJR9T|59}U4|H<;4`1wPD&Ehu&j{VS(01`j~NB{{S0VIF~kN^@u0!RP}{G$ZU z`~1xZTU-3s0=3@xj_XB~groUwt6CT}yxp_9UUK;wo-i24)R;S+W z!GYc@{*K!gJA51Z8{@)d*|uZ99gtx_7rE(RM1tcem3Hbykry0ambeICq)ylHI6j-_ zZr|rN4+=l;{9pq#B!C2v01`j~NB{{S0VMFh5tz{223Oy>$A5n!m*m|YN!pQALz1_Ow`$U3-w&AjQZ4%FJL00u93D}{-id>83 zS|cW%&}Rp9U0YSYl2)#1QcbK? z6s212n>P|1XZ3JdIZUfzUJUVPq@gxKa%MYWV#g1u=lki2*Jp5jg-jHa4cW0Mb)7TT w77pw7