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

" 2 (2013)/1_1 - Tum Hi Ho-vbr-V5.mp3"

" 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

"< 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
# syantax : python3 <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 = ""
mio = requests.get(url)
mio_soup = bs4.BeautifulSoup(mio.text,'html.parser')

#Extracts some informations :

movie_name =".*?\([0-9]+\)",'div.heading')[0].text).group(0)
art_work =' > img["src"]')[0]["src"]
year ='\(([0-9][0-9]+)\)',movie_name).group(1)
link ='*?)/(.*)/Art-350.jpg',art_work).group(1)
artwork_path = movie_name+"/artwork.jpg"

print("\nMovie Name : "+movie_name )
# print("Music Director : "+music_director)["mkdir" ,"-p",movie_name])

#Downloading the artwork
if not os.path.exists(artwork_path):["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 = ""+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):["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]
python3  < link >

Some Code snippet

New Release From Hindi Malayalam and Tamil catagory

import bs4,requests

url = ["", "",""]
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"a"):
             print(j.find("h2").text+"\t" + 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"}):
          url = "" + mio_soup.find_all("a" , {"class" : "next-page"})[0]["href"]
      except IndexError:

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 ../../$i/Movie+Songs/albums/decade/`echo $j | sed -r 's/([0-9]+)s/\1/'` >> list 
        sleep 1s
        echo 1 > count
        cd ..
    cd ..

As all the links has been created we could now download all the movie

for i in "$MOVIE_DIR"/{Hindi,Malayalam,Tamil};do
cd $i
    for j in *; do
    cd $j
    echo  $j
    if  [ ! -e "$i"/robot.txt ]
        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 ../../  >> log 2>&1
            echo $COUNTER > count
        touch robot.txt
        echo "Robot Exsist !"
    cd ..
cd ..

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