M
M
mystique_man2015-10-28 08:45:26
Programming
mystique_man, 2015-10-28 08:45:26

Script to extract text limited to two characters from a file and paste it into another file. How?

Good day to all.
1. There is an m3u file (playlist), it is often updated, and is available via a direct link in the public domain on the Internet.
It has the following structure:
EXTM3U
#EXTINF:-1, Channel Five
http: //bla.bla.bla.bla:4022 /udp/some ip of the stream:1234 The
part that changes is highlighted in bold.
2. There is another file. TXT, stored locally, or on a public ftp (my personal, preferred option)
Its structure is:
amedia1,Amedia 1 HD,http: //bla.bla.bla.bla:1234 /udp/somestreamip:1234
amedia-hit,Amedia HIT HD, http:// blah.bla.bla.bla:1234 /udp/someipstream:1234
amedia-hd,Amedia Premium HD,http://blah.bla.bla.bla:1234 /udp/somestreamip:1234
animal-hd,Animal Planet HD,http: //bla.bla.bla.bla:1234 /udp/somestreamip:1234
discov_rus-hd,Discovery Channel HD, http:// bla.bla.bla.bla:1234 /udp/someipstream:1234
Task: to automate the replacement of "bla.bla.bla.bla" in the txt file with the value from the m3u file. There is only one value, it is repeated in each line.
Those. briefly: downloaded the file, found the value, opened the file, replaced the value, closed it, uploaded it back.
I am also interested in the possibility of executing this on a schedule and not on a local machine, maybe there are some services ... without buying a vps
ps, the iptv relay server is constantly changing (

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mark Doe, 2015-10-28
@mourr

Well, for example, such a regular expression to pull out the desired stream url
Then replace the streams in the file. Implemented in any programming language
And here is an example , you can put on cron on any free hosting, for example Hostinger

A
Alexey Shumkin, 2015-10-29
@ashumkin

prepare a template (they are easier to work with), let's call it <template_file>

amedia1,Amedia 1 HD,http://@@[email protected]@/udp/некийipпотока:1234
amedia-hit,Amedia HIT HD,http://@@[email protected]@/udp/некийipпотока:1234
amedia-hd,Amedia Premium HD,http://@@[email protected]@/udp/некийipпотока:1234
animal-hd,Animal Planet HD,http://@@[email protected]@/udp/некийipпотока:1234
discov_rus-hd,Discovery Channel HD,http://@@[email protected]@/udp/некийipпотока:1234

Save the m3u file in <file_from_server>
run the script on Bash( sedusually installed)
# get new addr
blah_blah=$(sed -ne '\#http://\(.\+\?\)/udp/.\+#{s//\1/p;q}' <file_from_server>)
# replace @@[email protected]@ to blah-blah
# nota bene double quotes
sed -e "s/@@[email protected]@/$blah_blah/" <template_file>

at the output you get the file you need, by redirecting you save

C
cardinalus, 2015-11-05
@cardinalus

Variant in Python

import urllib2
urlInputFile = 'http://xxxx' # link to m3u file
outputFile = 'result.txt'

response = urllib2.urlopen(urlInputFile)
fileM3U = response.readlines()

streamIP = ''
for line in fileM3U:
    if 'http' in line:
        if not streamIP: streamIP = line.split('/')[2]

with open(outputFile,mode='r') as f:
    lines = f.readlines()

with open(outputFile,mode='w') as f:
    for line in lines:
        f.write(line.replace(line.split('/')[2],streamIP))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question