i need to run curl command, multiline like this one:
but cmd run each line separately. so, with first line i get all elements from web page, but idk how run right full commandCode:curl -s "https://link" \ | grep -oP '<img src="\K[^"]*' \ | head -n1
+ Reply to Thread
Results 1 to 11 of 11
-
-
thanks for your reply, but same behavior. also with curl only (not cmd/powershell)
my goal is download the file
Code:https://i1.sndcdn.com/artworks-4KDEzUk5fgjxkLoT-4kINZA-t500x500.jpg
[Attachment 77338 - Click to enlarge]
here the full command
Code:curl -s "https://soundcloud.com/defectedrecords/defected-radio-show-most-rated-special-hosted-by-sam-divine-221223" \ | grep -oP '<img src="\K[^"]*' \ | head -n1
here my log:
Code:D:\curl-8.6.0\bin curl -s "https://soundcloud.com/defectedrecords/defected-radio-show-most-rated-special-hosted-by-sam-divine-221223" \ <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="theme-color" content="#333"> <link rel="dns-prefetch" href="//style.sndcdn.com"> <link rel="dns-prefetch" href="//a-v2.sndcdn.com"> <link rel="dns-prefetch" href="//api-v2.soundcloud.com"> <link rel="dns-prefetch" href="//sb.scorecardresearch.com"> <link rel="dns-prefetch" href="//secure.quantserve.com"> <link rel="dns-prefetch" href="//eventlogger.soundcloud.com"> <link rel="dns-prefetch" href="//api.soundcloud.com"> <link rel="dns-prefetch" href="//ssl.google-analytics.com"> <link rel="dns-prefetch" href="//i1.sndcdn.com"> (cut) ...... ....... D:\curl-8.6.0\bin | grep -oP '<img src="\K[^"]*' \ | not expected D:\curl-8.6.0\bin | head -n1
-
finally i've get right command to rip and print jpg link with:
Code:curl -s "https://soundcloud.com/defectedrecords/defected-radio-show-most-rated-special-hosted-by-sam-divine-221223" | awk -F'"' '/<img src="https:\/\/i1\.sndcdn\.com\/artworks-.*\.jpg/ {print $2; exit}'
Code:https://i1.sndcdn.com/artworks-4KDEzUk5fgjxkLoT-4kINZA-t500x500.jpg
-
edit command from my first post, get jpg link (removed < before 'image', and put command on a single line)
Code:curl -s "https://soundcloud.com/defectedrecords/defected-radio-show-most-rated-special-hosted-by-sam-divine-221223" | grep -oP 'img src="\K[^"]*' | head -n1
-
problem solved (thanks to chatGPT). here 4 alternative ways
this command, trough curl, download jpg file with original filename (put link on command above)
Code:curl -s "https://link" | grep -oP 'img src="\K[^"]*' | tail -n 1 | xargs -n 1 sh -c 'curl -o "$(basename "$0")" "$0"'
Code:#!/bin/bash read -p "Enter the SoundCloud link: " soundcloud_link curl -s "$soundcloud_link" | grep -oP 'img src="\K[^"]*' | tail -n 1 | xargs -n 1 sh -c 'curl -o "$(basename "$0")" "$0"'
Code:import subprocess import os def extract_image_url(soundcloud_link): curl_command = f'curl -s "{soundcloud_link}"' curl_output = subprocess.check_output(curl_command, shell=True, text=True) # Extract the image URL directly in Python for line in curl_output.split('\n'): if '<meta property="og:image" content="' in line: image_url = line.split('<meta property="og:image" content="')[1].split('"')[0] return image_url raise ValueError("Image URL not found") def download_image(image_url): filename = os.path.basename(image_url) subprocess.run(['curl', '-o', filename, image_url]) if __name__ == "__main__": soundcloud_link = input("Enter the SoundCloud link: ") try: image_url = extract_image_url(soundcloud_link) download_image(image_url) print(f"Image downloaded successfully! Saved as: {os.path.basename(image_url)}") except Exception as e: print(f"Error: {e}")
Code:import yt_dlp URL = input('soundcloud link: ') ydl_opts = { 'writethumbnail': True, 'skip_download': True, } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(URL, download=False, process=False) thumbnails = info.get('thumbnails') or [] info['thumbnails'] = [t for t in thumbnails if t.get('height') == 500] ydl.process_ie_result(info)
-
use curl -s -o "defected_radio.jpg" to download the image
curl to scrape the soundcloud URL, grep "<img src=.http" to capture the required line, awk "BEGIN{FS=\"\042\"} {print $2}" to parse the line and get the image name and lastly xargs curl -s -o "defected_radio.jpg" to feed the image name to curl and then download the image to current directory.
here is the complete code
Code:curl -s "https://soundcloud.com/defectedrecords/defected-radio-show-most-rated-special-hosted-by-sam-divine-221223" | grep "<img src=.http" | awk "BEGIN{FS=\"\042\"} {print $2}" | xargs curl -s -o "defected_radio.jpg"
-
thank you jack for your advice, but what difference (advantage) from my curl command above ?
Last edited by whs912km; 1st Mar 2024 at 09:56.
-
what difference (advantage) from my curl command above ?
Advantage ... absolutely none
Difference ... Your code is for linux. The code I provided is for Windows.
I posted because some other person, using windows, may wish to do the the same as you.
I tried to show that piping does not require multiline. Multiline is used when the line of code is very long and you wish to show it confined to a smaller space. -
thanks for your clarification.
however i am win user, i don't use linux ...! and my command above post#6 for curl or also bash file, work great on windows
also my command above (thanks to chatGPT) save file with original filename, without edit manually curl command for -o "defected_radio.jpg"
also bash file ask each time new soundcloud link. this allows to use bash file with different links without edit curl command
Similar Threads
-
Need curl command to extract m3u8 url
By tonygables in forum Video Streaming DownloadingReplies: 2Last Post: 26th Feb 2024, 01:11 -
Need curl command to extract m3u8 from live TV website
By tonygables in forum Video Streaming DownloadingReplies: 5Last Post: 25th Apr 2023, 05:10 -
Curl or Wget command to capture vtt subs?
By daigo99 in forum SubtitleReplies: 3Last Post: 5th Sep 2021, 20:16 -
Divide each line of text into new subtitle line
By martanius in forum SubtitleReplies: 1Last Post: 11th Apr 2021, 16:21 -
Multi-line, heavily stylized subtitles (ASS) possible on Blu-ray?
By Deli295 in forum Authoring (Blu-ray)Replies: 12Last Post: 25th Jan 2021, 15:41