Downloading Songs !!
Music India Online Download script
Who likes to download music one by one we are too lazy , we script . This is a script i wrote to download music from MusicIndiaOnline . This site contain a large repositories of Indian Music and the service is free . It plays the music in a custom player . Opening the firefox web developer option and inspecting we could see the mp3 request links . interestingly there is pattern in the link
"http://media-audio.mio.to/various_artists/A/Aashiqui 2 (2013)/1_1 - Tum Hi Ho-vbr-V5.mp3"
" http://media-audio.mio.to/by_artist/A/AR. Rahman/I (2014)/1_1 - Mersalaayitten-vbr-V5.mp3 "
by looking into the source html we could extract all the informations to create the link
"http://media-audio.mio.to/< by_artist or various_artists >/< first letter of album_id >/< album_id >/< disk_number >_< track_number > - < track_name >-vbr-V5.mp3 "
so we scrap the webpage using BeautifulSoup and extract all the details . the source contains the artwork link from which we can get whether it is by_artist
or various_artists
by search with Regular expression
final we create the link and download the file to its respective folder . the mp3 file downloaded does not contain any tag so we add them using a eyed3 which is a tag editor
Download Movie Songs
Download Movie songs into the directory
# Made by : Nemesis
# Discription :This downloads The songs from site named mio.to
# syantax : python3 mio.py <link>
# Requirements : python modules bs4,taglib
# System Package : eyed3 [User for insterting artwork]
import bs4,requests,sys,re,taglib,subprocess,os
#Downloads the webpage and create a Beautifull Soup Object
url=sys.argv[1]
# url = "http://mio.to/album/Aashiqui+2+%282013%29"
mio = requests.get(url)
mio_soup = bs4.BeautifulSoup(mio.text,'html.parser')
#Extracts some informations :
movie_name = re.search(r".*?\([0-9]+\)",mio_soup.select('div.heading')[0].text).group(0)
art_work = mio_soup.select('div.group.info > img["src"]')[0]["src"]
year = re.search(r'\(([0-9][0-9]+)\)',movie_name).group(1)
link = re.search(r'http://media-images.mio.to/(.*?)/(.*)/Art-350.jpg',art_work).group(1)
artwork_path = movie_name+"/artwork.jpg"
print("\nMovie Name : "+movie_name )
# print("Music Director : "+music_director)
subprocess.call(["mkdir" ,"-p",movie_name])
#Downloading the artwork
if not os.path.exists(artwork_path):
subprocess.call(["wget","-c","-q",art_work,"-O",artwork_path])
#Finds all the songs links and downloads the and inserts the tags
for i in mio_soup.find_all("tr" ,{"class" : "song-link"}):
artist = ",".join(re.findall('"(.*?)"',i['track_artist']))
album_name = movie_name
track_number = i["track_number"]
disk_number = i["disc_number"]
track_name = i["track_name"]
path = album_name+"/"+track_name+".mp3"
#Create the download links of the mp3
mp3_link = "http://media-audio.mio.to/"+link+"/"+i["album_id"][0]+"/"+i["album_id"]+"/"+disk_number+"_"+track_number+" - "+track_name+"-vbr-V5.mp3"
print("Downloading ",track_name," ...")
# if not os.path.exists(path):
subprocess.call(["wget","-q","-c",mp3_link,"-O",path])
# Inserting the tag details
command = ["eyeD3","--add-image",artwork_path+":FRONT_COVER",path,"-a",artist,"-A",album_name,"-t",track_name,"-n",track_number,"-Y",year]
subprocess.call(command)
python3 mio.py < link >
Some Code snippet
New Release From Hindi Malayalam and Tamil catagory
import bs4,requests
url = ["http://mio.to/Malayalam/Movie+Songs", "http://mio.to/Hindi/Movie+Songs","http://mio.to/Tamil/Movie+Songs"]
for i in url:
mio = requests.get(i)
mio_soup = bs4.BeautifulSoup(mio.text,"html.parser")
for i in mio_soup.find_all('div', {'id' : '#trending-now'}):
for j in i.select("a"):
print(j.find("h2").text+"\t http://mio.to" + j["href"])
List of All Movies in That catagory
import requests,bs4,sys
url = sys.argv[1]
while True:
mio = requests.get(url)
mio_soup = bs4.BeautifulSoup(mio.text,'html.parser')
for i in mio_soup.find_all("a" , {"class" : "img-cover-175"}):
print("http://mio.to"+i["href"])
try:
url = "http://mio.to" + mio_soup.find_all("a" , {"class" : "next-page"})[0]["href"]
except IndexError:
exit()
The Grand Finale
scraping the webpage and getting all the list of movie songs .
mkdir {Hindi,Malayalam,Tamil} Hindi/{19{3..9}0,20{0,1}0}s Tamil/{19{3..9}0,20{0,1}0}s Malayalam/{19{5..9}0,20{0,1}0}s
for i in {Hindi,Malayalam,Tamil} ; do
cd $i
for j in *; do
cd $j
echo listing $i/$j ...
python3 ../../list.py http://mio.to/$i/Movie+Songs/albums/decade/`echo $j | sed -r 's/([0-9]+)s/\1/'` >> list
sleep 1s
echo 1 > count
cd ..
done
cd ..
done
As all the links has been created we could now download all the movie
MOVIE_DIR=/root/mio
cd $MOVIE_DIR
for i in "$MOVIE_DIR"/{Hindi,Malayalam,Tamil};do
cd $i
for j in *; do
cd $j
echo $j
if [ ! -e "$i"/robot.txt ]
then
echo "Robot Does not exists !"
COUNTER=$(cat count)
while [ $COUNTER -lt `cat list | wc -l` ];do
sed -n $COUNTER,$(($COUNTER+10))p list | parallel -P 2 python3 ../../mio.py >> log 2>&1
COUNTER=$(($COUNTER+10))
echo $COUNTER > count
done
touch robot.txt
else
echo "Robot Exsist !"
fi
cd ..
done
cd ..
done
Setting the MOVIE_DIR
variable to the location to download and adding the script to the cronjob with @reboot
to start the script at boot it sits there downloading whole file . cronjob can be edited using crontab -e