Skip to content

Instantly share code, notes, and snippets.

@kangfend
Last active August 21, 2017 05:49
Show Gist options
  • Save kangfend/dca9cb6e20250d8ea559d9b75b2534b4 to your computer and use it in GitHub Desktop.
Save kangfend/dca9cb6e20250d8ea559d9b75b2534b4 to your computer and use it in GitHub Desktop.

Revisions

  1. kangfend revised this gist Aug 21, 2017. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions akhyartv_downloader.py
    Original file line number Diff line number Diff line change
    @@ -14,23 +14,23 @@ class Downloader:
    def __init__(self, url):
    self.url = url
    self.files = []
    self.base_url = 'http://stream.asianastream.com/vod/akhyartv'
    self.collect_data()

    def collect_data(self):
    punctuation = "!@#$%^&*()'"
    response = requests.get(self.url)
    filename = re.findall(
    '%s/(.*)/index.m3u8' % self.base_url, response.content)
    filename = re.findall('http://stream.asianastream.com/vod/akhyartv/(.*)/index.m3u8', response.content)
    if filename:
    self.video_filename = filename[0]
    self.video_name, _ = self.video_filename.split('.')
    self.video_name = self.video_name.replace(' ', '_')
    self.temporary_path = '%s/' % self.video_name
    self.video_name = self.video_name.translate(None, punctuation)
    self.temporary_path = '%s/' % self.video_name.translate(None, punctuation)
    if not os.path.isdir(self.temporary_path):
    os.mkdir(self.temporary_path)

    def merge_video(self):
    collections = " ".join(self.files)
    print
    os.system('cat %s > %s.mp4' % (collections, self.video_name))
    os.system('rm -rf %s/' % self.video_name)
    print "Video saved to %s" % '%s.mp4' % self.video_name
    @@ -40,8 +40,7 @@ def run(self):
    while True:
    filename = 'seg-%s-v1-a1.ts' % number
    path = self.temporary_path + filename
    download_url = '%s/%s/%s' % (
    self.base_url, self.video_filename, filename)
    download_url = 'http://stream.asianastream.com/vod/akhyartv/%s/%s' % (self.video_filename, filename)
    response = requests.get(download_url)

    if response.status_code != 200:
    @@ -65,3 +64,4 @@ def run(self):
    downloader.run()
    else:
    parser.print_help()

  2. kangfend renamed this gist Mar 31, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. kangfend revised this gist Dec 7, 2016. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions akyartv_downloader.py
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,13 @@ class Downloader:
    def __init__(self, url):
    self.url = url
    self.files = []
    self.base_url = 'http://stream.asianastream.com/vod/akhyartv'
    self.collect_data()

    def collect_data(self):
    response = requests.get(self.url)
    filename = re.findall(
    'http://stream.asianastream.com/vod/akhyartv/(.*)/index.m3u8',
    response.content
    )
    '%s/(.*)/index.m3u8' % self.base_url, response.content)
    if filename:
    self.video_filename = filename[0]
    self.video_name, _ = self.video_filename.split('.')
    @@ -41,9 +40,9 @@ def run(self):
    while True:
    filename = 'seg-%s-v1-a1.ts' % number
    path = self.temporary_path + filename
    download_url = 'http://stream.asianastream.com/vod/akhyartv/%s/%s'
    response = requests.get(
    download_url % (self.video_filename, filename))
    download_url = '%s/%s/%s' % (
    self.base_url, self.video_filename, filename)
    response = requests.get(download_url)

    if response.status_code != 200:
    self.merge_video()
  4. kangfend revised this gist Dec 7, 2016. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions akyartv_downloader.py
    Original file line number Diff line number Diff line change
    @@ -18,10 +18,14 @@ def __init__(self, url):

    def collect_data(self):
    response = requests.get(self.url)
    filename = re.findall('http://stream.asianastream.com/vod/akhyartv/(.*)/index.m3u8', response.content)
    filename = re.findall(
    'http://stream.asianastream.com/vod/akhyartv/(.*)/index.m3u8',
    response.content
    )
    if filename:
    self.video_filename = filename[0]
    self.video_name, _ = self.video_filename.split('.')
    self.video_name = self.video_name.replace(' ', '_')
    self.temporary_path = '%s/' % self.video_name
    if not os.path.isdir(self.temporary_path):
    os.mkdir(self.temporary_path)
    @@ -37,8 +41,9 @@ def run(self):
    while True:
    filename = 'seg-%s-v1-a1.ts' % number
    path = self.temporary_path + filename
    download_url = 'http://stream.asianastream.com/vod/akhyartv/%s/%s' % (self.video_filename, filename)
    response = requests.get(download_url)
    download_url = 'http://stream.asianastream.com/vod/akhyartv/%s/%s'
    response = requests.get(
    download_url % (self.video_filename, filename))

    if response.status_code != 200:
    self.merge_video()
  5. kangfend created this gist Dec 6, 2016.
    63 changes: 63 additions & 0 deletions akyartv_downloader.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    # Copyright © 2016 Sutrisno Efendi <[email protected]>
    # Auto download video from akhyar.tv

    import argparse
    import os
    import re
    import requests


    class Downloader:
    def __init__(self, url):
    self.url = url
    self.files = []
    self.collect_data()

    def collect_data(self):
    response = requests.get(self.url)
    filename = re.findall('http://stream.asianastream.com/vod/akhyartv/(.*)/index.m3u8', response.content)
    if filename:
    self.video_filename = filename[0]
    self.video_name, _ = self.video_filename.split('.')
    self.temporary_path = '%s/' % self.video_name
    if not os.path.isdir(self.temporary_path):
    os.mkdir(self.temporary_path)

    def merge_video(self):
    collections = " ".join(self.files)
    os.system('cat %s > %s.mp4' % (collections, self.video_name))
    os.system('rm -rf %s/' % self.video_name)
    print "Video saved to %s" % '%s.mp4' % self.video_name

    def run(self):
    number = 1
    while True:
    filename = 'seg-%s-v1-a1.ts' % number
    path = self.temporary_path + filename
    download_url = 'http://stream.asianastream.com/vod/akhyartv/%s/%s' % (self.video_filename, filename)
    response = requests.get(download_url)

    if response.status_code != 200:
    self.merge_video()
    break

    with open(path, 'wb') as ts_file:
    print download_url
    ts_file.write(response.content)

    self.files.append(path)
    number += 1


    if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='AkyarTV Downloader')
    parser.add_argument('url', nargs=1)
    args = parser.parse_args()
    if args.url:
    downloader = Downloader(args.url[0])
    downloader.run()
    else:
    parser.print_help()